-
Notifications
You must be signed in to change notification settings - Fork 133
/
marsDeploy.sh
executable file
·81 lines (73 loc) · 2.13 KB
/
marsDeploy.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
#!/bin/bash
set -eu
# Example usage:
# $ ./marsDeploy.sh deploy/truefi.ts --network ropsten --dry-run
# PRIVATE_KEY=0x123..64
# Consume the first argument as a path to the Mars deploy script.
# All other command line arguments get forwarded to Mars.
DEPLOY_SCRIPT="$1"
shift 1
yes='false'
network='mainnet'
args="$@"
dry_run='false'
while [[ "$@" ]]; do
case "$1" in
--network)
if [ "$2" ]; then
network="$2"
shift 1
fi
;;
--yes)
yes='true'
;;
--dry-run)
dry_run='true'
;;
-?)
# ignore
;;
esac
shift 1
done
if [[ "${dry_run}" == 'false' ]]; then
if [[ "$(git status --porcelain)" ]]; then
echo "Error: git working directory must be empty to run deploy script."
exit 1
fi
if [[ "$(git log --pretty=format:'%H' -n 1)" != "$(cat ./build/canary.hash)" ]]; then
echo "Error: Build canary does not match current commit hash. Please run yarn build."
exit 1
fi
fi
# Skip PRIVATE_KEY prompt if --yes flag passed
if [[ "${yes}" == 'false' ]]; then
# Prompt the user for a PRIVATE_KEY without echoing to bash output.
# Then export PRIVATE_KEY to an environment variable that won't get
# leaked to bash history.
#
# WARNING: environment variables are still leaked to the process table
# while a process is running, and hence visible in a call to `ps -E`.
echo "Enter a private key (0x{64 hex chars}) for contract deployment,"
echo "or leave blank if performing a dry run without authorization."
read -s -p "PRIVATE_KEY=" PRIVATE_KEY
export PRIVATE_KEY
fi
export INFURA_KEY="ec659e9f6af4425c8a13aeb0af9f2809"
export ETHERSCAN_KEY="XQPPJGFR4J3I6PEISYEG4JPETFZ2EF56EX"
# Log file name
network_log="-${network}"
target_file_name="$(basename -- ${DEPLOY_SCRIPT})"
target_log="-${target_file_name%.*}"
dry_run_log=''
if [[ "${dry_run}" == 'true' ]]; then
dry_run_log='-dry-run'
fi
timestamp_log="-$(date +%s)"
yarn mars
yarn ts-node ${DEPLOY_SCRIPT} \
--waffle-config ./.waffle.json \
${args} \
--out-file "deployments-${network}.json" \
--log "./cache/deploy${network_log}${target_log}${dry_run_log}${timestamp_log}.log"