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-cinnamon"
14ASSETS_DIR="../cinnamon/assets"
15ASSETS_LIGHT_DIR="../cinnamon-light/assets"
16ASSETS_DARK_DIR="../cinnamon-dark/assets"
17INDEX="assets-cinnamon.txt"
18KEY_FILE="../../gtk/sass/common/resources/_key_colors.scss"
19
20# Default colours
21selection1="`grep 'Indigo500' ../../gtk/sass/common/_colors.scss | \
22                   cut -d' ' -f3`"
23accent1="`grep 'Indigo300' ../../gtk/sass/common/_colors.scss | \
24                cut -d' ' -f3`"
25destruction1="`grep 'Red500' ../../gtk/sass/common/_colors.scss | \
26                     cut -d' ' -f3`"
27
28# Check and re-color SVG files
29if [ -e $KEY_FILE ]; then
30    selection2="`grep 'key_selection' $KEY_FILE | \
31                 cut -d' ' -f2 | cut -d';' -f1`"
32    accent2="`grep 'key_accent' $KEY_FILE | \
33              cut -d' ' -f2 | cut -d';' -f1`"
34    destruction2="`grep 'key_destruction' $KEY_FILE | \
35                   cut -d' ' -f2 | cut -d';' -f1`"
36
37IFS=$'
38'
39for i in $(<$INDEX)
40do
41    s="`echo $i | cut -d' ' -f1`.svg" # source
42    r="`echo $i | cut -d' ' -f2`" # recolor flag
43
44    if [ "$r" = "r1" ]; then
45        cp -f $SRC_DIR/$s.in $SRC_DIR/$s
46
47        if [ $selection1 != $selection2 ]; then
48            sed -i '' "s/$selection1/$selection2/gi" $SRC_DIR/$s
49            echo $s is re-colored with $selection2.
50        fi
51    elif [ "$r" = "r2" ]; then
52        cp -f $SRC_DIR/$s.in $SRC_DIR/$s
53
54        if [ $accent1 != $accent2 ]; then
55            sed -i '' "s/$accent1/$accent2/gi" $SRC_DIR/$s
56            echo $s is re-colored with $accent2.
57        fi
58    elif [ "$r" = "r3" ]; then
59        cp -f $SRC_DIR/$s.in $SRC_DIR/$s
60
61        if [ $destruction1 != $destruction2 ]; then
62            sed -i '' "s/$destruction1/$destruction2/gi" $SRC_DIR/$s
63            echo $s is re-colored with $destruction2.
64        fi
65    fi
66done
67unset IFS
68
69else
70    echo ../../gtk/sass/common/resources/_key_colors.scss was not found. Stopped...
71    exit 1
72fi
73
74# Clone stock SVG files
75IFS=$'
76'
77for i in $(<$INDEX)
78do
79    s="`echo $i | cut -d' ' -f1`.svg"                 # source
80    f="`echo $i | cut -d' ' -f1 | cut -d'/' -f3`.svg" # file name
81    v="`echo $i | cut -c1`"                           # variant type
82    d="`echo $i | cut -d'/' -f2`"                     # target directory
83
84    if [ $v = "c" ]; then # 'commmon'
85        if [ -f $ASSETS_DIR/$d/$f ] && \
86            [ $SRC_DIR/$s -ot $ASSETS_DIR/$d/$f ]; then
87            echo $ASSETS_DIR/$d/$f exists.
88            echo $ASSETS_LIGHT_DIR/$d/$f exists.
89            echo $ASSETS_DARK_DIR/$d/$f exists.
90        else
91            echo Cloning $ASSETS_DIR/$d/$f
92            cp $SRC_DIR/$s $ASSETS_DIR/$d/$f
93            echo Cloning $ASSETS_LIGHT_DIR/$d/$f
94            cp $SRC_DIR/$s $ASSETS_LIGHT_DIR/$d/$f
95            echo Cloning $ASSETS_DARK_DIR/$d/$f
96            cp $SRC_DIR/$s $ASSETS_DARK_DIR/$d/$f
97        fi
98    elif [ $v = "m" ]; then # 'mixed'
99        if [ -f $ASSETS_DIR/$d/$f ] && \
100            [ $SRC_DIR/$s -ot $ASSETS_DIR/$d/$f ]; then
101            echo $ASSETS_DIR/$d/$f exists.
102        else
103            echo Cloning $ASSETS_DIR/$d/$f
104            cp $SRC_DIR/$s $ASSETS_DIR/$d/$f
105        fi
106    elif [ $v = "l" ]; then # 'light'
107        if [ -f $ASSETS_LIGHT_DIR/$d/$f ] && \
108            [ $SRC_DIR/$s -ot $ASSETS_LIGHT_DIR/$d/$f ]; then
109            echo $ASSETS_LIGHT_DIR/$d/$f exists.
110        else
111            echo Cloning $ASSETS_LIGHT_DIR/$d/$f
112            cp $SRC_DIR/$s $ASSETS_LIGHT_DIR/$d/$f
113        fi
114    elif [ $v = "d" ]; then # 'dark'
115        if [ -f $ASSETS_DARK_DIR/$d/$f ] && \
116            [ $SRC_DIR/$s -ot $ASSETS_DARK_DIR/$d/$f ]; then
117            echo $ASSETS_DARK_DIR/$d/$f exists.
118        else
119            echo Cloning $ASSETS_DARK_DIR/$d/$f
120            cp $SRC_DIR/$s $ASSETS_DARK_DIR/$d/$f
121        fi
122    fi
123done
124unset IFS
125
126exit 0
127