firefox-gnome-theme/scripts/install.sh

86 lines
2.2 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
# Determine firefox profile being currently used programatically
# credits: https://stackoverflow.com/questions/57526217/
function current_profile() {
2020-06-04 02:41:42 +03:00
pgrep firefox | xargs -I{} lsof -p {} 2>/dev/null | grep .parentlock |
awk '{for(i=9;i<=NF;++i)printf $i""FS ; print ""}' | cut -d'/' -f6
}
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
2019-07-12 19:07:20 +03:00
# Define profile folder path.
if test -z "$PROFILENAME"
then
PROFILEFOLDER="$FIREFOXFOLDER/$(current_profile)"
else
PROFILEFOLDER="$FIREFOXFOLDER/$PROFILENAME"
fi
2019-07-12 19:07:20 +03:00
# Enter Firefox profile folder.
if ! cd $PROFILEFOLDER ; then
2019-07-24 01:53:01 +03:00
echo "Error entering profile folder."
echo "Try using -p flag to specify a custom profile name."
exit 1
fi
2019-07-12 19:07:20 +03:00
echo "Installing theme in $PWD"
# Create a chrome directory if it doesn't exist.
mkdir -p chrome
cd chrome
# Copy theme repo inside
2020-04-10 16:59:47 +03:00
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.
2019-07-12 19:07:20 +03:00
sed -i '1s/^/@import "firefox-gnome-theme\/userChrome.css";\n/' userChrome.css
if [ $THEME = "DEFAULT" ]; then
2020-10-22 01:14:43 +03:00
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 ..
2019-07-12 19:38:16 +03:00
# 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
2019-07-12 19:38:16 +03:00
2020-10-22 01:14:43 +03:00
echo "Done."