From d9cf0d7918f51b26a4c96e56d86d4b33278d1c83 Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Mon, 5 Jun 2023 17:55:59 +0200 Subject: [PATCH] Add MSYNK_CONFIG_HOME, show delete list again --- msynk.sh | 72 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/msynk.sh b/msynk.sh index 619d1dd..154e066 100755 --- a/msynk.sh +++ b/msynk.sh @@ -9,15 +9,19 @@ # SETTINGS # The directory that is searched for config files, use ~/.config if $XDG_CONFIG_HOME is not defined -[[ -z $XDG_CONFIG_HOME ]] && XDG_CONFIG_HOME=~/.config -CONFIG_DIR=$XDG_CONFIG_HOME/msynk/ -# When using encrypt/decrypt, the source is en/decrypted to TMP_DIR and then rsynced to receiver from there +CONFIG_DIR=~/.config/msynk +[[ -n $XDG_CONFIG_HOME ]] && CONFIG_DIR=$XDG_CONFIG_HOME/msynk +[[ -n $MSYNK_CONFIG_HOME ]] && CONFIG_DIR=$MSYNK_CONFIG_HOME + +# YOU CAN OVERRIDE THESE IN THE CONFIG FILES +# When using encrypt/decrypt, the source is en/decrypted to TMP_DIR and then rsynced to receiver from there Path must contain 'msynk' TMP_DIR=/tmp/msynk/ When using --delete, this file is used to determine the files that will be deleted TMP_FILE=/tmp/msynk_file Path to the mkrypt script mkrypt=/usr/bin/mkrypt # Path must contain 'msynk' TMP_DIR=/tmp/msynk/ # When using --delete, this file is used to determine the files that will be deleted TMP_FILE=/tmp/msynk_file # Path to the mkrypt script mkrypt=/usr/bin/mkrypt + # Additional flags for mkrypt mkrypt_flags=() @@ -35,12 +39,13 @@ rsync_flags=(-ruh) shopt -s dotglob # UTILITY -FMT_MESSAGE="\e[1;34m%s\e[0m %s\n" -FMT_ERROR="\e[1;31mmsync ERROR: \e[0m%s\n" +NAME="\e[1;34mmsynk" +FMT_MESSAGE="$NAME: \e[0;34m%s\e[0m %s\n" +FMT_ERROR="\e[1;31m$NAME: \e[1;31mERROR: \e[0m%s\n" # exit 1: error, exit 2: rsync exited non 0, exit 3: mkrypt exited non 0 -FMT_SYNC="\e[1;32mSyncing: \e[0m%s\n" +FMT_SYNC="$NAME: \e[1;32mSyncing: \e[0m%s\n" +FMT_CMD="$NAME: \e[1;33mRunning: \e[0m%s\n" FMT_CONFIG="\e[34m%s\e:\t\e[1;33m%s\e[0m\n" -FMT_CMD="\e[1;33mRunning: \e[0m%s\n" # FUNCTIONS # silence commands @@ -84,18 +89,27 @@ sync_sender_to_receiver() # print files that will be deleted and ask if continue # grep deleting $TMP_FILE | sed "s(deleting (${receiver}/(" | less less $TMP_FILE - - printf "$FMT_MESSAGE" "The listed files will be deleted from $receiver." - printf "Proceed?\e[34m (y/n)\e[0m: " - read answer - case $answer in - y|Y) - # printf "$FMT_MESSAGE" "Backing up to $receiver..." - ;; - *) - printf "$FMT_MESSAGE" "Cancelled." - exit 0 ;; - esac + DONE=0 + while [[ $DONE == 0 ]]; do + printf "$FMT_MESSAGE" "The listed files will be deleted from $receiver." + printf "Proceed?\e[34m ([y]es, [s]how again, [*] no)\e[0m: " + # printf "Proceed?\e[34m ([y]es, [s]how again, [l]ist all files, [*] no)\e[0m: " + read answer + case $answer in + y|Y) + DONE=1 + ;; + s|S) + less $TMP_FILE + ;; + # l|L) + # less $TMP_FILE + # ;; + *) + printf "$FMT_MESSAGE" "Cancelled." + exit 0 ;; + esac + done fi # actual syncing @@ -147,12 +161,12 @@ sync_sender_to_receiver() # put todays date in the config if [[ -f $CONFIG_DIR/$config ]]; then - if grep -xq "date=.*" $CONFIG_DIR$config; then - [[ $v -ge 2 ]] && printf "$FMT_MESSAGE" "Updating" "date in $CONFIG_DIR$config." - sed "s/date=.*/date=\"$(date --iso=sec)\"/" $CONFIG_DIR$config -i + if grep -xq "date=.*" $CONFIG_DIR/$config; then + [[ $v -ge 2 ]] && printf "$FMT_MESSAGE" "Updating" "date in $CONFIG_DIR/$config." + sed "s/date=.*/date=\"$(date --iso=sec)\"/" $CONFIG_DIR/$config -i else - [[ $v -ge 2 ]] && printf "$FMT_MESSAGE" "Writing" "current date to $CONFIG_DIR$config." - echo "date=\"$(date --iso=sec)\"" >> $CONFIG_DIR$config + [[ $v -ge 2 ]] && printf "$FMT_MESSAGE" "Writing" "current date to $CONFIG_DIR/$config." + echo "date=\"$(date --iso=sec)\"" >> $CONFIG_DIR/$config fi fi @@ -214,9 +228,9 @@ show_settings() show_config() { - [[ ! -f $CONFIG_DIR$config ]] && { printf "$FMT_ERROR" "Invalid path: $CONFIG_DIR$config"; exit 1; } - source $CONFIG_DIR$config - printf "\e[1m$CONFIG_DIR$config:\e[0m\n" + [[ ! -f $CONFIG_DIR/$config ]] && { printf "$FMT_ERROR" "Invalid path: $CONFIG_DIR/$config"; exit 1; } + source $CONFIG_DIR/$config + printf "\e[1m$CONFIG_DIR/$config:\e[0m\n" printf "$FMT_CONFIG" "\$sender " "$sender" printf "$FMT_CONFIG" "\$receiver " "$receiver" printf "$FMT_CONFIG" "\$paths " "${paths[*]}" @@ -337,11 +351,11 @@ fi # if using a config if [[ -n $config ]]; then - source $CONFIG_DIR$config || { printf "$FMT_ERROR" "Error running the config file: $CONFIG_DIR$config"; exit 1; } + source $CONFIG_DIR/$config || { printf "$FMT_ERROR" "Error running the config file: $CONFIG_DIR/$config"; exit 1; } if [[ $use_encryption = 1 ]]; then [[ -z $reverse ]] && encrypt=1 || decrypt=1 fi - [[ $v -ge 3 ]] && printf "$FMT_MESSAGE" "Loaded config:" "$CONFIG_DIR$config: date:$date sender:$sender receiver:$receiver use_encryption:$use_encryption encrypt:$encrypt decrypt:$decrypt paths:${paths[*]}" + [[ $v -ge 3 ]] && printf "$FMT_MESSAGE" "Loaded config:" "$CONFIG_DIR/$config: date:$date sender:$sender receiver:$receiver use_encryption:$use_encryption encrypt:$encrypt decrypt:$decrypt paths:${paths[*]}" fi # overwrite stuff from the config if anything else was given / set variables of no config was given