2021-05-23 15:04:01 +02:00
#! /usr/bin/env bash
2021-04-08 02:09:27 +02:00
# WARNING: Please make this shell not working-directory dependant, for example
2021-06-03 01:43:49 +02:00
# instead of using 'ls blabla', use 'ls "${REPO_DIR}/blabla"'
2021-04-08 02:09:27 +02:00
#
# WARNING: Don't use "cd" in this shell, use it in a subshell instead,
# for example ( cd blabla && do_blabla ) or $( cd .. && do_blabla )
2021-06-11 13:59:07 +02:00
#
# SUGGESTION: Please don't put any dependency installation here
2021-04-08 02:09:27 +02:00
###############################################################################
# VARIABLES & HELP #
###############################################################################
readonly REPO_DIR = " $( dirname " $( readlink -m " ${ 0 } " ) " ) "
source " ${ REPO_DIR } /lib-install.sh "
2021-08-21 16:39:24 +02:00
# Customization, default values
colors = ( " ${ COLOR_VARIANTS [@] } " )
opacities = ( " ${ OPACITY_VARIANTS [@] } " )
2021-04-08 02:09:27 +02:00
usage( ) {
# Please specify their default value manually, some of them are come from _variables.scss
# You also have to check and update them regurally
helpify_title
2021-08-21 05:41:37 +02:00
helpify "-f, --firefox" "[default|monterey]" " Install ' ${ THEME_NAME } |Monterey' theme for Firefox and connect it to the current Firefox profiles " " Default is ${ THEME_NAME } "
helpify "-e, --edit-firefox" "" " Edit ' ${ THEME_NAME } ' theme for Firefox settings and also connect the theme to the current Firefox profiles " ""
helpify "-F, --flatpak" "" " Connect ' ${ THEME_NAME } ' theme to Flatpak " ""
helpify "-s, --snap" "" " Connect ' ${ THEME_NAME } ' theme the currently installed snap apps " ""
2021-08-23 12:42:07 +02:00
helpify "-g, --gdm" "[default|x2]" " Install ' ${ THEME_NAME } ' theme for GDM (scaling: 100%/200%, default is 100%) " "Requires to run this shell as root"
2021-08-21 16:39:24 +02:00
helpify "-d, --dash-to-dock" "" " Install ' ${ THEME_NAME } ' theme for Dash to Dock when Gnome < 40 or install fixed version on Gnome > 40 " ""
2021-08-21 05:41:37 +02:00
helpify "-N, --no-darken" "" " Don't darken ' ${ THEME_NAME } ' GDM theme background image " ""
helpify "-n, --no-blur" "" " Don't blur ' ${ THEME_NAME } ' GDM theme background image " ""
helpify "-b, --background" "[default|blank|IMAGE_PATH]" " Set ' ${ THEME_NAME } ' GDM theme background image " "Default is BigSur-like wallpaper"
helpify "-o, --opacity" " [ $( IFS = '|' ; echo " ${ OPACITY_VARIANTS [*] } " ) ] " " Set ' ${ THEME_NAME } ' GDM theme opacity variants " "Default is 'normal'"
helpify "-c, --color" " [ $( IFS = '|' ; echo " ${ COLOR_VARIANTS [*] } " ) ] " " Set ' ${ THEME_NAME } ' GDM and Dash to Dock theme color variants " "Default is 'light'"
helpify "-t, --theme" " [ $( IFS = '|' ; echo " ${ THEME_VARIANTS [*] } " ) ] " " Set ' ${ THEME_NAME } ' GDM theme accent color " "Default is BigSur-like theme"
helpify "-p, --panel-opacity" " [ $( IFS = '|' ; echo " ${ PANEL_OPACITY_VARIANTS [*] } " ) ] " " Set ' ${ THEME_NAME } ' GDM (GNOME Shell) theme panel transparency " "Default is 15%"
helpify "-P, --panel-size" " [ $( IFS = '|' ; echo " ${ PANEL_SIZE_VARIANTS [*] } " ) ] " " Set ' ${ THEME_NAME } ' Gnome shell panel height size " "Default is 32px"
helpify "-i, --icon" " [ $( IFS = '|' ; echo " ${ ICON_VARIANTS [*] } " ) ] " " Set ' ${ THEME_NAME } ' GDM (GNOME Shell) 'Activities' icon " "Default is 'standard'"
helpify "-r, --remove, --revert" "" "Revert to the original themes, do the opposite things of install and connect" ""
helpify "--silent-mode" "" "Meant for developers: ignore any confirm prompt and params become more strict" ""
helpify "-h, --help" "" "Show this help" ""
2021-04-08 02:09:27 +02:00
}
###############################################################################
# MAIN #
###############################################################################
#-----------------------------PARSE ARGUMENTS---------------------------------#
2021-06-13 16:47:00 +02:00
echo
2021-04-08 02:09:27 +02:00
while [ [ $# -gt 0 ] ] ; do
# Don't show any dialog here. Let this loop checks for errors or shows help
# We can only show dialogs when there's no error and no -r parameter
#
# * shift for parameters that have no value
# * shift 2 for parameter that have a value
#
# Please don't exit any error here if possible. Let it show all error warnings
# at once
case " ${ 1 } " in
2021-06-02 18:04:59 +02:00
# Parameters that don't require value
2021-04-08 02:09:27 +02:00
-r| --remove| --revert)
uninstall = 'true' ; shift ; ;
2021-06-15 15:15:34 +02:00
--silent-mode)
full_sudo " ${ 1 } " ; silent_mode = 'true' ; shift ; ;
2021-04-08 02:09:27 +02:00
-h| --help)
need_help = "true" ; shift ; ;
2021-07-04 17:14:42 +02:00
-f| --firefox| -e| --edit-firefox)
2021-04-08 02:09:27 +02:00
case " ${ 1 } " in
-f| --firefox)
firefox = "true" ; ;
-e| --edit-firefox)
edit_firefox = "true" ; ;
esac
2021-07-04 17:14:42 +02:00
for variant in " ${ @ } " ; do
case " ${ variant } " in
default)
shift 1
; ;
monterey)
monterey = "true"
name = "Monterey"
shift 1
; ;
esac
done
2021-05-31 12:04:08 +02:00
if ! has_command firefox && ! has_flatpak_app org.mozilla.firefox && ! has_snap_app firefox; then
2021-04-08 02:09:27 +02:00
prompt -e " ' ${ 1 } ' ERROR: There's no Firefox installed in your system "
has_any_error = "true"
2021-05-31 12:04:08 +02:00
elif [ [ ! -d " ${ FIREFOX_DIR_HOME } " && ! -d " ${ FIREFOX_FLATPAK_DIR_HOME } " && ! -d " ${ FIREFOX_SNAP_DIR_HOME } " ] ] ; then
2021-04-08 02:09:27 +02:00
prompt -e " ' ${ 1 } ' ERROR: Firefox is installed but not yet initialized. "
prompt -w " ' ${ 1 } ': Don't forget to close it after you run/initialize it "
has_any_error = "true"
2021-05-30 14:19:49 +02:00
elif pidof "firefox" & > /dev/null || pidof "firefox-bin" & > /dev/null; then
2021-04-08 02:09:27 +02:00
prompt -e " ' ${ 1 } ' ERROR: Firefox is running, please close it "
has_any_error = "true"
fi ; shift ; ;
-F| --flatpak)
2021-08-21 16:39:24 +02:00
flatpak = "true" ; signal_exit
2021-04-08 02:09:27 +02:00
2021-04-21 14:56:32 +02:00
if ! has_command flatpak; then
2021-04-08 02:09:27 +02:00
prompt -e " ' ${ 1 } ' ERROR: There's no Flatpak installed in your system "
has_any_error = "true"
fi ; shift ; ;
-s| --snap)
snap = "true" ;
2021-04-21 14:56:32 +02:00
if ! has_command snap; then
2021-04-08 02:09:27 +02:00
prompt -e " ' ${ 1 } ' ERROR: There's no Snap installed in your system "
has_any_error = "true"
fi ; shift ; ;
-g| --gdm)
2021-06-10 05:57:01 +02:00
gdm = "true" ; full_sudo " ${ 1 } "
2021-07-18 15:20:59 +02:00
showapps_normal = "true" # use normal showapps icon
2021-07-19 09:34:20 +02:00
background = "default"
2021-04-08 02:09:27 +02:00
2021-08-23 12:42:07 +02:00
for variant in " ${ @ } " ; do
case " ${ variant } " in
default)
shift 1
; ;
x2)
scale = "x2"
shift 1
; ;
esac
done
2021-05-31 12:04:08 +02:00
if ! has_command gdm && ! has_command gdm3 && [ [ ! -e /usr/sbin/gdm3 ] ] ; then
2021-04-08 02:09:27 +02:00
prompt -e " ' ${ 1 } ' ERROR: There's no GDM installed in your system "
has_any_error = "true"
fi ; shift ; ;
-d| --dash-to-dock)
2021-05-14 12:31:26 +02:00
if [ [ " ${ GNOME_VERSION } " = = 'new' ] ] ; then
2021-08-21 16:39:24 +02:00
dash_to_dock = "new"
2021-05-31 12:04:08 +02:00
elif [ [ ! -d " ${ DASH_TO_DOCK_DIR_HOME } " && ! -d " ${ DASH_TO_DOCK_DIR_ROOT } " ] ] ; then
prompt -e " ' ${ 1 } ' ERROR: There's no Dash to Dock installed in your system "
2021-05-14 12:31:26 +02:00
has_any_error = "true"
else
dash_to_dock = "true"
2021-04-08 02:09:27 +02:00
fi ; shift ; ;
2021-05-24 07:18:19 +02:00
-N| --no-darken)
no_darken = "true" ; shift ; ;
2021-04-08 02:09:27 +02:00
-n| --no-blur)
no_blur = "true" ; shift ; ;
2021-06-02 18:04:59 +02:00
# Parameters that require value, single use
2021-04-08 02:09:27 +02:00
-b| --background)
check_param " ${ 1 } " " ${ 1 } " " ${ 2 } " "must" "must" "must" "false" && shift 2 || shift ; ;
-i| --icon)
check_param " ${ 1 } " " ${ 1 } " " ${ 2 } " "must" "must" "must" "false" && shift 2 || shift ; ;
2021-08-21 05:41:37 +02:00
-p| --panel-opacity)
check_param " ${ 1 } " " ${ 1 } " " ${ 2 } " "optional" "optional" "optional" && shift 2 || shift ; ;
-P| --panel-size)
check_param " ${ 1 } " " ${ 1 } " " ${ 2 } " "optional" "optional" "optional" && shift 2 || shift ; ;
2021-04-08 02:09:27 +02:00
-o| --opacity)
check_param " ${ 1 } " " ${ 1 } " " ${ 2 } " "must" "must" "must" "false" && shift 2 || shift ; ;
-c| --color)
check_param " ${ 1 } " " ${ 1 } " " ${ 2 } " "must" "must" "must" "false" && shift 2 || shift ; ;
-t| --theme)
check_param " ${ 1 } " " ${ 1 } " " ${ 2 } " "must" "must" "must" "false" && shift 2 || shift ; ;
*)
prompt -e " ERROR: Unrecognized tweak option ' ${ 1 } '. "
has_any_error = "true" ; shift ; ;
esac
done
finalize_argument_parsing
#---------------------------START INSTALL THEMES-------------------------------#
if [ [ " ${ uninstall } " = = 'true' ] ] ; then
2021-06-12 09:01:28 +02:00
prompt -w "REMOVAL: Non file-related parameters will be ignored."
2021-04-08 02:09:27 +02:00
2021-08-23 10:00:41 +02:00
if [ [ " ${ snap } " = = 'true' ] ] ; then
prompt -i " Disconnecting ' ${ name } ' theme from your installed snap apps... \n "
disconnect_snap
prompt -s " Done! ' ${ name } ' theme has been disconnected from your snap apps. " ; echo
fi
if [ [ " ${ flatpak } " = = 'true' ] ] ; then
prompt -i " Disconnecting ' ${ name } ' theme from your Flatpak... \n "
disconnect_flatpak
prompt -s " Done! ' ${ name } ' theme has been disconnected from your Flatpak. " ; echo
fi
2021-04-08 02:09:27 +02:00
if [ [ " ${ gdm } " = = 'true' ] ] ; then
2021-08-21 16:39:24 +02:00
prompt -i " Removing ' ${ name } ' GDM theme... \n "
2021-04-08 02:09:27 +02:00
revert_gdm_theme
2021-06-13 16:47:00 +02:00
prompt -s " Done! ' ${ name } ' GDM theme has been removed. " ; echo
2021-04-08 02:09:27 +02:00
fi
if [ [ " ${ dash_to_dock } " = = 'true' ] ] ; then
2021-08-21 16:39:24 +02:00
prompt -i " Removing ' ${ name } ' Dash to Dock theme... \n "
2021-04-08 02:09:27 +02:00
revert_dash_to_dock_theme
2021-06-13 16:47:00 +02:00
prompt -s " Done! ' ${ name } ' Dash to Dock theme has been removed. " ; echo
2021-04-08 02:09:27 +02:00
fi
2021-08-21 16:39:24 +02:00
if [ [ " ${ dash_to_dock } " = = 'new' ] ] ; then
prompt -i " Removing ' ${ name } ' Dash to Dock extension... \n "
revert_dash_to_dock
prompt -s " Done! ' ${ name } ' Dash to Dock extension has been removed. " ; echo
fi
2021-04-08 02:09:27 +02:00
if [ [ " ${ firefox } " = = 'true' ] ] ; then
2021-08-21 16:39:24 +02:00
prompt -i " Removing ' ${ name } ' Firefox theme... \n "
2021-04-08 02:09:27 +02:00
remove_firefox_theme
2021-06-13 16:47:00 +02:00
prompt -s " Done! ' ${ name } ' Firefox theme has been removed. " ; echo
2021-04-08 02:09:27 +02:00
fi
2021-08-23 10:00:41 +02:00
else
show_needed_dialogs; customize_theme
2021-04-08 02:09:27 +02:00
if [ [ " ${ snap } " = = 'true' ] ] ; then
2021-08-23 10:00:41 +02:00
prompt -i " Connecting ' ${ name } ' theme to your installed snap apps... \n "
connect_snap
prompt -s " Done! ' ${ name } ' theme has been connected to your snap apps. " ; echo
2021-04-08 02:09:27 +02:00
fi
if [ [ " ${ flatpak } " = = 'true' ] ] ; then
2021-08-23 10:00:41 +02:00
if [ [ -d " ${ THEME_DIR } / ${ name } ${ color } ${ opacity } " ] ] ; then
prompt -i " Connecting ' ${ name } ' themes to your Flatpak... \n "
connect_flatpak
prompt -s " Done! ' ${ name } ' theme has been connected to your Flatpak. " ; echo
else
prompt -e "ERROR: Befaore you run '-F' you need install this theme first... \n"
exit 0
fi
2021-04-08 02:09:27 +02:00
fi
if [ [ " ${ gdm } " = = 'true' ] ] ; then
2021-08-21 16:39:24 +02:00
prompt -i " Installing ' ${ name } ' GDM theme... \n "
2021-06-12 11:11:53 +02:00
install_gdm_theme
2021-06-13 16:47:00 +02:00
prompt -s " Done! ' ${ name } ' GDM theme has been installed. " ; echo
2021-04-08 02:09:27 +02:00
fi
if [ [ " ${ dash_to_dock } " = = 'true' ] ] ; then
2021-08-21 16:39:24 +02:00
prompt -i " Installing ' ${ name } ' ${ colors [0] } Dash to Dock theme... \n "
2021-04-08 02:09:27 +02:00
install_dash_to_dock_theme
2021-06-13 16:47:00 +02:00
prompt -s " Done! ' ${ name } ' Dash to Dock theme has been installed. "
prompt -w "DASH TO DOCK: You may need to logout to take effect." ; echo
2021-04-08 02:09:27 +02:00
fi
2021-08-21 16:39:24 +02:00
if [ [ " ${ dash_to_dock } " = = 'new' ] ] ; then
prompt -i "Installing fixed Dash to Dock... \n"
install_dash_to_dock
prompt -s " Done! ' ${ name } ' Dash to Dock extension has been installed. "
prompt -w "DASH TO DOCK: You may need to logout to take effect." ; echo
fi
2021-04-08 02:09:27 +02:00
if [ [ " ${ firefox } " = = 'true' || " ${ edit_firefox } " = = 'true' ] ] ; then
if [ [ " ${ firefox } " = = 'true' ] ] ; then
2021-08-21 16:39:24 +02:00
prompt -i " Installing ' ${ name } ' Firefox theme... \n "
2021-04-08 02:09:27 +02:00
install_firefox_theme
2021-06-13 16:47:00 +02:00
prompt -s " Done! ' ${ name } ' Firefox theme has been installed. " ; echo
2021-04-08 02:09:27 +02:00
fi
if [ [ " ${ edit_firefox } " = = 'true' ] ] ; then
2021-08-21 16:39:24 +02:00
prompt -i " Editing ' ${ name } ' Firefox theme preferences... \n "
2021-04-08 02:09:27 +02:00
edit_firefox_theme_prefs
2021-06-13 16:47:00 +02:00
prompt -s " Done! ' ${ name } ' Firefox theme preferences has been edited. " ; echo
2021-04-08 02:09:27 +02:00
fi
prompt -w "FIREFOX: Please go to [Firefox menu] > [Customize...], and customize your Firefox to make it work. Move your 'new tab' button to the titlebar instead of tab-switcher."
2021-06-12 17:45:49 +02:00
prompt -i "FIREFOX: Anyways, you can also edit 'userChrome.css' and 'customChrome.css' later in your Firefox profile directory."
2021-06-13 16:47:00 +02:00
echo
2021-04-08 02:09:27 +02:00
fi
fi
if [ [ " ${ firefox } " = = "false" && " ${ edit_firefox } " = = "false" && " ${ flatpak } " = = "false" && " ${ snap } " = = "false" && " ${ gdm } " = = "false" && " ${ dash_to_dock } " = = "false" ] ] ; then
2021-06-13 16:47:00 +02:00
prompt -e "Oops... there's nothing to tweak..."
prompt -i "HINT: Don't forget to define which component to tweak, e.g. '--gdm'"
prompt -i "HINT: Run ./tweaks.sh -h for help!..." ; echo
2021-04-08 02:09:27 +02:00
fi