mirror of
https://github.com/arkenfox/user.js.git
synced 2025-05-23 09:07:11 +02:00
Move prefsCleaner.sh closer to POSIX
and make note of things that don't follow POSIX.
This commit is contained in:
parent
4ff931781a
commit
1e3cbb3cd1
1 changed files with 103 additions and 76 deletions
171
prefsCleaner.sh
171
prefsCleaner.sh
|
@ -1,114 +1,141 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
## prefs.js cleaner for Linux/Mac
|
## prefs.js cleaner for *nix (mostly POSIX) like systems
|
||||||
## author: @claustromaniac
|
## author: @claustromaniac
|
||||||
## version: 1.4
|
## version: 1.5
|
||||||
|
|
||||||
## special thanks to @overdodactyl and @earthlng for a few snippets that I stol..*cough* borrowed from the updater.sh
|
## Special thanks to @overdodactyl and @earthlng for a few snippets that
|
||||||
|
## I stol..*cough* borrowed from the updater.sh
|
||||||
|
|
||||||
currdir=$(pwd)
|
currdir=$(pwd)
|
||||||
|
|
||||||
## get the full path of this script (readlink for Linux, greadlink for Mac with coreutils installed)
|
# Get the full path of this script
|
||||||
sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null)
|
# readlink for systems that have it,
|
||||||
|
# greadlink for Mac with coreutils installed.
|
||||||
|
# Note: If you source (.) this script, "$0" will
|
||||||
|
# show the invoking shell instead of the path.
|
||||||
|
# readlink/greadlink is not POSIX.
|
||||||
|
ffpdir=$(readlink -f "$0" 2>/dev/null || greadlink -f "$0" 2>/dev/null)
|
||||||
|
|
||||||
## fallback for Macs without coreutils
|
# Fallback for Macs without coreutils
|
||||||
if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi
|
if [ -z "${ffpdir}" ]; then ffpdir="$0"; fi
|
||||||
|
|
||||||
## change directory to the Firefox profile directory
|
# Change directory to the Firefox profile directory
|
||||||
cd "$(dirname "${sfp}")"
|
cd "$(dirname "${ffpdir}")" || exit 1
|
||||||
|
|
||||||
fQuit() {
|
fQuit() {
|
||||||
## change directory back to the original working directory
|
# Change directory back to the original working directory.
|
||||||
cd "${currdir}"
|
cd "${currdir}" || exit 1
|
||||||
[ "$1" -eq 0 ] && echo -e "\n$2" || echo -e "\n$2" >&2
|
[ "$1" -eq 0 ] && printf "%s\n" "$2" || printf "%s\n" "$2" >&2
|
||||||
exit $1
|
exit "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
fUsage() {
|
fUsage() {
|
||||||
echo -e "\nUsage: $0 [-s]"
|
printf "
|
||||||
echo -e "
|
Usage: %s [-s]
|
||||||
|
|
||||||
Optional Arguments:
|
Optional Arguments:
|
||||||
-s Start immediately"
|
-s Start immediately\n" "$0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fUsage_Help() {
|
||||||
|
printf "%s\n\n" "
|
||||||
|
This script creates a backup of your prefs.js file before doing anything.
|
||||||
|
It should be safe, but you can follow these steps if something goes wrong:
|
||||||
|
|
||||||
|
1. Make sure Firefox is closed.
|
||||||
|
2. Delete prefs.js in your profile folder.
|
||||||
|
3. Delete Invalidprefs.js if you have one in the same folder.
|
||||||
|
4. Rename or copy your latest backup to 'prefs.js'.
|
||||||
|
5. Run Firefox and see if you notice anything wrong with it.
|
||||||
|
6. If you do notice something wrong, especially with your extensions,
|
||||||
|
and/or with the UI, go to about:support, and restart Firefox with
|
||||||
|
add-ons disabled. Then, restart it again normally, and see if the
|
||||||
|
problems were solved.
|
||||||
|
If you are able to identify the cause of your issues, please bring it up
|
||||||
|
on the arkenfox user.js GitHub repository:
|
||||||
|
https://github.com/arkenfox/user.js"
|
||||||
|
}
|
||||||
|
|
||||||
|
# There are many ways to see if firefox is running or not, some more
|
||||||
|
# reliable than others. This isn't elegant and might not be
|
||||||
|
# future-proof but should at least be compatible with any environment.
|
||||||
fFF_check() {
|
fFF_check() {
|
||||||
# there are many ways to see if firefox is running or not, some more reliable than others
|
while [ -e cookies.sqlite-wal ] || \
|
||||||
# this isn't elegant and might not be future-proof but should at least be compatible with any environment
|
[ -e favicons.sqlite-wal ] || \
|
||||||
while [ -e lock ]; do
|
[ -e lock ] || \
|
||||||
echo -e "\nThis Firefox profile seems to be in use. Close Firefox and try again.\n" >&2
|
[ -e places.sqlite-wal ]
|
||||||
read -r -p "Press any key to continue."
|
do
|
||||||
|
printf "\nThis Firefox profile seems to be in use. Close Firefox and try again.\n" >&2
|
||||||
|
printf "Press Enter to continue."
|
||||||
|
read -r
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
fClean() {
|
fClean() {
|
||||||
# the magic happens here
|
# The 2nd "grep" is to get the pref surrounded by <"> (2nd <">
|
||||||
prefs="@@"
|
# is followed by <,> so it matches the pref name part). The
|
||||||
prefexp="user_pref[ ]*\([ ]*[\"']([^\"']+)[\"'][ ]*,"
|
# reason we do this is so when we run against "$bakfile" we
|
||||||
while read -r line; do
|
# won't hit other prefs modified by the user with the same base.
|
||||||
if [[ "$line" =~ $prefexp && $prefs != *"@@${BASH_REMATCH[1]}@@"* ]]; then
|
# ie:
|
||||||
prefs="${prefs}${BASH_REMATCH[1]}@@"
|
# accessibility.typeaheadfind = accessibility.typeaheadfind.flashBar
|
||||||
fi
|
# "accessibility.typeaheadfind" != accessibility.typeaheadfind.flashBar
|
||||||
done <<< "$(grep -E "$prefexp" user.js)"
|
# Note: "grep -o" is not POSIX
|
||||||
|
trackedprefs="$(grep -oE "user_pref[ ]*\([ ]*[\"'][^\"']+[\"'][ ]*,.*\);" user.js | grep -o '".*",')"
|
||||||
|
|
||||||
while IFS='' read -r line || [[ -n "$line" ]]; do
|
# "$1" is "$bakfile"
|
||||||
if [[ "$line" =~ ^$prefexp ]]; then
|
grep -vF "$trackedprefs" "$1" > prefs.js
|
||||||
if [[ $prefs != *"@@${BASH_REMATCH[1]}@@"* ]]; then
|
|
||||||
echo "$line"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "$line"
|
|
||||||
fi
|
|
||||||
done < "$1" > prefs.js
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fStart() {
|
fStart() {
|
||||||
if [ ! -e user.js ]; then
|
if [ ! -e user.js ]
|
||||||
|
then
|
||||||
fQuit 1 "user.js not found in the current directory."
|
fQuit 1 "user.js not found in the current directory."
|
||||||
elif [ ! -e prefs.js ]; then
|
elif [ ! -e prefs.js ]
|
||||||
|
then
|
||||||
fQuit 1 "prefs.js not found in the current directory."
|
fQuit 1 "prefs.js not found in the current directory."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fFF_check
|
fFF_check
|
||||||
bakfile="prefs.js.backup.$(date +"%Y-%m-%d_%H%M")"
|
bakfile="prefs.js.$(date +"%Y-%m-%d_%H%M")"
|
||||||
mv prefs.js "${bakfile}" || fQuit 1 "Operation aborted.\nReason: Could not create backup file $bakfile"
|
mv prefs.js "${bakfile}" || fQuit 1 "Operation aborted.
|
||||||
echo -e "\nprefs.js backed up: $bakfile"
|
Reason: Could not create backup file: $bakfile"
|
||||||
echo "Cleaning prefs.js..."
|
printf "prefs.js backed up as: %s\n" "$bakfile"
|
||||||
|
printf "Cleaning prefs.js...\n"
|
||||||
fClean "$bakfile"
|
fClean "$bakfile"
|
||||||
fQuit 0 "All done!"
|
fQuit 0 "All done!"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo -e "\n\n"
|
printf "
|
||||||
echo " ╔══════════════════════════╗"
|
|
||||||
echo " ║ prefs.js cleaner ║"
|
|
||||||
echo " ║ by claustromaniac ║"
|
|
||||||
echo " ║ v1.4 ║"
|
|
||||||
echo " ╚══════════════════════════╝"
|
|
||||||
echo -e "\nThis script should be run from your Firefox profile directory.\n"
|
|
||||||
echo "It will remove any entries from prefs.js that also exist in user.js."
|
|
||||||
echo "This will allow inactive preferences to be reset to their default values."
|
|
||||||
echo -e "\nThis Firefox profile shouldn't be in use during the process.\n"
|
|
||||||
|
|
||||||
[ "$1" == '-s' ] && fStart
|
|
||||||
|
|
||||||
select option in Start Help Exit; do
|
╔══════════════════════════╗
|
||||||
case $option in
|
║ prefs.js cleaner ║
|
||||||
Start)
|
║ by claustromaniac ║
|
||||||
|
║ v1.5 ║
|
||||||
|
╚══════════════════════════╝
|
||||||
|
|
||||||
|
This script should be run from your Firefox profile directory.
|
||||||
|
|
||||||
|
It will remove any entries from prefs.js that also exist in user.js.
|
||||||
|
This will allow inactive preferences to be reset to their default values.
|
||||||
|
|
||||||
|
This Firefox profile shouldn't be in use during the process.\n\n"
|
||||||
|
|
||||||
|
[ "$1" = '-s' ] && fStart
|
||||||
|
|
||||||
|
while printf "1) Start\n2) Help\n3) Exit\n#? "; read -r option
|
||||||
|
do
|
||||||
|
case "$option" in
|
||||||
|
1 | start | Start)
|
||||||
fStart
|
fStart
|
||||||
;;
|
;;
|
||||||
Help)
|
3 | exit | Exit)
|
||||||
fUsage
|
|
||||||
echo -e "\nThis script creates a backup of your prefs.js file before doing anything."
|
|
||||||
echo -e "It should be safe, but you can follow these steps if something goes wrong:\n"
|
|
||||||
echo "1. Make sure Firefox is closed."
|
|
||||||
echo "2. Delete prefs.js in your profile folder."
|
|
||||||
echo "3. Delete Invalidprefs.js if you have one in the same folder."
|
|
||||||
echo "4. Rename or copy your latest backup to prefs.js."
|
|
||||||
echo "5. Run Firefox and see if you notice anything wrong with it."
|
|
||||||
echo "6. If you do notice something wrong, especially with your extensions, and/or with the UI, go to about:support, and restart Firefox with add-ons disabled. Then, restart it again normally, and see if the problems were solved."
|
|
||||||
echo -e "If you are able to identify the cause of your issues, please bring it up on the arkenfox user.js GitHub repository.\n"
|
|
||||||
;;
|
|
||||||
Exit)
|
|
||||||
fQuit 0
|
fQuit 0
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
fUsage
|
||||||
|
fUsage_Help
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue