-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_xpk.sh
executable file
·45 lines (37 loc) · 1.07 KB
/
make_xpk.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
#!/bin/bash -e
#
# Purpose: Pack a CrossWalk directory into xpk format
# Modified from http://developer.chrome.com/extensions/crx.html
if test $# -ne 3; then
echo "Usage: `basename $0` <unpacked dir> <pem file path> <packagename>"
exit 1
fi
dir=$1
key=$2
#name=$(basename "$dir")
name=$3
xpk="$name.xpk"
pub="$name.pub"
sig="$name.sig"
zip="$name.zip"
trap 'rm -f "$pub" "$sig" "$zip"' EXIT
[ ! -f $key ] && openssl genrsa -out $key 1024
# zip up the xpk dir
cwd=$(pwd -P)
(cd "$dir" && /usr/bin/zip -qr -9 -X "$cwd/$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 576B" # CrWk
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 $pub_len_hex $sig_len_hex" | xxd -r -p
cat "$pub" "$sig" "$zip"
) > "$xpk"
echo "Wrote $xpk"