install.sh
Bourne-Again shell script, ASCII text executable
1#!/bin/bash 2set -ueo pipefail 3#set -x 4 5REPO_DIR="$(cd "$(dirname "$0")" && pwd)" 6SRC_DIR="$REPO_DIR/src" 7 8DEST_DIR="/usr/share/themes" 9THEME_NAME="Materia" 10COLOR_VARIANTS=('' '-dark' '-light') 11SIZE_VARIANTS=('' '-compact') 12 13GTK_VERSIONS=('3.0') 14 15if [[ -z "${GS_VERSION:-}" ]]; then 16# Set a proper gnome-shell theme version 17if [[ "$(command -v gnome-shell)" ]]; then 18CURRENT_GS_VERSION="$(gnome-shell --version | cut -d ' ' -f 3 | cut -d . -f -2)" 19MAJOR_VER="$(echo "$CURRENT_GS_VERSION" | cut -d . -f 1)" 20MINOR_VER="$(echo "$CURRENT_GS_VERSION" | cut -d . -f 2)" 21 22if (( "$MINOR_VER" % 2 == 0 )); then 23GS_VERSION="$MAJOR_VER.$MINOR_VER" 24else 25GS_VERSION="$MAJOR_VER.$(($MINOR_VER + 1))" 26fi 27else 28echo "'gnome-shell' not found, using styles for last gnome-shell version available." 29GS_VERSION="3.36" 30fi 31fi 32 33if [[ ! "$(command -v sassc)" ]]; then 34echo "'sassc' needs to be installed to generate the CSS." 35exit 1 36fi 37 38SASSC_OPT=('-M' '-t' 'expanded') 39 40usage() { 41cat << EOF 42Usage: $0 [OPTION]... 43 44OPTIONS: 45-d, --dest DIR Specify destination directory (Default: $DEST_DIR) 46-n, --name NAME Specify theme name (Default: $THEME_NAME) 47-c, --color VARIANT... Specify color variant(s) [standard|dark|light] (Default: All variants) 48-s, --size VARIANT Specify size variant [standard|compact] (Default: All variants) 49-g, --gdm Install and apply GDM theme (for advanced users) 50See also: src/gnome-shell/README.md 51-h, --help Show help 52 53INSTALLATION EXAMPLES: 54Install all theme variants into ~/.themes 55$0 --dest ~/.themes 56Install all theme variants including GDM theme 57$0 --gdm 58Install standard theme variant only 59$0 --color standard --size standard 60Install specific theme variants with different name into ~/.themes 61$0 --dest ~/.themes --name MyTheme --color light dark --size compact 62EOF 63} 64 65install() { 66local dest="$1" 67local name="$2$3$4" 68local color="$3" 69local size="$4" 70 71if [[ "$color" == '' ]]; then 72local scss_dark_theme="false" 73local scss_light_topbar="false" 74elif [[ "$color" == '-light' ]]; then 75local scss_dark_theme="false" 76local scss_light_topbar="true" 77elif [[ "$color" == '-dark' ]]; then 78local scss_dark_theme="true" 79local scss_light_topbar="false" 80fi 81 82if [[ "$size" == '' ]]; then 83local scss_compact="false" 84elif [[ "$size" == '-compact' ]]; then 85local scss_compact="true" 86fi 87 88[[ "$color" == '-dark' ]] && local ELSE_DARK="$color" 89[[ "$color" == '-light' ]] && local ELSE_LIGHT="$color" 90 91local THEME_DIR="$dest/$name" 92 93# SC2115: Protect /. 94[[ -d "$THEME_DIR" ]] && rm -rf "${THEME_DIR:?}" 95 96echo "Installing '$THEME_DIR'..." 97 98mkdir -p "$THEME_DIR" 99cp -r "$REPO_DIR/COPYING" "$THEME_DIR" 100sed \ 101-e "s/@theme_name@/$name/g" \ 102"$SRC_DIR/index.theme.in" > "$THEME_DIR/index.theme" 103 104mkdir -p "$THEME_DIR/chrome" 105cp -r "$SRC_DIR/chrome/chrome-theme$color.crx" "$THEME_DIR/chrome/chrome-theme.crx" 106cp -r "$SRC_DIR/chrome/chrome-scrollbar${ELSE_DARK:-}.crx" "$THEME_DIR/chrome/chrome-scrollbar.crx" 107 108mkdir -p "$THEME_DIR/cinnamon" 109cp -r "$SRC_DIR/cinnamon/assets" "$THEME_DIR/cinnamon" 110cp -r "$SRC_DIR/cinnamon/thumbnail.png" "$THEME_DIR/cinnamon" 111sed \ 112-e "s/@dark_theme@/$scss_dark_theme/g" \ 113-e "s/@light_topbar@/$scss_light_topbar/g" \ 114-e "s/@compact@/$scss_compact/g" \ 115"$SRC_DIR/cinnamon/cinnamon.scss.in" > "$SRC_DIR/cinnamon/cinnamon.$name.scss" 116sassc "${SASSC_OPT[@]}" "$SRC_DIR/cinnamon/cinnamon.$name.scss" "$THEME_DIR/cinnamon/cinnamon.css" 117 118mkdir -p "$THEME_DIR/gnome-shell" 119cp -r "$SRC_DIR/gnome-shell/"{*.svg,extensions,noise-texture.png,pad-osd.css} "$THEME_DIR/gnome-shell" 120cp -r "$SRC_DIR/gnome-shell/gnome-shell-theme.gresource.xml" "$THEME_DIR/gnome-shell" 121cp -r "$SRC_DIR/gnome-shell/icons" "$THEME_DIR/gnome-shell" 122cp -r "$SRC_DIR/gnome-shell/README.md" "$THEME_DIR/gnome-shell" 123cp -r "$SRC_DIR/gnome-shell/assets${ELSE_DARK:-}" "$THEME_DIR/gnome-shell/assets" 124sed \ 125-e "s/@dark_theme@/$scss_dark_theme/g" \ 126-e "s/@light_topbar@/$scss_light_topbar/g" \ 127-e "s/@compact@/$scss_compact/g" \ 128-e "s/@version@/$GS_VERSION/g" \ 129"$SRC_DIR/gnome-shell/gnome-shell.scss.in" > "$SRC_DIR/gnome-shell/gnome-shell.$name.scss" 130sassc "${SASSC_OPT[@]}" "$SRC_DIR/gnome-shell/gnome-shell.$name.scss" "$THEME_DIR/gnome-shell/gnome-shell.css" 131 132mkdir -p "$THEME_DIR/gtk-2.0" 133cp -r "$SRC_DIR/gtk-2.0/"{apps.rc,hacks.rc,main.rc} "$THEME_DIR/gtk-2.0" 134cp -r "$SRC_DIR/gtk-2.0/assets${ELSE_DARK:-}" "$THEME_DIR/gtk-2.0/assets" 135cp -r "$SRC_DIR/gtk-2.0/gtkrc$color" "$THEME_DIR/gtk-2.0/gtkrc" 136 137local GTK_VARIANTS=('') 138[[ "$color" != '-dark' ]] && local GTK_VARIANTS+=('-dark') 139 140for version in "${GTK_VERSIONS[@]}"; do 141mkdir -p "$THEME_DIR/gtk-$version" 142cp -r "$SRC_DIR/gtk-3.0/assets" "$THEME_DIR/gtk-$version" 143cp -r "$SRC_DIR/gtk-3.0/icons" "$THEME_DIR/gtk-$version" 144 145for variant in "${GTK_VARIANTS[@]}"; do 146sed \ 147-e "s/@dark_theme@/$scss_dark_theme/g" \ 148-e "s/@light_topbar@/$scss_light_topbar/g" \ 149-e "s/@compact@/$scss_compact/g" \ 150"$SRC_DIR/gtk-$version/gtk$variant.scss.in" > "$SRC_DIR/gtk-$version/gtk$variant.$name.scss" 151sassc "${SASSC_OPT[@]}" "$SRC_DIR/gtk-$version/gtk$variant.$name.scss" "$THEME_DIR/gtk-$version/gtk$variant.css" 152done 153done 154 155mkdir -p "$THEME_DIR/metacity-1" 156cp -r "$SRC_DIR/metacity-1/"{assets,metacity-theme-3.xml} "$THEME_DIR/metacity-1" 157cp -r "$SRC_DIR/metacity-1/metacity-theme-2$color.xml" "$THEME_DIR/metacity-1/metacity-theme-2.xml" 158 159mkdir -p "$THEME_DIR/plank" 160cp -r "$SRC_DIR/plank/dock.theme" "$THEME_DIR/plank" 161 162mkdir -p "$THEME_DIR/unity" 163cp -rT "$SRC_DIR/unity/dash-buttons" "$THEME_DIR/unity" 164cp -r "$SRC_DIR/unity/dash-widgets.json" "$THEME_DIR/unity" 165cp -rT "$SRC_DIR/unity/launcher" "$THEME_DIR/unity" 166cp -rT "$SRC_DIR/unity/window-buttons${ELSE_LIGHT:-}" "$THEME_DIR/unity" 167 168cp -r "$SRC_DIR/xfwm4/xfwm4$color" "$THEME_DIR/xfwm4" 169} 170 171# Bakup and install files related to GDM theme 172install_gdm() { 173local THEME_DIR="$1/$2$3$4" 174local GS_THEME_FILE="/usr/share/gnome-shell/gnome-shell-theme.gresource" 175local UBUNTU_THEME_FILE="/usr/share/gnome-shell/theme/ubuntu.css" 176 177if [[ -f "$GS_THEME_FILE" ]] && command -v glib-compile-resources >/dev/null; then 178echo "Installing '$GS_THEME_FILE'..." 179cp -an "$GS_THEME_FILE" "$GS_THEME_FILE.bak" 180glib-compile-resources \ 181--sourcedir="$THEME_DIR/gnome-shell" \ 182--target="$GS_THEME_FILE" \ 183"$THEME_DIR/gnome-shell/gnome-shell-theme.gresource.xml" 184else 185echo 186echo "ERROR: Failed to install '$GS_THEME_FILE'" 187exit 1 188fi 189 190if [[ -f "$UBUNTU_THEME_FILE" ]]; then 191echo "Installing '$UBUNTU_THEME_FILE'..." 192cp -an "$UBUNTU_THEME_FILE" "$UBUNTU_THEME_FILE.bak" 193cp -af "$THEME_DIR/gnome-shell/gnome-shell.css" "$UBUNTU_THEME_FILE" 194fi 195} 196 197colors=() 198sizes=() 199while [[ "$#" -gt 0 ]]; do 200case "${1:-}" in 201-d|--dest) 202dest="$2" 203mkdir -p "$dest" 204shift 2 205;; 206-n|--name) 207_name="$2" 208shift 2 209;; 210-g|--gdm) 211gdm='true' 212shift 1 213;; 214-c|--color) 215shift 216for variant in "$@"; do 217case "$variant" in 218standard) 219colors+=("${COLOR_VARIANTS[0]}") 220shift 221;; 222dark) 223colors+=("${COLOR_VARIANTS[1]}") 224shift 225;; 226light) 227colors+=("${COLOR_VARIANTS[2]}") 228shift 229;; 230-*) 231break 232;; 233*) 234echo "ERROR: Unrecognized color variant '$1'." 235echo "Try '$0 --help' for more information." 236exit 1 237;; 238esac 239done 240;; 241-s|--size) 242shift 243for variant in "$@"; do 244case "$variant" in 245standard) 246sizes+=("${SIZE_VARIANTS[0]}") 247shift 248;; 249compact) 250sizes+=("${SIZE_VARIANTS[1]}") 251shift 252;; 253-*) 254break 255;; 256*) 257echo "ERROR: Unrecognized size variant '${1:-}'." 258echo "Try '$0 --help' for more information." 259exit 1 260;; 261esac 262done 263;; 264-h|--help) 265usage 266exit 0 267;; 268*) 269echo "ERROR: Unrecognized installation option '${1:-}'." 270echo "Try '$0 --help' for more information." 271exit 1 272;; 273esac 274done 275 276if [[ ! -w "${dest:-$DEST_DIR}" ]]; then 277echo "Please run as root." 278exit 1 279fi 280 281if [[ "${#colors[@]}" -eq 0 ]] ; then 282colors=("${COLOR_VARIANTS[@]}") 283fi 284if [[ "${#sizes[@]}" -eq 0 ]] ; then 285sizes=("${SIZE_VARIANTS[@]}") 286fi 287for color in "${colors[@]}"; do 288for size in "${sizes[@]}"; do 289install "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size" 290done 291done 292 293if [[ "${gdm:-}" == 'true' ]]; then 294install_gdm "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size" 295fi 296 297echo 298echo "Done." 299