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