Skip to content

Instantly share code, notes, and snippets.

@checktravis
Last active February 25, 2018 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save checktravis/a0d057d5403df6a706ef283561be30a0 to your computer and use it in GitHub Desktop.
Save checktravis/a0d057d5403df6a706ef283561be30a0 to your computer and use it in GitHub Desktop.
#!/bin/bash
. /usr/local/bin/myFunctions.sh
SRCDIR="/downloads/completed"
DESTDIR="/backup"
###############################################################################
# goto in bash https://bobcopeland.com/blog/2012/10/goto-in-bash/
function jumpto
{
label=$1
cmd=$(sed -n "/$label:/{:a;n;p;ba};" $0 | grep -v ':$')
eval "$cmd"
exit
}
start=${1:-"start"}
clear
jumpto $start
start:
echo "### SYNC *FROM* ###############################################################"
selectSub $SRCDIR
if [ "$TRV_SELECTED" == "...other" ]
then
echo "selected other"
read -e -p "Full path: " SRCPATH
# echo "new source is $SRCPATH"
else
echo " ... you selected $TRV_SELECTED"
SRCPATH="$SRCDIR/$TRV_SELECTED/"
fi
echo "checking..."
if checkEmpty $SRCPATH
then
clear
echo "...dir is empty, pick again"
jumpto $start
else
echo "...dir not empty, ready for destination"
echo "### SYNC *TO* #################################################################"
selectSub $DESTDIR
if [ "$TRV_SELECTED" == "...other" ]
then
echo "selected other"
read -e -p "Full path: " DESTPATH
else
clear
echo " ... you selected $TRV_SELECTED"
DESTPATH="$DESTDIR/$TRV_SELECTED/"
fi
clear
echo "Copy to $DESTPATH"
echo
echo
echo "here is the plan..."
echo
echo "rsync -r -vh --append-verify --no-compress --info=progress2 --out-format='[%t] [%i] (Last Modified: %M) (bytes: %-10l) %-100n' $SRCPATH* $DESTPATH"
echo
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
# do dangerous stuff
echo "confirmed"
rsync -r -vh --append-verify --no-compress --info=progress2 --out-format='[%t] [%i] (Last Modified: %M) (bytes: %-10l) %-100n' $SRCPATH* $DESTPATH
else
jumpto $start
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment