2018-05-03 08:49:43 -04:00
|
|
|
|
#!/usr/bin/env bash
|
2017-11-17 09:26:27 -05:00
|
|
|
|
|
2020-09-15 07:58:52 -04:00
|
|
|
|
## arkenfox user.js updater for macOS and Linux
|
2018-11-19 12:34:14 -05:00
|
|
|
|
|
2021-06-06 17:30:14 -04:00
|
|
|
|
## version: 3.2
|
2018-11-19 12:34:14 -05:00
|
|
|
|
## Author: Pat Johnson (@overdodactyl)
|
2018-11-27 11:57:51 -05:00
|
|
|
|
## Additional contributors: @earthlng, @ema-pe, @claustromaniac
|
2017-11-17 09:26:27 -05:00
|
|
|
|
|
2018-11-25 12:16:05 -05:00
|
|
|
|
## DON'T GO HIGHER THAN VERSION x.9 !! ( because of ASCII comparison in update_updater() )
|
|
|
|
|
|
2018-11-26 09:44:52 -05:00
|
|
|
|
readonly CURRDIR=$(pwd)
|
2018-11-25 12:16:05 -05:00
|
|
|
|
|
2020-12-25 09:02:35 -05: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 12:16:05 -05:00
|
|
|
|
|
2017-11-17 09:26:27 -05:00
|
|
|
|
|
2018-11-19 12:34:14 -05:00
|
|
|
|
#########################
|
|
|
|
|
# Base variables #
|
|
|
|
|
#########################
|
2018-11-25 12:16:05 -05:00
|
|
|
|
|
|
|
|
|
# Colors used for printing
|
2018-11-19 12:34:14 -05:00
|
|
|
|
RED='\033[0;31m'
|
|
|
|
|
BLUE='\033[0;34m'
|
2018-11-25 12:16:05 -05:00
|
|
|
|
BBLUE='\033[1;34m'
|
2018-11-19 12:34:14 -05:00
|
|
|
|
GREEN='\033[0;32m'
|
|
|
|
|
ORANGE='\033[0;33m'
|
2018-11-25 12:16:05 -05:00
|
|
|
|
CYAN='\033[0;36m'
|
2018-11-19 12:34:14 -05:00
|
|
|
|
NC='\033[0m' # No Color
|
2017-11-17 09:26:27 -05:00
|
|
|
|
|
2018-11-25 12:16:05 -05:00
|
|
|
|
# Argument defaults
|
2018-11-26 09:44:52 -05:00
|
|
|
|
UPDATE='check'
|
|
|
|
|
CONFIRM='yes'
|
|
|
|
|
OVERRIDE='user-overrides.js'
|
|
|
|
|
BACKUP='multiple'
|
2018-11-25 12:16:05 -05:00
|
|
|
|
COMPARE=false
|
|
|
|
|
SKIPOVERRIDE=false
|
|
|
|
|
VIEW=false
|
|
|
|
|
PROFILE_PATH=false
|
2018-12-01 09:47:58 -05:00
|
|
|
|
ESR=false
|
2018-07-06 08:06:01 -04:00
|
|
|
|
|
2018-11-26 09:44:52 -05:00
|
|
|
|
# Download method priority: curl -> wget
|
|
|
|
|
DOWNLOAD_METHOD=''
|
|
|
|
|
if [[ $(command -v 'curl') ]]; then
|
2020-08-28 06:51:15 -04:00
|
|
|
|
DOWNLOAD_METHOD='curl --max-redirs 3 -so'
|
2018-11-26 09:44:52 -05:00
|
|
|
|
elif [[ $(command -v 'wget') ]]; then
|
2020-08-28 06:51:15 -04:00
|
|
|
|
DOWNLOAD_METHOD='wget --max-redirect 3 --quiet -O'
|
2018-11-26 09:44:52 -05:00
|
|
|
|
else
|
|
|
|
|
echo -e "${RED}This script requires curl or wget.\nProcess aborted${NC}"
|
2020-09-15 09:36:39 -04:00
|
|
|
|
exit 1
|
2018-11-26 09:44:52 -05:00
|
|
|
|
fi
|
2018-07-06 08:06:01 -04:00
|
|
|
|
|
2018-11-26 09:44:52 -05:00
|
|
|
|
|
|
|
|
|
show_banner () {
|
2020-08-22 08:07:13 -04:00
|
|
|
|
echo -e "${BBLUE}
|
|
|
|
|
############################################################################
|
|
|
|
|
#### ####
|
2020-09-15 07:58:52 -04:00
|
|
|
|
#### arkenfox user.js ####
|
2020-08-22 08:07:13 -04: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 09:44:52 -05:00
|
|
|
|
echo -e "${NC}\n"
|
2020-09-15 07:58:52 -04:00
|
|
|
|
echo -e "Documentation for this script is available here: ${CYAN}https://github.com/arkenfox/user.js/wiki/3.3-Updater-Scripts${NC}\n"
|
2018-11-25 12:16:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#########################
|
2018-11-26 09:44:52 -05:00
|
|
|
|
# Arguments #
|
2018-11-25 12:16:05 -05:00
|
|
|
|
#########################
|
2017-11-18 07:39:29 -05:00
|
|
|
|
|
2018-11-25 12:16:05 -05:00
|
|
|
|
usage() {
|
2020-08-22 08:07:13 -04: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 09:36:39 -04:00
|
|
|
|
IMPORTANT: If the path contains spaces, wrap the entire argument in quotes.
|
2020-08-22 08:07:13 -04: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 09:36:39 -04: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 08:07:13 -04: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 12:16:05 -05:00
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-19 12:34:14 -05:00
|
|
|
|
#########################
|
2018-11-25 12:16:05 -05:00
|
|
|
|
# File Handling #
|
2018-11-19 12:34:14 -05:00
|
|
|
|
#########################
|
2018-07-06 08:06:01 -04:00
|
|
|
|
|
2020-09-15 09:36:39 -04:00
|
|
|
|
download_file () { # expects URL as argument ($1)
|
2018-11-25 12:16:05 -05:00
|
|
|
|
declare -r tf=$(mktemp)
|
2018-05-03 08:49:43 -04:00
|
|
|
|
|
2020-08-28 06:51:15 -04:00
|
|
|
|
$DOWNLOAD_METHOD "${tf}" "$1" && echo "$tf" || echo '' # return the temp-filename or empty string on error
|
2018-05-03 08:49:43 -04:00
|
|
|
|
}
|
2017-11-18 07:39:29 -05:00
|
|
|
|
|
2020-09-15 09:36:39 -04:00
|
|
|
|
open_file () { # expects one argument: file_path
|
2018-11-26 09:44:52 -05:00
|
|
|
|
if [ "$(uname)" == 'Darwin' ]; then
|
2018-11-25 12:16:05 -05:00
|
|
|
|
open "$1"
|
2020-08-28 06:51:15 -04:00
|
|
|
|
elif [ "$(uname -s | cut -c -5)" == "Linux" ]; then
|
2018-11-25 12:16:05 -05:00
|
|
|
|
xdg-open "$1"
|
|
|
|
|
else
|
2018-11-26 09:44:52 -05:00
|
|
|
|
echo -e "${RED}Error: Sorry, opening files is not supported for your OS.${NC}"
|
2018-11-25 12:16:05 -05:00
|
|
|
|
fi
|
2018-11-19 12:34:14 -05:00
|
|
|
|
}
|
2017-11-17 09:26:27 -05:00
|
|
|
|
|
2018-11-26 09:44:52 -05:00
|
|
|
|
readIniFile () { # expects one argument: absolute path of profiles.ini
|
|
|
|
|
declare -r inifile="$1"
|
2018-11-19 12:34:14 -05:00
|
|
|
|
|
2021-03-07 08:29:33 -05:00
|
|
|
|
# tempIni will contain: [ProfileX], Name=, IsRelative= and Path= (and Default= if present) of the only (if) or the selected (else) profile
|
|
|
|
|
if [ $(grep -c '^\[Profile' "${inifile}") -eq "1" ]; then ### only 1 profile found
|
|
|
|
|
tempIni="$(grep '^\[Profile' -A 4 "${inifile}")"
|
2018-11-26 09:44:52 -05:00
|
|
|
|
else
|
2021-03-07 08:29:33 -05: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 09:44:52 -05: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 08:29:33 -05:00
|
|
|
|
tempIni="$(grep "^\[Profile${REPLY}" -A 4 "${inifile}")" || {
|
|
|
|
|
echo -e "${RED}Profile${REPLY} does not exist!${NC}" && exit 1
|
|
|
|
|
}
|
2018-11-26 09:44:52 -05:00
|
|
|
|
else
|
2021-03-07 08:29:33 -05:00
|
|
|
|
echo -e "${RED}Invalid selection!${NC}" && exit 1
|
2018-11-26 09:44:52 -05:00
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2021-03-07 08:29:33 -05:00
|
|
|
|
# extracting 0 or 1 from the "IsRelative=" line
|
|
|
|
|
declare -r pathisrel=$(sed -n 's/^IsRelative=\([01]\)$/\1/p' <<< "${tempIni}")
|
2018-11-26 09:44:52 -05:00
|
|
|
|
|
2021-03-07 08:29:33 -05: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 12:34:14 -05:00
|
|
|
|
}
|
2017-11-17 09:26:27 -05:00
|
|
|
|
|
2018-11-26 09:44:52 -05:00
|
|
|
|
getProfilePath () {
|
|
|
|
|
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 08:29:33 -05:00
|
|
|
|
readIniFile "$f1" # updates PROFILE_PATH or exits on error
|
2018-11-26 09:44:52 -05:00
|
|
|
|
elif [[ -f "$f2" ]]; then
|
2021-03-07 08:29:33 -05:00
|
|
|
|
readIniFile "$f2"
|
2018-11-26 09:44:52 -05: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 08:49:43 -04:00
|
|
|
|
|
2018-11-19 12:34:14 -05:00
|
|
|
|
#########################
|
|
|
|
|
# Update updater.sh #
|
|
|
|
|
#########################
|
2018-05-03 08:49:43 -04:00
|
|
|
|
|
2018-11-19 12:34:14 -05:00
|
|
|
|
# Returns the version number of a updater.sh file
|
|
|
|
|
get_updater_version () {
|
2018-11-25 12:16:05 -05:00
|
|
|
|
echo $(sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p' "$1")
|
2018-11-19 12:34:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Update updater.sh
|
|
|
|
|
# Default: Check for update, if available, ask user if they want to execute it
|
|
|
|
|
# Args:
|
2020-08-22 08:07:13 -04:00
|
|
|
|
# -d: New version will not be looked for and update will not occur
|
|
|
|
|
# -u: Check for update, if available, execute without asking
|
2018-11-19 12:34:14 -05:00
|
|
|
|
update_updater () {
|
2021-03-07 08:29:33 -05:00
|
|
|
|
[ $UPDATE = 'no' ] && return 0 # User signified not to check for updates
|
2018-05-03 08:49:43 -04:00
|
|
|
|
|
2020-09-15 07:58:52 -04:00
|
|
|
|
declare -r tmpfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/updater.sh')"
|
2020-08-28 06:51:15 -04:00
|
|
|
|
[ -z "${tmpfile}" ] && echo -e "${RED}Error! Could not download updater.sh${NC}" && return 1 # check if download failed
|
2017-11-17 09:26:27 -05:00
|
|
|
|
|
2020-12-25 09:02:35 -05:00
|
|
|
|
if [[ $(get_updater_version "$SCRIPT_FILE") < $(get_updater_version "${tmpfile}") ]]; then
|
2018-11-26 09:44:52 -05:00
|
|
|
|
if [ $UPDATE = 'check' ]; then
|
2018-11-25 12:16:05 -05:00
|
|
|
|
echo -e "There is a newer version of updater.sh available. ${RED}Update and execute Y/N?${NC}"
|
2018-11-19 12:34:14 -05:00
|
|
|
|
read -p "" -n 1 -r
|
|
|
|
|
echo -e "\n\n"
|
2020-08-22 08:07:13 -04:00
|
|
|
|
[[ $REPLY =~ ^[Nn]$ ]] && return 0 # Update available, but user chooses not to update
|
2018-05-03 08:49:43 -04:00
|
|
|
|
fi
|
|
|
|
|
else
|
2018-11-25 12:16:05 -05:00
|
|
|
|
return 0 # No update available
|
2017-11-17 09:26:27 -05:00
|
|
|
|
fi
|
2020-12-25 09:02:35 -05:00
|
|
|
|
mv "${tmpfile}" "$SCRIPT_FILE"
|
|
|
|
|
chmod u+x "$SCRIPT_FILE"
|
|
|
|
|
"$SCRIPT_FILE" "$@" -d
|
2020-09-15 09:36:39 -04:00
|
|
|
|
exit 0
|
2018-05-03 08:49:43 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-19 12:34:14 -05:00
|
|
|
|
#########################
|
|
|
|
|
# Update user.js #
|
|
|
|
|
#########################
|
|
|
|
|
|
|
|
|
|
# Returns version number of a user.js file
|
|
|
|
|
get_userjs_version () {
|
2020-08-22 08:07:13 -04:00
|
|
|
|
[ -e $1 ] && echo "$(sed -n '4p' "$1")" || echo "Not detected."
|
2018-11-25 12:16:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add_override () {
|
|
|
|
|
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 06:51:15 -04:00
|
|
|
|
SAVEIFS=$IFS
|
2018-11-25 12:16:05 -05: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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remove_comments () { # expects 2 arguments: from-file and to-file
|
2021-06-06 17:30:14 -04:00
|
|
|
|
sed -e '/^\/\*.*\*\/[[:space:]]*$/d' -e '/^\/\*/,/\*\//d' -e 's|^[[:space:]]*//.*$||' -e '/^[[:space:]]*$/d' -e 's|);[[:space:]]*//.*|);|' "$1" > "$2"
|
2018-11-19 12:34:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Applies latest version of user.js and any custom overrides
|
|
|
|
|
update_userjs () {
|
2020-09-15 07:58:52 -04:00
|
|
|
|
declare -r newfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/user.js')"
|
2020-08-28 06:51:15 -04:00
|
|
|
|
[ -z "${newfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && return 1 # check if download failed
|
2018-11-25 12:16:05 -05:00
|
|
|
|
|
2020-08-22 08:07:13 -04:00
|
|
|
|
echo -e "Please observe the following information:
|
|
|
|
|
Firefox profile: ${ORANGE}$(pwd)${NC}
|
|
|
|
|
Available online: ${ORANGE}$(get_userjs_version $newfile)${NC}
|
|
|
|
|
Currently using: ${ORANGE}$(get_userjs_version user.js)${NC}\n\n"
|
2018-11-25 12:16:05 -05:00
|
|
|
|
|
2018-11-26 09:44:52 -05:00
|
|
|
|
if [ $CONFIRM = 'yes' ]; then
|
2018-11-25 12:16:05 -05: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"
|
|
|
|
|
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
2018-11-26 09:44:52 -05:00
|
|
|
|
echo -e "${RED}Process aborted${NC}"
|
2018-11-25 12:16:05 -05:00
|
|
|
|
rm $newfile
|
|
|
|
|
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 11:57:51 -05:00
|
|
|
|
cp user.js userjs_diffs/past_user.js &>/dev/null
|
2018-11-25 12:16:05 -05:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# backup user.js
|
|
|
|
|
mkdir -p userjs_backups
|
|
|
|
|
local bakname="userjs_backups/user.js.backup.$(date +"%Y-%m-%d_%H%M")"
|
2020-08-22 08:07:13 -04:00
|
|
|
|
[ $BACKUP = 'single' ] && bakname='userjs_backups/user.js.backup'
|
2018-11-27 11:57:51 -05:00
|
|
|
|
cp user.js "$bakname" &>/dev/null
|
2018-11-25 12:16:05 -05: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 09:47:58 -05: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 12:16:05 -05:00
|
|
|
|
# apply overrides
|
|
|
|
|
if [ "$SKIPOVERRIDE" = false ]; then
|
2020-05-26 07:54:55 -04:00
|
|
|
|
while IFS=',' read -ra FILES; do
|
|
|
|
|
for FILE in "${FILES[@]}"; do
|
|
|
|
|
add_override "$FILE"
|
|
|
|
|
done
|
2018-11-25 12:16:05 -05:00
|
|
|
|
done <<< "$OVERRIDE"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# create diff
|
|
|
|
|
if [ "$COMPARE" = true ]; then
|
2018-11-26 09:44:52 -05:00
|
|
|
|
pastuserjs='userjs_diffs/past_user.js'
|
|
|
|
|
past_nocomments='userjs_diffs/past_userjs.txt'
|
|
|
|
|
current_nocomments='userjs_diffs/current_userjs.txt'
|
2018-11-25 12:16:05 -05:00
|
|
|
|
|
|
|
|
|
remove_comments $pastuserjs $past_nocomments
|
|
|
|
|
remove_comments user.js $current_nocomments
|
|
|
|
|
|
|
|
|
|
diffname="userjs_diffs/diff_$(date +"%Y-%m-%d_%H%M").txt"
|
2018-11-26 09:44:52 -05:00
|
|
|
|
diff=$(diff -w -B -U 0 $past_nocomments $current_nocomments)
|
2018-11-25 12:16:05 -05:00
|
|
|
|
if [ ! -z "$diff" ]; then
|
|
|
|
|
echo "$diff" > "$diffname"
|
|
|
|
|
echo -e "Status: ${GREEN}A diff file was created:${NC} ${PWD}/${diffname}"
|
|
|
|
|
else
|
2018-11-26 09:44:52 -05:00
|
|
|
|
echo -e "Warning: ${ORANGE}Your new user.js file appears to be identical. No diff file was created.${NC}"
|
2020-08-22 08:07:13 -04:00
|
|
|
|
[ $BACKUP = 'multiple' ] && rm $bakname &>/dev/null
|
2018-11-25 12:16:05 -05:00
|
|
|
|
fi
|
2018-11-27 11:57:51 -05:00
|
|
|
|
rm $past_nocomments $current_nocomments $pastuserjs &>/dev/null
|
2018-11-25 12:16:05 -05:00
|
|
|
|
fi
|
|
|
|
|
|
2020-08-22 08:07:13 -04:00
|
|
|
|
[ "$VIEW" = true ] && open_file "${PWD}/user.js"
|
2018-11-19 12:34:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#########################
|
|
|
|
|
# Execute #
|
|
|
|
|
#########################
|
|
|
|
|
|
2018-11-25 12:16:05 -05:00
|
|
|
|
if [ $# != 0 ]; then
|
|
|
|
|
# Display usage if first argument is -help or --help
|
|
|
|
|
if [ $1 = '--help' ] || [ $1 = '-help' ]; then
|
|
|
|
|
usage
|
|
|
|
|
else
|
2018-12-01 09:47:58 -05:00
|
|
|
|
while getopts ":hp:ludsno:bcvre" opt; do
|
2018-11-25 12:16:05 -05:00
|
|
|
|
case $opt in
|
|
|
|
|
h)
|
|
|
|
|
usage
|
|
|
|
|
;;
|
|
|
|
|
p)
|
|
|
|
|
PROFILE_PATH=${OPTARG}
|
|
|
|
|
;;
|
|
|
|
|
l)
|
2018-11-26 09:44:52 -05:00
|
|
|
|
PROFILE_PATH='list'
|
2018-11-25 12:16:05 -05:00
|
|
|
|
;;
|
|
|
|
|
u)
|
2018-11-26 09:44:52 -05:00
|
|
|
|
UPDATE='yes'
|
2018-11-25 12:16:05 -05:00
|
|
|
|
;;
|
|
|
|
|
d)
|
2018-11-26 09:44:52 -05:00
|
|
|
|
UPDATE='no'
|
2018-11-25 12:16:05 -05:00
|
|
|
|
;;
|
|
|
|
|
s)
|
2018-11-26 09:44:52 -05:00
|
|
|
|
CONFIRM='no'
|
2018-11-25 12:16:05 -05:00
|
|
|
|
;;
|
|
|
|
|
n)
|
|
|
|
|
SKIPOVERRIDE=true
|
|
|
|
|
;;
|
|
|
|
|
o)
|
|
|
|
|
OVERRIDE=${OPTARG}
|
|
|
|
|
;;
|
|
|
|
|
b)
|
2018-11-26 09:44:52 -05:00
|
|
|
|
BACKUP='single'
|
2018-11-25 12:16:05 -05:00
|
|
|
|
;;
|
|
|
|
|
c)
|
|
|
|
|
COMPARE=true
|
|
|
|
|
;;
|
|
|
|
|
v)
|
|
|
|
|
VIEW=true
|
|
|
|
|
;;
|
2018-12-01 09:47:58 -05:00
|
|
|
|
e)
|
|
|
|
|
ESR=true
|
|
|
|
|
;;
|
2018-11-25 12:16:05 -05:00
|
|
|
|
r)
|
2020-09-15 07:58:52 -04:00
|
|
|
|
tfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/user.js')"
|
2020-08-28 06:51:15 -04:00
|
|
|
|
[ -z "${tfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && exit 1 # check if download failed
|
2018-11-25 12:16:05 -05:00
|
|
|
|
mv $tfile "${tfile}.js"
|
2018-11-26 09:44:52 -05:00
|
|
|
|
echo -e "${ORANGE}Warning: user.js was saved to temporary file ${tfile}.js${NC}"
|
2018-11-25 12:16:05 -05:00
|
|
|
|
open_file "${tfile}.js"
|
2020-09-15 09:36:39 -04:00
|
|
|
|
exit 0
|
2018-11-25 12:16:05 -05:00
|
|
|
|
;;
|
|
|
|
|
\?)
|
2018-11-26 09:44:52 -05:00
|
|
|
|
echo -e "${RED}\n Error! Invalid option: -$OPTARG${NC}" >&2
|
2018-11-25 12:16:05 -05:00
|
|
|
|
usage
|
|
|
|
|
;;
|
|
|
|
|
:)
|
2018-11-26 09:44:52 -05:00
|
|
|
|
echo -e "${RED}Error! Option -$OPTARG requires an argument.${NC}" >&2
|
2020-09-15 09:36:39 -04:00
|
|
|
|
exit 2
|
2018-11-25 12:16:05 -05:00
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2018-11-19 12:34:14 -05:00
|
|
|
|
|
2018-11-25 12:16:05 -05:00
|
|
|
|
show_banner
|
2019-01-25 09:28:00 -05:00
|
|
|
|
update_updater $@
|
2018-11-25 12:16:05 -05:00
|
|
|
|
|
2018-11-26 09:44:52 -05:00
|
|
|
|
getProfilePath # updates PROFILE_PATH or exits on error
|
|
|
|
|
cd "$PROFILE_PATH" && update_userjs
|
|
|
|
|
|
|
|
|
|
cd "$CURRDIR"
|