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() { 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 -r "$REPO_DIR/COPYING" "$THEME_DIR" 122sed \ 123-e "s/@theme_name@/$name/g" \ 124"$SRC_DIR/index.theme.in" > "$THEME_DIR/index.theme" 125 126# 127# Chrome extensions 128# 129 130mkdir -p "$THEME_DIR/chrome" 131cp -r "$SRC_DIR/chrome/chrome-theme$color.crx" "$THEME_DIR/chrome/chrome-theme.crx" 132cp -r "$SRC_DIR/chrome/chrome-scrollbar${ELSE_DARK:-}.crx" "$THEME_DIR/chrome/chrome-scrollbar.crx" 133 134# 135# Cinnamon 136# 137 138mkdir -p "$THEME_DIR/cinnamon" 139cp -r "$SRC_DIR/cinnamon/assets" "$THEME_DIR/cinnamon" 140cp -r "$SRC_DIR/cinnamon/thumbnail.png" "$THEME_DIR/cinnamon" 141sed \ 142-e "s/@dark_theme@/$scss_dark_theme/g" \ 143-e "s/@light_topbar@/$scss_light_topbar/g" \ 144-e "s/@compact@/$scss_compact/g" \ 145"$SRC_DIR/cinnamon/cinnamon.scss.in" > "$SRC_DIR/cinnamon/cinnamon.$name.scss" 146sassc "${SASSC_OPT[@]}" "$SRC_DIR/cinnamon/cinnamon.$name.scss" "$THEME_DIR/cinnamon/cinnamon.css" 147 148# 149# GNOME Shell 150# 151 152mkdir -p "$THEME_DIR/gnome-shell" 153cp -r "$SRC_DIR/gnome-shell/extensions" "$THEME_DIR/gnome-shell" 154cp -r "$SRC_DIR/gnome-shell/gnome-shell-theme.gresource.xml" "$THEME_DIR/gnome-shell" 155cp -r "$SRC_DIR/gnome-shell/icons" "$THEME_DIR/gnome-shell" 156cp -r "$SRC_DIR/gnome-shell/noise-texture.png" "$THEME_DIR/gnome-shell" 157cp -r "$SRC_DIR/gnome-shell/pad-osd.css" "$THEME_DIR/gnome-shell" 158cp -r "$SRC_DIR/gnome-shell/process-working.svg" "$THEME_DIR/gnome-shell" 159cp -r "$SRC_DIR/gnome-shell/README.md" "$THEME_DIR/gnome-shell" 160cp -r "$SRC_DIR/gnome-shell/assets${ELSE_DARK:-}" "$THEME_DIR/gnome-shell/assets" 161sed \ 162-e "s/@dark_theme@/$scss_dark_theme/g" \ 163-e "s/@light_topbar@/$scss_light_topbar/g" \ 164-e "s/@compact@/$scss_compact/g" \ 165-e "s/@version@/$GS_VERSION/g" \ 166"$SRC_DIR/gnome-shell/gnome-shell.scss.in" > "$SRC_DIR/gnome-shell/gnome-shell.$name.scss" 167sassc "${SASSC_OPT[@]}" "$SRC_DIR/gnome-shell/gnome-shell.$name.scss" "$THEME_DIR/gnome-shell/gnome-shell.css" 168 169# 170# GTK 2 171# 172 173mkdir -p "$THEME_DIR/gtk-2.0" 174cp -r "$SRC_DIR/gtk-2.0/apps.rc" "$THEME_DIR/gtk-2.0" 175cp -r "$SRC_DIR/gtk-2.0/hacks.rc" "$THEME_DIR/gtk-2.0" 176cp -r "$SRC_DIR/gtk-2.0/main.rc" "$THEME_DIR/gtk-2.0" 177cp -r "$SRC_DIR/gtk-2.0/assets${ELSE_DARK:-}" "$THEME_DIR/gtk-2.0/assets" 178cp -r "$SRC_DIR/gtk-2.0/gtkrc$color" "$THEME_DIR/gtk-2.0/gtkrc" 179 180# 181# GTK 3 & 4 182# 183 184local GTK_VARIANTS=('') 185[[ "$color" != '-dark' ]] && local GTK_VARIANTS+=('-dark') 186 187for version in "3.0" "4.0"; do 188mkdir -p "$THEME_DIR/gtk-$version" 189cp -r "$SRC_DIR/gtk-3.0/assets" "$THEME_DIR/gtk-$version" 190cp -r "$SRC_DIR/gtk-3.0/icons" "$THEME_DIR/gtk-$version" 191 192for variant in "${GTK_VARIANTS[@]}"; do 193sed \ 194-e "s/@dark_theme@/$scss_dark_theme/g" \ 195-e "s/@light_topbar@/$scss_light_topbar/g" \ 196-e "s/@compact@/$scss_compact/g" \ 197-e "s/@version@/$GTK4_VERSION/g" \ 198"$SRC_DIR/gtk-$version/gtk$variant.scss.in" > "$SRC_DIR/gtk-$version/gtk$variant.$name.scss" 199sassc "${SASSC_OPT[@]}" "$SRC_DIR/gtk-$version/gtk$variant.$name.scss" "$THEME_DIR/gtk-$version/gtk$variant.css" 200done 201done 202 203# 204# Metacity 205# 206 207mkdir -p "$THEME_DIR/metacity-1" 208cp -r "$SRC_DIR/metacity-1/assets" "$THEME_DIR/metacity-1" 209cp -r "$SRC_DIR/metacity-1/metacity-theme-3.xml" "$THEME_DIR/metacity-1" 210cp -r "$SRC_DIR/metacity-1/metacity-theme-2$color.xml" "$THEME_DIR/metacity-1/metacity-theme-2.xml" 211 212# 213# Plank 214# 215 216mkdir -p "$THEME_DIR/plank" 217cp -r "$SRC_DIR/plank/dock.theme" "$THEME_DIR/plank" 218 219# 220# Unity 221# 222 223mkdir -p "$THEME_DIR/unity" 224cp -rT "$SRC_DIR/unity/dash-buttons" "$THEME_DIR/unity" 225cp -r "$SRC_DIR/unity/dash-widgets.json" "$THEME_DIR/unity" 226cp -rT "$SRC_DIR/unity/launcher" "$THEME_DIR/unity" 227cp -rT "$SRC_DIR/unity/window-buttons${ELSE_LIGHT:-}" "$THEME_DIR/unity" 228 229# 230# Xfwm4 231# 232 233cp -r "$SRC_DIR/xfwm4/xfwm4$color" "$THEME_DIR/xfwm4" 234} 235 236# Bakup and install files related to GDM theme 237install_gdm() { 238local THEME_DIR="$1/$2$3$4" 239local GS_THEME_FILE="/usr/share/gnome-shell/gnome-shell-theme.gresource" 240local UBUNTU_THEME_FILE="/usr/share/gnome-shell/theme/ubuntu.css" 241 242if [[ -f "$GS_THEME_FILE" ]] && command -v glib-compile-resources >/dev/null; then 243echo "Installing '$GS_THEME_FILE'..." 244cp -an "$GS_THEME_FILE" "$GS_THEME_FILE.bak" 245glib-compile-resources \ 246--sourcedir="$THEME_DIR/gnome-shell" \ 247--target="$GS_THEME_FILE" \ 248"$THEME_DIR/gnome-shell/gnome-shell-theme.gresource.xml" 249else 250echo 251echo "ERROR: Failed to install '$GS_THEME_FILE'" 252exit 1 253fi 254 255if [[ -f "$UBUNTU_THEME_FILE" ]]; then 256echo "Installing '$UBUNTU_THEME_FILE'..." 257cp -an "$UBUNTU_THEME_FILE" "$UBUNTU_THEME_FILE.bak" 258cp -af "$THEME_DIR/gnome-shell/gnome-shell.css" "$UBUNTU_THEME_FILE" 259fi 260} 261 262colors=() 263sizes=() 264while [[ "$#" -gt 0 ]]; do 265case "${1:-}" in 266-d|--dest) 267dest="$2" 268mkdir -p "$dest" 269shift 2 270;; 271-n|--name) 272_name="$2" 273shift 2 274;; 275-g|--gdm) 276gdm='true' 277shift 1 278;; 279-c|--color) 280shift 281for variant in "$@"; do 282case "$variant" in 283standard) 284colors+=("${COLOR_VARIANTS[0]}") 285shift 286;; 287dark) 288colors+=("${COLOR_VARIANTS[1]}") 289shift 290;; 291light) 292colors+=("${COLOR_VARIANTS[2]}") 293shift 294;; 295-*) 296break 297;; 298*) 299echo "ERROR: Unrecognized color variant '$1'." 300echo "Try '$0 --help' for more information." 301exit 1 302;; 303esac 304done 305;; 306-s|--size) 307shift 308for variant in "$@"; do 309case "$variant" in 310standard) 311sizes+=("${SIZE_VARIANTS[0]}") 312shift 313;; 314compact) 315sizes+=("${SIZE_VARIANTS[1]}") 316shift 317;; 318-*) 319break 320;; 321*) 322echo "ERROR: Unrecognized size variant '${1:-}'." 323echo "Try '$0 --help' for more information." 324exit 1 325;; 326esac 327done 328;; 329-h|--help) 330usage 331exit 0 332;; 333*) 334echo "ERROR: Unrecognized installation option '${1:-}'." 335echo "Try '$0 --help' for more information." 336exit 1 337;; 338esac 339done 340 341if [[ ! -w "${dest:-$DEST_DIR}" ]]; then 342echo "Please run as root." 343exit 1 344fi 345 346if [[ "${#colors[@]}" -eq 0 ]] ; then 347colors=("${COLOR_VARIANTS[@]}") 348fi 349if [[ "${#sizes[@]}" -eq 0 ]] ; then 350sizes=("${SIZE_VARIANTS[@]}") 351fi 352for color in "${colors[@]}"; do 353for size in "${sizes[@]}"; do 354install "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size" 355done 356done 357 358if [[ "${gdm:-}" == 'true' ]]; then 359install_gdm "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size" 360fi 361 362echo 363echo "Done." 364