firefox-gnome-theme/scripts/install.sh

91 lines
2.4 KiB
Bash
Raw Normal View History

#!/bin/bash
THEMEDIRECTORY=$(cd `dirname $0` && cd .. && pwd)
2019-07-17 21:33:41 +03:00
FIREFOXFOLDER=~/.mozilla/firefox
PROFILENAME=""
THEME=DEFAULT
2019-07-12 19:07:20 +03:00
# Get options.
while getopts 'f:p:g:t:h' flag; do
case "${flag}" in
f) FIREFOXFOLDER="${OPTARG}" ;;
p) PROFILENAME="${OPTARG}" ;;
t) THEME="${OPTARG}" ;;
h)
echo "Gnome Theme Install Script:"
echo " -f <firefox_folder_path>. Set custom Firefox folder path."
echo " -p <profile_name>. Set custom profile name."
echo " -t <theme_name>. Set the colors used in the theme."
echo " -h to show this message."
exit 0
;;
esac
done
2020-10-23 02:39:57 +03:00
function saveProfile(){
cd $FIREFOXFOLDER/$PROFILE_PATH
echo "Installing theme in $PWD"
# Create a chrome directory if it doesn't exist.
mkdir -p chrome
cd chrome
# Copy theme repo inside
echo "Copying repo in $PWD"
cp -fR $THEMEDIRECTORY $PWD
# Create single-line user CSS files if non-existent or empty.
if [ -s userChrome.css ]; then
# Remove older theme imports
sed 's/@import "firefox-gnome-theme.*.//g' userChrome.css | sed '/^\s*$/d' > userChrome.css
echo >> userChrome.css
else
echo >> userChrome.css
fi
# Import this theme at the beginning of the CSS files.
sed -i '1s/^/@import "firefox-gnome-theme\/userChrome.css";\n/' userChrome.css
if [ $THEME = "DEFAULT" ]; then
echo "No theme set, using default adwaita."
else
echo "Setting $THEME theme."
echo "@import \"firefox-gnome-theme\/theme/colors/light-$THEME.css\";" >> userChrome.css
echo "@import \"firefox-gnome-theme\/theme/colors/dark-$THEME.css\";" >> userChrome.css
fi
cd ..
# Symlink user.js to firefox-gnome-theme one.
echo "Set configuration user.js file"
ln -fs chrome/firefox-gnome-theme/configuration/user.js user.js
echo "Done."
cd ..
}
2020-10-23 02:39:57 +03:00
PROFILES_FILE="${FIREFOXFOLDER}/profiles.ini"
if [ ! -f "${PROFILES_FILE}" ]; then
>&2 echo "failed, lease check Firefox installation, unable to find profile.ini at ${FIREFOX_DIR}"
exit 1
fi
2020-10-23 02:39:57 +03:00
echo "Profiles file found"
2020-10-23 02:39:57 +03:00
PROFILES_PATHS=($(grep -E "^Path=" "${PROFILES_FILE}" | cut -d "=" -f2-))
2019-07-12 19:07:20 +03:00
2020-10-23 02:39:57 +03:00
if [ ${#PROFILES_PATHS[@]} -eq 0 ]; then
>&2 echo "failed, no profiles found at ${PROFILES_FILE}"
exit 0
elif [ ${#PROFILES_PATHS[@]} -eq 1 ]; then
echo "one profile found"
saveProfile "0" "${PROFILES_PATHS[0]}"
else
2020-10-23 02:39:57 +03:00
echo "${#PROFILES_PATHS[@]} profiles found"
ITEM=0
for PROFILE_PATH in "${PROFILES_PATHS[@]}"; do
saveProfile "${ITEM}" "${PROFILE_PATH}"
ITEM="$((${ITEM}+1))"
done
fi