-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
build.sh
executable file
·167 lines (144 loc) · 4.65 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
if ! [ -x "$(command -v rsvg-convert)" ]; then
apt install -y librsvg2-bin
fi
# Copy folder, without symlinks, but use actual files instead
mkdir -p build/_
mkdir -p build/brands
# Clone MDI icons
rm -f -r mdi
git clone --depth=1 https://github.com/Templarian/MaterialDesign mdi
# Copy custom integrations
rsync -aL custom_integrations/ build/_
rsync -aL custom_integrations/ build
# Copy core integrations
rsync -aL --exclude '_homeassistant' core_integrations/ build/_
rsync -aL --exclude '_homeassistant' --exclude '_placeholder' core_integrations/ build
# Generate integration icons based on MDI
find ./build -type f -name "icon.txt" | while read icon; do
dir=$(dirname "${icon}")
mdi=$(<${icon})
mdi="${mdi##mdi:}"
rsvg-convert \
--stylesheet scripts/mdi.css \
--keep-aspect-ratio \
--height 256 \
--width 256 \
--background-color transparent \
--output "${dir}/icon.png" \
"mdi/svg/${mdi}.svg"
rsvg-convert \
--stylesheet scripts/mdi.css \
--keep-aspect-ratio \
--height 512 \
--width 512 \
--background-color transparent \
--output "${dir}/[email protected]" \
"mdi/svg/${mdi}.svg"
optipng -silent "${dir}/icon.png" "${dir}/[email protected]"
rm "${icon}"
echo "Generated mdi:${mdi} for ${icon}"
done
# Use icon as logo in case of a missing logo
find ./build -type f -name "icon.png" | while read icon; do
dir=$(dirname "${icon}")
if [[ ! -f "${dir}/logo.png" ]]; then
cp "${icon}" "${dir}/logo.png"
echo "Using ${icon} as logo"
fi
done
# Use icon as icon@2x in case it is missing
find ./build -type f -name "icon.png" | while read icon; do
dir=$(dirname "${icon}")
if [[ ! -f "${dir}/[email protected]" ]]; then
cp "${icon}" "${dir}/[email protected]"
echo "Using ${icon} as hDPI icon"
fi
done
# Use logo as logo@2x in case it is missing
find ./build -type f -name "logo.png" | while read logo; do
dir=$(dirname "${logo}")
if [[ ! -f "${dir}/[email protected]" ]]; then
cp "${logo}" "${dir}/[email protected]"
echo "Using ${logo} as hDPI logo"
fi
done
# Copy in all integrations as fallback for brands
rsync -aL --exclude 'brands' build/ build/brands
# Overwrite brands with actual brands
rsync -aL --exclude '_homeassistant' --exclude '_placeholder' core_brands/ build/brands
rsync -aL --exclude '_homeassistant' --exclude '_placeholder' core_brands/ build/brands/_
# Use brand icon as logo in case of a missing logo
find ./build/brands -type f -name "icon.png" | while read icon; do
dir=$(dirname "${icon}")
if [[ ! -f "${dir}/logo.png" ]]; then
cp "${icon}" "${dir}/logo.png"
echo "Using ${icon} as logo"
fi
done
# Use brand icon as icon@2x in case it is missing
find ./build/brands -type f -name "icon.png" | while read icon; do
dir=$(dirname "${icon}")
if [[ ! -f "${dir}/[email protected]" ]]; then
cp "${icon}" "${dir}/[email protected]"
echo "Using ${icon} as hDPI icon"
fi
done
# Use brand logo as logo@2x in case it is missing
find ./build/brands -type f -name "logo.png" | while read logo; do
dir=$(dirname "${logo}")
if [[ ! -f "${dir}/[email protected]" ]]; then
cp "${logo}" "${dir}/[email protected]"
echo "Using ${logo} as hDPI logo"
fi
done
# Create fallback for dark variants
find ./build -type f -type f -name "icon.png" -o -name "[email protected]" -o -name "logo.png" -o -name "[email protected]" | while read image; do
dir=$(dirname "${image}")
filename=$(basename -s .png "${image}")
if [[ ! -f "${dir}/dark_${filename}.png" ]]; then
cp "${image}" "${dir}/dark_${filename}.png"
echo "Using ${image} as dark_${filename}"
fi
done
# Copy hardware
rsync -aL hardware/ build/hardware
# Create fallback for dark hardware variants
find ./build/hardware -type f -name "*.png" | while read image; do
dir=$(dirname "${image}")
filename=$(basename -s .png "${image}")
if [[ ! -f "${dir}/dark_${filename}.png" ]]; then
cp "${image}" "${dir}/dark_${filename}.png"
echo "Using ${image} as dark_${filename}"
fi
done
# Create domains.json
core_brands=$(
find ./core_brands \
-maxdepth 1 \
-exec basename {} \; \
| sort \
| jq -sR 'split("\n")[1:]' \
| jq -r 'map(select(length > 0))'
)
core_integrations=$(
find ./core_integrations \
-maxdepth 1 \
-exec basename {} \; \
| sort \
| jq -sR 'split("\n")[1:]' \
| jq -r 'map(select(length > 0))'
)
custom_integrations=$(
find ./custom_integrations \
-maxdepth 1 \
-exec basename {} \; \
| sort \
| jq -sR 'split("\n")[1:]' \
| jq -r 'map(select(length > 0))'
)
jq -n '{"brands": $brands, "core": $core, "custom": $custom}' \
--argjson brands "$core_brands" \
--argjson core "$core_integrations" \
--argjson custom "$custom_integrations" \
| jq -r . > ./build/domains.json