Revision 6106c789
Added by koszko almost 2 years ago
upload_amo.sh | ||
---|---|---|
24 | 24 |
XPI_PATH="$4" |
25 | 25 |
|
26 | 26 |
base64url() { |
27 |
ech "$1" | base64 -w 0 | tr '/+' '_-' | tr -d '='
|
|
27 |
printf %s "$1" | base64 -w 0 | tr '/+' '_-' | tr -d '='
|
|
28 | 28 |
} |
29 | 29 |
|
30 | 30 |
sha256hmac() { |
31 |
base64url "$(ech "$2" | openssl dgst -sha256 -hmac "$1" -binary -)"
|
|
31 |
base64url "$(printf %s "$2" | openssl dgst -sha256 -hmac "$1" -binary -)"
|
|
32 | 32 |
} |
33 | 33 |
|
34 | 34 |
get_manifest_key() { |
... | ... | |
52 | 52 |
local JWT_MESSAGE=$(base64url "$JWT_HEAD").$(base64url "$JWT_PAYLOAD") |
53 | 53 |
local JWT_SIGNATURE=$(sha256hmac "$SECRET" "$JWT_MESSAGE") |
54 | 54 |
local JWT=$JWT_MESSAGE.$JWT_SIGNATURE |
55 |
errcho "Using JWT: $JWT"
|
|
56 |
ech $JWT
|
|
55 |
printf "Using JWT: $JWT\n" >&2
|
|
56 |
printf $JWT
|
|
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
get_extension_url() { |
... | ... | |
61 | 61 |
EXTENSION_VER="$(get_manifest_key version "$XPI_PATH")" |
62 | 62 |
|
63 | 63 |
if [ -z "$EXTENSION_ID" -o -z "$EXTENSION_VER" ]; then |
64 |
errcho "Couldn't extract extension id and version. Please check if $XPI_PATH contains proper manifest.json file." |
|
64 |
printf "Couldn't extract extension id and version. Please check if %s contains proper manifest.json file.\n" \ |
|
65 |
"$XPI_PATH" >&2 |
|
65 | 66 |
exit 1 |
66 | 67 |
fi |
67 | 68 |
|
68 |
ech "https://addons.mozilla.org/api/v4/addons/$EXTENSION_ID/versions/$EXTENSION_VER/" |
|
69 |
printf 'https://addons.mozilla.org/api/v4/addons/%s/versions/%s/' \ |
|
70 |
"$EXTENSION_ID" "$EXTENSION_VER" |
|
69 | 71 |
} |
70 | 72 |
|
71 |
usage() { |
|
72 |
errcho "Usage: $_PROG_NAME upload|check|test API_KEY SECRET XPI_PATH" |
|
73 |
print_usage() { |
|
74 |
printf 'Usage: %s upload|check|test API_KEY SECRET XPI_PATH\n' \ |
|
75 |
"$_PROG_NAME" >&2 |
|
73 | 76 |
} |
74 | 77 |
|
75 | 78 |
if [ $# != 4 ]; then |
76 |
usage |
|
79 |
print_usage
|
|
77 | 80 |
exit 1 |
78 | 81 |
fi |
79 | 82 |
|
... | ... | |
83 | 86 |
test) |
84 | 87 |
curl "https://addons.mozilla.org/api/v4/accounts/profile/" \ |
85 | 88 |
-g -H "Authorization: JWT $(generate_jwt)" |
86 |
echo
|
|
89 |
printf '\n'
|
|
87 | 90 |
;; |
88 | 91 |
check) |
89 | 92 |
RETURNED_DATA="$(curl $(get_extension_url) \ |
... | ... | |
95 | 98 |
-H "Authorization: JWT $(generate_jwt)")" |
96 | 99 |
;; |
97 | 100 |
*) |
98 |
usage |
|
101 |
print_usage
|
|
99 | 102 |
exit 1 |
100 | 103 |
;; |
101 | 104 |
esac |
Also available in: Unified diff
rewrite parts of build script in awk