Simple maintenance improvements (#1255)
* Use direct check for existence of file * Fix shellcheck warnings * Unify codestyle in scripts * Trim excess whitespace
This commit is contained in:
parent
b37df0bcfe
commit
5cdea955e7
@ -23,5 +23,3 @@ Also be aware that the `arkenfox user.js` is made specifically for desktop Firef
|
|||||||
|
|
||||||
### 🟥 acknowledgments
|
### 🟥 acknowledgments
|
||||||
Literally thousands of sources, references and suggestions. Many thanks, and much appreciated.
|
Literally thousands of sources, references and suggestions. Many thanks, and much appreciated.
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ cd "$(dirname "${sfp}")"
|
|||||||
fQuit() {
|
fQuit() {
|
||||||
## change directory back to the original working directory
|
## change directory back to the original working directory
|
||||||
cd "${currdir}"
|
cd "${currdir}"
|
||||||
[ $1 -eq 0 ] && echo -e "\n$2" || echo -e "\n$2" >&2
|
[ "$1" -eq 0 ] && echo -e "\n$2" || echo -e "\n$2" >&2
|
||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ fFF_check() {
|
|||||||
# this isn't elegant and might not be future-proof but should at least be compatible with any environment
|
# this isn't elegant and might not be future-proof but should at least be compatible with any environment
|
||||||
while [ -e lock ]; do
|
while [ -e lock ]; do
|
||||||
echo -e "\nThis Firefox profile seems to be in use. Close Firefox and try again.\n" >&2
|
echo -e "\nThis Firefox profile seems to be in use. Close Firefox and try again.\n" >&2
|
||||||
read -p "Press any key to continue."
|
read -r -p "Press any key to continue."
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ fClean() {
|
|||||||
if [[ "$line" =~ $prefexp && $prefs != *"@@${BASH_REMATCH[1]}@@"* ]]; then
|
if [[ "$line" =~ $prefexp && $prefs != *"@@${BASH_REMATCH[1]}@@"* ]]; then
|
||||||
prefs="${prefs}${BASH_REMATCH[1]}@@"
|
prefs="${prefs}${BASH_REMATCH[1]}@@"
|
||||||
fi
|
fi
|
||||||
done <<< "`grep -E \"$prefexp\" user.js`"
|
done <<< "$(grep -E \"$prefexp\" user.js)"
|
||||||
|
|
||||||
while IFS='' read -r line || [[ -n "$line" ]]; do
|
while IFS='' read -r line || [[ -n "$line" ]]; do
|
||||||
if [[ "$line" =~ ^$prefexp ]]; then
|
if [[ "$line" =~ ^$prefexp ]]; then
|
||||||
|
@ -69,4 +69,3 @@
|
|||||||
return 'all done';
|
return 'all done';
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*** arkenfox user.js troubleshooter.js v1.6.3 ***/
|
/*** arkenfox user.js troubleshooter.js v1.6.3 ***/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
62
updater.sh
62
updater.sh
@ -41,9 +41,9 @@ ESR=false
|
|||||||
|
|
||||||
# Download method priority: curl -> wget
|
# Download method priority: curl -> wget
|
||||||
DOWNLOAD_METHOD=''
|
DOWNLOAD_METHOD=''
|
||||||
if [[ $(command -v 'curl') ]]; then
|
if command -v curl >/dev/null; then
|
||||||
DOWNLOAD_METHOD='curl --max-redirs 3 -so'
|
DOWNLOAD_METHOD='curl --max-redirs 3 -so'
|
||||||
elif [[ $(command -v 'wget') ]]; then
|
elif command -v wget >/dev/null; then
|
||||||
DOWNLOAD_METHOD='wget --max-redirect 3 --quiet -O'
|
DOWNLOAD_METHOD='wget --max-redirect 3 --quiet -O'
|
||||||
else
|
else
|
||||||
echo -e "${RED}This script requires curl or wget.\nProcess aborted${NC}"
|
echo -e "${RED}This script requires curl or wget.\nProcess aborted${NC}"
|
||||||
@ -51,7 +51,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
show_banner () {
|
show_banner() {
|
||||||
echo -e "${BBLUE}
|
echo -e "${BBLUE}
|
||||||
############################################################################
|
############################################################################
|
||||||
#### ####
|
#### ####
|
||||||
@ -103,13 +103,13 @@ Optional Arguments:
|
|||||||
# File Handling #
|
# File Handling #
|
||||||
#########################
|
#########################
|
||||||
|
|
||||||
download_file () { # expects URL as argument ($1)
|
download_file() { # expects URL as argument ($1)
|
||||||
declare -r tf=$(mktemp)
|
declare -r tf=$(mktemp)
|
||||||
|
|
||||||
$DOWNLOAD_METHOD "${tf}" "$1" && echo "$tf" || echo '' # return the temp-filename or empty string on error
|
$DOWNLOAD_METHOD "${tf}" "$1" && echo "$tf" || echo '' # return the temp-filename or empty string on error
|
||||||
}
|
}
|
||||||
|
|
||||||
open_file () { # expects one argument: file_path
|
open_file() { # expects one argument: file_path
|
||||||
if [ "$(uname)" == 'Darwin' ]; then
|
if [ "$(uname)" == 'Darwin' ]; then
|
||||||
open "$1"
|
open "$1"
|
||||||
elif [ "$(uname -s | cut -c -5)" == "Linux" ]; then
|
elif [ "$(uname -s | cut -c -5)" == "Linux" ]; then
|
||||||
@ -119,11 +119,11 @@ open_file () { # expects one argument: file_path
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
readIniFile () { # expects one argument: absolute path of profiles.ini
|
readIniFile() { # expects one argument: absolute path of profiles.ini
|
||||||
declare -r inifile="$1"
|
declare -r inifile="$1"
|
||||||
|
|
||||||
# tempIni will contain: [ProfileX], Name=, IsRelative= and Path= (and Default= if present) of the only (if) or the selected (else) profile
|
# 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
|
if [ "$(grep -c '^\[Profile' "${inifile}")" -eq "1" ]; then ### only 1 profile found
|
||||||
tempIni="$(grep '^\[Profile' -A 4 "${inifile}")"
|
tempIni="$(grep '^\[Profile' -A 4 "${inifile}")"
|
||||||
else
|
else
|
||||||
echo -e "Profiles found:\n––––––––––––––––––––––––––––––"
|
echo -e "Profiles found:\n––––––––––––––––––––––––––––––"
|
||||||
@ -150,7 +150,7 @@ readIniFile () { # expects one argument: absolute path of profiles.ini
|
|||||||
[[ ${pathisrel} == "1" ]] && PROFILE_PATH="$(dirname "${inifile}")/${PROFILE_PATH}"
|
[[ ${pathisrel} == "1" ]] && PROFILE_PATH="$(dirname "${inifile}")/${PROFILE_PATH}"
|
||||||
}
|
}
|
||||||
|
|
||||||
getProfilePath () {
|
getProfilePath() {
|
||||||
declare -r f1=~/Library/Application\ Support/Firefox/profiles.ini
|
declare -r f1=~/Library/Application\ Support/Firefox/profiles.ini
|
||||||
declare -r f2=~/.mozilla/firefox/profiles.ini
|
declare -r f2=~/.mozilla/firefox/profiles.ini
|
||||||
|
|
||||||
@ -175,8 +175,8 @@ getProfilePath () {
|
|||||||
#########################
|
#########################
|
||||||
|
|
||||||
# Returns the version number of a updater.sh file
|
# Returns the version number of a updater.sh file
|
||||||
get_updater_version () {
|
get_updater_version() {
|
||||||
echo $(sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p' "$1")
|
echo "$(sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p' "$1")"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update updater.sh
|
# Update updater.sh
|
||||||
@ -184,14 +184,14 @@ get_updater_version () {
|
|||||||
# Args:
|
# Args:
|
||||||
# -d: 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
|
||||||
# -u: Check for update, if available, execute without asking
|
# -u: Check for update, if available, execute without asking
|
||||||
update_updater () {
|
update_updater() {
|
||||||
[ $UPDATE = 'no' ] && return 0 # User signified not to check for updates
|
[ "$UPDATE" = 'no' ] && return 0 # User signified not to check for updates
|
||||||
|
|
||||||
declare -r tmpfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/updater.sh')"
|
declare -r tmpfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/updater.sh')"
|
||||||
[ -z "${tmpfile}" ] && echo -e "${RED}Error! Could not download updater.sh${NC}" && return 1 # check if download failed
|
[ -z "${tmpfile}" ] && echo -e "${RED}Error! Could not download updater.sh${NC}" && return 1 # check if download failed
|
||||||
|
|
||||||
if [[ $(get_updater_version "$SCRIPT_FILE") < $(get_updater_version "${tmpfile}") ]]; then
|
if [[ $(get_updater_version "$SCRIPT_FILE") < $(get_updater_version "${tmpfile}") ]]; then
|
||||||
if [ $UPDATE = 'check' ]; then
|
if [ "$UPDATE" = 'check' ]; then
|
||||||
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"
|
||||||
@ -211,11 +211,11 @@ update_updater () {
|
|||||||
#########################
|
#########################
|
||||||
|
|
||||||
# Returns version number of a user.js file
|
# Returns version number of a user.js file
|
||||||
get_userjs_version () {
|
get_userjs_version() {
|
||||||
[ -e $1 ] && echo "$(sed -n '4p' "$1")" || echo "Not detected."
|
[ -e "$1" ] && echo "$(sed -n '4p' "$1")" || echo "Not detected."
|
||||||
}
|
}
|
||||||
|
|
||||||
add_override () {
|
add_override() {
|
||||||
input=$1
|
input=$1
|
||||||
if [ -f "$input" ]; then
|
if [ -f "$input" ]; then
|
||||||
echo "" >> user.js
|
echo "" >> user.js
|
||||||
@ -235,27 +235,27 @@ add_override () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_comments () { # expects 2 arguments: from-file and to-file
|
remove_comments() { # expects 2 arguments: from-file and to-file
|
||||||
sed -e '/^\/\*.*\*\/[[:space:]]*$/d' -e '/^\/\*/,/\*\//d' -e 's|^[[:space:]]*//.*$||' -e '/^[[:space:]]*$/d' -e 's|);[[:space:]]*//.*|);|' "$1" > "$2"
|
sed -e '/^\/\*.*\*\/[[:space:]]*$/d' -e '/^\/\*/,/\*\//d' -e 's|^[[:space:]]*//.*$||' -e '/^[[:space:]]*$/d' -e 's|);[[:space:]]*//.*|);|' "$1" > "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Applies latest version of user.js and any custom overrides
|
# Applies latest version of user.js and any custom overrides
|
||||||
update_userjs () {
|
update_userjs() {
|
||||||
declare -r newfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/user.js')"
|
declare -r newfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/user.js')"
|
||||||
[ -z "${newfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && return 1 # check if download failed
|
[ -z "${newfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && return 1 # check if download failed
|
||||||
|
|
||||||
echo -e "Please observe the following information:
|
echo -e "Please observe the following information:
|
||||||
Firefox profile: ${ORANGE}$(pwd)${NC}
|
Firefox profile: ${ORANGE}$(pwd)${NC}
|
||||||
Available online: ${ORANGE}$(get_userjs_version $newfile)${NC}
|
Available online: ${ORANGE}$(get_userjs_version "$newfile")${NC}
|
||||||
Currently using: ${ORANGE}$(get_userjs_version user.js)${NC}\n\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}"
|
||||||
read -p "" -n 1 -r
|
read -p "" -n 1 -r
|
||||||
echo -e "\n"
|
echo -e "\n"
|
||||||
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||||
echo -e "${RED}Process aborted${NC}"
|
echo -e "${RED}Process aborted${NC}"
|
||||||
rm $newfile
|
rm "$newfile"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -269,7 +269,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")"
|
||||||
[ $BACKUP = 'single' ] && bakname='userjs_backups/user.js.backup'
|
[ "$BACKUP" = 'single' ] && bakname='userjs_backups/user.js.backup'
|
||||||
cp user.js "$bakname" &>/dev/null
|
cp user.js "$bakname" &>/dev/null
|
||||||
|
|
||||||
mv "${newfile}" user.js
|
mv "${newfile}" user.js
|
||||||
@ -295,19 +295,19 @@ update_userjs () {
|
|||||||
past_nocomments='userjs_diffs/past_userjs.txt'
|
past_nocomments='userjs_diffs/past_userjs.txt'
|
||||||
current_nocomments='userjs_diffs/current_userjs.txt'
|
current_nocomments='userjs_diffs/current_userjs.txt'
|
||||||
|
|
||||||
remove_comments $pastuserjs $past_nocomments
|
remove_comments "$pastuserjs" "$past_nocomments"
|
||||||
remove_comments user.js $current_nocomments
|
remove_comments user.js "$current_nocomments"
|
||||||
|
|
||||||
diffname="userjs_diffs/diff_$(date +"%Y-%m-%d_%H%M").txt"
|
diffname="userjs_diffs/diff_$(date +"%Y-%m-%d_%H%M").txt"
|
||||||
diff=$(diff -w -B -U 0 $past_nocomments $current_nocomments)
|
diff=$(diff -w -B -U 0 "$past_nocomments" "$current_nocomments")
|
||||||
if [ ! -z "$diff" ]; then
|
if [ -n "$diff" ]; then
|
||||||
echo "$diff" > "$diffname"
|
echo "$diff" > "$diffname"
|
||||||
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}"
|
||||||
[ $BACKUP = 'multiple' ] && rm $bakname &>/dev/null
|
[ "$BACKUP" = 'multiple' ] && rm "$bakname" &>/dev/null
|
||||||
fi
|
fi
|
||||||
rm $past_nocomments $current_nocomments $pastuserjs &>/dev/null
|
rm "$past_nocomments" "$current_nocomments" "$pastuserjs" &>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ "$VIEW" = true ] && open_file "${PWD}/user.js"
|
[ "$VIEW" = true ] && open_file "${PWD}/user.js"
|
||||||
@ -319,7 +319,7 @@ update_userjs () {
|
|||||||
|
|
||||||
if [ $# != 0 ]; then
|
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
|
||||||
else
|
else
|
||||||
while getopts ":hp:ludsno:bcvre" opt; do
|
while getopts ":hp:ludsno:bcvre" opt; do
|
||||||
@ -363,7 +363,7 @@ if [ $# != 0 ]; then
|
|||||||
r)
|
r)
|
||||||
tfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/user.js')"
|
tfile="$(download_file 'https://raw.githubusercontent.com/arkenfox/user.js/master/user.js')"
|
||||||
[ -z "${tfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && exit 1 # check if download failed
|
[ -z "${tfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && exit 1 # check if download failed
|
||||||
mv $tfile "${tfile}.js"
|
mv "$tfile" "${tfile}.js"
|
||||||
echo -e "${ORANGE}Warning: user.js was saved to temporary file ${tfile}.js${NC}"
|
echo -e "${ORANGE}Warning: user.js was saved to temporary file ${tfile}.js${NC}"
|
||||||
open_file "${tfile}.js"
|
open_file "${tfile}.js"
|
||||||
exit 0
|
exit 0
|
||||||
@ -382,7 +382,7 @@ if [ $# != 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
show_banner
|
show_banner
|
||||||
update_updater $@
|
update_updater "$@"
|
||||||
|
|
||||||
getProfilePath # updates PROFILE_PATH or exits on error
|
getProfilePath # updates PROFILE_PATH or exits on error
|
||||||
cd "$PROFILE_PATH" && update_userjs
|
cd "$PROFILE_PATH" && update_userjs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user