diff --git a/lib/sapphrc/sapphrc-functions b/lib/sapphrc/sapphrc-functions index 44d821b..8ecd2cf 100644 --- a/lib/sapphrc/sapphrc-functions +++ b/lib/sapphrc/sapphrc-functions @@ -96,3 +96,7 @@ inex_rm(){ sed -i "${rmlines}" "${sapphrc_config}/backups/${profile_name}/${inex}" echo "Removed ${#choices[@]} paths from ${profile_name} ${inex} list" } + +validate_backupdir(){ + [ -d "$HOME/.config/sapphrc/backups/.git" ] || echo "git repo not initialized! Something's gone wrong" && exit 1 +} diff --git a/usr/bin/sapphrc b/usr/bin/sapphrc index e908887..386972e 100755 --- a/usr/bin/sapphrc +++ b/usr/bin/sapphrc @@ -19,6 +19,14 @@ restore() { sapphrc_restore $@ } +updown() { + sapphrc_updown $@ +} + +push() { + sapphrc_push $@ +} + usage() { echo "Sapphic Package Manager v${VERSION}" cat ./usr/share/doc/sapphrc/sapphrc @@ -29,7 +37,7 @@ usage() { } case $COMMAND in - setup|profile|backup|restore ) + setup|profile|backup|restore|updown|push ) shift 1;;& setup ) setup $@;; @@ -39,6 +47,10 @@ case $COMMAND in backup $@;; restore ) restore $@;; + updown ) + updown $@;; + push ) + push $@;; *|usage ) usage;; esac diff --git a/usr/bin/sapphrc_backup b/usr/bin/sapphrc_backup index 328ff73..581f3ef 100755 --- a/usr/bin/sapphrc_backup +++ b/usr/bin/sapphrc_backup @@ -1,5 +1,9 @@ #!/bin/bash +source ./lib/sapphrc/sapphrc-functions +source ./lib/sapphrc/sapphrc-font +validate_backupdir + sapphrc_config="$HOME/.config/sapphrc" cat "${sapphrc_config}/active_profiles" | while read profile_name diff --git a/usr/bin/sapphrc_exclude b/usr/bin/sapphrc_exclude index 59e6ce2..24f655d 100755 --- a/usr/bin/sapphrc_exclude +++ b/usr/bin/sapphrc_exclude @@ -4,6 +4,7 @@ COMMAND=$1 source ./lib/sapphrc/sapphrc-functions source ./lib/sapphrc/sapphrc-font +validate_backupdir inex="exclude" diff --git a/usr/bin/sapphrc_include b/usr/bin/sapphrc_include index 81d4cac..8e4221d 100755 --- a/usr/bin/sapphrc_include +++ b/usr/bin/sapphrc_include @@ -4,6 +4,7 @@ COMMAND=$1 source ./lib/sapphrc/sapphrc-functions source ./lib/sapphrc/sapphrc-font +validate_backupdir inex="include" diff --git a/usr/bin/sapphrc_profile b/usr/bin/sapphrc_profile index ea188c1..07e5dc4 100755 --- a/usr/bin/sapphrc_profile +++ b/usr/bin/sapphrc_profile @@ -2,6 +2,7 @@ source ./lib/sapphrc/sapphrc-functions source ./lib/sapphrc/sapphrc-font +validate_backupdir COMMAND="${1}" diff --git a/usr/bin/sapphrc_push b/usr/bin/sapphrc_push index 397a247..6cf9c44 100755 --- a/usr/bin/sapphrc_push +++ b/usr/bin/sapphrc_push @@ -1,5 +1,9 @@ #!/bin/bash +source ./lib/sapphrc/sapphrc-functions +source ./lib/sapphrc/sapphrc-font +validate_backupdir + cd "$HOME/.config/sapphrc/backups" git add .; git add -u; diff --git a/usr/bin/sapphrc_restore b/usr/bin/sapphrc_restore index ec6fdd1..5a909b4 100755 --- a/usr/bin/sapphrc_restore +++ b/usr/bin/sapphrc_restore @@ -1,5 +1,9 @@ #!/bin/bash +source ./lib/sapphrc/sapphrc-functions +source ./lib/sapphrc/sapphrc-font +validate_backupdir + cd "$HOME/.config/sapphrc/backups" git pull --no-edit diff --git a/usr/bin/sapphrc_setup b/usr/bin/sapphrc_setup index 8013561..67400cc 100755 --- a/usr/bin/sapphrc_setup +++ b/usr/bin/sapphrc_setup @@ -1,8 +1,7 @@ #!/bin/bash - sapphrc_config="$HOME/.config/sapphrc" -if [ -f "${aspphic_config}/.init_complete"];then +if [ -f "${aspphic_config}/.init_complete" ];then echo "already setup" exit 0 fi @@ -11,7 +10,7 @@ mkdir -p "${sapphrc_config}" mkdir -p "${HOME}/.sapphrc" while true;do - read -p "use an existing git repo? (y/n)" gitrepo_exists + read -p "pull from an existing backup repo? (y/n) " gitrepo_exists case $gitrepo_exists in [Yy] ) read -p "Enter YOUR git repo url: " git_url @@ -36,7 +35,8 @@ while true;do mkdir -p "${sapphrc_config}/backups" cd "${sapphrc_config}/backups" git init - git add "${sapphrc_config}/backups/." + touch ./active_profiles + git add . git commit -m "first commit" git branch -M main read -p "Enter YOUR git repo url: " git_url @@ -57,8 +57,10 @@ if [[ "${#sapphrc_bashrc}" -eq 0 ]];then echo "done" >> $HOME/.bashrc fi -mkdir -p $HOME/.cache/sapphrc/ -crontab -l > $HOME/.cache/sapphrc/crontab -echo "*/15 * * * * sapphrc_updown" >> $HOME/.cache/sapphrc/crontab -crontab $HOME/.cache/sapphrc/crontab -rm $HOME/.cache/sapphrc/crontab +if [ ! "$(crontab -l | grep -i 'sapphrc_updown')" ];then + mkdir -p $HOME/.cache/sapphrc/ + crontab -l > $HOME/.cache/sapphrc/crontab + echo "*/15 * * * * sapphrc_updown" >> $HOME/.cache/sapphrc/crontab + crontab $HOME/.cache/sapphrc/crontab + rm $HOME/.cache/sapphrc/crontab +fi diff --git a/usr/bin/sapphrc_updown b/usr/bin/sapphrc_updown index 8e26252..7cdaf19 100755 --- a/usr/bin/sapphrc_updown +++ b/usr/bin/sapphrc_updown @@ -1,5 +1,9 @@ #!/bin/bash +source ./lib/sapphrc/sapphrc-functions +source ./lib/sapphrc/sapphrc-font +validate_backupdir + cd "$HOME/.config/sapphrc/backups" sapphrc_backup gs="$(git status | grep -i 'modified')"