user.js
user.js copied to clipboard
updater.sh returns with exit code 0 when failing in update_userjs
updater.sh returns with exit code 0 when failing to download user.js file, for example, when no internet connection. The assumed result would be to return a non-zero exit code. This way, if the updater fails, one can retry after some time. One way to solve would be by explicitly returning 0 at the end of update_userjs function when it completes succesfully and calling update_userjs || exit 1 to exit when the update_userjs function returns non-zero value.
I'll let someone else who knows what they're doing handle this request/suggestion (earthlng usually pops in once a month)
There are already checks to handle this: https://github.com/arkenfox/user.js/blob/33a84b608c8a1f871c6ce9c4d2b932dc57078fae/updater.sh#L115 https://github.com/arkenfox/user.js/blob/33a84b608c8a1f871c6ce9c4d2b932dc57078fae/updater.sh#L250-L251
Please post the output you are getting @odhil
after disabling network connection...
$ ./updater.sh
############################################################################
#### ####
#### arkenfox user.js ####
#### Hardening the Privacy and Security Settings of Firefox ####
#### Maintained by @Thorin-Oakenpants and @earthlng ####
#### Updater for macOS and Linux by @overdodactyl ####
#### ####
############################################################################
Documentation for this script is available here: https://github.com/arkenfox/user.js/wiki/5.1-Updater-[Options]#-maclinux
Error! Could not download updater.sh
Error! Could not download user.js
[atom@atompc w6zte69z.default]$ echo $?
0
this is a problem if the script is run from another script
unrelated, but shellcheck says...
$ shellcheck -o all updater.sh
In updater.sh line 12:
if [ "${EUID:-"$(id -u)"}" -eq 0 ]; then
^-----------------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^---^ SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
Did you mean:
if [[ "${EUID:-"$(id -u)"}" -eq 0 ]]; then
In updater.sh line 17:
readonly CURRDIR=$(pwd)
^-----^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In updater.sh line 20:
[ -z "$SCRIPT_FILE" ] && SCRIPT_FILE=${BASH_SOURCE[0]}
^-------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^----------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
[[ -z "${SCRIPT_FILE}" ]] && SCRIPT_FILE=${BASH_SOURCE[0]}
In updater.sh line 21:
readonly SCRIPT_DIR=$(dirname "${SCRIPT_FILE}")
^--------^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In updater.sh line 115:
$DOWNLOAD_METHOD "${tf}" "$1" &>/dev/null && echo "$tf" || echo '' # return the temp-filename or empty string on error
^--------------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
^-^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
${DOWNLOAD_METHOD} "${tf}" "$1" &>/dev/null && echo "${tf}" || echo '' # return the temp-filename or empty string on error
In updater.sh line 119:
if [ "$(uname)" == 'Darwin' ]; then
^------------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^---^ SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
Did you mean:
if [[ "$(uname)" == 'Darwin' ]]; then
In updater.sh line 121:
elif [ "$(uname -s | cut -c -5)" == "Linux" ]; then
^-- SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^------^ SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
^-------^ SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
Did you mean:
elif [[ "$(uname -s | cut -c -5)" == "Linux" ]]; then
In updater.sh line 132:
if [ "$(grep -c '^\[Profile' "${inifile}")" -eq "1" ]; then ### only 1 profile found
^-- SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^-- SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
Did you mean:
if [[ "$(grep -c '^\[Profile' "${inifile}")" -eq "1" ]]; then ### only 1 profile found
In updater.sh line 137:
echo "$(grep --color=never -E 'Default=[^1]|\[Profile[0-9]*\]|Name=|Path=|^$' "${inifile}")"
^-- SC2005 (style): Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
^-- SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
In updater.sh line 141:
if [[ $REPLY =~ ^(0|[1-9][0-9]*)$ ]]; then
^----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if [[ ${REPLY} =~ ^(0|[1-9][0-9]*)$ ]]; then
In updater.sh line 163:
if [ "$PROFILE_PATH" = false ]; then
^-------------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^-----------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if [[ "${PROFILE_PATH}" = false ]]; then
In updater.sh line 164:
PROFILE_PATH="$SCRIPT_DIR"
^---------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
PROFILE_PATH="${SCRIPT_DIR}"
In updater.sh line 165:
elif [ "$PROFILE_PATH" = 'list' ]; then
^--------------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^-----------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
elif [[ "${PROFILE_PATH}" = 'list' ]]; then
In updater.sh line 166:
if [[ -f "$f1" ]]; then
^-^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if [[ -f "${f1}" ]]; then
In updater.sh line 167:
readIniFile "$f1" # updates PROFILE_PATH or exits on error
^-^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
readIniFile "${f1}" # updates PROFILE_PATH or exits on error
In updater.sh line 168:
elif [[ -f "$f2" ]]; then
^-^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
elif [[ -f "${f2}" ]]; then
In updater.sh line 169:
readIniFile "$f2"
^-^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
readIniFile "${f2}"
In updater.sh line 185:
echo "$(sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p' "$1")"
^-- SC2005 (style): Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
^-- SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
In updater.sh line 194:
[ "$UPDATE" = 'no' ] && return 0 # User signified not to check for updates
^------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^-----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
[[ "${UPDATE}" = 'no' ]] && return 0 # User signified not to check for updates
In updater.sh line 197:
[ -z "${tmpfile}" ] && echo -e "${RED}Error! Could not download updater.sh${NC}" && return 1 # check if download failed
^-----------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
Did you mean:
[[ -z "${tmpfile}" ]] && echo -e "${RED}Error! Could not download updater.sh${NC}" && return 1 # check if download failed
In updater.sh line 199:
if [[ $(get_updater_version "$SCRIPT_FILE") < $(get_updater_version "${tmpfile}") ]]; then
^-- SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
^----------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
^-- SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
Did you mean:
if [[ $(get_updater_version "${SCRIPT_FILE}") < $(get_updater_version "${tmpfile}") ]]; then
In updater.sh line 200:
if [ "$UPDATE" = 'check' ]; then
^---------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^-----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if [[ "${UPDATE}" = 'check' ]]; then
In updater.sh line 204:
[[ $REPLY =~ ^[Yy]$ ]] || return 0 # Update available, but user chooses not to update
^----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
[[ ${REPLY} =~ ^[Yy]$ ]] || return 0 # Update available, but user chooses not to update
In updater.sh line 209:
mv "${tmpfile}" "$SCRIPT_FILE"
^----------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
mv "${tmpfile}" "${SCRIPT_FILE}"
In updater.sh line 210:
chmod u+x "$SCRIPT_FILE"
^----------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
chmod u+x "${SCRIPT_FILE}"
In updater.sh line 211:
"$SCRIPT_FILE" "$@" -d
^----------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
"${SCRIPT_FILE}" "$@" -d
In updater.sh line 221:
[ -e "$1" ] && echo "$(sed -n '4p' "$1")" || echo "Not detected."
^---------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^-------------------^ SC2005 (style): Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
^--------------^ SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
Did you mean:
[[ -e "$1" ]] && echo "$(sed -n '4p' "$1")" || echo "Not detected."
In updater.sh line 226:
if [ -f "$input" ]; then
^-------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if [[ -f "${input}" ]]; then
In updater.sh line 228:
cat "$input" >> user.js
^----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
cat "${input}" >> user.js
In updater.sh line 230:
elif [ -d "$input" ]; then
^-------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
elif [[ -d "${input}" ]]; then
In updater.sh line 231:
SAVEIFS=$IFS
^--^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
SAVEIFS=${IFS}
In updater.sh line 233:
FILES="${input}"/*.js
^-------------^ SC2125 (warning): Brace expansions and globs are literal in assignments. Quote it or use an array.
In updater.sh line 234:
for f in $FILES
^----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
for f in ${FILES}
In updater.sh line 236:
add_override "$f"
^-- SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
add_override "${f}"
In updater.sh line 238:
IFS=$SAVEIFS # restore $IFS
^------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
IFS=${SAVEIFS} # restore $IFS
In updater.sh line 251:
[ -z "${newfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && return 1 # check if download failed
^-----------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
Did you mean:
[[ -z "${newfile}" ]] && echo -e "${RED}Error! Could not download user.js${NC}" && return 1 # check if download failed
In updater.sh line 254:
Firefox profile: ${ORANGE}$(pwd)${NC}
^-^ SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
In updater.sh line 255:
Available online: ${ORANGE}$(get_userjs_version "$newfile")${NC}
^---------------------------^ SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
^------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
Available online: ${ORANGE}$(get_userjs_version "${newfile}")${NC}
In updater.sh line 256:
Currently using: ${ORANGE}$(get_userjs_version user.js)${NC}\n\n"
^------------------------^ SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
In updater.sh line 258:
if [ "$CONFIRM" = 'yes' ]; then
^--------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if [[ "${CONFIRM}" = 'yes' ]]; then
In updater.sh line 262:
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
^----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if ! [[ ${REPLY} =~ ^[Yy]$ ]]; then
In updater.sh line 264:
rm "$newfile"
^------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
rm "${newfile}"
In updater.sh line 270:
if [ "$COMPARE" = true ]; then
^-------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if [[ "${COMPARE}" = true ]]; then
In updater.sh line 277:
local bakname="userjs_backups/user.js.backup.$(date +"%Y-%m-%d_%H%M")"
^-----^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In updater.sh line 278:
[ "$BACKUP" = 'single' ] && bakname='userjs_backups/user.js.backup'
^----------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^-----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
[[ "${BACKUP}" = 'single' ]] && bakname='userjs_backups/user.js.backup'
In updater.sh line 279:
cp user.js "$bakname" &>/dev/null
^------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
cp user.js "${bakname}" &>/dev/null
In updater.sh line 284:
if [ "$ESR" = true ]; then
^---------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^--^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if [[ "${ESR}" = true ]]; then
In updater.sh line 290:
if [ "$SKIPOVERRIDE" = false ]; then
^-------------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^-----------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if [[ "${SKIPOVERRIDE}" = false ]]; then
In updater.sh line 293:
add_override "$FILE"
^---^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
add_override "${FILE}"
In updater.sh line 295:
done <<< "$OVERRIDE"
^-------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
done <<< "${OVERRIDE}"
In updater.sh line 299:
if [ "$COMPARE" = true ]; then
^-------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if [[ "${COMPARE}" = true ]]; then
In updater.sh line 304:
remove_comments "$pastuserjs" "$past_nocomments"
^---------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
^--------------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
remove_comments "${pastuserjs}" "${past_nocomments}"
In updater.sh line 305:
remove_comments user.js "$current_nocomments"
^-----------------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
remove_comments user.js "${current_nocomments}"
In updater.sh line 308:
diff=$(diff -w -B -U 0 "$past_nocomments" "$current_nocomments")
^--------------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
^-----------------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
diff=$(diff -w -B -U 0 "${past_nocomments}" "${current_nocomments}")
In updater.sh line 309:
if [ -n "$diff" ]; then
^------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^---^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
if [[ -n "${diff}" ]]; then
In updater.sh line 310:
echo "$diff" > "$diffname"
^---^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
^-------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
echo "${diff}" > "${diffname}"
In updater.sh line 314:
[ "$BACKUP" = 'multiple' ] && rm "$bakname" &>/dev/null
^------------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^-----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
^------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
[[ "${BACKUP}" = 'multiple' ]] && rm "${bakname}" &>/dev/null
In updater.sh line 316:
rm "$past_nocomments" "$current_nocomments" "$pastuserjs" &>/dev/null
^--------------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
^-----------------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
^---------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
rm "${past_nocomments}" "${current_nocomments}" "${pastuserjs}" &>/dev/null
In updater.sh line 319:
[ "$VIEW" = true ] && open_file "${PWD}/user.js"
^----------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^---^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
[[ "${VIEW}" = true ]] && open_file "${PWD}/user.js"
In updater.sh line 326:
if [ $# != 0 ]; then
^---------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
Did you mean:
if [[ $# != 0 ]]; then
In updater.sh line 328:
if [ "$1" = '--help' ] || [ "$1" = '-help' ]; then
^-----------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^----------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
Did you mean:
if [[ "$1" = '--help' ]] || [[ "$1" = '-help' ]]; then
In updater.sh line 332:
case $opt in
^-- SC2249 (info): Consider adding a default *) case, even if it just exits with error.
^--^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
case ${opt} in
In updater.sh line 371:
[ -z "${tfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && exit 1 # check if download failed
^---------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
Did you mean:
[[ -z "${tfile}" ]] && echo -e "${RED}Error! Could not download user.js${NC}" && exit 1 # check if download failed
In updater.sh line 372:
mv "$tfile" "${tfile}.js"
^----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
mv "${tfile}" "${tfile}.js"
In updater.sh line 378:
echo -e "${RED}\n Error! Invalid option: -$OPTARG${NC}" >&2
^-----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
echo -e "${RED}\n Error! Invalid option: -${OPTARG}${NC}" >&2
In updater.sh line 382:
echo -e "${RED}Error! Option -$OPTARG requires an argument.${NC}" >&2
^-----^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
echo -e "${RED}Error! Option -${OPTARG} requires an argument.${NC}" >&2
In updater.sh line 394:
cd "$PROFILE_PATH" || exit 1
^-----------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
cd "${PROFILE_PATH}" || exit 1
In updater.sh line 397:
if [ -n "$(find ./ -user 0)" ]; then
^-------------------------^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
^-------------^ SC2312 (info): Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
Did you mean:
if [[ -n "$(find ./ -user 0)" ]]; then
In updater.sh line 401:
cd "$CURRDIR"
^-----------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
^------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
cd "${CURRDIR}" || exit
In updater.sh line 407:
cd "$CURRDIR"
^-----------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
^------^ SC2250 (style): Prefer putting braces around variable references even when not strictly required.
Did you mean:
cd "${CURRDIR}" || exit
For more information:
https://www.shellcheck.net/wiki/SC2125 -- Brace expansions and globs are li...
https://www.shellcheck.net/wiki/SC2155 -- Declare and assign separately to ...
https://www.shellcheck.net/wiki/SC2164 -- Use 'cd ... || exit' or 'cd ... |...
</details>
Please post the output you are getting @odhil
been over two months since requested and I consider this an (expected) edge case
I think I found the reason.
update_userjs function returns 1. this is OK.
But after that function, you also call another command ("cd" command) which returns 0. Here is the line:
https://github.com/arkenfox/user.js/blob/33a84b608c8a1f871c6ce9c4d2b932dc57078fae/updater.sh#L407
Shell scripts always return the last exit/return code. Therefore you got 0.
I will not open a pull request. Because I don't know why the script needs the "cd" command on the last phase.
As a temporary solution, you can can store the last-exit-code and return it:
update_userjs
LAST_EXIT_CODE="$?"
cd "$CURRDIR"
exit $LAST_EXIT_CODE
I already suggested a simpler fix in #1828. The last cd should be removed when the script is cleaned up but I wanted to keep the change simple.