From 7a0b79fb597b9f4d16e72da7ff0bef98c8932cc8 Mon Sep 17 00:00:00 2001 From: Greenpete Date: Sun, 22 Jan 2023 20:39:56 +0000 Subject: [PATCH] Changed the logic to check for the pendrive itself and then the project directory on that drive and creating it if not found. Bumped version. --- install.sh | 11 ++++++++--- main.sh | 23 ++++++++++++++--------- uninstall.sh | 6 +++++- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index db424a6..ac2e52a 100644 --- a/install.sh +++ b/install.sh @@ -1,4 +1,5 @@ #!/bin/bash + # Figure out where the root folder of this script is on the users computer... current_dir=$(pwd) @@ -12,12 +13,15 @@ while [ -d ~/bin/"$project_name" ]; done # Get paths for rsync... -echo "What is the full path for your pendrive (including any subdirectories you want to use. Trailing slashes will be added automatically)..." +echo "What is the full path for your pendrive..." read -r pen echo "And what is the full path to your local directory we will syncing with?..." read -r local +# Define the variable 'remote'... +remote=/$pen/$project_name + # Check for the 'bin' dir in the users 'Home' directory and create it if not present... if [ -d "$HOME"/bin ]; then echo "$HOME/bin exists, nothing to do..." @@ -28,11 +32,12 @@ fi cp -r "$current_dir" "$HOME"/bin # Rename the project directory... -mv "$HOME"/bin/Pendrive "$HOME"/bin/"$project_name" +mv "$HOME"/bin/USB_pendrive_backup "$HOME"/bin/"$project_name" # Set new paths in main.sh... -sed -i "s|/pendrive/path/|${pen}/|" "$HOME"/bin/"$project_name"/main.sh +sed -i "s|/pendrive/path/|${pen}|" "$HOME"/bin/"$project_name"/main.sh sed -i "s|/local/dir/path/|${local}/|" "$HOME"/bin/"$project_name"/main.sh +sed -i "s|/full_path_to_project_dir|${remote}|" "$HOME"/bin/"$project_name"/main.sh # Edit menu entry... sed -i "s/name/${project_name}/" "$HOME"/bin/"$project_name"/menu.desktop diff --git a/main.sh b/main.sh index cdd81d4..8bd97bc 100644 --- a/main.sh +++ b/main.sh @@ -4,10 +4,10 @@ # # # Script for backing up projects via pendrive # # By Peter Green # -# Version 0.1 # -# Date of first version; 03-09-2022 # -# Date of last update; 2022-05-08 # -# Moved to my own Gitea instance 27-12-2022 # +# Version 0.2 # +# Date of first version; 2022-09-03 # +# Date of last update; 2023-01-22 # +# Moved to my own Gitea instance 2022-12-27 # # # ############################################### @@ -15,6 +15,7 @@ # Set backup dir paths... pen=/pendrive/path/ local=/local/dir/path/ +remote=/full_path_to_project_dir # Full path to project dir on pendrive. # Announce the name of the script... echo " @@ -29,14 +30,18 @@ if [ -d $pen ]; Press 'Enter' to close this window..." && read -r && exit fi +# Check to see if the dest dir on pendrive is present... +if [ -d remote ]; + then echo "Directory on pendrive found, proceeding..." + else echo "Directory on pendrive not found, creating... " && mkdir $remote +fi + # Give the keyboard monkey the heads up... echo " ::IMPORTANT NOTE:: - This script used to back-up 'incrementally' so data would have accumulated. - - So it's not 'so' important now to get your transfer direction right!!!" + This script backs up 'incrementally' so data will accumulate." # Ask if we should send to or fetch from the pendrive... echo " @@ -58,8 +63,8 @@ done # Run the backup... if [ "$direction" = t ]; - then rsync -atv --progress $local $pen - else rsync -atv --progress $pen $local + then rsync -atv --progress $local $remote + else rsync -atv --progress $remote/ $local fi # Let the mouse molester know we are finished and get some engagement from them... diff --git a/uninstall.sh b/uninstall.sh index 104df85..e07a279 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -30,4 +30,8 @@ rm ~/.local/share/applications/"$project_name.desktop" cd ~/ || exit # Remove root dir... -rm -rf ~/bin/$project_name \ No newline at end of file +rm -rf ~/bin/$project_name + +echo "This instance of Pendrive Backup $project_name has been removed" +echo "Please press 'Enter to close this window..." +read -r \ No newline at end of file