2018-05-03 14:49:43 +02:00
|
|
|
|
#!/usr/bin/env bash
|
2017-11-17 15:26:27 +01:00
|
|
|
|
|
2020-09-15 13:58:52 +02:00
|
|
|
|
## arkenfox user.js updater for macOS and Linux
|
2018-11-19 18:34:14 +01:00
|
|
|
|
|
2022-07-24 15:10:06 +02:00
|
|
|
|
## version: 3.5
|
2018-11-19 18:34:14 +01:00
|
|
|
|
## Author: Pat Johnson (@overdodactyl)
|
2022-07-24 15:10:06 +02:00
|
|
|
|
## Additional contributors: @earthlng, @ema-pe, @claustromaniac, @infinitewarp
|
2017-11-17 15:26:27 +01:00
|
|
|
|
|
2018-11-25 18:16:05 +01:00
|
|
|
|
## DON'T GO HIGHER THAN VERSION x.9 !! ( because of ASCII comparison in update_updater() )
|
|
|
|
|
|
2018-11-26 15:44:52 +01:00
|
|
|
|
readonly CURRDIR=$(pwd)
|
2018-11-25 18:16:05 +01:00
|
|
|
|
|
2020-12-25 15:02:35 +01:00
|
|
|
|
SCRIPT_FILE=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null)
|
|
|
|
|
[ -z "$SCRIPT_FILE" ] && SCRIPT_FILE=${BASH_SOURCE[0]}
|
|
|
|
|
readonly SCRIPT_DIR=$(dirname "${SCRIPT_FILE}")
|
2018-11-25 18:16:05 +01:00
|
|
|
|
|
2017-11-17 15:26:27 +01:00
|
|
|
|
|
2018-11-19 18:34:14 +01:00
|
|
|
|
#########################
|
|
|
|
|
# Base variables #
|
|
|
|
|
#########################
|
2018-11-25 18:16:05 +01:00
|
|
|
|
|
|
|
|
|
# Colors used for printing
|
2018-11-19 18:34:14 +01:00
|
|
|
|
RED='\033[0;31m'
|
|
|
|
|
BLUE='\033[0;34m'
|
2018-11-25 18:16:05 +01:00
|
|
|
|
BBLUE='\033[1;34m'
|
2018-11-19 18:34:14 +01:00
|
|
|
|
GREEN='\033[0;32m'
|
|
|
|
|
ORANGE='\033[0;33m'
|
2018-11-25 18:16:05 +01:00
|
|
|
|
CYAN='\033[0;36m'
|
2018-11-19 18:34:14 +01:00
|
|
|
|
NC='\033[0m' # No Color
|
2017-11-17 15:26:27 +01:00
|
|
|
|
|
2018-11-25 18:16:05 +01:00
|
|
|
|
# Argument defaults
|
2018-11-26 15:44:52 +01:00
|
|
|
|
UPDATE='check'
|
|
|
|
|
CONFIRM='yes'
|
|
|
|
|
OVERRIDE='user-overrides.js'
|
|
|
|
|
BACKUP='multiple'
|
2018-11-25 18:16:05 +01:00
|
|
|
|
COMPARE=false
|
|
|
|
|
SKIPOVERRIDE=false
|
|
|
|
|
VIEW=false
|
|
|
|
|
PROFILE_PATH=false
|
2018-12-01 15:47:58 +01:00
|
|
|
|
ESR=false
|
2018-07-06 14:06:01 +02:00
|
|
|
|
|
2018-11-26 15:44:52 +01:00
|
|
|
|
# Download method priority: curl -> wget
|
|
|
|
|
DOWNLOAD_METHOD=''
|
2021-09-27 17:23:12 +02:00
|
|
|
|
if command -v curl >/dev/null; then
|
2020-08-28 12:51:15 +02:00
|
|
|
|
DOWNLOAD_METHOD='curl --max-redirs 3 -so'
|
2021-09-27 17:23:12 +02:00
|
|
|
|
elif command -v wget >/dev/null; then
|
2020-08-28 12:51:15 +02:00
|
|
|
|
DOWNLOAD_METHOD='wget --max-redirect 3 --quiet -O'
|
2018-11-26 15:44:52 +01:00
|
|
|
|
else
|
|
|
|
|
echo -e "${RED}This script requires curl or wget.\nProcess aborted${NC}"
|
2020-09-15 15:36:39 +02:00
|
|
|
|
exit 1
|
2018-11-26 15:44:52 +01:00
|
|
|
|
fi
|
2018-07-06 14:06:01 +02:00
|
|
|
|
|
2018-11-26 15:44:52 +01:00
|
|
|
|
|
2021-09-27 17:23:12 +02:00
|
|
|
|
show_banner() {
|
2020-08-22 14:07:13 +02:00
|
|
|
|
echo -e "${BBLUE}
|
|
|
|
|
############################################################################
|
|
|
|
|
#### ####
|
2020-09-15 13:58:52 +02:00
|
|
|
|
#### arkenfox user.js ####
|
2020-08-22 14:07:13 +02:00
|
|
|
|
#### Hardening the Privacy and Security Settings of Firefox ####
|
|
|
|
|
#### Maintained by @Thorin-Oakenpants and @earthlng ####
|
|
|
|
|
#### Updater for macOS and Linux by @overdodactyl ####
|
|
|
|
|
#### ####
|
|
|
|
|
############################################################################"
|
2018-11-26 15:44:52 +01:00
|
|
|
|
echo -e "${NC}\n"
|
2022-02-06 13:23:20 +01:00
|
|
|
|
echo -e "Documentation for this script is available here: ${CYAN}https://github.com/arkenfox/user.js/wiki/5.1-Updater-[Options]#-maclinux${NC}\n"
|
2018-11-25 18:16:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#########################
|
2018-11-26 15:44:52 +01:00
|
|
|
|
# Arguments #
|
2018-11-25 18:16:05 +01:00
|
|
|
|
#########################
|
2017-11-18 13:39:29 +01:00
|
|
|
|
|
2018-11-25 18:16:05 +01:00
|
|
|
|
usage() {
|
2020-08-22 14:07:13 +02:00
|
|
|
|
echo
|
|
|
|
|
echo -e "${BLUE}Usage: $0 [-bcdehlnrsuv] [-p PROFILE] [-o OVERRIDE]${NC}" 1>&2 # Echo usage string to standard error
|
|
|
|
|
echo -e "
|
|
|
|
|
Optional Arguments:
|
|
|
|
|
-h Show this help message and exit.
|
|
|
|
|
-p PROFILE Path to your Firefox profile (if different than the dir of this script)
|
2020-09-15 15:36:39 +02:00
|
|
|
|
IMPORTANT: If the path contains spaces, wrap the entire argument in quotes.
|
2020-08-22 14:07:13 +02:00
|
|
|
|
-l Choose your Firefox profile from a list
|
|
|
|
|
-u Update updater.sh and execute silently. Do not seek confirmation.
|
|
|
|
|
-d Do not look for updates to updater.sh.
|
|
|
|
|
-s Silently update user.js. Do not seek confirmation.
|
|
|
|
|
-b Only keep one backup of each file.
|
|
|
|
|
-c Create a diff file comparing old and new user.js within userjs_diffs.
|
|
|
|
|
-o OVERRIDE Filename or path to overrides file (if different than user-overrides.js).
|
|
|
|
|
If used with -p, paths should be relative to PROFILE or absolute paths
|
|
|
|
|
If given a directory, all files inside will be appended recursively.
|
|
|
|
|
You can pass multiple files or directories by passing a comma separated list.
|
|
|
|
|
Note: If a directory is given, only files inside ending in the extension .js are appended
|
2020-09-15 15:36:39 +02:00
|
|
|
|
IMPORTANT: Do not add spaces between files/paths. Ex: -o file1.js,file2.js,dir1
|
|
|
|
|
IMPORTANT: If any file/path contains spaces, wrap the entire argument in quotes.
|
2020-08-22 14:07:13 +02:00
|
|
|
|
Ex: -o \"override folder\"
|
|
|
|
|
-n Do not append any overrides, even if user-overrides.js exists.
|
|
|
|
|
-v Open the resulting user.js file.
|
|
|
|
|
-r Only download user.js to a temporary file and open it.
|
|
|
|
|
-e Activate ESR related preferences."
|
|
|
|
|
echo
|
2018-11-25 18:16:05 +01:00
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-19 18:34:14 +01:00
|
|
|
|
#########################
|
2018-11-25 18:16:05 +01:00
|
|
|
|
# File Handling #
|
2018-11-19 18:34:14 +01:00
|
|
|
|
#########################
|
2018-07-06 14:06:01 +02:00
|
|
|
|
|
2021-09-27 17:23:12 +02:00
|
|
|
|
download_file() { # expects URL as argument ($1)
|
2018-11-25 18:16:05 +01:00
|
|
|
|
declare -r tf=$(mktemp)
|
2018-05-03 14:49:43 +02:00
|
|
|
|
|
2022-03-19 08:46:08 +01:00
|
|
|
|
$DOWNLOAD_METHOD "${tf}" "$1" &>/dev/null && echo "$tf" || echo '' # return the temp-filename or empty string on error
|
2018-05-03 14:49:43 +02:00
|
|
|
|
}
|
2017-11-18 13:39:29 +01:00
|
|
|
|
|
2021-09-27 17:23:12 +02:00
|
|
|
|
open_file() { # expects one argument: file_path
|
2018-11-26 15:44:52 +01:00
|
|
|
|
if [ "$(uname)" == 'Darwin' ]; then
|
2018-11-25 18:16:05 +01:00
|
|
|
|
open "$1"
|
2020-08-28 12:51:15 +02:00
|
|
|
|
elif [ "$(uname -s | cut -c -5)" == "Linux" ]; then
|
2018-11-25 18:16:05 +01:00
|
|
|
|
xdg-open "$1"
|
|
|
|
|
else
|
2018-11-26 15:44:52 +01:00
|
|
|
|
echo -e "${RED}Error: Sorry, opening files is not supported for your OS.${NC}"
|
2018-11-25 18:16:05 +01:00
|
|
|
|
fi
|
2018-11-19 18:34:14 +01:00
|
|
|
|
}
|
2017-11-17 15:26:27 +01:00
|
|
|
|
|
2021-09-27 17:23:12 +02:00
|
|
|
|
readIniFile() { # expects one argument: absolute path of profiles.ini
|
2018-11-26 15:44:52 +01:00
|
|
|
|
declare -r inifile="$1"
|
2018-11-19 18:34:14 +01:00
|
|
|
|
|
2021-03-07 14:29:33 +01:00
|
|
|
|
# tempIni will contain: [ProfileX], Name=, IsRelative= and Path= (and Default= if present) of the only (if) or the selected (else) profile
|
2021-09-27 17:23:12 +02:00
|
|
|
|
if [ "$(grep -c '^\[Profile' "${inifile}")" -eq "1" ]; then ### only 1 profile found
|
2021-03-07 14:29:33 +01:00
|
|
|
|
tempIni="$(grep '^\[Profile' -A 4 "${inifile}")"
|
2018-11-26 15:44:52 +01:00
|
|
|
|
else
|
2021-03-07 14:29:33 +01:00
|
|
|
|
echo -e "Profiles found:\n––––––––––––––––––––––––––––––"
|
|
|
|
|
## cmd-substitution to strip trailing newlines and in quotes to keep internal ones:
|
|
|
|
|
echo "$(grep --color=never -E 'Default=[^1]|\[Profile[0-9]*\]|Name=|Path=|^$' "${inifile}")"
|
|
|
|
|
echo '––––––––––––––––––––––––––––––'
|
2018-11-26 15:44:52 +01:00
|
|
|
|
read -p 'Select the profile number ( 0 for Profile0, 1 for Profile1, etc ) : ' -r
|
|
|
|
|
echo -e "\n"
|
|
|
|
|
if [[ $REPLY =~ ^(0|[1-9][0-9]*)$ ]]; then
|
2021-03-07 14:29:33 +01:00
|
|
|
|
tempIni="$(grep "^\[Profile${REPLY}" -A 4 "${inifile}")" || {
|
|
|
|
|
echo -e "${RED}Profile${REPLY} does not exist!${NC}" && exit 1
|
|
|
|
|
}
|
2018-11-26 15:44:52 +01:00
|
|
|
|
else
|
2021-03-07 14:29:33 +01:00
|
|
|
|
echo -e "${RED}Invalid selection!${NC}" && exit 1
|
2018-11-26 15:44:52 +01:00
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2021-03-07 14:29:33 +01:00
|
|
|
|
# extracting 0 or 1 from the "IsRelative=" line
|
|
|
|
|
declare -r pathisrel=$(sed -n 's/^IsRelative=\([01]\)$/\1/p' <<< "${tempIni}")
|
2018-11-26 15:44:52 +01:00
|
|
|
|
|
2021-03-07 14:29:33 +01:00
|
|
|
|
# extracting only the path itself, excluding "Path="
|
|
|
|
|
PROFILE_PATH=$(sed -n 's/^Path=\(.*\)$/\1/p' <<< "${tempIni}")
|
|
|
|
|
# update global variable if path is relative
|
|
|
|
|
[[ ${pathisrel} == "1" ]] && PROFILE_PATH="$(dirname "${inifile}")/${PROFILE_PATH}"
|
2018-11-19 18:34:14 +01:00
|
|
|
|
}
|
2017-11-17 15:26:27 +01:00
|
|
|
|
|
2021-09-27 17:23:12 +02:00
|
|
|
|
getProfilePath() {
|
2018-11-26 15:44:52 +01:00
|
|
|
|
declare -r f1=~/Library/Application\ Support/Firefox/profiles.ini
|
|
|
|
|
declare -r f2=~/.mozilla/firefox/profiles.ini
|
|
|
|
|
|
|
|
|
|
if [ "$PROFILE_PATH" = false ]; then
|
|
|
|
|
PROFILE_PATH="$SCRIPT_DIR"
|
|
|
|
|
elif [ "$PROFILE_PATH" = 'list' ]; then
|
|
|
|
|
if [[ -f "$f1" ]]; then
|
2021-03-07 14:29:33 +01:00
|
|
|
|
readIniFile "$f1" # updates PROFILE_PATH or exits on error
|
2018-11-26 15:44:52 +01:00
|
|
|
|
elif [[ -f "$f2" ]]; then
|
2021-03-07 14:29:33 +01:00
|
|
|
|
readIniFile "$f2"
|
2018-11-26 15:44:52 +01:00
|
|
|
|
else
|
|
|
|
|
echo -e "${RED}Error: Sorry, -l is not supported for your OS${NC}"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
#else
|
|
|
|
|
# PROFILE_PATH already set by user with -p
|
|
|
|
|
fi
|
|
|
|
|
}
|
2018-05-03 14:49:43 +02:00
|
|
|
|
|
2018-11-19 18:34:14 +01:00
|
|
|
|
#########################
|
|
|
|
|
# Update updater.sh #
|
|
|
|
|
#########################
|
2018-05-03 14:49:43 +02:00
|
|
|
|
|
2018-11-19 18:34:14 +01:00
|
|
|
|
# Returns the version number of a updater.sh file
|
2021-09-27 17:23:12 +02:00
|
|
|
|
get_updater_version() {
|
|
|
|
|
echo "$(sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p' "$1")"
|
2018-11-19 18:34:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Update updater.sh
|
|
|
|
|
# Default: Check for update, if available, ask user if they want to execute it
|
|
|
|
|
# Args:
|
2020-08-22 14:07:13 +02:00
|
|
|
|
# -d: New version will not be looked for and update will not occur
|
|
|
|
|
# -u: Check for update, if available, execute without asking
|
2021-09-27 17:23:12 +02:00
|
|
|
|
update_updater() {
|
|
|
|
|
[ "$UPDATE" = 'no' ] && return 0 # User signified not to check for updates
|
2018-05-03 14:49:43 +02:00
|
|
|
|
|
2020-09-15 13:58:52 +02:00
|
|
|
|
declare -r tmpfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/updater.sh')"
|
2020-08-28 12:51:15 +02:00
|
|
|
|
[ -z "${tmpfile}" ] && echo -e "${RED}Error! Could not download updater.sh${NC}" && return 1 # check if download failed
|
2017-11-17 15:26:27 +01:00
|
|
|
|
|
2020-12-25 15:02:35 +01:00
|
|
|
|
if [[ $(get_updater_version "$SCRIPT_FILE") < $(get_updater_version "${tmpfile}") ]]; then
|
2021-09-27 17:23:12 +02:00
|
|
|
|
if [ "$UPDATE" = 'check' ]; then
|
2018-11-25 18:16:05 +01:00
|
|
|
|
echo -e "There is a newer version of updater.sh available. ${RED}Update and execute Y/N?${NC}"
|
2018-11-19 18:34:14 +01:00
|
|
|
|
read -p "" -n 1 -r
|
|
|
|
|
echo -e "\n\n"
|
2022-07-24 15:11:28 +02:00
|
|
|
|
[[ $REPLY =~ ^[Yy]$ ]] || return 0 # Update available, but user chooses not to update
|
2018-05-03 14:49:43 +02:00
|
|
|
|
fi
|
|
|
|
|
else
|
2022-07-24 15:11:28 +02:00
|
|
|
|
return 0 # No update available
|
2017-11-17 15:26:27 +01:00
|
|
|
|
fi
|
2020-12-25 15:02:35 +01:00
|
|
|
|
mv "${tmpfile}" "$SCRIPT_FILE"
|
|
|
|
|
chmod u+x "$SCRIPT_FILE"
|
|
|
|
|
"$SCRIPT_FILE" "$@" -d
|
2020-09-15 15:36:39 +02:00
|
|
|
|
exit 0
|
2018-05-03 14:49:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-19 18:34:14 +01:00
|
|
|
|
#########################
|
|
|
|
|
# Update user.js #
|
|
|
|
|
#########################
|
|
|
|
|
|
|
|
|
|
# Returns version number of a user.js file
|
2021-09-27 17:23:12 +02:00
|
|
|
|
get_userjs_version() {
|
|
|
|
|
[ -e "$1" ] && echo "$(sed -n '4p' "$1")" || echo "Not detected."
|
2018-11-25 18:16:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 17:23:12 +02:00
|
|
|
|
add_override() {
|
2018-11-25 18:16:05 +01:00
|
|
|
|
input=$1
|
|
|
|
|
if [ -f "$input" ]; then
|
|
|
|
|
echo "" >> user.js
|
|
|
|
|
cat "$input" >> user.js
|
|
|
|
|
echo -e "Status: ${GREEN}Override file appended:${NC} ${input}"
|
|
|
|
|
elif [ -d "$input" ]; then
|
2020-08-28 12:51:15 +02:00
|
|
|
|
SAVEIFS=$IFS
|
2018-11-25 18:16:05 +01:00
|
|
|
|
IFS=$'\n\b' # Set IFS
|
|
|
|
|
FILES="${input}"/*.js
|
|
|
|
|
for f in $FILES
|
|
|
|
|
do
|
|
|
|
|
add_override "$f"
|
|
|
|
|
done
|
|
|
|
|
IFS=$SAVEIFS # restore $IFS
|
|
|
|
|
else
|
|
|
|
|
echo -e "${ORANGE}Warning: Could not find override file:${NC} ${input}"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 17:23:12 +02:00
|
|
|
|
remove_comments() { # expects 2 arguments: from-file and to-file
|
2021-06-06 23:30:14 +02:00
|
|
|
|
sed -e '/^\/\*.*\*\/[[:space:]]*$/d' -e '/^\/\*/,/\*\//d' -e 's|^[[:space:]]*//.*$||' -e '/^[[:space:]]*$/d' -e 's|);[[:space:]]*//.*|);|' "$1" > "$2"
|
2018-11-19 18:34:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Applies latest version of user.js and any custom overrides
|
2021-09-27 17:23:12 +02:00
|
|
|
|
update_userjs() {
|
2020-09-15 13:58:52 +02:00
|
|
|
|
declare -r newfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/user.js')"
|
2020-08-28 12:51:15 +02:00
|
|
|
|
[ -z "${newfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && return 1 # check if download failed
|
2018-11-25 18:16:05 +01:00
|
|
|
|
|
2020-08-22 14:07:13 +02:00
|
|
|
|
echo -e "Please observe the following information:
|
|
|
|
|
Firefox profile: ${ORANGE}$(pwd)${NC}
|
2021-09-27 17:23:12 +02:00
|
|
|
|
Available online: ${ORANGE}$(get_userjs_version "$newfile")${NC}
|
2020-08-22 14:07:13 +02:00
|
|
|
|
Currently using: ${ORANGE}$(get_userjs_version user.js)${NC}\n\n"
|
2018-11-25 18:16:05 +01:00
|
|
|
|
|
2021-09-27 17:23:12 +02:00
|
|
|
|
if [ "$CONFIRM" = 'yes' ]; then
|
2018-11-25 18:16:05 +01:00
|
|
|
|
echo -e "This script will update to the latest user.js file and append any custom configurations from user-overrides.js. ${RED}Continue Y/N? ${NC}"
|
|
|
|
|
read -p "" -n 1 -r
|
|
|
|
|
echo -e "\n"
|
2022-07-24 15:10:06 +02:00
|
|
|
|
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
|
2018-11-26 15:44:52 +01:00
|
|
|
|
echo -e "${RED}Process aborted${NC}"
|
2021-09-27 17:23:12 +02:00
|
|
|
|
rm "$newfile"
|
2018-11-25 18:16:05 +01:00
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Copy a version of user.js to diffs folder for later comparison
|
|
|
|
|
if [ "$COMPARE" = true ]; then
|
|
|
|
|
mkdir -p userjs_diffs
|
2018-11-27 17:57:51 +01:00
|
|
|
|
cp user.js userjs_diffs/past_user.js &>/dev/null
|
2018-11-25 18:16:05 +01:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# backup user.js
|
|
|
|
|
mkdir -p userjs_backups
|
|
|
|
|
local bakname="userjs_backups/user.js.backup.$(date +"%Y-%m-%d_%H%M")"
|
2021-09-27 17:23:12 +02:00
|
|
|
|
[ "$BACKUP" = 'single' ] && bakname='userjs_backups/user.js.backup'
|
2018-11-27 17:57:51 +01:00
|
|
|
|
cp user.js "$bakname" &>/dev/null
|
2018-11-25 18:16:05 +01:00
|
|
|
|
|
|
|
|
|
mv "${newfile}" user.js
|
|
|
|
|
echo -e "Status: ${GREEN}user.js has been backed up and replaced with the latest version!${NC}"
|
|
|
|
|
|
2018-12-01 15:47:58 +01:00
|
|
|
|
if [ "$ESR" = true ]; then
|
|
|
|
|
sed -e 's/\/\* \(ESR[0-9]\{2,\}\.x still uses all.*\)/\/\/ \1/' user.js > user.js.tmp && mv user.js.tmp user.js
|
|
|
|
|
echo -e "Status: ${GREEN}ESR related preferences have been activated!${NC}"
|
|
|
|
|
fi
|
|
|
|
|
|
2018-11-25 18:16:05 +01:00
|
|
|
|
# apply overrides
|
|
|
|
|
if [ "$SKIPOVERRIDE" = false ]; then
|
2020-05-26 13:54:55 +02:00
|
|
|
|
while IFS=',' read -ra FILES; do
|
|
|
|
|
for FILE in "${FILES[@]}"; do
|
|
|
|
|
add_override "$FILE"
|
|
|
|
|
done
|
2018-11-25 18:16:05 +01:00
|
|
|
|
done <<< "$OVERRIDE"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# create diff
|
|
|
|
|
if [ "$COMPARE" = true ]; then
|
2018-11-26 15:44:52 +01:00
|
|
|
|
pastuserjs='userjs_diffs/past_user.js'
|
|
|
|
|
past_nocomments='userjs_diffs/past_userjs.txt'
|
|
|
|
|
current_nocomments='userjs_diffs/current_userjs.txt'
|
2018-11-25 18:16:05 +01:00
|
|
|
|
|
2021-09-27 17:23:12 +02:00
|
|
|
|
remove_comments "$pastuserjs" "$past_nocomments"
|
|
|
|
|
remove_comments user.js "$current_nocomments"
|
2018-11-25 18:16:05 +01:00
|
|
|
|
|
|
|
|
|
diffname="userjs_diffs/diff_$(date +"%Y-%m-%d_%H%M").txt"
|
2021-09-27 17:23:12 +02:00
|
|
|
|
diff=$(diff -w -B -U 0 "$past_nocomments" "$current_nocomments")
|
|
|
|
|
if [ -n "$diff" ]; then
|
2018-11-25 18:16:05 +01:00
|
|
|
|
echo "$diff" > "$diffname"
|
|
|
|
|
echo -e "Status: ${GREEN}A diff file was created:${NC} ${PWD}/${diffname}"
|
|
|
|
|
else
|
2018-11-26 15:44:52 +01:00
|
|
|
|
echo -e "Warning: ${ORANGE}Your new user.js file appears to be identical. No diff file was created.${NC}"
|
2021-09-27 17:23:12 +02:00
|
|
|
|
[ "$BACKUP" = 'multiple' ] && rm "$bakname" &>/dev/null
|
2018-11-25 18:16:05 +01:00
|
|
|
|
fi
|
2021-09-27 17:23:12 +02:00
|
|
|
|
rm "$past_nocomments" "$current_nocomments" "$pastuserjs" &>/dev/null
|
2018-11-25 18:16:05 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2020-08-22 14:07:13 +02:00
|
|
|
|
[ "$VIEW" = true ] && open_file "${PWD}/user.js"
|
2018-11-19 18:34:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#########################
|
|
|
|
|
# Execute #
|
|
|
|
|
#########################
|
|
|
|
|
|
2018-11-25 18:16:05 +01:00
|
|
|
|
if [ $# != 0 ]; then
|
|
|
|
|
# Display usage if first argument is -help or --help
|
2021-09-27 17:23:12 +02:00
|
|
|
|
if [ "$1" = '--help' ] || [ "$1" = '-help' ]; then
|
2018-11-25 18:16:05 +01:00
|
|
|
|
usage
|
|
|
|
|
else
|
2018-12-01 15:47:58 +01:00
|
|
|
|
while getopts ":hp:ludsno:bcvre" opt; do
|
2018-11-25 18:16:05 +01:00
|
|
|
|
case $opt in
|
|
|
|
|
h)
|
|
|
|
|
usage
|
|
|
|
|
;;
|
|
|
|
|
p)
|
|
|
|
|
PROFILE_PATH=${OPTARG}
|
|
|
|
|
;;
|
|
|
|
|
l)
|
2018-11-26 15:44:52 +01:00
|
|
|
|
PROFILE_PATH='list'
|
2018-11-25 18:16:05 +01:00
|
|
|
|
;;
|
|
|
|
|
u)
|
2018-11-26 15:44:52 +01:00
|
|
|
|
UPDATE='yes'
|
2018-11-25 18:16:05 +01:00
|
|
|
|
;;
|
|
|
|
|
d)
|
2018-11-26 15:44:52 +01:00
|
|
|
|
UPDATE='no'
|
2018-11-25 18:16:05 +01:00
|
|
|
|
;;
|
|
|
|
|
s)
|
2018-11-26 15:44:52 +01:00
|
|
|
|
CONFIRM='no'
|
2018-11-25 18:16:05 +01:00
|
|
|
|
;;
|
|
|
|
|
n)
|
|
|
|
|
SKIPOVERRIDE=true
|
|
|
|
|
;;
|
|
|
|
|
o)
|
|
|
|
|
OVERRIDE=${OPTARG}
|
|
|
|
|
;;
|
|
|
|
|
b)
|
2018-11-26 15:44:52 +01:00
|
|
|
|
BACKUP='single'
|
2018-11-25 18:16:05 +01:00
|
|
|
|
;;
|
|
|
|
|
c)
|
|
|
|
|
COMPARE=true
|
|
|
|
|
;;
|
|
|
|
|
v)
|
|
|
|
|
VIEW=true
|
|
|
|
|
;;
|
2018-12-01 15:47:58 +01:00
|
|
|
|
e)
|
|
|
|
|
ESR=true
|
|
|
|
|
;;
|
2018-11-25 18:16:05 +01:00
|
|
|
|
r)
|
2020-09-15 13:58:52 +02:00
|
|
|
|
tfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/user.js')"
|
2020-08-28 12:51:15 +02:00
|
|
|
|
[ -z "${tfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && exit 1 # check if download failed
|
2021-09-27 17:23:12 +02:00
|
|
|
|
mv "$tfile" "${tfile}.js"
|
2018-11-26 15:44:52 +01:00
|
|
|
|
echo -e "${ORANGE}Warning: user.js was saved to temporary file ${tfile}.js${NC}"
|
2018-11-25 18:16:05 +01:00
|
|
|
|
open_file "${tfile}.js"
|
2020-09-15 15:36:39 +02:00
|
|
|
|
exit 0
|
2018-11-25 18:16:05 +01:00
|
|
|
|
;;
|
|
|
|
|
\?)
|
2018-11-26 15:44:52 +01:00
|
|
|
|
echo -e "${RED}\n Error! Invalid option: -$OPTARG${NC}" >&2
|
2018-11-25 18:16:05 +01:00
|
|
|
|
usage
|
|
|
|
|
;;
|
|
|
|
|
:)
|
2018-11-26 15:44:52 +01:00
|
|
|
|
echo -e "${RED}Error! Option -$OPTARG requires an argument.${NC}" >&2
|
2020-09-15 15:36:39 +02:00
|
|
|
|
exit 2
|
2018-11-25 18:16:05 +01:00
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2018-11-19 18:34:14 +01:00
|
|
|
|
|
2018-11-25 18:16:05 +01:00
|
|
|
|
show_banner
|
2021-09-27 17:23:12 +02:00
|
|
|
|
update_updater "$@"
|
2018-11-25 18:16:05 +01:00
|
|
|
|
|
2018-11-26 15:44:52 +01:00
|
|
|
|
getProfilePath # updates PROFILE_PATH or exits on error
|
|
|
|
|
cd "$PROFILE_PATH" && update_userjs
|
|
|
|
|
|
|
|
|
|
cd "$CURRDIR"
|