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.
This commit is contained in:
Peter Green 2023-01-22 20:39:56 +00:00
parent b927e8e6ba
commit 7a0b79fb59
3 changed files with 27 additions and 13 deletions

View File

@ -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

23
main.sh
View File

@ -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...

View File

@ -30,4 +30,8 @@ rm ~/.local/share/applications/"$project_name.desktop"
cd ~/ || exit
# Remove root dir...
rm -rf ~/bin/$project_name
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