|
1 | 1 | #!/bin/bash
|
2 |
| -set -e |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +LOG_START='\n\e[1;36m' # new line + bold + color |
| 5 | +LOG_END='\n\e[0m' # new line + reset color |
3 | 6 |
|
4 |
| -# Dafault inputs. |
5 |
| -KEEP_ETHEREUM_PASSWORD_DEFAULT="password" |
6 | 7 | KEEP_CORE_PATH=$PWD
|
| 8 | +KEEP_CORE_SOL_PATH="$KEEP_CORE_PATH/solidity" |
| 9 | + |
| 10 | +# Defaults, can be overwritten by env variables/input parameters |
7 | 11 | CONFIG_DIR_PATH_DEFAULT="$KEEP_CORE_PATH/configs"
|
| 12 | +NETWORK_DEFAULT="local" |
| 13 | +KEEP_ETHEREUM_PASSWORD=${KEEP_ETHEREUM_PASSWORD:-"password"} |
| 14 | +CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY=${CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY:-""} |
8 | 15 |
|
9 |
| -# Read user inputs. |
10 |
| -read -p "Enter ethereum accounts password [$KEEP_ETHEREUM_PASSWORD_DEFAULT]: " ethereum_password |
11 |
| -KEEP_ETHEREUM_PASSWORD=${ethereum_password:-$KEEP_ETHEREUM_PASSWORD_DEFAULT} |
| 16 | +help() |
| 17 | +{ |
| 18 | + echo -e "\nUsage: ENV_VAR(S) $0"\ |
| 19 | + "--config-dir <path>"\ |
| 20 | + "--network <network>" |
| 21 | + echo -e "\nEnvironment variables:\n" |
| 22 | + echo -e "\tKEEP_ETHEREUM_PASSWORD: The password to unlock local Ethereum accounts to set up delegations."\ |
| 23 | + "Required only for 'local' network. Default value is 'password'" |
| 24 | + echo -e "\tCONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY: Contracts owner private key on Ethereum" |
| 25 | + echo -e "\nCommand line arguments:\n" |
| 26 | + echo -e "\t--config-dir: Path to keep-core client configuration file(s)" |
| 27 | + echo -e "\t--network: Ethereum network for keep-core client."\ |
| 28 | + "Available networks and settings are specified in the 'truffle-config.js'\n" |
| 29 | + exit 1 # Exit script after printing help |
| 30 | +} |
12 | 31 |
|
13 |
| -read -p "Enter dir path to keep-core client configs [$CONFIG_DIR_PATH_DEFAULT]: " config_dir_path |
14 |
| -CONFIG_DIR_PATH=${config_dir_path:-$CONFIG_DIR_PATH_DEFAULT} |
| 32 | +# Transform long options to short ones |
| 33 | +for arg in "$@"; do |
| 34 | + shift |
| 35 | + case "$arg" in |
| 36 | + "--config-dir") set -- "$@" "-c" ;; |
| 37 | + "--network") set -- "$@" "-n" ;; |
| 38 | + "--help") set -- "$@" "-h" ;; |
| 39 | + *) set -- "$@" "$arg" |
| 40 | + esac |
| 41 | +done |
15 | 42 |
|
16 |
| -# Run script. |
17 |
| -LOG_START='\n\e[1;36m' # new line + bold + color |
18 |
| -LOG_END='\n\e[0m' # new line + reset color |
| 43 | +# Parse short options |
| 44 | +OPTIND=1 |
| 45 | +while getopts "c:n:h" opt |
| 46 | +do |
| 47 | + case "$opt" in |
| 48 | + c ) config_dir_path="$OPTARG" ;; |
| 49 | + n ) network="$OPTARG" ;; |
| 50 | + h ) help ;; |
| 51 | + ? ) help ;; # Print help in case parameter is non-existent |
| 52 | + esac |
| 53 | +done |
| 54 | +shift $(expr $OPTIND - 1) # remove options from positional parameters |
| 55 | + |
| 56 | +# Overwrite default properties |
| 57 | +CONFIG_DIR_PATH=${config_dir_path:-$CONFIG_DIR_PATH_DEFAULT} |
| 58 | +NETWORK=${network:-$NETWORK_DEFAULT} |
19 | 59 |
|
| 60 | +# Run script |
20 | 61 | printf "${LOG_START}Starting installation...${LOG_END}"
|
21 |
| -KEEP_CORE_CONFIG_DIR_PATH=$CONFIG_DIR_PATH |
22 |
| -KEEP_CORE_SOL_PATH="$KEEP_CORE_PATH/solidity" |
| 62 | + |
| 63 | +printf "Config dir path: $CONFIG_DIR_PATH\n" |
| 64 | +printf "Network: $NETWORK" |
23 | 65 |
|
24 | 66 | cd $KEEP_CORE_SOL_PATH
|
25 | 67 |
|
26 | 68 | printf "${LOG_START}Installing NPM dependencies...${LOG_END}"
|
27 | 69 | npm install
|
28 | 70 |
|
29 |
| -printf "${LOG_START}Unlocking ethereum accounts...${LOG_END}" |
30 |
| -KEEP_ETHEREUM_PASSWORD=$KEEP_ETHEREUM_PASSWORD \ |
31 |
| - npx truffle exec scripts/unlock-eth-accounts.js --network local |
| 71 | +if [ "$NETWORK" == "local" ]; then |
| 72 | + printf "${LOG_START}Unlocking ethereum accounts...${LOG_END}" |
| 73 | + KEEP_ETHEREUM_PASSWORD=$KEEP_ETHEREUM_PASSWORD \ |
| 74 | + npx truffle exec scripts/unlock-eth-accounts.js --network $NETWORK |
| 75 | +fi |
32 | 76 |
|
33 | 77 | printf "${LOG_START}Migrating contracts...${LOG_END}"
|
34 | 78 | rm -rf build/
|
35 |
| -npx truffle migrate --reset --network local |
| 79 | + |
| 80 | +CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY=$CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY \ |
| 81 | + npx truffle migrate --reset --network $NETWORK |
36 | 82 |
|
37 | 83 | KEEP_CORE_SOL_ARTIFACTS_PATH="$KEEP_CORE_SOL_PATH/build/contracts"
|
38 | 84 |
|
39 | 85 | printf "${LOG_START}Initializing contracts...${LOG_END}"
|
40 |
| -npx truffle exec scripts/delegate-tokens.js --network local |
| 86 | + |
| 87 | +CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY=$CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY \ |
| 88 | + npx truffle exec scripts/delegate-tokens.js --network $NETWORK |
41 | 89 |
|
42 | 90 | printf "${LOG_START}Updating keep-core client configs...${LOG_END}"
|
43 |
| -for CONFIG_FILE in $KEEP_CORE_CONFIG_DIR_PATH/*.toml |
| 91 | +for CONFIG_FILE in $CONFIG_DIR_PATH/*.toml |
44 | 92 | do
|
45 | 93 | KEEP_CORE_CONFIG_FILE_PATH=$CONFIG_FILE \
|
46 |
| - npx truffle exec scripts/lcl-client-config.js --network local |
| 94 | + CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY=$CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY \ |
| 95 | + npx truffle exec scripts/lcl-client-config.js --network $NETWORK |
47 | 96 | done
|
48 | 97 |
|
49 | 98 | printf "${LOG_START}Building keep-core client...${LOG_END}"
|
|
0 commit comments