1
0
Fork 0
mirror of https://github.com/arkenfox/user.js.git synced 2025-05-16 05:37:11 +02:00

support for different named file

This commit is contained in:
overdodactyl 2018-04-22 20:11:42 -06:00
parent 88a87ff253
commit 344704d45f

View file

@ -1,12 +1,12 @@
#!/usr/bin/env bash #!/bin/bash
### ghacks-user.js updater for Mac/Linux ### ghacks-user.js updater for Mac/Linux
## author: @overdodactyl ## author: @overdodactyl
## version: 1.3 ## version: 1.2
ghacksjs="https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js" ghacksjs="https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js"
updater="https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/updater.sh"
update_pref=${1:--ask} echo -e "\nThis script should be run from your Firefox profile directory.\n"
currdir=$(pwd) currdir=$(pwd)
@ -19,62 +19,27 @@ 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}")"
## Used to check if a new version of updater.sh is available echo -e "Updating the user.js for Firefox profile:\n$(pwd)\n"
update_available="no"
check_for_update () {
online_version="$(curl -s ${updater} | sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p')"
path_to_script="$(dirname "${sfp}")/updater.sh"
current_version="$(sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p' "$path_to_script")"
if (( $(echo "$online_version > $current_version" | bc -l) )); then
update_available="yes"
fi
}
## Used to backup the current script, and download and execute the latest version of updater.sh if [ -e user.js ]; then
update_script () {
echo -e "This script will be backed up and the latest version of updater.sh will be executed.\n"
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"
# make new file executable
chmod +x updater.sh
# execute new updater script
./updater.sh -donotupdate
# exit script
exit 1
}
main () {
## create backup folder if it doesn't exist
mkdir -p userjs_backups;
echo -e "\nThis script should be run from your Firefox profile directory.\n"
echo -e "Updating the user.js for Firefox profile:\n$(pwd)\n"
if [ -e user.js ]; then
echo "Your current user.js file for this profile will be backed up and the latest ghacks version from github will take its place." echo "Your current user.js file for this profile will be backed up and the latest ghacks version from github will take its place."
echo -e "\nIf currently using the ghacks user.js, please compare versions:" echo -e "\nIf currently using the ghacks user.js, please compare versions:"
echo " Available online: $(curl -s ${ghacksjs} | sed -n '4p')" echo " Available online: $(curl -s ${ghacksjs} | sed -n '4p')"
echo " Currently using: $(sed -n '4p' user.js)" echo " Currently using: $(sed -n '4p' user.js)"
else else
echo "A user.js file does not exist in this profile. If you continue, the latest ghacks version from github will be downloaded." echo "A user.js file does not exist in this profile. If you continue, the latest ghacks version from github will be downloaded."
fi fi
echo -e "\nIf a user-overrides.js file exists in this profile, it will be appended to the user.js.\n" echo -e "\nIf a user-overrides.js file exists in this profile, it will be appended to the user.js.\n"
read -p "Continue Y/N? " -n 1 -r read -p "Continue Y/N? " -n 1 -r
echo -e "\n\n" echo -e "\n\n"
if [[ $REPLY =~ ^[Yy]$ ]]; then 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 "userjs_backups/${bakfile}" && echo "Your previous user.js file was backed up: userjs_backups/${bakfile}" mv user.js "${bakfile}" && echo "Your previous user.js file was backed up: ${bakfile}"
fi fi
# download latest ghacks user.js # download latest ghacks user.js
@ -85,34 +50,9 @@ main () {
echo "user-overrides.js file found" echo "user-overrides.js file found"
cat user-overrides.js >> user.js && echo "user-overrides.js has been appended to user.js" cat user-overrides.js >> user.js && echo "user-overrides.js has been appended to user.js"
fi fi
else
echo "Process aborted"
fi
## change directory back to the original working directory
cd "${currdir}"
}
if [ "$(echo $update_pref | tr '[A-Z]' '[a-z]')" = "-donotupdate" ]; then
main
else else
check_for_update echo "Process aborted"
if [ $update_available = "no" ]; then
main
else
## there is an update available
if [ "$(echo $update_pref | tr '[A-Z]' '[a-z]')" = "-update" ]; then
## update without asking
update_script
else
read -p "There is a newer version of updater.sh available. Download and execute? Y/N? " -n 1 -r
echo -e "\n\n"
if [[ $REPLY =~ ^[Yy]$ ]]; then
update_script
else
main
fi
fi
fi
fi fi
## change directory back to the original working directory
cd "${currdir}"