1#!/usr/local/bin/bash
2
3ROOT_UID=0
4DEST_DIR=
5
6# Destination directory
7if [ "$UID" -eq "$ROOT_UID" ]; then
8  DEST_DIR="/usr/share/themes"
9  ICON_DEST_DIR="/usr/share/icons"
10else
11  DEST_DIR="$HOME/.themes"
12  ICON_DEST_DIR="$HOME/.icons"
13fi
14
15SRC_DIR=$(cd $(dirname $0) && pwd)
16
17THEME_NAME=Canta
18COLOR_VARIANTS=('' '-light' '-dark')
19SIZE_VARIANTS=('' '-compact')
20THEME_VARIANTS=('' '-blue' '-indigo')
21
22show_info() {
23  echo -e "\033[1;34m$@\033[0m"
24}
25
26show_tips() {
27  echo -e "\033[1;32m$@\033[0m"
28}
29
30if [[ "$(command -v gnome-shell)" ]]; then
31  SHELL_VERSION="$(gnome-shell --version | cut -d ' ' -f 3 | cut -d . -f -1)"
32  if [[ "${SHELL_VERSION:-}" -ge "40" ]]; then
33    GS_VERSION="new"
34  else
35    GS_VERSION="old"
36  fi
37  else
38    echo "'gnome-shell' not found, using styles for last gnome-shell version available."
39    GS_VERSION="new"
40fi
41
42usage() {
43  printf "%s\n" "Usage: $0 [OPTIONS...]"
44  printf "\n%s\n" "OPTIONS:"
45  printf "  %-25s%s\n" "-d, --dest DIR" "Specify theme destination directory (Default: ${DEST_DIR})"
46  printf "  %-25s%s\n" "-n, --name NAME" "Specify theme name (Default: ${THEME_NAME})"
47  printf "  %-25s%s\n" "-t, --theme VARIANTS" "Specify theme color variant(s) [standard|blue|indigo] (Default: All variants)"
48  printf "  %-25s%s\n" "-c, --color VARIANTS" "Specify theme bright variant(s) [standard|light|dark] (Default: All variants)"
49  printf "  %-25s%s\n" "-s, --size VARIANT" "Specify theme size variant [standard|compact] (Default: All variants)"
50  printf "  %-25s%s\n" "-o, --ordinary" "Install ordinary theme without nautilus background images"
51  printf "  %-25s%s\n" "-g, --gdm" "Install GDM theme"
52  printf "  %-25s%s\n" "-i, --icon" "Install icon theme"
53  printf "  %-25s%s\n" "-h, --help" "Show this help"
54  printf "\n%s\n" "INSTALLATION EXAMPLES:"
55  printf "%s\n" "Install all theme variants into ~/themes"
56  printf "  %s\n" "$0 --dest ~/themes"
57  printf "%s\n" "Install all theme variants into ~/themes including GDM theme"
58  printf "  %s\n" "$0 --dest ~/themes --gdm"
59  printf "%s\n" "Install standard theme variant only"
60  printf "  %s\n" "$0 --dest ~/icons --icon"
61  printf "%s\n" "Install standard icon theme only"
62  printf "  %s\n" "$0 --color standard --size standard"
63  printf "%s\n" "Install square theme variant only"
64  printf "%s\n" "Install specific theme variants with different name into ~/themes"
65  printf "  %s\n" "$0 --dest ~/themes --name MyTheme --color light dark --size compact"
66}
67
68install() {
69  local dest=${1}
70  local name=${2}
71  local theme=${3}
72  local color=${4}
73  local size=${5}
74
75  [[ ${color} == '-dark' ]] && local ELSE_DARK=${color}
76  [[ ${color} == '-light' ]] && local ELSE_LIGHT=${color}
77
78  local THEME_DIR=${dest}/${name}${theme}${color}${size}
79
80  [[ -d ${THEME_DIR} ]] && rm -rf ${THEME_DIR}
81
82  echo "Installing '${THEME_DIR}'..."
83
84  theme_tweaks
85
86  mkdir -p                                                                           ${THEME_DIR}
87  cp -rf ${SRC_DIR}/COPYING                                                          ${THEME_DIR}
88  cp -rf ${SRC_DIR}/AUTHORS                                                          ${THEME_DIR}
89
90  echo "[Desktop Entry]" >> ${THEME_DIR}/index.theme
91  echo "Type=X-GNOME-Metatheme" >> ${THEME_DIR}/index.theme
92  echo "Name=${name}${theme}${color}${size}" >> ${THEME_DIR}/index.theme
93  echo "Comment=An Flat Gtk+ theme based on Material Design" >> ${THEME_DIR}/index.theme
94  echo "Encoding=UTF-8" >> ${THEME_DIR}/index.theme
95  echo "" >> ${THEME_DIR}/index.theme
96  echo "[X-GNOME-Metatheme]" >> ${THEME_DIR}/index.theme
97  echo "GtkTheme=${name}${theme}${color}${size}" >> ${THEME_DIR}/index.theme
98  echo "MetacityTheme=${name}${theme}${color}${size}" >> ${THEME_DIR}/index.theme
99  echo "IconTheme=Adwaita" >> ${THEME_DIR}/index.theme
100  echo "CursorTheme=Adwaita" >> ${THEME_DIR}/index.theme
101  echo "ButtonLayout=menu:minimize,maximize,close" >> ${THEME_DIR}/index.theme
102
103  mkdir -p                                                                           ${THEME_DIR}/gnome-shell
104  cp -rf ${SRC_DIR}/src/gnome-shell/{*.svg,extensions,noise-texture.png,pad-osd.css} ${THEME_DIR}/gnome-shell
105  cp -rf ${SRC_DIR}/src/gnome-shell/gnome-shell-theme.gresource.xml                  ${THEME_DIR}/gnome-shell
106  cp -rf ${SRC_DIR}/src/gnome-shell/assets${ELSE_DARK}                               ${THEME_DIR}/gnome-shell/assets
107  cp -rf ${SRC_DIR}/src/gnome-shell/common-assets/*.svg                              ${THEME_DIR}/gnome-shell/assets
108
109  if [[ "$tweaks" == 'true' ]]; then
110    if [[ "${GS_VERSION:-}" == 'new' ]]; then
111      sassc $SASSC_OPT ${SRC_DIR}/src/gnome-shell/shell-40-0/gnome-shell${color}${size}.scss ${THEME_DIR}/gnome-shell/gnome-shell.css
112    else
113      sassc $SASSC_OPT ${SRC_DIR}/src/gnome-shell/shell-3-36/gnome-shell${color}${size}.scss ${THEME_DIR}/gnome-shell/gnome-shell.css
114    fi
115  else
116    if [[ "${GS_VERSION:-}" == 'new' ]]; then
117      cp -rf ${SRC_DIR}/src/gnome-shell/shell-40-0/gnome-shell${color}${size}.css    ${THEME_DIR}/gnome-shell/gnome-shell.css
118    else
119      cp -rf ${SRC_DIR}/src/gnome-shell/shell-3-36/gnome-shell${color}${size}.css    ${THEME_DIR}/gnome-shell/gnome-shell.css
120    fi
121  fi
122
123  mkdir -p                                                                           ${THEME_DIR}/gtk-2.0
124  cp -rf ${SRC_DIR}/src/gtk-2.0/{apps.rc,hacks.rc,panel.rc}                          ${THEME_DIR}/gtk-2.0
125  cp -rf ${SRC_DIR}/src/gtk-2.0/main.rc${theme}                                      ${THEME_DIR}/gtk-2.0/main.rc
126  cp -rf ${SRC_DIR}/src/gtk-2.0/assets${ELSE_DARK}                                   ${THEME_DIR}/gtk-2.0/assets
127  [[ ${theme} != '' && ${color} == '-dark' ]] && \
128  cp -rf ${SRC_DIR}/src/gtk-2.0/assets-theme-dark/*.png                              ${THEME_DIR}/gtk-2.0/assets
129  cp -rf ${SRC_DIR}/src/gtk-2.0/gtkrc${theme}${color}                                ${THEME_DIR}/gtk-2.0/gtkrc
130
131  mkdir -p                                                                           ${THEME_DIR}/gtk-3.0
132  cp -rf ${SRC_DIR}/src/gtk/assets                                                   ${THEME_DIR}/gtk-3.0
133  cp -rf ${SRC_DIR}/src/gtk/common-assets                                            ${THEME_DIR}/gtk-3.0
134
135  if [[ "$tweaks" == 'true' ]]; then
136    sassc $SASSC_OPT ${SRC_DIR}/src/gtk/3.0/gtk${color}${size}.scss                  ${THEME_DIR}/gtk-3.0/gtk.css
137    [[ ${color} != '-dark' ]] && \
138    sassc $SASSC_OPT ${SRC_DIR}/src/gtk/3.0/gtk-dark${size}.scss                     ${THEME_DIR}/gtk-3.0/gtk-dark.css
139  else
140    cp -rf ${SRC_DIR}/src/gtk/3.0/gtk${color}${size}.css                             ${THEME_DIR}/gtk-3.0/gtk.css
141    [[ ${color} != '-dark' ]] && \
142    cp -rf ${SRC_DIR}/src/gtk/3.0/gtk-dark${size}.css                                ${THEME_DIR}/gtk-3.0/gtk-dark.css
143  fi
144
145  mkdir -p                                                                           ${THEME_DIR}/gtk-4.0
146  cp -rf ${SRC_DIR}/src/gtk/assets                                                   ${THEME_DIR}/gtk-4.0
147  cp -rf ${SRC_DIR}/src/gtk/common-assets                                            ${THEME_DIR}/gtk-4.0
148
149  if [[ "$tweaks" == 'true' ]]; then
150    sassc $SASSC_OPT ${SRC_DIR}/src/gtk/4.0/gtk${color}${size}.scss                  ${THEME_DIR}/gtk-4.0/gtk.css
151    [[ ${color} != '-dark' ]] && \
152    sassc $SASSC_OPT ${SRC_DIR}/src/gtk/4.0/gtk-dark${size}.scss                     ${THEME_DIR}/gtk-4.0/gtk-dark.css
153  else
154    cp -rf ${SRC_DIR}/src/gtk/4.0/gtk${color}${size}.css                             ${THEME_DIR}/gtk-4.0/gtk.css
155    [[ ${color} != '-dark' ]] && \
156    cp -rf ${SRC_DIR}/src/gtk/4.0/gtk-dark${size}.css                                ${THEME_DIR}/gtk-4.0/gtk-dark.css
157  fi
158
159  mkdir -p                                                                           ${THEME_DIR}/metacity-1
160  cp -rf ${SRC_DIR}/src/metacity-1/assets/*.png                                      ${THEME_DIR}/metacity-1
161  cp -rf ${SRC_DIR}/src/metacity-1/metacity-theme-1${color}.xml                      ${THEME_DIR}/metacity-1/metacity-theme-1.xml
162  cd ${THEME_DIR}/metacity-1
163  ln -s metacity-theme-1.xml metacity-theme-2.xml
164  ln -s metacity-theme-1.xml metacity-theme-3.xml
165
166  mkdir -p                                                                           ${THEME_DIR}/unity
167  cp -rf ${SRC_DIR}/src/unity/{*.svg,*.png,dash-widgets.json}                        ${THEME_DIR}/unity
168  cp -rf ${SRC_DIR}/src/unity/assets${ELSE_LIGHT}                                    ${THEME_DIR}/unity/assets
169
170  mkdir -p                                                                           ${THEME_DIR}/xfwm4
171  cp -rf ${SRC_DIR}/src/xfwm4/{*.svg,themerc}                                        ${THEME_DIR}/xfwm4
172  cp -rf ${SRC_DIR}/src/xfwm4/assets${ELSE_LIGHT}                                    ${THEME_DIR}/xfwm4/assets
173
174  if [[ "${theme}" == '' ]]; then
175    mkdir -p                                                                         ${THEME_DIR}/cinnamon
176    cp -rf ${SRC_DIR}/src/cinnamon/cinnamon${ELSE_DARK}.css                          ${THEME_DIR}/cinnamon/cinnamon.css
177    cp -rf ${SRC_DIR}/src/cinnamon/assets/common-assets                              ${THEME_DIR}/cinnamon/assets
178    cp -rf ${SRC_DIR}/src/cinnamon/assets/assets${ELSE_DARK}/checkbox/*.svg          ${THEME_DIR}/cinnamon/assets/checkbox
179    cp -rf ${SRC_DIR}/src/cinnamon/assets/assets${ELSE_DARK}/menu/*.svg              ${THEME_DIR}/cinnamon/assets/menu
180    cp -rf ${SRC_DIR}/src/cinnamon/assets/assets${ELSE_DARK}/misc/*.svg              ${THEME_DIR}/cinnamon/assets/misc
181    cp -rf ${SRC_DIR}/src/cinnamon/assets/assets${ELSE_DARK}/switch/*.svg            ${THEME_DIR}/cinnamon/assets/switch
182    cp -rf ${SRC_DIR}/src/cinnamon/thumbnail${ELSE_DARK}.png                         ${THEME_DIR}/cinnamon/thumbnail.png
183  fi
184
185  mkdir -p                                                                           ${THEME_DIR}/plank
186  cp -rf ${SRC_DIR}/src/plank/dock${ELSE_LIGHT}.theme                                ${THEME_DIR}/plank/dock.theme
187}
188
189install_gdm() {
190  local THEME_DIR=${1}/${2}${3}${4}${5}
191  local GS_THEME_FILE="/usr/share/gnome-shell/gnome-shell-theme.gresource"
192  local UBUNTU_THEME_FILE="/usr/share/gnome-shell/theme/ubuntu.css"
193
194  if [[ -f "$GS_THEME_FILE" ]] && [[ "$(which glib-compile-resources 2> /dev/null)" ]]; then
195    echo "Installing '$GS_THEME_FILE'..."
196    cp -an "$GS_THEME_FILE" "$GS_THEME_FILE.bak"
197    glib-compile-resources \
198      --sourcedir="$THEME_DIR/gnome-shell" \
199      --target="$GS_THEME_FILE" \
200      "$THEME_DIR/gnome-shell/gnome-shell-theme.gresource.xml"
201  else
202    echo
203    echo "ERROR: Failed to install '$GS_THEME_FILE'"
204    exit 1
205  fi
206
207  if [[ -f "$UBUNTU_THEME_FILE" ]]; then
208    echo "Installing '$UBUNTU_THEME_FILE'..."
209    cp -an "$UBUNTU_THEME_FILE" "$UBUNTU_THEME_FILE.bak"
210    cp -af "$THEME_DIR/gnome-shell/gnome-shell.css" "$UBUNTU_THEME_FILE"
211  fi
212}
213
214install_icon() {
215  echo -e "\nInstalling Canta icon theme..."
216
217  # Copying files
218  cp -rf ${SRC_DIR}/icons/Canta ${ICON_DEST_DIR}
219
220  # update icon caches
221  gtk-update-icon-cache ${ICON_DEST_DIR}/Canta
222
223  echo -e "\nInstallation complete!"
224  show_tips "\nIf you want a better experience you should install numix-circle first!"
225  show_tips "Because Canta icon theme use numix-icon-theme-circle icon theme for Inherits!\n"
226}
227
228# check command avalibility
229function has_command() {
230  command -v $1 > /dev/null
231}
232
233install_package() {
234  if [ ! "$(which sassc 2> /dev/null)" ]; then
235     echo sassc needs to be installed to generate the css.
236     if has_command zypper; then
237      sudo zypper in sassc
238        elif has_command apt-get; then
239      sudo apt-get install sassc
240        elif has_command dnf; then
241      sudo dnf install sassc
242        elif has_command yum; then
243      sudo yum install sassc
244        elif has_command pacman; then
245      sudo pacman -S --noconfirm sassc
246      fi
247  fi
248}
249
250themes=()
251colors=()
252sizes=()
253
254while [[ "$#" -gt 0 ]]; do
255  case "${1:-}" in
256    -d|--dest)
257      dest="${2}"
258      if [[ ! -d "${dest}" ]]; then
259        echo "ERROR: Destination directory does not exist."
260        exit 1
261      fi
262      shift 2
263      ;;
264    -n|--name)
265      name="${2}"
266      shift 2
267      ;;
268    -g|--gdm)
269      gdm='true'
270      shift 1
271      ;;
272    -i|--icon)
273      icon='true'
274      shift 1
275      ;;
276    -o|--ordinary)
277      ordinary='true'
278      shift 1
279      ;;
280    -t|--theme)
281      accent='true'
282      shift
283      for theme in "${@}"; do
284        case "${theme}" in
285          standard)
286            themes+=("${THEME_VARIANTS[0]}")
287            shift
288            ;;
289          blue)
290            themes+=("${THEME_VARIANTS[1]}")
291            shift
292            ;;
293          indigo)
294            themes+=("${THEME_VARIANTS[2]}")
295            shift
296            ;;
297          -*|--*)
298            break
299            ;;
300          *)
301            echo "ERROR: Unrecognized theme variant '$1'."
302            echo "Try '$0 --help' for more information."
303            exit 1
304            ;;
305        esac
306      done
307      ;;
308    -c|--color)
309      shift
310      for color in "${@}"; do
311        case "${color}" in
312          standard)
313            colors+=("${COLOR_VARIANTS[0]}")
314            shift
315            ;;
316          light)
317            colors+=("${COLOR_VARIANTS[1]}")
318            shift
319            ;;
320          dark)
321            colors+=("${COLOR_VARIANTS[2]}")
322            shift
323            ;;
324          -*|--*)
325            break
326            ;;
327          *)
328            echo "ERROR: Unrecognized color variant '$1'."
329            echo "Try '$0 --help' for more information."
330            exit 1
331            ;;
332        esac
333      done
334      ;;
335    -s|--size)
336      shift
337      for size in "${@}"; do
338        case "${size}" in
339          standard)
340            sizes+=("${SIZE_VARIANTS[0]}")
341            shift
342            ;;
343          compact)
344            sizes+=("${SIZE_VARIANTS[1]}")
345            shift
346            ;;
347          -*|--*)
348            break
349            ;;
350          *)
351            echo "ERROR: Unrecognized size variant '$1'."
352            echo "Try '$0 --help' for more information."
353            exit 1
354            ;;
355        esac
356      done
357      ;;
358    -h|--help)
359      usage
360      exit 0
361      ;;
362    *)
363      echo "ERROR: Unrecognized installation option '$1'."
364      echo "Try '$0 --help' for more information."
365      exit 1
366      ;;
367  esac
368done
369
370if [[ "${#themes[@]}" -eq 0 ]] ; then
371  themes=("${THEME_VARIANTS[0]}")
372fi
373
374if [[ "${#colors[@]}" -eq 0 ]] ; then
375  colors=("${COLOR_VARIANTS[@]}")
376fi
377
378if [[ "${#sizes[@]}" -eq 0 ]] ; then
379  sizes=("${SIZE_VARIANTS[@]}")
380fi
381
382install_theme() {
383  for theme in "${themes[@]}"; do
384    for color in "${colors[@]}"; do
385      for size in "${sizes[@]}"; do
386         install "${dest:-${DEST_DIR}}" "${name:-${THEME_NAME}}" "${theme}" "${color}" "${size}"
387      done
388    done
389  done
390}
391
392tweaks_temp() {
393  cp -rf ${SRC_DIR}/src/_sass/_tweaks.scss ${SRC_DIR}/src/_sass/_tweaks-temp.scss
394}
395
396theme_colors() {
397  if [[ "$theme" != '' ]]; then
398    case "$theme" in
399      -blue)
400        theme_color='blue'
401        ;;
402      -indigo)
403        theme_color='indigo'
404        ;;
405    esac
406    gsed -i "/\$color:/s/default/${theme_color}/" ${SRC_DIR}/src/_sass/_tweaks-temp.scss
407  fi
408}
409
410bakground_image() {
411    echo "Install with no nautilus bakground image..."
412    gsed -i "/\$theme_image:/s/true/false/" ${SRC_DIR}/src/_sass/_tweaks-temp.scss
413}
414
415theme_tweaks() {
416  if [[ "$accent" == 'true' || "${ordinary}" == 'true' ]]; then
417    tweaks='true'
418    install_package; tweaks_temp
419  fi
420
421  if [[ "$accent" == 'true' ]] ; then
422    theme_colors
423  fi
424
425  if [[ "${ordinary}" == 'true' ]] ; then
426    bakground_image
427  fi
428}
429
430install_theme
431
432if [[ "${gdm:-}" == 'true' ]]; then
433  install_gdm "${dest:-${DEST_DIR}}" "${name:-${THEME_NAME}}" "${theme}" "${color}" "${size}"
434fi
435
436if [[ "${icon:-}" == 'true' ]]; then
437  install_icon "${dest:-${DEST_DIR}}" "${name:-${THEME_NAME}}" "${theme}" "${color}" "${size}"
438fi
439
440echo
441echo Done.
442