This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
/
crxmake.sh
executable file
·140 lines (110 loc) · 3.58 KB
/
crxmake.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
#!/bin/bash -e
#
# Package Augury into crx format Chrome extension
# (This will not be needed for official distribution)
# Based on https://developer.chrome.com/extensions/crx#scripts
node -v
npm -v
echo "ARTIFACTS_PATH: $ARTIFACTS_PATH"
dir="temp"
key="key.pem"
name="augury"
files="manifest.json build images index.html frontend.html popup.html popup.js"
pub="$name.pub"
sig="$name.sig"
zip="$name.zip"
crx="$name.crx"
xpi="$name.xpi"
# Ensure environment variables exist ($sentry_key isnt used anywhere)
#sentry_key=${SENTRY_KEY:?"The environment variable 'SENTRY_KEY' must be set and non-empty"}
# assign build name to zip and crx file in circleci env
if [ $CIRCLE_BUILD_NUM ]; then
chrome_canary_zip="$name-$CIRCLE_BUILD_NUM.chrome.canary.zip"
chrome_zip="$name-$CIRCLE_BUILD_NUM.chrome.zip"
chrome_crx="$name-$CIRCLE_BUILD_NUM.chrome.crx"
firefox_zip="$name-$CIRCLE_BUILD_NUM.firefox.zip"
firefox_xpi="$name-$CIRCLE_BUILD_NUM.firefox.xpi"
else
chrome_canary_zip="$name.chrome.canary.zip"
chrome_zip="$name.chrome.zip"
chrome_crx="$name.chrome.crx"
firefox_zip="$name.firefox.zip"
firefox_xpi="$name.firefox.xpi"
fi
trap 'rm -f "$pub" "$sig"' EXIT
function do_build {
npm run build:prod:${BUILD_LOWERCASE}
}
function grab_files_and_zip {
# copy all the files we need
rm -rf $dir
mkdir $dir
cp -R $files $dir/
# zip up the crx dir
cwd=$(pwd -P)
(cd "$dir" && zip -qr -9 -X "$cwd/$zip" .)
}
# generate private key key.pem if it doesn't exist already
if [ ! -f $key ]; then
echo "$key doesn't exist."
openssl genrsa -out key.pem 1024
fi
# ---------------------------------------------------------
# build for chrome (.crx, .zip) ---------------------------------
BUILD_LOWERCASE=chrome
do_build
grab_files_and_zip
cp $zip $chrome_zip
# signature
openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig"
# public key
openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null
byte_swap () {
# Take "abcdefgh" and return it as "ghefcdab"
echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}"
}
crmagic_hex="4372 3234" # Cr24
version_hex="0200 0000" # 2
pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}')))
sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}')))
(
echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p
cat "$pub" "$sig" "$zip"
) > "$chrome_crx"
echo "Wrote $chrome_crx"
echo "<script>window.location.href = 'https://s3.amazonaws.com/batarangle.io/$crx';</script>" > download.html
echo "Wrote file"
# moving files to CircleCI Artifacts is now handled in config.yml
# move files to artifacts folder in circleci
if [ $ARTIFACTS_PATH ]; then
mv $chrome_zip $ARTIFACTS_PATH
mv $chrome_crx $ARTIFACTS_PATH
else
echo "CIRCLE_ARTIFACTS is not defined"
fi
# ---------------------------------------------------------
# build for firefox (.xpi, .zip) --------------------------------
# TODO: add digital signatures. (firefox requires add-on verification)
BUILD_LOWERCASE=firefox
do_build
grab_files_and_zip
cp $zip $firefox_zip
cp $zip $firefox_xpi
if [ $ARTIFACTS_PATH ]; then
mv $firefox_zip $ARTIFACTS_PATH
mv $firefox_xpi $ARTIFACTS_PATH
fi
# ---------------------------------------------------------
# build canary (.zip) --------------------------------
BUILD_LOWERCASE=canary
do_build
grab_files_and_zip
cp $zip $chrome_canary_zip
if [ $ARTIFACTS_PATH ]; then
mv $chrome_canary_zip $ARTIFACTS_PATH
fi
# ---------------------------------------------------------
# done. clean up ---------------------
rm 'manifest.json' # this file is generated by build process (browser specific)
rm -rf $dir
echo "Fin."