22
33# # prefs.js cleaner for Linux/Mac
44# # author: @claustromaniac
5- # # version: 1.5
5+ # # version: 1.6
66
77# # special thanks to @overdodactyl and @earthlng for a few snippets that I stol..*cough* borrowed from the updater.sh
88
9- currdir=$( pwd)
9+ # # DON'T GO HIGHER THAN VERSION x.9 !! ( because of ASCII comparison in update_prefsCleaner() )
10+
11+ readonly CURRDIR=$( pwd)
1012
1113# # get the full path of this script (readlink for Linux, greadlink for Mac with coreutils installed)
12- sfp =$( readlink -f " ${BASH_SOURCE[0]} " 2> /dev/null || greadlink -f " ${BASH_SOURCE[0]} " 2> /dev/null)
14+ SCRIPT_FILE =$( readlink -f " ${BASH_SOURCE[0]} " 2> /dev/null || greadlink -f " ${BASH_SOURCE[0]} " 2> /dev/null)
1315
1416# # fallback for Macs without coreutils
15- if [ -z " $sfp " ]; then sfp =${BASH_SOURCE[0]} ; fi
17+ [ -z " $SCRIPT_FILE " ] && SCRIPT_FILE =${BASH_SOURCE[0]}
1618
17- # # change directory to the Firefox profile directory
18- cd " $( dirname " ${sfp} " ) "
19+
20+ AUTOUPDATE=true
21+ QUICKSTART=false
22+
23+ # # download method priority: curl -> wget
24+ DOWNLOAD_METHOD=' '
25+ if command -v curl > /dev/null; then
26+ DOWNLOAD_METHOD=' curl --max-redirs 3 -so'
27+ elif command -v wget > /dev/null; then
28+ DOWNLOAD_METHOD=' wget --max-redirect 3 --quiet -O'
29+ else
30+ AUTOUPDATE=false
31+ echo -e " No curl or wget detected.\nAutomatic self-update disabled!"
32+ fi
1933
2034fQuit () {
2135 # # change directory back to the original working directory
22- cd " ${currdir } "
36+ cd " ${CURRDIR } "
2337 [ " $1 " -eq 0 ] && echo -e " \n$2 " || echo -e " \n$2 " >&2
2438 exit $1
2539}
2640
2741fUsage () {
28- echo -e " \nUsage: $0 [-s ]"
42+ echo -e " \nUsage: $0 [-ds ]"
2943 echo -e "
3044Optional Arguments:
31- -s Start immediately"
45+ -s Start immediately
46+ -d Don't auto-update prefsCleaner.sh"
47+ }
48+
49+ download_file () { # expects URL as argument ($1)
50+ declare -r tf=$( mktemp)
51+
52+ $DOWNLOAD_METHOD " ${tf} " " $1 " & > /dev/null && echo " $tf " || echo ' ' # return the temp-filename or empty string on error
3253}
3354
3455fFF_check () {
@@ -40,6 +61,24 @@ fFF_check() {
4061 done
4162}
4263
64+ # # returns the version number of a prefsCleaner.sh file
65+ get_prefsCleaner_version () {
66+ echo " $( sed -n ' 5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p' " $1 " ) "
67+ }
68+
69+ # # updates the prefsCleaner.sh file based on the latest public version
70+ update_prefsCleaner () {
71+ declare -r tmpfile=" $( download_file ' https://raw.githubusercontent.com/arkenfox/user.js/master/prefsCleaner.sh' ) "
72+ [ -z " $tmpfile " ] && echo -e " Error! Could not download prefsCleaner.sh" && return 1 # check if download failed
73+
74+ [[ $( get_prefsCleaner_version " $SCRIPT_FILE " ) == $( get_prefsCleaner_version " $tmpfile " ) ]] && return 0
75+
76+ mv " $tmpfile " " $SCRIPT_FILE "
77+ chmod u+x " $SCRIPT_FILE "
78+ " $SCRIPT_FILE " -s -d
79+ exit 0
80+ }
81+
4382fClean () {
4483 # the magic happens here
4584 prefs=" @@"
@@ -78,19 +117,37 @@ fStart() {
78117 fQuit 0 " All done!"
79118}
80119
120+
121+ while getopts " sd" opt; do
122+ case $opt in
123+ s)
124+ QUICKSTART=true
125+ ;;
126+ d)
127+ AUTOUPDATE=false
128+ ;;
129+ esac
130+ done
131+
132+ # # change directory to the Firefox profile directory
133+ cd " $( dirname " ${SCRIPT_FILE} " ) "
134+
135+ [ " $AUTOUPDATE " = true ] && update_prefsCleaner
136+
81137echo -e " \n\n"
82138echo " ╔══════════════════════════╗"
83139echo " ║ prefs.js cleaner ║"
84140echo " ║ by claustromaniac ║"
85- echo " ║ v1.5 ║"
141+ echo " ║ v1.6 ║"
86142echo " ╚══════════════════════════╝"
87143echo -e " \nThis script should be run from your Firefox profile directory.\n"
88144echo " It will remove any entries from prefs.js that also exist in user.js."
89145echo " This will allow inactive preferences to be reset to their default values."
90146echo -e " \nThis Firefox profile shouldn't be in use during the process.\n"
91- echo -e " \nIn order to proceed, select a command below by entering its corresponding number.\n"
92147
93- [ " $1 " == ' -s' ] && fStart
148+ [ " $QUICKSTART " = true ] && fStart
149+
150+ echo -e " \nIn order to proceed, select a command below by entering its corresponding number.\n"
94151
95152select option in Start Help Exit; do
96153 case $option in
@@ -114,3 +171,5 @@ select option in Start Help Exit; do
114171 ;;
115172 esac
116173done
174+
175+ fQuit 0
0 commit comments