forked from dodpiu/data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-archive.txt
96 lines (79 loc) · 2 KB
/
deploy-archive.txt
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
#!/usr/bin/env bash
set -euo pipefail
declare wasm=
declare canister_id=
declare network=
#########
# USAGE #
#########
function title() {
echo "Deploy the archive to an II canister"
}
function usage() {
cat << EOF
Usage:
$0 --wasm PATH --canister-id CANISTER_ID [--network URL]
Options:
--wasm PATH Path to the archive wasm file to deploy.
--canister-id CANISTER_ID Canister id of the II canister to deploy the archive to.
--network URL Optional network parameter. Defaults to local replica.
EOF
}
function help() {
cat << EOF
Deploys the archive to the specified II canister.
NOTE: This requires dfx, hexdump, sed, a running II canister with the appropriate configuration to accept the supplied archive wasm.
EOF
}
# ARGUMENT PARSING
while [[ $# -gt 0 ]]
do
case $1 in
--help)
title
usage
help
exit 0
;;
--wasm)
wasm="${2:?missing value for '--wasm'}"
shift; # shift past --wasm and value
shift;
;;
--canister-id)
canister_id="${2:?missing value for '--canister-id'}"
shift; # shift past --canister-id and value
shift;
;;
--network)
network="${2:?missing value for '--network'}"
shift; # shift past --network and value
shift;
;;
*)
echo "ERROR: unknown argument $1"
usage
echo
echo "Use 'release --help' for more information."
exit 1
;;
esac
done
if [ -z "$wasm" ]
then
echo no wasm
usage
exit 1
fi
if [ -z "$canister_id" ]
then
echo no canister id
usage
exit 1
fi
declare -a network_arg=( )
if [ "$network" ]
then
network_arg+=( "--network" "$network")
fi
dfx canister "${network_arg[@]}" call "$canister_id" deploy_archive --argument-file <(echo "(blob \"$(hexdump -ve '1/1 "%.2x"' "$wasm" | sed 's/../\\&/g')\")")