improve readability, remove lots of unnecessary echo commands, remove legacy arguments (#997)
Co-authored-by: TotallyLeGIT <bbkqx24kxlgvgbss@mailban.de>
This commit is contained in:
parent
8d6d17d46b
commit
b3eee6c9fd
118
updater.sh
118
updater.sh
@ -11,7 +11,7 @@
|
||||
readonly CURRDIR=$(pwd)
|
||||
|
||||
sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null)
|
||||
if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi
|
||||
[ -z "$sfp" ] && sfp=${BASH_SOURCE[0]}
|
||||
readonly SCRIPT_DIR=$(dirname "${sfp}")
|
||||
|
||||
|
||||
@ -52,15 +52,15 @@ fi
|
||||
|
||||
|
||||
show_banner () {
|
||||
echo -e "${BBLUE}\n"
|
||||
echo ' ############################################################################'
|
||||
echo ' #### ####'
|
||||
echo ' #### ghacks user.js ####'
|
||||
echo ' #### Hardening the Privacy and Security Settings of Firefox ####'
|
||||
echo ' #### Maintained by @Thorin-Oakenpants and @earthlng ####'
|
||||
echo ' #### Updater for macOS and Linux by @overdodactyl ####'
|
||||
echo ' #### ####'
|
||||
echo ' ############################################################################'
|
||||
echo -e "${BBLUE}
|
||||
############################################################################
|
||||
#### ####
|
||||
#### ghacks user.js ####
|
||||
#### Hardening the Privacy and Security Settings of Firefox ####
|
||||
#### Maintained by @Thorin-Oakenpants and @earthlng ####
|
||||
#### Updater for macOS and Linux by @overdodactyl ####
|
||||
#### ####
|
||||
############################################################################"
|
||||
echo -e "${NC}\n"
|
||||
echo -e "Documentation for this script is available here: ${CYAN}https://github.com/ghacksuserjs/ghacks-user.js/wiki/3.3-Updater-Scripts${NC}\n"
|
||||
}
|
||||
@ -70,43 +70,35 @@ 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 '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\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-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."
|
||||
echo -e "\t-b,\t\t Only keep one backup of each file."
|
||||
echo -e "\t-c,\t\t Create a diff file comparing old and new user.js within userjs_diffs. "
|
||||
echo -e "\t-o OVERRIDE,\t Filename or path to overrides file (if different than user-overrides.js)."
|
||||
echo -e "\t\t\t If used with -p, paths should be relative to PROFILE or absolute paths"
|
||||
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\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-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"
|
||||
echo -e "\t-update,\t Use instead -u"
|
||||
echo -e
|
||||
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)
|
||||
IMPORTANT: if the path includes spaces, wrap the entire argument in quotes.
|
||||
-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
|
||||
IMPORTANT: do not add spaces between files/paths. Ex: -o file1.js,file2.js,dir1
|
||||
IMPORTANT: if any files/paths include spaces, wrap the entire argument in quotes.
|
||||
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
|
||||
exit 1
|
||||
}
|
||||
|
||||
legacy_argument () {
|
||||
echo -e "${ORANGE}\nWarning: command line arguments have changed."
|
||||
echo -e "$1 has been deprecated and may not work in the future.\n"
|
||||
echo -e "Please view the new options using the -h argument.${NC}"
|
||||
}
|
||||
|
||||
#########################
|
||||
# File Handling #
|
||||
#########################
|
||||
@ -204,8 +196,8 @@ get_updater_version () {
|
||||
# Update updater.sh
|
||||
# Default: Check for update, if available, ask user if they want to execute it
|
||||
# Args:
|
||||
# -donotupdate: New version will not be looked for and update will not occur
|
||||
# -update: Check for update, if available, execute without asking
|
||||
# -d: New version will not be looked for and update will not occur
|
||||
# -u: Check for update, if available, execute without asking
|
||||
update_updater () {
|
||||
if [ $UPDATE = 'no' ]; then
|
||||
return 0 # User signified not to check for updates
|
||||
@ -218,9 +210,7 @@ update_updater () {
|
||||
echo -e "There is a newer version of updater.sh available. ${RED}Update and execute Y/N?${NC}"
|
||||
read -p "" -n 1 -r
|
||||
echo -e "\n\n"
|
||||
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||
return 0 # Update available, but user chooses not to update
|
||||
fi
|
||||
[[ $REPLY =~ ^[Nn]$ ]] && return 0 # Update available, but user chooses not to update
|
||||
fi
|
||||
else
|
||||
return 0 # No update available
|
||||
@ -238,11 +228,7 @@ update_updater () {
|
||||
|
||||
# Returns version number of a user.js file
|
||||
get_userjs_version () {
|
||||
if [ -e $1 ]; then
|
||||
echo "$(sed -n '4p' "$1")"
|
||||
else
|
||||
echo "Not detected."
|
||||
fi
|
||||
[ -e $1 ] && echo "$(sed -n '4p' "$1")" || echo "Not detected."
|
||||
}
|
||||
|
||||
add_override () {
|
||||
@ -273,10 +259,10 @@ remove_comments () { # expects 2 arguments: from-file and to-file
|
||||
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 "\tAvailable online: ${ORANGE}$(get_userjs_version $newfile)${NC}"
|
||||
echo -e "\tCurrently using: ${ORANGE}$(get_userjs_version user.js)\n${NC}\n"
|
||||
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"
|
||||
|
||||
if [ $CONFIRM = 'yes' ]; then
|
||||
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}"
|
||||
@ -298,9 +284,7 @@ update_userjs () {
|
||||
# backup user.js
|
||||
mkdir -p userjs_backups
|
||||
local bakname="userjs_backups/user.js.backup.$(date +"%Y-%m-%d_%H%M")"
|
||||
if [ $BACKUP = 'single' ]; then
|
||||
bakname='userjs_backups/user.js.backup'
|
||||
fi
|
||||
[ $BACKUP = 'single' ] && bakname='userjs_backups/user.js.backup'
|
||||
cp user.js "$bakname" &>/dev/null
|
||||
|
||||
mv "${newfile}" user.js
|
||||
@ -336,14 +320,12 @@ update_userjs () {
|
||||
echo -e "Status: ${GREEN}A diff file was created:${NC} ${PWD}/${diffname}"
|
||||
else
|
||||
echo -e "Warning: ${ORANGE}Your new user.js file appears to be identical. No diff file was created.${NC}"
|
||||
if [ $BACKUP = 'multiple' ]; then
|
||||
rm $bakname &>/dev/null
|
||||
fi
|
||||
[ $BACKUP = 'multiple' ] && rm $bakname &>/dev/null
|
||||
fi
|
||||
rm $past_nocomments $current_nocomments $pastuserjs &>/dev/null
|
||||
fi
|
||||
|
||||
if [ "$VIEW" = true ]; then open_file "${PWD}/user.js"; fi
|
||||
[ "$VIEW" = true ] && open_file "${PWD}/user.js"
|
||||
}
|
||||
|
||||
#########################
|
||||
@ -355,12 +337,6 @@ if [ $# != 0 ]; then
|
||||
# Display usage if first argument is -help or --help
|
||||
if [ $1 = '--help' ] || [ $1 = '-help' ]; then
|
||||
usage
|
||||
elif [ $legacy_lc = '-donotupdate' ]; then
|
||||
UPDATE='no'
|
||||
legacy_argument $1
|
||||
elif [ $legacy_lc = '-update' ]; then
|
||||
UPDATE='yes'
|
||||
legacy_argument $1
|
||||
else
|
||||
while getopts ":hp:ludsno:bcvre" opt; do
|
||||
case $opt in
|
||||
|
Loading…
Reference in New Issue
Block a user