-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·224 lines (176 loc) · 6.08 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env bash
set -e
if [[ "$1" == clean ]]; then
rm -rf dist
shift
timestamp=$(git log --format='%ci' HEAD~1..HEAD)
fi
VERSION=$(jq -r .version ./manifest-common.json)
iconTheme=privateer
for target in "$@"; do
echo "Building $target..."
NAME="Hoardy-Web-$target"
NAME_VERSION="$NAME-v$VERSION"
DEST="dist/$NAME"
install -d "$DEST"
if [[ "$target" == tiles ]]; then
echo " Tailing all icons into a single image..."
icons=()
for a in icon/"$iconTheme"/{main,work_offline,off,idle,limbo,neglimbo,bothlimbo,tracking,problematic,in_limbo,archiving,failed}.svg icon/"$iconTheme"/*.svg; do
n=$(basename "$a")
file="$DEST/$n.png"
if [[ "$a" -nt "$file" ]]; then
echo " Building $file..."
convert -geometry 128x128 -background none "$a" "$file"
fi
l="${#icons[@]}"
found=
for ((i=0; i<l; ++i)); do
if [[ "${icons[$i]}" == "$file" ]]; then
found=1
break
fi
done
if [[ -z "$found" ]]; then
icons+=("$file")
fi
done
l="${#icons[@]}"
maketile() {
x=$1; y=$2; bg=$3
local args=()
s=$((x*y))
for ((i=0; i<s; i++)); do
e=$((i % l))
args+=("${icons[$e]}")
done
file="$DEST/tile-$x-$y-$bg.png"
echo " Building $file..."
montage -geometry +3+3 -tile "${x}x" -background "$bg" "${args[@]}" "$file"
}
maketile $l 1 white
maketile $l 1 black
maketile 16 6 white
maketile 16 6 black
continue
fi
pandocArgs=( \
-V "version=$VERSION" \
)
echo " Preparing icons..."
if [[ "$target" =~ firefox-* ]]; then
pandocArgs+=(-V iconMIME=image/svg+xml -V iconFile=main.svg)
install -d "$DEST"/icon
install -C -t "$DEST"/icon icon/"$iconTheme"/*.svg
elif [[ "$target" =~ chromium-* ]]; then
pandocArgs+=(-V iconMIME=image/png -V iconFile=128/main.png)
install -d "$DEST"/icon
makeicons() {
install -d "$DEST/icon/$1"
for a in icon/"$iconTheme"/*.svg ; do
n=$(basename "$a")
file="$DEST/icon/$1/${n%.svg}.png"
if [[ "$a" -nt "$file" ]]; then
echo " Building $file..."
convert -geometry "$1x$1" -background none "$a" "$file"
fi
done
}
#makeicons 48
#makeicons 96
makeicons 128
fi
runPandoc() {
local destfile="$DEST/$2".html
mkdir -p "$(dirname "$destfile")"
pandoc -f $1 -t html --wrap=none --template="$2".template -M pagetitle="$2" "${pandocArgs[@]}" > "$destfile"
}
for p in background/main page/popup page/state page/saved; do
echo " Building $p..."
echo | runPandoc markdown "$p"
done
echo " Building page/help..."
cat page/help.org | runPandoc org page/help
echo " Building page/changelog..."
cat ../CHANGELOG.md \
| sed '
s%\./extension/page/help\.org%./help.html%g
s%#state-in-extension-ui-only%./state.html%g
t end
s%(\./\([^)]*\))%(https://oxij.org/software/hoardy-web/tree/master/\1)%g
: end
' \
| runPandoc markdown page/changelog
echo " Copying files..."
install -d "$DEST"/lib
install -C -t "$DEST"/lib lib/*.js
install -C -t "$DEST"/lib ../vendor/pako/dist/pako.js
install -d "$DEST"/page
install -C -t "$DEST"/page page/*.css page/*.js
install -d "$DEST"/background
install -C -t "$DEST"/background background/*.js
install -d "$DEST"/inject
install -C -t "$DEST"/inject inject/*.js
install -C -t "$DEST" ../LICENSE.txt
if [[ "$target" =~ chromium-* ]]; then
(
cd "dist"
if [[ ! -e "manifest-chromium-key.json" ]]; then
echo " Generating Chromium ID..."
mkdir -p "../private"
res=$(../bin/gen-chromium-key.sh "../private/chromium.key.pem" "manifest-chromium")
if [[ -n "$res" ]]; then
echo -e "\e[1;31m"
echo " $res"
echo -e "\e[0m"
fi
fi
)
fi
echo " Building manifest.json..."
if [[ "$target" =~ firefox-* ]]; then
jq -s --indent 4 '.[0] * .[1]' manifest-common.json "manifest-$target.json" > "$DEST"/manifest.json
elif [[ "$target" =~ chromium-* ]]; then
jq -s --indent 4 '.[0] * .[1] * .[2]' manifest-common.json "dist/manifest-chromium-key.json" "manifest-$target.json" > "$DEST"/manifest.json
fi
if [[ -n "$timestamp" ]]; then
find "$DEST" -exec touch --date="$timestamp" {} \;
fi
if [[ "$target" =~ firefox-* ]]; then
echo " Zipping..."
(
cd "$DEST"
zip -qr -9 -X "../$NAME_VERSION.xpi" .
)
elif [[ "$target" =~ chromium-* ]]; then
echo " Zipping..."
cd dist
zip -qr -9 -X "$NAME_VERSION.zip" "$NAME"
cd ..
echo " Making CRX..."
(
key=$(readlink -f "./private/chromium.key.pem")
cd "$DEST"
if false && which chromium ; then
cd ..
chromium --pack-extension="./$NAME_VERSION" --pack-extension-key="$key"
else
../../bin/crx.sh "../$NAME_VERSION" "$key"
fi
)
chromium_id=$(cat "dist/manifest-chromium-id.txt")
chromium_crx_url="https://github.com/Own-Data-Privateer/hoardy-web/releases/download/extension-v$VERSION/$NAME_VERSION.crx"
echo " Making update.xml..."
sed "
s%@VERSION@%${VERSION}%g
s%@ID@%${chromium_id}%g
s%@CRX_URL@%${chromium_crx_url}%g
" gupdate.xml.template > "dist/update-$target.xml"
if [[ -d ../metadata ]]; then
cp "dist/update-$target.xml" ../metadata/
fi
fi
done
# for `web-ext --watch-file`
touch dist/build-done
echo "Done."