save backups to folder

This commit is contained in:
overdodactyl 2018-04-20 14:38:33 -06:00
parent 512d62d70c
commit f7c727112d

View file

@ -19,14 +19,18 @@ if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi
## change directory to the Firefox profile directory ## change directory to the Firefox profile directory
cd "$(dirname "${sfp}")" cd "$(dirname "${sfp}")"
## create backup folder if it doesn't exist
mkdir -p userjs_backups;
## Check if there's a newer version of the updater script available ## Check if there's a newer version of the updater script available
online_version="$(curl -s ${updater} | sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p')" online_version="$(curl -s ${updater} | sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p')"
path_to_script="$(dirname "${sfp}")/updater.sh" path_to_script="$(dirname "${sfp}")/updater.sh"
current_version="$(sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p' "$path_to_script")" current_version="$(sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p' "$path_to_script")"
if (( $(echo "$online_version > $current_version" | bc -l) )); then if (( $(echo "$online_version > $current_version" | bc -l) )); then
echo -e "There is a new updater script available online. It will replace this one and be executed.\n" echo -e "There is a new updater script available online. This updater will be backed up and the latest will be executed.\n"
mv updater.sh old_updater.sh bakfile="updater.sh.backup.$(date +"%Y-%m-%d_%H%M")"
mv updater.sh "userjs_backups/${bakfile}"
curl -O ${updater} && echo -e "\nThe latest updater script has been downloaded\n" curl -O ${updater} && echo -e "\nThe latest updater script has been downloaded\n"
# make new file executable # make new file executable
chmod +x updater.sh chmod +x updater.sh
@ -60,7 +64,7 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
if [ -e user.js ]; then if [ -e user.js ]; then
# backup current user.js # backup current user.js
bakfile="user.js.backup.$(date +"%Y-%m-%d_%H%M")" bakfile="user.js.backup.$(date +"%Y-%m-%d_%H%M")"
mv user.js "${bakfile}" && echo "Your previous user.js file was backed up: ${bakfile}" mv user.js "userjs_backups/${bakfile}" && echo "Your previous user.js file was backed up: userjs_backups/${bakfile}"
fi fi
# download latest ghacks user.js # download latest ghacks user.js