1#!/usr/local/bin/bash
2#
3# This file is part of plata-theme
4#
5# Copyright (C) 2018-2020 Tista <tista.gma500@gmail.com>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12
13SRC_DIR="assets-gnome-shell"
14ASSETS_DIR="../gnome-shell"
15ASSETS_LIGHT_DIR="../gnome-shell-light"
16ASSETS_DARK_DIR="../gnome-shell-dark"
17ASSETS_ETA_DIR="../gnome-shell-compact"
18ASSETS_LIGHT_ETA_DIR="../gnome-shell-light-compact"
19ASSETS_DARK_ETA_DIR="../gnome-shell-dark-compact"
20INDEX="assets-gnome-shell.txt"
21KEY_FILE="../../gtk/sass/common/resources/_key_colors.scss"
22
23# Default colours
24selection1="`grep 'Indigo500' ../../gtk/sass/common/_colors.scss | \
25                   cut -d' ' -f3`"
26accent1="`grep 'Indigo300' ../../gtk/sass/common/_colors.scss | \
27                cut -d' ' -f3`"
28destruction1="`grep 'Red500' ../../gtk/sass/common/_colors.scss | \
29                     cut -d' ' -f3`"
30
31# Check and re-color SVG files
32if [ -e $KEY_FILE ]; then
33    selection2="`grep 'key_selection' $KEY_FILE | \
34                 cut -d' ' -f2 | cut -d';' -f1`"
35    accent2="`grep 'key_accent' $KEY_FILE | \
36              cut -d' ' -f2 | cut -d';' -f1`"
37    destruction2="`grep 'key_destruction' $KEY_FILE | \
38                   cut -d' ' -f2 | cut -d';' -f1`"
39
40IFS=$'
41'
42for i in $(<$INDEX)
43do
44    s="`echo $i | cut -d' ' -f1`" # source
45    r="`echo $i | cut -d' ' -f3`" # recolor flag
46
47    if [ "$r" = "r1" ]; then
48        cp -f $SRC_DIR/$s.in $SRC_DIR/$s
49
50        if [ $selection1 != $selection2 ]; then
51            sed -i '' "s/$selection1/$selection2/gi" $SRC_DIR/$s
52            echo $s is re-colored with $selection2.
53        fi
54    elif [ "$r" = "r2" ]; then
55        cp -f $SRC_DIR/$s.in $SRC_DIR/$s
56
57        if [ $accent1 != $accent2 ]; then
58            sed -i '' "s/$accent1/$accent2/gi" $SRC_DIR/$s
59            echo $s is re-colored with $accent2.
60        fi
61    elif [ "$r" = "r3" ]; then
62        cp -f $SRC_DIR/$s.in $SRC_DIR/$s
63
64        if [ $destruction1 != $destruction2 ]; then
65            sed -i '' "s/$destruction1/$destruction2/gi" $SRC_DIR/$s
66            echo $s is re-colored with $destruction2.
67        fi
68    fi
69done
70unset IFS
71
72else
73    echo ../../gtk/sass/common/resources/_key_colors.scss was not found. Stopped...
74    exit 1
75fi
76
77# Clone stock SVG files
78IFS=$'
79'
80for i in $(<$INDEX)
81do
82    s="`echo $i | cut -d' ' -f1`"                     # source
83    f="`echo $i | cut -d'.' -f1 | cut -d'/' -f2`.svg" # file name
84    v="`echo $i | cut -c1`"                           # variant type
85    d="`echo $i | cut -d' ' -f2`"                     # target directory
86
87    if [ $v = "c" ] || [ $v = "w" ]; then # 'commmon'
88        if [ -f $ASSETS_DIR/$d/$f ] && \
89            [ $SRC_DIR/$s -ot $ASSETS_DIR/$d/$f ]; then
90            echo $ASSETS_DIR/$d/$f exists.
91            echo $ASSETS_LIGHT_DIR/$d/$f exists.
92            echo $ASSETS_DARK_DIR/$d/$f exists.
93            echo $ASSETS_ETA_DIR/$d/$f exists.
94            echo $ASSETS_LIGHT_ETA_DIR/$d/$f exists.
95            echo $ASSETS_DARK_ETA_DIR/$d/$f exists.
96        elif [ $i = "common/noise-texture.png ." ]; then # PNG special case
97            f="`echo $i | cut -d'.' -f1 | cut -d'/' -f2`.png"
98            echo Cloning $ASSETS_DIR/$d/$f
99            cp -f $SRC_DIR/$s $ASSETS_DIR/$d/$f
100            echo Cloning $ASSETS_ETA_DIR/$d/$f
101            cp -f $SRC_DIR/$s $ASSETS_ETA_DIR/$d/$f
102            echo Cloning $ASSETS_LIGHT_DIR/$d/$f
103            cp -f $SRC_DIR/$s $ASSETS_LIGHT_DIR/$d/$f
104            echo Cloning $ASSETS_LIGHT_ETA_DIR/$d/$f
105            cp -f $SRC_DIR/$s $ASSETS_LIGHT_ETA_DIR/$d/$f
106            echo Cloning $ASSETS_DARK_DIR/$d/$f
107            cp -f $SRC_DIR/$s $ASSETS_DARK_DIR/$d/$f
108            echo Cloning $ASSETS_DARK_ETA_DIR/$d/$f
109            cp -f $SRC_DIR/$s $ASSETS_DARK_ETA_DIR/$d/$f
110        else
111            echo Cloning $ASSETS_DIR/$d/$f
112            cp -f $SRC_DIR/$s $ASSETS_DIR/$d/$f
113            echo Cloning $ASSETS_ETA_DIR/$d/$f
114            cp -f $SRC_DIR/$s $ASSETS_ETA_DIR/$d/$f
115            echo Cloning $ASSETS_LIGHT_DIR/$d/$f
116            cp -f $SRC_DIR/$s $ASSETS_LIGHT_DIR/$d/$f
117            echo Cloning $ASSETS_LIGHT_ETA_DIR/$d/$f
118            cp -f $SRC_DIR/$s $ASSETS_LIGHT_ETA_DIR/$d/$f
119            echo Cloning $ASSETS_DARK_DIR/$d/$f
120            cp -f $SRC_DIR/$s $ASSETS_DARK_DIR/$d/$f
121            echo Cloning $ASSETS_DARK_ETA_DIR/$d/$f
122            cp -f $SRC_DIR/$s $ASSETS_DARK_ETA_DIR/$d/$f
123        fi
124    elif [ $v = "m" ]; then # 'mixed'
125        if [ -f $ASSETS_DIR/$d/$f ] && \
126            [ $SRC_DIR/$s -ot $ASSETS_DIR/$d/$f ]; then
127            echo $ASSETS_DIR/$d/$f exists.
128            echo $ASSETS_ETA_DIR/$d/$f exists.
129        else
130            echo Cloning $ASSETS_DIR/$d/$f
131            cp -f $SRC_DIR/$s $ASSETS_DIR/$d/$f
132            echo Cloning $ASSETS_ETA_DIR/$d/$f
133            cp -f $SRC_DIR/$s $ASSETS_ETA_DIR/$d/$f
134        fi
135    elif [ $v = "l" ]; then # 'light'
136        if [ -f $ASSETS_LIGHT_DIR/$d/$f ] && \
137            [ $SRC_DIR/$s -ot $ASSETS_LIGHT_DIR/$d/$f ]; then
138            echo $ASSETS_LIGHT_DIR/$d/$f exists.
139            echo $ASSETS_LIGHT_ETA_DIR/$d/$f exists.
140        else
141            echo Cloning $ASSETS_LIGHT_DIR/$d/$f
142            cp -f $SRC_DIR/$s $ASSETS_LIGHT_DIR/$d/$f
143            echo Cloning $ASSETS_LIGHT_ETA_DIR/$d/$f
144            cp -f $SRC_DIR/$s $ASSETS_LIGHT_ETA_DIR/$d/$f
145        fi
146    elif [ $v = "d" ]; then # 'dark'
147        if [ -f $ASSETS_DARK_DIR/$d/$f ] && \
148            [ $SRC_DIR/$s -ot $ASSETS_DARK_DIR/$d/$f ]; then
149            echo $ASSETS_DARK_DIR/$d/$f exists.
150            echo $ASSETS_DARK_ETA_DIR/$d/$f exists.
151        else
152            echo Cloning $ASSETS_DARK_DIR/$d/$f
153            cp -f $SRC_DIR/$s $ASSETS_DARK_DIR/$d/$f
154            echo Cloning $ASSETS_DARK_ETA_DIR/$d/$f
155            cp -f $SRC_DIR/$s $ASSETS_DARK_ETA_DIR/$d/$f
156        fi
157    fi
158done
159unset IFS
160
161exit 0
162