Skip to content

Instantly share code, notes, and snippets.

@HorlogeSkynet
Created April 4, 2020 13:29
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 HorlogeSkynet/e10de6566095b2e5a33b2886ba43c798 to your computer and use it in GitHub Desktop.
Save HorlogeSkynet/e10de6566095b2e5a33b2886ba43c798 to your computer and use it in GitHub Desktop.
Git patch allowing GHacks User.JS's Updater BASH script to work with Thunderbird (see arkenfox/user.js#910)
From 71705c402e0abc7392c08f185ef932e68621368c Mon Sep 17 00:00:00 2001
From: Samuel FORESTIER <dev@samuel.domains>
Date: Mon, 23 Mar 2020 15:42:57 +0100
Subject: [PATCH 1/6] Adds `-t` option to work with Thunderbird profiles
(instead of Firefox)
See (and closes) [HorlogeSkynet/thunderbird-user.js#1].
Co-Authored-By: atomGit <atomgit@users.noreply.github.com>
---
updater.sh | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/updater.sh b/updater.sh
index 226a492..2cc1578 100755
--- a/updater.sh
+++ b/updater.sh
@@ -38,6 +38,7 @@ SKIPOVERRIDE=false
VIEW=false
PROFILE_PATH=false
ESR=false
+APPNAME='firefox'
# Download method priority: curl -> wget
DOWNLOAD_METHOD=''
@@ -52,11 +53,14 @@ fi
show_banner () {
+ # Capitalize and properly pad with white-spaces the application name.
+ pretty_name="${APPNAME^}$(printf '%*s' $((14-${#APPNAME})) ' ')"
+
echo -e "${BBLUE}\n"
echo ' ############################################################################'
echo ' #### ####'
echo ' #### ghacks user.js ####'
- echo ' #### Hardening the Privacy and Security Settings of Firefox ####'
+ echo " #### Hardening the Privacy and Security Settings of ${pretty_name}####"
echo ' #### Maintained by @Thorin-Oakenpants and @earthlng ####'
echo ' #### Updater for macOS and Linux by @overdodactyl ####'
echo ' #### ####'
@@ -73,9 +77,9 @@ usage() {
echo -e "${BLUE}\nUsage: $0 [-h] [-p PROFILE] [-u] [-d] [-s] [-n] [-b] [-c] [-v] [-r] [-e] [-o OVERRIDE]\n${NC}" 1>&2 # Echo usage string to standard error
echo 'Optional Arguments:'
echo -e "\t-h,\t\t Show this help message and exit."
- echo -e "\t-p PROFILE,\t Path to your Firefox profile (if different than the dir of this script)"
+ echo -e "\t-p PROFILE,\t Path to your ${APPNAME^} profile (if different than the dir of this script)"
echo -e "\t\t\t IMPORTANT: if the path include spaces, wrap the entire argument in quotes."
- echo -e "\t-l, \t\t Choose your Firefox profile from a list"
+ echo -e "\t-l, \t\t Choose your ${APPNAME^} profile from a list"
echo -e "\t-u,\t\t Update updater.sh and execute silently. Do not seek confirmation."
echo -e "\t-d,\t\t Do not look for updates to updater.sh."
echo -e "\t-s,\t\t Silently update user.js. Do not seek confirmation."
@@ -91,8 +95,9 @@ usage() {
echo -e "\t\t\t\t\t Ex: -o \"override folder\" "
echo -e "\t-n,\t\t Do not append any overrides, even if user-overrides.js exists."
echo -e "\t-v,\t\t Open the resulting user.js file."
+ echo -e "\t-e,\t\t Activate ESR related preferences."
+ echo -e "\t-t,\t\t Work with Thunderbird instead of Firefox."
echo -e "\t-r,\t\t Only download user.js to a temporary file and open it."
- echo -e "\t-e,\t\t Activate ESR related preferences."
echo -e
echo 'Deprecated Arguments (they still work for now):'
echo -e "\t-donotupdate,\t Use instead -d"
@@ -171,8 +176,13 @@ readIniFile () { # expects one argument: absolute path of profiles.ini
}
getProfilePath () {
- declare -r f1=~/Library/Application\ Support/Firefox/profiles.ini
- declare -r f2=~/.mozilla/firefox/profiles.ini
+ if [[ $APPNAME == 'firefox' ]]; then
+ declare -r f1=~/Library/Application\ Support/Firefox/profiles.ini
+ declare -r f2=~/.mozilla/firefox/profiles.ini
+ else
+ declare -r f1=~/Library/Application\ Support/Thunderbird/profiles.ini
+ declare -r f2=~/.thunderbird/profiles.ini
+ fi
if [ "$PROFILE_PATH" = false ]; then
PROFILE_PATH="$SCRIPT_DIR"
@@ -274,7 +284,7 @@ update_userjs () {
declare -r newfile=$(download_file 'https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js')
echo 'Please observe the following information:'
- echo -e "\tFirefox profile: ${ORANGE}$(pwd)${NC}"
+ echo -e "\t${APPNAME^} profile: ${ORANGE}$(pwd)${NC}"
echo -e "\tAvailable online: ${ORANGE}$(get_userjs_version $newfile)${NC}"
echo -e "\tCurrently using: ${ORANGE}$(get_userjs_version user.js)\n${NC}\n"
@@ -360,7 +370,7 @@ if [ $# != 0 ]; then
UPDATE='yes'
legacy_argument $1
else
- while getopts ":hp:ludsno:bcvre" opt; do
+ while getopts ":hp:ludsno:bcvetr" opt; do
case $opt in
h)
usage
@@ -398,6 +408,9 @@ if [ $# != 0 ]; then
e)
ESR=true
;;
+ t)
+ APPNAME='thunderbird'
+ ;;
r)
tfile=$(download_file 'https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js')
mv $tfile "${tfile}.js"
From 4d34d2e755ecf51db15e9cc2808fe8c85b576e81 Mon Sep 17 00:00:00 2001
From: Samuel FORESTIER <dev@samuel.domains>
Date: Tue, 24 Mar 2020 09:03:24 +0100
Subject: [PATCH 2/6] Fixes some exit error codes, according to "standards" :
* 0 : successful termination
* 2 : command line syntax error
* 1 : other kind of error
---
updater.sh | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/updater.sh b/updater.sh
index 2cc1578..a65188a 100755
--- a/updater.sh
+++ b/updater.sh
@@ -48,7 +48,7 @@ elif [[ $(command -v 'wget') ]]; then
DOWNLOAD_METHOD='wget'
else
echo -e "${RED}This script requires curl or wget.\nProcess aborted${NC}"
- exit 0
+ exit 1
fi
@@ -103,7 +103,7 @@ usage() {
echo -e "\t-donotupdate,\t Use instead -d"
echo -e "\t-update,\t Use instead -u"
echo -e
- exit 1
+ exit 2
}
legacy_argument () {
@@ -238,7 +238,7 @@ update_updater () {
mv "${tmpfile}" "${SCRIPT_DIR}/updater.sh"
chmod u+x "${SCRIPT_DIR}/updater.sh"
"${SCRIPT_DIR}/updater.sh" "$@" -d
- exit 1
+ exit 0
}
@@ -416,7 +416,7 @@ if [ $# != 0 ]; then
mv $tfile "${tfile}.js"
echo -e "${ORANGE}Warning: user.js was saved to temporary file ${tfile}.js${NC}"
open_file "${tfile}.js"
- exit 1
+ exit 0
;;
\?)
echo -e "${RED}\n Error! Invalid option: -$OPTARG${NC}" >&2
@@ -424,7 +424,7 @@ if [ $# != 0 ]; then
;;
:)
echo -e "${RED}Error! Option -$OPTARG requires an argument.${NC}" >&2
- exit 1
+ exit 2
;;
esac
done
From 82a04a17347bac4b0401ba636b9f7d8af1a056de Mon Sep 17 00:00:00 2001
From: Samuel FORESTIER <dev@samuel.domains>
Date: Tue, 24 Mar 2020 09:16:38 +0100
Subject: [PATCH 3/6] Downloads Thunderbird version on `-t` and fixes one more
exit code error
---
updater.sh | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/updater.sh b/updater.sh
index a65188a..39019d3 100755
--- a/updater.sh
+++ b/updater.sh
@@ -38,7 +38,9 @@ SKIPOVERRIDE=false
VIEW=false
PROFILE_PATH=false
ESR=false
+DOWNLOAD_ONLY=false
APPNAME='firefox'
+USERJS_URL='https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js'
# Download method priority: curl -> wget
DOWNLOAD_METHOD=''
@@ -138,6 +140,7 @@ open_file () { #expects one argument: file_path
xdg-open "$1"
else
echo -e "${RED}Error: Sorry, opening files is not supported for your OS.${NC}"
+ exit 1
fi
}
@@ -279,9 +282,17 @@ remove_comments () { # expects 2 arguments: from-file and to-file
sed -e 's/^[[:space:]]*\/\/.*$//' -e '/^\/\*/,/\*\//d' -e '/^[[:space:]]*$/d' -e 's/);[[:space:]]*\/\/.*/);/' "$1" > "$2"
}
+# Downloads latest version of user.js and (try to) open it
+download_and_open_userjs () {
+ tfile=$(download_file "${USERJS_URL}")
+ mv "$tfile" "${tfile}.js"
+ echo -e "${ORANGE}Warning: user.js was saved to temporary file ${tfile}.js${NC}"
+ open_file "${tfile}.js"
+}
+
# Applies latest version of user.js and any custom overrides
update_userjs () {
- declare -r newfile=$(download_file 'https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js')
+ declare -r newfile=$(download_file ${USERJS_URL})
echo 'Please observe the following information:'
echo -e "\t${APPNAME^} profile: ${ORANGE}$(pwd)${NC}"
@@ -410,13 +421,10 @@ if [ $# != 0 ]; then
;;
t)
APPNAME='thunderbird'
+ USERJS_URL='https://raw.githubusercontent.com/HorlogeSkynet/thunderbird-user.js/master/user.js'
;;
r)
- tfile=$(download_file 'https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js')
- mv $tfile "${tfile}.js"
- echo -e "${ORANGE}Warning: user.js was saved to temporary file ${tfile}.js${NC}"
- open_file "${tfile}.js"
- exit 0
+ DOWNLOAD_ONLY=true
;;
\?)
echo -e "${RED}\n Error! Invalid option: -$OPTARG${NC}" >&2
@@ -434,6 +442,10 @@ fi
show_banner
update_updater $@
+if [[ "$DOWNLOAD_ONLY" = true ]]; then
+ download_and_open_userjs
+fi
+
getProfilePath # updates PROFILE_PATH or exits on error
cd "$PROFILE_PATH" && update_userjs
From 0e481b078e68914122d111f68da4163bbf6150a7 Mon Sep 17 00:00:00 2001
From: Samuel FORESTIER <dev@samuel.domains>
Date: Tue, 24 Mar 2020 14:11:57 +0100
Subject: [PATCH 4/6] Fixes application name on `-t` & `-h` and (still)
improves `exit` calls
---
updater.sh | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/updater.sh b/updater.sh
index 39019d3..d6b3a41 100755
--- a/updater.sh
+++ b/updater.sh
@@ -29,6 +29,7 @@ CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Argument defaults
+SHOW_USAGE=false
UPDATE='check'
CONFIRM='yes'
OVERRIDE='user-overrides.js'
@@ -105,7 +106,6 @@ usage() {
echo -e "\t-donotupdate,\t Use instead -d"
echo -e "\t-update,\t Use instead -u"
echo -e
- exit 2
}
legacy_argument () {
@@ -241,7 +241,7 @@ update_updater () {
mv "${tmpfile}" "${SCRIPT_DIR}/updater.sh"
chmod u+x "${SCRIPT_DIR}/updater.sh"
"${SCRIPT_DIR}/updater.sh" "$@" -d
- exit 0
+ exit
}
@@ -374,6 +374,7 @@ if [ $# != 0 ]; then
# Display usage if first argument is -help or --help
if [ $1 = '--help' ] || [ $1 = '-help' ]; then
usage
+ exit
elif [ $legacy_lc = '-donotupdate' ]; then
UPDATE='no'
legacy_argument $1
@@ -384,7 +385,7 @@ if [ $# != 0 ]; then
while getopts ":hp:ludsno:bcvetr" opt; do
case $opt in
h)
- usage
+ SHOW_USAGE=true
;;
p)
PROFILE_PATH=${OPTARG}
@@ -429,6 +430,7 @@ if [ $# != 0 ]; then
\?)
echo -e "${RED}\n Error! Invalid option: -$OPTARG${NC}" >&2
usage
+ exit 2
;;
:)
echo -e "${RED}Error! Option -$OPTARG requires an argument.${NC}" >&2
@@ -439,6 +441,11 @@ if [ $# != 0 ]; then
fi
fi
+if [[ "$SHOW_USAGE" = true ]]; then
+ usage
+ exit
+fi
+
show_banner
update_updater $@
From 4fbb2be98d8d156efd0f172e24cbbf77591ef4fc Mon Sep 17 00:00:00 2001
From: Samuel FORESTIER <dev@samuel.domains>
Date: Tue, 24 Mar 2020 14:12:14 +0100
Subject: [PATCH 5/6] Fixes some typos, and improves usage message format
---
updater.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/updater.sh b/updater.sh
index d6b3a41..2ff74c5 100755
--- a/updater.sh
+++ b/updater.sh
@@ -81,7 +81,7 @@ usage() {
echo 'Optional Arguments:'
echo -e "\t-h,\t\t Show this help message and exit."
echo -e "\t-p PROFILE,\t Path to your ${APPNAME^} profile (if different than the dir of this script)"
- echo -e "\t\t\t IMPORTANT: if the path include spaces, wrap the entire argument in quotes."
+ echo -e "\t\t\t\t IMPORTANT: If the path contains spaces, wrap the entire argument in quotes."
echo -e "\t-l, \t\t Choose your ${APPNAME^} profile from a list"
echo -e "\t-u,\t\t Update updater.sh and execute silently. Do not seek confirmation."
echo -e "\t-d,\t\t Do not look for updates to updater.sh."
@@ -93,8 +93,8 @@ usage() {
echo -e "\t\t\t If given a directory, all files inside will be appended recursively."
echo -e "\t\t\t You can pass multiple files or directories by passing a comma separated list."
echo -e "\t\t\t\t Note: If a directory is given, only files inside ending in the extension .js are appended"
- echo -e "\t\t\t\t IMPORTANT: do not add spaces between files/paths. Ex: -o file1.js,file2.js,dir1"
- echo -e "\t\t\t\t IMPORTANT: if any files/paths include spaces, wrap the entire argument in quotes."
+ echo -e "\t\t\t\t IMPORTANT: Do not add spaces between files/paths. Ex: -o file1.js,file2.js,dir1"
+ echo -e "\t\t\t\t IMPORTANT: If any file/path contains spaces, wrap the entire argument in quotes."
echo -e "\t\t\t\t\t Ex: -o \"override folder\" "
echo -e "\t-n,\t\t Do not append any overrides, even if user-overrides.js exists."
echo -e "\t-v,\t\t Open the resulting user.js file."
From 1370702bcdb1db55bbdd532c67f08ad7ba169dd6 Mon Sep 17 00:00:00 2001
From: Samuel FORESTIER <dev@samuel.domains>
Date: Wed, 25 Mar 2020 08:48:21 +0100
Subject: [PATCH 6/6] Adds missing new `-t` option to the usage excerpt message
---
updater.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/updater.sh b/updater.sh
index 2ff74c5..9a81149 100755
--- a/updater.sh
+++ b/updater.sh
@@ -77,7 +77,7 @@ show_banner () {
#########################
usage() {
- echo -e "${BLUE}\nUsage: $0 [-h] [-p PROFILE] [-u] [-d] [-s] [-n] [-b] [-c] [-v] [-r] [-e] [-o OVERRIDE]\n${NC}" 1>&2 # Echo usage string to standard error
+ echo -e "${BLUE}\nUsage: $0 [-h] [-p PROFILE] [-u] [-d] [-s] [-n] [-b] [-c] [-v] [-e] [-t] [-r] [-o OVERRIDE]\n${NC}" 1>&2 # Echo usage string to standard error
echo 'Optional Arguments:'
echo -e "\t-h,\t\t Show this help message and exit."
echo -e "\t-p PROFILE,\t Path to your ${APPNAME^} profile (if different than the dir of this script)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment