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