2021-07-09 21:37:49 +03:00
#!/usr/bin/env bash
2019-07-11 19:58:40 +03:00
2022-12-21 15:55:26 +02:00
THEMEDIRECTORY = $( cd " $( dirname $0 ) " && cd .. && pwd )
2019-07-17 21:33:41 +03:00
FIREFOXFOLDER = ~/.mozilla/firefox
2019-07-11 19:58:40 +03:00
PROFILENAME = ""
2022-12-21 15:55:26 +02:00
THEME = "DEFAULT"
2019-07-11 19:58:40 +03:00
2020-04-11 09:59:57 +03:00
2019-07-12 19:07:20 +03:00
# Get options.
2022-12-21 15:55:26 +02:00
while getopts 'f:p:t' flag; do
2020-04-11 09:59:57 +03:00
case " ${ flag } " in
2020-10-22 02:23:31 +03:00
f) FIREFOXFOLDER = " ${ OPTARG } " ; ;
p) PROFILENAME = " ${ OPTARG } " ; ;
t) THEME = " ${ OPTARG } " ; ;
2022-12-21 15:55:26 +02:00
*)
2020-10-21 23:31:59 +03:00
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
; ;
2019-07-11 19:58:40 +03:00
esac
done
2020-10-23 02:39:57 +03:00
function saveProfile( ) {
2020-10-27 17:49:16 +02:00
local PROFILE_PATH = " $1 "
2022-12-21 15:55:26 +02:00
cd " $FIREFOXFOLDER / $PROFILE_PATH " || { echo "FAIL, Firefox profile path was not found." ; exit 1; }
echo " Installing theme in $PWD " >$( tty)
2020-10-23 02:39:57 +03:00
# Create a chrome directory if it doesn't exist.
mkdir -p chrome
2022-12-21 15:55:26 +02:00
cd chrome || { echo " FAIL, couldn't create chrome dir in $PWD , please check if there's something else named 'chrome'. " ; exit 1; }
2020-10-23 02:39:57 +03:00
# Copy theme repo inside
2022-12-21 15:55:26 +02:00
echo " Copying repo in $PWD " >& 2
cp -fR " $THEMEDIRECTORY " " $PWD " || { echo " FAIL, couldn't copy to $PWD /chrome, please check if there's something named 'chrome', that is not a dir. " ; exit 1; }
2020-10-23 02:39:57 +03:00
# Create single-line user CSS files if non-existent or empty.
if [ -s userChrome.css ] ; then
# Remove older theme imports
2022-12-21 15:55:26 +02:00
sed 's/@import "firefox-gnome-theme.*.//g' userChrome.css | sed '/^\s*$/d' > tmpfile && mv tmpfile userChrome.css
2020-10-23 02:39:57 +03:00
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
2022-12-21 15:55:26 +02:00
if [ " $THEME " = "DEFAULT" ] ; then
echo "No theme set, using default adwaita." >& 2
2020-10-23 02:39:57 +03:00
else
2022-12-21 15:55:26 +02:00
echo " Setting $THEME theme. " >& 2
2020-10-23 02:39:57 +03:00
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
2022-05-23 18:14:33 +03:00
# Create single-line user content CSS files if non-existent or empty.
if [ -s userContent.css ] ; then
# Remove older theme imports
2022-12-21 15:55:26 +02:00
sed 's/@import "firefox-gnome-theme.*.//g' userContent.css | sed '/^\s*$/d' > tmpfile1 && mv tmpfile1 userContent.css
2022-05-23 18:14:33 +03:00
echo >> userContent.css
else
echo >> userContent.css
fi
# Import this theme at the beginning of the CSS files.
sed -i '1s/^/@import "firefox-gnome-theme\/userContent.css";\n/' userContent.css
2022-12-21 15:55:26 +02:00
if [ " $THEME " = "DEFAULT" ] ; then
echo "No theme set, using default adwaita." >& 2
2022-05-23 18:14:33 +03:00
else
echo " Setting $THEME theme. "
echo " @import \"firefox-gnome-theme\/theme/colors/light- $THEME .css\"; " >> userContent.css
echo " @import \"firefox-gnome-theme\/theme/colors/dark- $THEME .css\"; " >> userContent.css
fi
2020-10-23 02:39:57 +03:00
cd ..
# Symlink user.js to firefox-gnome-theme one.
2022-12-21 15:55:26 +02:00
echo "Set configuration user.js file" >& 2
2022-10-10 04:45:08 +03:00
ln -is chrome/firefox-gnome-theme/configuration/user.js user.js
2020-10-23 02:39:57 +03:00
2022-12-21 15:55:26 +02:00
echo "Done." >& 2
2020-10-23 02:39:57 +03:00
cd ..
}
2019-07-11 19:58:40 +03:00
2020-10-23 02:39:57 +03:00
PROFILES_FILE = " ${ FIREFOXFOLDER } /profiles.ini "
if [ ! -f " ${ PROFILES_FILE } " ] ; then
2022-12-21 15:55:26 +02:00
>& 2 echo " FAIL, please check Firefox installation, unable to find 'profile.ini' at ${ FIREFOXFOLDER } . "
2019-07-18 01:38:26 +03:00
exit 1
fi
2022-12-21 15:55:26 +02:00
echo " 'profiles.ini' found in ${ FIREFOXFOLDER } "
2019-07-18 01:38:26 +03:00
2021-05-10 17:54:01 +03:00
PROFILES_PATHS = ( $( grep -E "^Path=" " ${ PROFILES_FILE } " | tr -d '\n' | sed -e 's/\s\+/SPACECHARACTER/g' | sed 's/Path=/::/g' ) )
PROFILES_PATHS += ::
PROFILES_ARRAY = ( )
2021-05-12 04:23:48 +03:00
if [ " ${ PROFILENAME } " != "" ] ;
then
2022-12-21 15:55:26 +02:00
echo " Using ${ PROFILENAME } profile "
2021-05-12 04:23:48 +03:00
PROFILES_ARRAY += ${ PROFILENAME }
else
2022-12-21 15:55:26 +02:00
echo "Finding all avaliable profiles" ;
while [ [ " $PROFILES_PATHS " ] ] ; do
2021-05-12 04:23:48 +03:00
PROFILES_ARRAY += ( " ${ PROFILES_PATHS %% : : * } " )
PROFILES_PATHS = ${ PROFILES_PATHS #* : : }
done
fi
2021-05-10 17:54:01 +03:00
if [ ${# PROFILES_ARRAY [@] } -eq 0 ] ; then
2022-12-21 15:55:26 +02:00
echo " FAIL, no Firefox profiles found in $PROFILES_FILE " .;
2019-07-12 19:07:20 +03:00
2020-10-22 02:23:31 +03:00
else
2021-05-10 17:54:01 +03:00
for i in " ${ PROFILES_ARRAY [@] } "
do
2022-12-21 15:55:26 +02:00
if [ [ -n " $i " ] ] ;
2021-05-10 17:54:01 +03:00
then
2022-12-21 15:55:26 +02:00
echo " Installing ${ THEME } theme for $( sed 's/SPACECHARACTER/ /g' <<< $i ) profile. " ;
2021-05-10 17:54:01 +03:00
saveProfile " $( sed 's/SPACECHARACTER/ /g' <<< $i ) "
fi ;
2020-10-23 02:39:57 +03:00
done
2022-03-22 19:12:38 +02:00
fi