foxtheme/foxtheme.sh

78 lines
2.6 KiB
Bash
Executable File

#!/bin/sh
SCRIPTLOCATION=$(dirname -- "$(readlink -f "$0")")
[ -d "$SCRIPTLOCATION" ] || { echo "$0: Could not verify script location as an existing directory. This is probably a bug."; exit 2; }
[ -d "$SCRIPTLOCATION"/chrome ] || { echo "$0: Could not proceed with installation as 'chrome' directory is missing from '$SCRIPTLOCATION'."; exit 2; }
[ -f "$SCRIPTLOCATION"/user.js ] || { echo "$0: Could not proceed with installation as 'user.js' file is missing from '$SCRIPTLOCATION'."; exit 2; }
helptext() {
echo "Usage: ./foxtheme.sh [OPTIONS] [PROFILE | -a PROFILESDIR] "
echo "-a Apply theme to all (current) browser profiles"
echo "-j Just create or modify user.js and not user-overrides.js"
echo "-o Remove and replace an existing theme if found"
echo "-h Display this help message"
}
installtoprofile() {
targetprofile="$1"
[ -d "$targetprofile" ] || { echo "$0: Profile at '$targetprofile' does not exist"; exit 2; }
[ -d "$targetprofile/chrome/" ] && {
[ "$OVERWRITE" ] || { echo "$0: A theme for this profile '${targetprofile}/chrome/' already exists. Pass -o to overwrite existing themes."; exit 2; }
rm -r "${targetprofile:?}/chrome/"
}
cp -r "${SCRIPTLOCATION}/chrome/" "${targetprofile}/"
cat "${SCRIPTLOCATION}/user.js" >> "${targetprofile:?}/user.js"
[ "$NOOVERRIDE" ] || cat "${SCRIPTLOCATION}/user.js" >> "${targetprofile:?}/user-overrides.js"
echo "Successfully installed to '${targetprofile}'"
}
while getopts "ajoh" opt; do
case $opt in
a)
ALL=1
;;
j)
NOOVERRIDE=1
;;
o)
OVERWRITE=1
;;
h)
helptext
exit
;;
*)
helptext
exit 2
;;
esac
done
[ -z "$*" ] && { helptext; exit; }
shift $((OPTIND -1))
[ "$2" ] && { echo "$0: Too many arguments"; helptext; exit 2; }
[ -d "$1" ] || { echo "$0: '$1' is not a valid directory"; helptext; exit 2; }
arg="$1"
if [ "$ALL" ]; then
profilesdir=$(realpath "$arg")
[ -f "$profilesdir"/installs.ini ] && [ -f "$profilesdir"/profiles.ini ] || { echo "$0: '$profilesdir' does not appear to be a valid Firefox (or derivative) profiles directory (could not find 'profiles.ini' or 'installs.ini'). Run without the -a option if you intended to apply the theme to only a single profile."; exit 2; }
IFS_=$IFS
IFS="
"
profiles=$(grep "^Path=" "$profilesdir/profiles.ini" | sed "s/^Path=//")
for profile in $profiles; do
installtoprofile "$profilesdir/$profile"
done
IFS=$IFS_
else
profile=$(realpath "$arg")
[ -f "$profile/times.json" ] || { echo "$0: '$profile' does not appear to be a valid Firefox (or derivative) profile directory (could not find 'times.json')."; exit 2; }
installtoprofile "$profile"
fi
echo "All done."