Install script: Add failproof (#531)
This commit is contained in:
parent
13a8ec9d8d
commit
4cc03fbafb
|
@ -1,18 +1,18 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
THEMEDIRECTORY=$(cd `dirname $0` && cd .. && pwd)
|
THEMEDIRECTORY=$(cd "$(dirname $0)" && cd .. && pwd)
|
||||||
FIREFOXFOLDER=~/.mozilla/firefox
|
FIREFOXFOLDER=~/.mozilla/firefox
|
||||||
PROFILENAME=""
|
PROFILENAME=""
|
||||||
THEME=DEFAULT
|
THEME="DEFAULT"
|
||||||
|
|
||||||
|
|
||||||
# Get options.
|
# Get options.
|
||||||
while getopts 'f:p:t:h' flag; do
|
while getopts 'f:p:t' flag; do
|
||||||
case "${flag}" in
|
case "${flag}" in
|
||||||
f) FIREFOXFOLDER="${OPTARG}" ;;
|
f) FIREFOXFOLDER="${OPTARG}" ;;
|
||||||
p) PROFILENAME="${OPTARG}" ;;
|
p) PROFILENAME="${OPTARG}" ;;
|
||||||
t) THEME="${OPTARG}" ;;
|
t) THEME="${OPTARG}" ;;
|
||||||
h)
|
*)
|
||||||
echo "Gnome Theme Install Script:"
|
echo "Gnome Theme Install Script:"
|
||||||
echo " -f <firefox_folder_path>. Set custom Firefox folder path."
|
echo " -f <firefox_folder_path>. Set custom Firefox folder path."
|
||||||
echo " -p <profile_name>. Set custom profile name."
|
echo " -p <profile_name>. Set custom profile name."
|
||||||
|
@ -26,20 +26,20 @@ done
|
||||||
function saveProfile(){
|
function saveProfile(){
|
||||||
local PROFILE_PATH="$1"
|
local PROFILE_PATH="$1"
|
||||||
|
|
||||||
cd "$FIREFOXFOLDER/$PROFILE_PATH"
|
cd "$FIREFOXFOLDER/$PROFILE_PATH" || { echo "FAIL, Firefox profile path was not found."; exit 1; }
|
||||||
echo "Installing theme in $PWD"
|
echo "Installing theme in $PWD" >$(tty)
|
||||||
# Create a chrome directory if it doesn't exist.
|
# Create a chrome directory if it doesn't exist.
|
||||||
mkdir -p chrome
|
mkdir -p chrome
|
||||||
cd chrome
|
cd chrome || { echo "FAIL, couldn't create chrome dir in $PWD, please check if there's something else named 'chrome'."; exit 1; }
|
||||||
|
|
||||||
# Copy theme repo inside
|
# Copy theme repo inside
|
||||||
echo "Copying repo in $PWD"
|
echo "Copying repo in $PWD" >&2
|
||||||
cp -fR "$THEMEDIRECTORY" "$PWD"
|
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; }
|
||||||
|
|
||||||
# Create single-line user CSS files if non-existent or empty.
|
# Create single-line user CSS files if non-existent or empty.
|
||||||
if [ -s userChrome.css ]; then
|
if [ -s userChrome.css ]; then
|
||||||
# Remove older theme imports
|
# Remove older theme imports
|
||||||
sed 's/@import "firefox-gnome-theme.*.//g' userChrome.css | sed '/^\s*$/d' > userChrome.css
|
sed 's/@import "firefox-gnome-theme.*.//g' userChrome.css | sed '/^\s*$/d' > tmpfile && mv tmpfile userChrome.css
|
||||||
echo >> userChrome.css
|
echo >> userChrome.css
|
||||||
else
|
else
|
||||||
echo >> userChrome.css
|
echo >> userChrome.css
|
||||||
|
@ -48,10 +48,10 @@ function saveProfile(){
|
||||||
# Import this theme at the beginning of the CSS files.
|
# Import this theme at the beginning of the CSS files.
|
||||||
sed -i '1s/^/@import "firefox-gnome-theme\/userChrome.css";\n/' userChrome.css
|
sed -i '1s/^/@import "firefox-gnome-theme\/userChrome.css";\n/' userChrome.css
|
||||||
|
|
||||||
if [ $THEME = "DEFAULT" ]; then
|
if [ "$THEME" = "DEFAULT" ]; then
|
||||||
echo "No theme set, using default adwaita."
|
echo "No theme set, using default adwaita." >&2
|
||||||
else
|
else
|
||||||
echo "Setting $THEME theme."
|
echo "Setting $THEME theme." >&2
|
||||||
echo "@import \"firefox-gnome-theme\/theme/colors/light-$THEME.css\";" >> userChrome.css
|
echo "@import \"firefox-gnome-theme\/theme/colors/light-$THEME.css\";" >> userChrome.css
|
||||||
echo "@import \"firefox-gnome-theme\/theme/colors/dark-$THEME.css\";" >> userChrome.css
|
echo "@import \"firefox-gnome-theme\/theme/colors/dark-$THEME.css\";" >> userChrome.css
|
||||||
fi
|
fi
|
||||||
|
@ -59,7 +59,7 @@ function saveProfile(){
|
||||||
# Create single-line user content CSS files if non-existent or empty.
|
# Create single-line user content CSS files if non-existent or empty.
|
||||||
if [ -s userContent.css ]; then
|
if [ -s userContent.css ]; then
|
||||||
# Remove older theme imports
|
# Remove older theme imports
|
||||||
sed 's/@import "firefox-gnome-theme.*.//g' userContent.css | sed '/^\s*$/d' > userContent.css
|
sed 's/@import "firefox-gnome-theme.*.//g' userContent.css | sed '/^\s*$/d' > tmpfile1 && mv tmpfile1 userContent.css
|
||||||
echo >> userContent.css
|
echo >> userContent.css
|
||||||
else
|
else
|
||||||
echo >> userContent.css
|
echo >> userContent.css
|
||||||
|
@ -68,8 +68,8 @@ function saveProfile(){
|
||||||
# Import this theme at the beginning of the CSS files.
|
# Import this theme at the beginning of the CSS files.
|
||||||
sed -i '1s/^/@import "firefox-gnome-theme\/userContent.css";\n/' userContent.css
|
sed -i '1s/^/@import "firefox-gnome-theme\/userContent.css";\n/' userContent.css
|
||||||
|
|
||||||
if [ $THEME = "DEFAULT" ]; then
|
if [ "$THEME" = "DEFAULT" ]; then
|
||||||
echo "No theme set, using default adwaita."
|
echo "No theme set, using default adwaita." >&2
|
||||||
else
|
else
|
||||||
echo "Setting $THEME theme."
|
echo "Setting $THEME theme."
|
||||||
echo "@import \"firefox-gnome-theme\/theme/colors/light-$THEME.css\";" >> userContent.css
|
echo "@import \"firefox-gnome-theme\/theme/colors/light-$THEME.css\";" >> userContent.css
|
||||||
|
@ -79,19 +79,19 @@ function saveProfile(){
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
# Symlink user.js to firefox-gnome-theme one.
|
# Symlink user.js to firefox-gnome-theme one.
|
||||||
echo "Set configuration user.js file"
|
echo "Set configuration user.js file" >&2
|
||||||
ln -is chrome/firefox-gnome-theme/configuration/user.js user.js
|
ln -is chrome/firefox-gnome-theme/configuration/user.js user.js
|
||||||
|
|
||||||
echo "Done."
|
echo "Done." >&2
|
||||||
cd ..
|
cd ..
|
||||||
}
|
}
|
||||||
|
|
||||||
PROFILES_FILE="${FIREFOXFOLDER}/profiles.ini"
|
PROFILES_FILE="${FIREFOXFOLDER}/profiles.ini"
|
||||||
if [ ! -f "${PROFILES_FILE}" ]; then
|
if [ ! -f "${PROFILES_FILE}" ]; then
|
||||||
>&2 echo "failed, lease check Firefox installation, unable to find profile.ini at ${FIREFOXFOLDER}"
|
>&2 echo "FAIL, please check Firefox installation, unable to find 'profile.ini' at ${FIREFOXFOLDER}."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Profiles file found"
|
echo "'profiles.ini' found in ${FIREFOXFOLDER}"
|
||||||
|
|
||||||
PROFILES_PATHS=($(grep -E "^Path=" "${PROFILES_FILE}" | tr -d '\n' | sed -e 's/\s\+/SPACECHARACTER/g' | sed 's/Path=/::/g' ))
|
PROFILES_PATHS=($(grep -E "^Path=" "${PROFILES_FILE}" | tr -d '\n' | sed -e 's/\s\+/SPACECHARACTER/g' | sed 's/Path=/::/g' ))
|
||||||
PROFILES_PATHS+=::
|
PROFILES_PATHS+=::
|
||||||
|
@ -99,11 +99,11 @@ PROFILES_PATHS+=::
|
||||||
PROFILES_ARRAY=()
|
PROFILES_ARRAY=()
|
||||||
if [ "${PROFILENAME}" != "" ];
|
if [ "${PROFILENAME}" != "" ];
|
||||||
then
|
then
|
||||||
echo "Using ${PROFILENAME} theme"
|
echo "Using ${PROFILENAME} profile"
|
||||||
PROFILES_ARRAY+=${PROFILENAME}
|
PROFILES_ARRAY+=${PROFILENAME}
|
||||||
else
|
else
|
||||||
echo "Finding all avaliable themes";
|
echo "Finding all avaliable profiles";
|
||||||
while [[ $PROFILES_PATHS ]]; do
|
while [[ "$PROFILES_PATHS" ]]; do
|
||||||
PROFILES_ARRAY+=( "${PROFILES_PATHS%%::*}" )
|
PROFILES_ARRAY+=( "${PROFILES_PATHS%%::*}" )
|
||||||
PROFILES_PATHS=${PROFILES_PATHS#*::}
|
PROFILES_PATHS=${PROFILES_PATHS#*::}
|
||||||
done
|
done
|
||||||
|
@ -112,14 +112,14 @@ fi
|
||||||
|
|
||||||
|
|
||||||
if [ ${#PROFILES_ARRAY[@]} -eq 0 ]; then
|
if [ ${#PROFILES_ARRAY[@]} -eq 0 ]; then
|
||||||
echo No Profiles found on $PROFILES_FILE;
|
echo "FAIL, no Firefox profiles found in $PROFILES_FILE".;
|
||||||
|
|
||||||
else
|
else
|
||||||
for i in "${PROFILES_ARRAY[@]}"
|
for i in "${PROFILES_ARRAY[@]}"
|
||||||
do
|
do
|
||||||
if [[ ! -z "$i" ]];
|
if [[ -n "$i" ]];
|
||||||
then
|
then
|
||||||
echo Installing Theme on $(sed 's/SPACECHARACTER/ /g' <<< $i) ;
|
echo "Installing ${THEME} theme for $(sed 's/SPACECHARACTER/ /g' <<< $i) profile.";
|
||||||
saveProfile "$(sed 's/SPACECHARACTER/ /g' <<< $i)"
|
saveProfile "$(sed 's/SPACECHARACTER/ /g' <<< $i)"
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue