Add MSYNK_CONFIG_HOME, show delete list again

This commit is contained in:
matthias@arch 2023-06-05 17:55:59 +02:00
parent 19c19f1d52
commit d9cf0d7918

View File

@ -9,15 +9,19 @@
# SETTINGS # SETTINGS
# The directory that is searched for config files, use ~/.config if $XDG_CONFIG_HOME is not defined # 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=~/.config/msynk
CONFIG_DIR=$XDG_CONFIG_HOME/msynk/ [[ -n $XDG_CONFIG_HOME ]] && 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 [[ -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' # Path must contain 'msynk'
TMP_DIR=/tmp/msynk/ TMP_DIR=/tmp/msynk/
# When using --delete, this file is used to determine the files that will be deleted # When using --delete, this file is used to determine the files that will be deleted
TMP_FILE=/tmp/msynk_file TMP_FILE=/tmp/msynk_file
# Path to the mkrypt script # Path to the mkrypt script
mkrypt=/usr/bin/mkrypt mkrypt=/usr/bin/mkrypt
# Additional flags for mkrypt # Additional flags for mkrypt
mkrypt_flags=() mkrypt_flags=()
@ -35,12 +39,13 @@ rsync_flags=(-ruh)
shopt -s dotglob shopt -s dotglob
# UTILITY # UTILITY
FMT_MESSAGE="\e[1;34m%s\e[0m %s\n" NAME="\e[1;34mmsynk"
FMT_ERROR="\e[1;31mmsync ERROR: \e[0m%s\n" 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 # 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_CONFIG="\e[34m%s\e:\t\e[1;33m%s\e[0m\n"
FMT_CMD="\e[1;33mRunning: \e[0m%s\n"
# FUNCTIONS # FUNCTIONS
# silence commands # silence commands
@ -84,18 +89,27 @@ sync_sender_to_receiver()
# print files that will be deleted and ask if continue # print files that will be deleted and ask if continue
# grep deleting $TMP_FILE | sed "s(deleting (${receiver}/(" | less # grep deleting $TMP_FILE | sed "s(deleting (${receiver}/(" | less
less $TMP_FILE less $TMP_FILE
DONE=0
while [[ $DONE == 0 ]]; do
printf "$FMT_MESSAGE" "The listed files will be deleted from $receiver." printf "$FMT_MESSAGE" "The listed files will be deleted from $receiver."
printf "Proceed?\e[34m (y/n)\e[0m: " 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 read answer
case $answer in case $answer in
y|Y) y|Y)
# printf "$FMT_MESSAGE" "Backing up to $receiver..." DONE=1
;; ;;
s|S)
less $TMP_FILE
;;
# l|L)
# less $TMP_FILE
# ;;
*) *)
printf "$FMT_MESSAGE" "Cancelled." printf "$FMT_MESSAGE" "Cancelled."
exit 0 ;; exit 0 ;;
esac esac
done
fi fi
# actual syncing # actual syncing
@ -147,12 +161,12 @@ sync_sender_to_receiver()
# put todays date in the config # put todays date in the config
if [[ -f $CONFIG_DIR/$config ]]; then if [[ -f $CONFIG_DIR/$config ]]; then
if grep -xq "date=.*" $CONFIG_DIR$config; then if grep -xq "date=.*" $CONFIG_DIR/$config; then
[[ $v -ge 2 ]] && printf "$FMT_MESSAGE" "Updating" "date in $CONFIG_DIR$config." [[ $v -ge 2 ]] && printf "$FMT_MESSAGE" "Updating" "date in $CONFIG_DIR/$config."
sed "s/date=.*/date=\"$(date --iso=sec)\"/" $CONFIG_DIR$config -i sed "s/date=.*/date=\"$(date --iso=sec)\"/" $CONFIG_DIR/$config -i
else else
[[ $v -ge 2 ]] && printf "$FMT_MESSAGE" "Writing" "current date to $CONFIG_DIR$config." [[ $v -ge 2 ]] && printf "$FMT_MESSAGE" "Writing" "current date to $CONFIG_DIR/$config."
echo "date=\"$(date --iso=sec)\"" >> $CONFIG_DIR$config echo "date=\"$(date --iso=sec)\"" >> $CONFIG_DIR/$config
fi fi
fi fi
@ -214,9 +228,9 @@ show_settings()
show_config() show_config()
{ {
[[ ! -f $CONFIG_DIR$config ]] && { printf "$FMT_ERROR" "Invalid path: $CONFIG_DIR$config"; exit 1; } [[ ! -f $CONFIG_DIR/$config ]] && { printf "$FMT_ERROR" "Invalid path: $CONFIG_DIR/$config"; exit 1; }
source $CONFIG_DIR$config source $CONFIG_DIR/$config
printf "\e[1m$CONFIG_DIR$config:\e[0m\n" printf "\e[1m$CONFIG_DIR/$config:\e[0m\n"
printf "$FMT_CONFIG" "\$sender " "$sender" printf "$FMT_CONFIG" "\$sender " "$sender"
printf "$FMT_CONFIG" "\$receiver " "$receiver" printf "$FMT_CONFIG" "\$receiver " "$receiver"
printf "$FMT_CONFIG" "\$paths " "${paths[*]}" printf "$FMT_CONFIG" "\$paths " "${paths[*]}"
@ -337,11 +351,11 @@ fi
# if using a config # if using a config
if [[ -n $config ]]; then 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 if [[ $use_encryption = 1 ]]; then
[[ -z $reverse ]] && encrypt=1 || decrypt=1 [[ -z $reverse ]] && encrypt=1 || decrypt=1
fi 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 fi
# overwrite stuff from the config if anything else was given / set variables of no config was given # overwrite stuff from the config if anything else was given / set variables of no config was given