mirror of
				https://github.com/arkenfox/user.js.git
				synced 2025-11-03 23:35:26 +01:00 
			
		
		
		
	improve readability, remove lots of unnecessary echo commands, remove legacy arguments (#997)
Co-authored-by: TotallyLeGIT <bbkqx24kxlgvgbss@mailban.de>
This commit is contained in:
		
							
								
								
									
										118
									
								
								updater.sh
									
									
									
									
									
								
							
							
						
						
									
										118
									
								
								updater.sh
									
									
									
									
									
								
							@@ -11,7 +11,7 @@
 | 
				
			|||||||
readonly CURRDIR=$(pwd)
 | 
					readonly CURRDIR=$(pwd)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null)
 | 
					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}")
 | 
					readonly SCRIPT_DIR=$(dirname "${sfp}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -52,15 +52,15 @@ fi
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
show_banner () {
 | 
					show_banner () {
 | 
				
			||||||
  echo -e "${BBLUE}\n"
 | 
					  echo -e "${BBLUE}
 | 
				
			||||||
  echo '                ############################################################################'
 | 
					                ############################################################################
 | 
				
			||||||
  echo '                ####                                                                    ####'
 | 
					                ####                                                                    ####
 | 
				
			||||||
  echo '                ####                           ghacks user.js                           ####'
 | 
					                ####                           ghacks user.js                           ####
 | 
				
			||||||
  echo '                ####       Hardening the Privacy and Security Settings of Firefox       ####'
 | 
					                ####       Hardening the Privacy and Security Settings of Firefox       ####
 | 
				
			||||||
  echo '                ####           Maintained by @Thorin-Oakenpants and @earthlng           ####'
 | 
					                ####           Maintained by @Thorin-Oakenpants and @earthlng           ####
 | 
				
			||||||
  echo '                ####            Updater for macOS and Linux by @overdodactyl            ####'
 | 
					                ####            Updater for macOS and Linux by @overdodactyl            ####
 | 
				
			||||||
  echo '                ####                                                                    ####'
 | 
					                ####                                                                    ####
 | 
				
			||||||
  echo '                ############################################################################'
 | 
					                ############################################################################"
 | 
				
			||||||
  echo -e "${NC}\n"
 | 
					  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"
 | 
					  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() {
 | 
					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
 | 
				
			||||||
  echo 'Optional Arguments:'
 | 
					  echo -e "${BLUE}Usage: $0 [-bcdehlnrsuv] [-p PROFILE] [-o OVERRIDE]${NC}" 1>&2  # Echo usage string to standard error
 | 
				
			||||||
  echo -e "\t-h,\t\t Show this help message and exit."
 | 
					  echo -e "
 | 
				
			||||||
  echo -e "\t-p PROFILE,\t Path to your Firefox profile (if different than the dir of this script)"
 | 
					Optional Arguments:
 | 
				
			||||||
  echo -e "\t\t\t IMPORTANT: if the path include spaces, wrap the entire argument in quotes."
 | 
					    -h           Show this help message and exit.
 | 
				
			||||||
  echo -e "\t-l, \t\t Choose your Firefox profile from a list"
 | 
					    -p PROFILE   Path to your Firefox profile (if different than the dir of this script)
 | 
				
			||||||
  echo -e "\t-u,\t\t Update updater.sh and execute silently.  Do not seek confirmation."
 | 
					                 IMPORTANT: if the path includes spaces, wrap the entire argument in quotes.
 | 
				
			||||||
  echo -e "\t-d,\t\t Do not look for updates to updater.sh."
 | 
					    -l           Choose your Firefox profile from a list
 | 
				
			||||||
  echo -e "\t-s,\t\t Silently update user.js.  Do not seek confirmation."
 | 
					    -u           Update updater.sh and execute silently.  Do not seek confirmation.
 | 
				
			||||||
  echo -e "\t-b,\t\t Only keep one backup of each file."
 | 
					    -d           Do not look for updates to updater.sh.
 | 
				
			||||||
  echo -e "\t-c,\t\t Create a diff file comparing old and new user.js within userjs_diffs. "
 | 
					    -s           Silently update user.js.  Do not seek confirmation.
 | 
				
			||||||
  echo -e "\t-o OVERRIDE,\t Filename or path to overrides file (if different than user-overrides.js)."
 | 
					    -b           Only keep one backup of each file.
 | 
				
			||||||
  echo -e "\t\t\t If used with -p, paths should be relative to PROFILE or absolute paths"
 | 
					    -c           Create a diff file comparing old and new user.js within userjs_diffs.
 | 
				
			||||||
  echo -e "\t\t\t If given a directory, all files inside will be appended recursively."
 | 
					    -o OVERRIDE  Filename or path to overrides file (if different than user-overrides.js).
 | 
				
			||||||
  echo -e "\t\t\t You can pass multiple files or directories by passing a comma separated list."
 | 
					                 If used with -p, paths should be relative to PROFILE or absolute paths
 | 
				
			||||||
  echo -e "\t\t\t\t Note: If a directory is given, only files inside ending in the extension .js are appended"
 | 
					                 If given a directory, all files inside will be appended recursively.
 | 
				
			||||||
  echo -e "\t\t\t\t IMPORTANT: do not add spaces between files/paths.  Ex: -o file1.js,file2.js,dir1"
 | 
					                 You can pass multiple files or directories by passing a comma separated list.
 | 
				
			||||||
  echo -e "\t\t\t\t IMPORTANT: if any files/paths include spaces, wrap the entire argument in quotes."
 | 
					                     Note: If a directory is given, only files inside ending in the extension .js are appended
 | 
				
			||||||
  echo -e "\t\t\t\t\t Ex: -o \"override folder\" "
 | 
					                     IMPORTANT: do not add spaces between files/paths.  Ex: -o file1.js,file2.js,dir1
 | 
				
			||||||
  echo -e "\t-n,\t\t Do not append any overrides, even if user-overrides.js exists."
 | 
					                     IMPORTANT: if any files/paths include spaces, wrap the entire argument in quotes.
 | 
				
			||||||
  echo -e "\t-v,\t\t Open the resulting user.js file."
 | 
					                         Ex: -o \"override folder\"
 | 
				
			||||||
  echo -e "\t-r,\t\t Only download user.js to a temporary file and open it."
 | 
					    -n           Do not append any overrides, even if user-overrides.js exists.
 | 
				
			||||||
    echo -e "\t-e,\t\t Activate ESR related preferences."
 | 
					    -v           Open the resulting user.js file.
 | 
				
			||||||
  echo -e
 | 
					    -r           Only download user.js to a temporary file and open it.
 | 
				
			||||||
  echo 'Deprecated Arguments (they still work for now):'
 | 
					    -e           Activate ESR related preferences."
 | 
				
			||||||
  echo -e "\t-donotupdate,\t Use instead -d"
 | 
					  echo
 | 
				
			||||||
  echo -e "\t-update,\t Use instead -u"
 | 
					 | 
				
			||||||
  echo -e
 | 
					 | 
				
			||||||
  exit 1
 | 
					  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     #
 | 
					#     File Handling     #
 | 
				
			||||||
#########################
 | 
					#########################
 | 
				
			||||||
@@ -204,8 +196,8 @@ get_updater_version () {
 | 
				
			|||||||
# Update updater.sh
 | 
					# Update updater.sh
 | 
				
			||||||
# Default: Check for update, if available, ask user if they want to execute it
 | 
					# Default: Check for update, if available, ask user if they want to execute it
 | 
				
			||||||
# Args:
 | 
					# Args:
 | 
				
			||||||
#   -donotupdate: New version will not be looked for and update will not occur
 | 
					#   -d: New version will not be looked for and update will not occur
 | 
				
			||||||
#   -update: Check for update, if available, execute without asking
 | 
					#   -u: Check for update, if available, execute without asking
 | 
				
			||||||
update_updater () {
 | 
					update_updater () {
 | 
				
			||||||
  if [ $UPDATE = 'no' ]; then
 | 
					  if [ $UPDATE = 'no' ]; then
 | 
				
			||||||
    return 0 # User signified not to check for updates
 | 
					    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}"
 | 
					      echo -e "There is a newer version of updater.sh available. ${RED}Update and execute Y/N?${NC}"
 | 
				
			||||||
      read -p "" -n 1 -r
 | 
					      read -p "" -n 1 -r
 | 
				
			||||||
      echo -e "\n\n"
 | 
					      echo -e "\n\n"
 | 
				
			||||||
      if [[ $REPLY =~ ^[Nn]$ ]]; then
 | 
					      [[ $REPLY =~ ^[Nn]$ ]] && return 0 # Update available, but user chooses not to update
 | 
				
			||||||
        return 0 # Update available, but user chooses not to update
 | 
					 | 
				
			||||||
      fi
 | 
					 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    return 0 # No update available
 | 
					    return 0 # No update available
 | 
				
			||||||
@@ -238,11 +228,7 @@ update_updater () {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Returns version number of a user.js file
 | 
					# Returns version number of a user.js file
 | 
				
			||||||
get_userjs_version () {
 | 
					get_userjs_version () {
 | 
				
			||||||
  if [ -e $1 ]; then
 | 
					  [ -e $1 ] && echo "$(sed -n '4p' "$1")" || echo "Not detected."
 | 
				
			||||||
    echo "$(sed -n '4p' "$1")"
 | 
					 | 
				
			||||||
  else
 | 
					 | 
				
			||||||
    echo "Not detected."
 | 
					 | 
				
			||||||
  fi
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_override () {
 | 
					add_override () {
 | 
				
			||||||
@@ -273,10 +259,10 @@ remove_comments () { # expects 2 arguments: from-file and to-file
 | 
				
			|||||||
update_userjs () {
 | 
					update_userjs () {
 | 
				
			||||||
  declare -r newfile=$(download_file 'https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js')
 | 
					  declare -r newfile=$(download_file 'https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  echo 'Please observe the following information:'
 | 
					  echo -e "Please observe the following information:
 | 
				
			||||||
  echo -e "\tFirefox profile:  ${ORANGE}$(pwd)${NC}"
 | 
					    Firefox profile:  ${ORANGE}$(pwd)${NC}
 | 
				
			||||||
  echo -e "\tAvailable online: ${ORANGE}$(get_userjs_version $newfile)${NC}"
 | 
					    Available online: ${ORANGE}$(get_userjs_version $newfile)${NC}
 | 
				
			||||||
  echo -e "\tCurrently using:  ${ORANGE}$(get_userjs_version user.js)\n${NC}\n"
 | 
					    Currently using:  ${ORANGE}$(get_userjs_version user.js)${NC}\n\n"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if [ $CONFIRM = 'yes' ]; then
 | 
					  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}"
 | 
					    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
 | 
					  # backup user.js
 | 
				
			||||||
  mkdir -p userjs_backups
 | 
					  mkdir -p userjs_backups
 | 
				
			||||||
  local bakname="userjs_backups/user.js.backup.$(date +"%Y-%m-%d_%H%M")"
 | 
					  local bakname="userjs_backups/user.js.backup.$(date +"%Y-%m-%d_%H%M")"
 | 
				
			||||||
  if [ $BACKUP = 'single' ]; then
 | 
					  [ $BACKUP = 'single' ] && bakname='userjs_backups/user.js.backup'
 | 
				
			||||||
    bakname='userjs_backups/user.js.backup'
 | 
					 | 
				
			||||||
  fi
 | 
					 | 
				
			||||||
  cp user.js "$bakname" &>/dev/null
 | 
					  cp user.js "$bakname" &>/dev/null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  mv "${newfile}" user.js
 | 
					  mv "${newfile}" user.js
 | 
				
			||||||
@@ -336,14 +320,12 @@ update_userjs () {
 | 
				
			|||||||
      echo -e "Status: ${GREEN}A diff file was created:${NC} ${PWD}/${diffname}"
 | 
					      echo -e "Status: ${GREEN}A diff file was created:${NC} ${PWD}/${diffname}"
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      echo -e "Warning: ${ORANGE}Your new user.js file appears to be identical.  No diff file was created.${NC}"
 | 
					      echo -e "Warning: ${ORANGE}Your new user.js file appears to be identical.  No diff file was created.${NC}"
 | 
				
			||||||
      if [ $BACKUP = 'multiple' ]; then
 | 
					      [ $BACKUP = 'multiple' ] && rm $bakname &>/dev/null
 | 
				
			||||||
        rm $bakname &>/dev/null
 | 
					 | 
				
			||||||
      fi
 | 
					 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
    rm $past_nocomments $current_nocomments $pastuserjs &>/dev/null
 | 
					    rm $past_nocomments $current_nocomments $pastuserjs &>/dev/null
 | 
				
			||||||
  fi
 | 
					  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
 | 
					  # Display usage if first argument is -help or --help
 | 
				
			||||||
  if [ $1 = '--help' ] || [ $1 = '-help' ]; then
 | 
					  if [ $1 = '--help' ] || [ $1 = '-help' ]; then
 | 
				
			||||||
    usage
 | 
					    usage
 | 
				
			||||||
  elif [ $legacy_lc = '-donotupdate' ]; then
 | 
					 | 
				
			||||||
    UPDATE='no'
 | 
					 | 
				
			||||||
    legacy_argument $1
 | 
					 | 
				
			||||||
  elif [ $legacy_lc = '-update' ]; then
 | 
					 | 
				
			||||||
    UPDATE='yes'
 | 
					 | 
				
			||||||
    legacy_argument $1
 | 
					 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    while getopts ":hp:ludsno:bcvre" opt; do
 | 
					    while getopts ":hp:ludsno:bcvre" opt; do
 | 
				
			||||||
      case $opt in
 | 
					      case $opt in
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user