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 137cp -r "$SRC_DIR/gtk/assets" "$THEME_DIR/gtk-assets" 138cp -r "$SRC_DIR/gtk/icons" "$THEME_DIR/gtk-icons" 139 140local GTK_VARIANTS=('') 141[[ "$color" != '-dark' ]] && local GTK_VARIANTS+=('-dark') 142 143for version in "${GTK_VERSIONS[@]}"; do 144mkdir -p "$THEME_DIR/gtk-$version" 145ln -s ../gtk-assets "$THEME_DIR/gtk-$version/assets" 146ln -s ../gtk-icons "$THEME_DIR/gtk-$version/icons" 147 148for variant in "${GTK_VARIANTS[@]}"; do 149sed \ 150-e "s/@dark_theme@/$scss_dark_theme/g" \ 151-e "s/@light_topbar@/$scss_light_topbar/g" \ 152-e "s/@compact@/$scss_compact/g" \ 153"$SRC_DIR/gtk/gtk$variant.scss.in" > "$SRC_DIR/gtk/gtk$variant.gtk-$version.$name.scss" 154sassc "${SASSC_OPT[@]}" "$SRC_DIR/gtk/gtk$variant.gtk-$version.$name.scss" "$THEME_DIR/gtk-$version/gtk$variant.css" 155done 156done 157 158mkdir -p "$THEME_DIR/metacity-1" 159cp -r "$SRC_DIR/metacity-1/"{assets,metacity-theme-3.xml} "$THEME_DIR/metacity-1" 160cp -r "$SRC_DIR/metacity-1/metacity-theme-2$color.xml" "$THEME_DIR/metacity-1/metacity-theme-2.xml" 161 162mkdir -p "$THEME_DIR/plank" 163cp -r "$SRC_DIR/plank/dock.theme" "$THEME_DIR/plank" 164 165mkdir -p "$THEME_DIR/unity" 166cp -rT "$SRC_DIR/unity/dash-buttons" "$THEME_DIR/unity" 167cp -r "$SRC_DIR/unity/dash-widgets.json" "$THEME_DIR/unity" 168cp -rT "$SRC_DIR/unity/launcher" "$THEME_DIR/unity" 169cp -rT "$SRC_DIR/unity/window-buttons${ELSE_LIGHT:-}" "$THEME_DIR/unity" 170 171cp -r "$SRC_DIR/xfwm4/xfwm4$color" "$THEME_DIR/xfwm4" 172} 173 174# Bakup and install files related to GDM theme 175install_gdm() { 176local THEME_DIR="$1/$2$3$4" 177local GS_THEME_FILE="/usr/share/gnome-shell/gnome-shell-theme.gresource" 178local UBUNTU_THEME_FILE="/usr/share/gnome-shell/theme/ubuntu.css" 179 180if [[ -f "$GS_THEME_FILE" ]] && command -v glib-compile-resources >/dev/null; then 181echo "Installing '$GS_THEME_FILE'..." 182cp -an "$GS_THEME_FILE" "$GS_THEME_FILE.bak" 183glib-compile-resources \ 184--sourcedir="$THEME_DIR/gnome-shell" \ 185--target="$GS_THEME_FILE" \ 186"$THEME_DIR/gnome-shell/gnome-shell-theme.gresource.xml" 187else 188echo 189echo "ERROR: Failed to install '$GS_THEME_FILE'" 190exit 1 191fi 192 193if [[ -f "$UBUNTU_THEME_FILE" ]]; then 194echo "Installing '$UBUNTU_THEME_FILE'..." 195cp -an "$UBUNTU_THEME_FILE" "$UBUNTU_THEME_FILE.bak" 196cp -af "$THEME_DIR/gnome-shell/gnome-shell.css" "$UBUNTU_THEME_FILE" 197fi 198} 199 200colors=() 201sizes=() 202while [[ "$#" -gt 0 ]]; do 203case "${1:-}" in 204-d|--dest) 205dest="$2" 206mkdir -p "$dest" 207shift 2 208;; 209-n|--name) 210_name="$2" 211shift 2 212;; 213-g|--gdm) 214gdm='true' 215shift 1 216;; 217-c|--color) 218shift 219for variant in "$@"; do 220case "$variant" in 221standard) 222colors+=("${COLOR_VARIANTS[0]}") 223shift 224;; 225dark) 226colors+=("${COLOR_VARIANTS[1]}") 227shift 228;; 229light) 230colors+=("${COLOR_VARIANTS[2]}") 231shift 232;; 233-*) 234break 235;; 236*) 237echo "ERROR: Unrecognized color variant '$1'." 238echo "Try '$0 --help' for more information." 239exit 1 240;; 241esac 242done 243;; 244-s|--size) 245shift 246for variant in "$@"; do 247case "$variant" in 248standard) 249sizes+=("${SIZE_VARIANTS[0]}") 250shift 251;; 252compact) 253sizes+=("${SIZE_VARIANTS[1]}") 254shift 255;; 256-*) 257break 258;; 259*) 260echo "ERROR: Unrecognized size variant '${1:-}'." 261echo "Try '$0 --help' for more information." 262exit 1 263;; 264esac 265done 266;; 267-h|--help) 268usage 269exit 0 270;; 271*) 272echo "ERROR: Unrecognized installation option '${1:-}'." 273echo "Try '$0 --help' for more information." 274exit 1 275;; 276esac 277done 278 279if [[ ! -w "${dest:-$DEST_DIR}" ]]; then 280echo "Please run as root." 281exit 1 282fi 283 284if [[ "${#colors[@]}" -eq 0 ]] ; then 285colors=("${COLOR_VARIANTS[@]}") 286fi 287if [[ "${#sizes[@]}" -eq 0 ]] ; then 288sizes=("${SIZE_VARIANTS[@]}") 289fi 290for color in "${colors[@]}"; do 291for size in "${sizes[@]}"; do 292install "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size" 293done 294done 295 296if [[ "${gdm:-}" == 'true' ]]; then 297install_gdm "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size" 298fi 299 300echo 301echo "Done." 302