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-theme.gresource.xml" \ 176"$SRC_DIR/gnome-shell/noise-texture.png" \ 177"$SRC_DIR/gnome-shell/pad-osd.css" \ 178"$SRC_DIR/gnome-shell/process-working.svg" \ 179"$THEME_DIR/gnome-shell" 180sed \ 181-e "s|@dark_theme@|$scss_dark_theme|g" \ 182-e "s|@light_topbar@|$scss_light_topbar|g" \ 183-e "s|@compact@|$scss_compact|g" \ 184-e "s|@version@|$GS_VERSION|g" \ 185-e "s|@current_source_dir@|$SRC_DIR/gnome-shell|g" \ 186"$SRC_DIR/gnome-shell/gnome-shell.scss.in" | \ 187sassc --stdin "${SASSC_OPT[@]}" \ 188"$THEME_DIR/gnome-shell/gnome-shell.css" 189 190# 191# GTK 2 192# 193 194mkdir -p "$THEME_DIR/gtk-2.0" 195cp -r -T \ 196"$SRC_DIR/gtk-2.0/assets${ELSE_DARK:-}" \ 197"$THEME_DIR/gtk-2.0/assets" 198cp -T \ 199"$SRC_DIR/gtk-2.0/gtkrc$color" \ 200"$THEME_DIR/gtk-2.0/gtkrc" 201cp \ 202"$SRC_DIR/gtk-2.0/apps.rc" \ 203"$SRC_DIR/gtk-2.0/hacks.rc" \ 204"$SRC_DIR/gtk-2.0/main.rc" \ 205"$THEME_DIR/gtk-2.0" 206 207# 208# GTK 3 & 4 209# 210 211local GTK_VARIANTS=('') 212[[ "$color" != '-dark' ]] && local GTK_VARIANTS+=('-dark') 213 214for version in "3.0" "4.0"; do 215mkdir -p "$THEME_DIR/gtk-$version" 216cp -r \ 217"$SRC_DIR/gtk-3.0/assets" \ 218"$SRC_DIR/gtk-3.0/icons" \ 219"$THEME_DIR/gtk-$version" 220 221for variant in "${GTK_VARIANTS[@]}"; do 222sed \ 223-e "s|@dark_theme@|$scss_dark_theme|g" \ 224-e "s|@light_topbar@|$scss_light_topbar|g" \ 225-e "s|@compact@|$scss_compact|g" \ 226-e "s|@version@|$GTK4_VERSION|g" \ 227-e "s|@current_source_dir@|$SRC_DIR/gtk-$version|g" \ 228"$SRC_DIR/gtk-$version/gtk$variant.scss.in" | \ 229sassc --stdin "${SASSC_OPT[@]}" \ 230"$THEME_DIR/gtk-$version/gtk$variant.css" 231done 232done 233 234# 235# Metacity 236# 237 238mkdir -p "$THEME_DIR/metacity-1" 239cp -r \ 240"$SRC_DIR/metacity-1/assets" \ 241"$THEME_DIR/metacity-1" 242cp -T \ 243"$SRC_DIR/metacity-1/metacity-theme-2$color.xml" \ 244"$THEME_DIR/metacity-1/metacity-theme-2.xml" 245cp \ 246"$SRC_DIR/metacity-1/metacity-theme-3.xml" \ 247"$THEME_DIR/metacity-1" 248 249# 250# Plank 251# 252 253mkdir -p "$THEME_DIR/plank" 254cp \ 255"$SRC_DIR/plank/dock.theme" \ 256"$THEME_DIR/plank" 257 258# 259# Unity 260# 261 262mkdir -p "$THEME_DIR/unity" 263cp -r -T \ 264"$SRC_DIR/unity/dash-buttons" \ 265"$THEME_DIR/unity" 266cp -r -T \ 267"$SRC_DIR/unity/launcher" \ 268"$THEME_DIR/unity" 269cp -r -T \ 270"$SRC_DIR/unity/window-buttons${ELSE_LIGHT:-}" \ 271"$THEME_DIR/unity" 272cp \ 273"$SRC_DIR/unity/dash-widgets.json" \ 274"$THEME_DIR/unity" 275 276# 277# Xfwm4 278# 279 280mkdir -p "$THEME_DIR/xfwm4" 281cp -r -T \ 282"$SRC_DIR/xfwm4/xfwm4$color" \ 283"$THEME_DIR/xfwm4" 284} 285 286# Bakup and install files related to GDM theme 287install_gdm_theme() { 288local THEME_DIR="$1/$2$3$4" 289local GS_THEME_FILE="/usr/share/gnome-shell/gnome-shell-theme.gresource" 290local UBUNTU_THEME_FILE="/usr/share/gnome-shell/theme/ubuntu.css" 291 292if [[ -f "$GS_THEME_FILE" ]] && command -v glib-compile-resources >/dev/null; then 293echo "Installing '$GS_THEME_FILE'..." 294cp -an "$GS_THEME_FILE" "$GS_THEME_FILE.bak" 295glib-compile-resources \ 296--sourcedir="$THEME_DIR/gnome-shell" \ 297--target="$GS_THEME_FILE" \ 298"$THEME_DIR/gnome-shell/gnome-shell-theme.gresource.xml" 299else 300echo 301echo "ERROR: Failed to install '$GS_THEME_FILE'" 302exit 1 303fi 304 305if [[ -f "$UBUNTU_THEME_FILE" ]]; then 306echo "Installing '$UBUNTU_THEME_FILE'..." 307cp -an "$UBUNTU_THEME_FILE" "$UBUNTU_THEME_FILE.bak" 308cp -af "$THEME_DIR/gnome-shell/gnome-shell.css" "$UBUNTU_THEME_FILE" 309fi 310} 311 312colors=() 313sizes=() 314while [[ "$#" -gt 0 ]]; do 315case "${1:-}" in 316-d|--dest) 317dest="$2" 318mkdir -p "$dest" 319shift 2 320;; 321-n|--name) 322_name="$2" 323shift 2 324;; 325-g|--gdm) 326gdm='true' 327shift 1 328;; 329-c|--color) 330shift 331for variant in "$@"; do 332case "$variant" in 333standard) 334colors+=("${COLOR_VARIANTS[0]}") 335shift 336;; 337dark) 338colors+=("${COLOR_VARIANTS[1]}") 339shift 340;; 341light) 342colors+=("${COLOR_VARIANTS[2]}") 343shift 344;; 345-*) 346break 347;; 348*) 349echo "ERROR: Unrecognized color variant '$1'." 350echo "Try '$0 --help' for more information." 351exit 1 352;; 353esac 354done 355;; 356-s|--size) 357shift 358for variant in "$@"; do 359case "$variant" in 360standard) 361sizes+=("${SIZE_VARIANTS[0]}") 362shift 363;; 364compact) 365sizes+=("${SIZE_VARIANTS[1]}") 366shift 367;; 368-*) 369break 370;; 371*) 372echo "ERROR: Unrecognized size variant '${1:-}'." 373echo "Try '$0 --help' for more information." 374exit 1 375;; 376esac 377done 378;; 379-h|--help) 380usage 381exit 0 382;; 383*) 384echo "ERROR: Unrecognized installation option '${1:-}'." 385echo "Try '$0 --help' for more information." 386exit 1 387;; 388esac 389done 390 391if [[ ! -w "${dest:-$DEST_DIR}" ]]; then 392echo "Please run as root." 393exit 1 394fi 395 396if [[ "${#colors[@]}" -eq 0 ]] ; then 397colors=("${COLOR_VARIANTS[@]}") 398fi 399if [[ "${#sizes[@]}" -eq 0 ]] ; then 400sizes=("${SIZE_VARIANTS[@]}") 401fi 402for color in "${colors[@]}"; do 403for size in "${sizes[@]}"; do 404install_theme "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size" 405done 406done 407 408if [[ "${gdm:-}" == 'true' ]]; then 409install_gdm_theme "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size" 410fi 411 412echo 413echo "Done." 414