2024-05-01 09:00:05 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function help() {
|
|
|
|
echo "Usage: deploy.sh IP1 [options]"
|
|
|
|
echo ""
|
|
|
|
echo " -i Identity file"
|
|
|
|
echo " -k Keyring password to create key (for Linux only)"
|
2024-05-03 15:14:04 +00:00
|
|
|
echo " -n Network (default: devnet)"
|
2024-05-01 09:00:05 +00:00
|
|
|
echo " -c Chain ID (default: \"zgtendermint_16600-1\")"
|
2024-07-30 02:30:56 +00:00
|
|
|
echo " -v schedule end time (unix epoch) for vesting accounts"
|
2024-05-01 09:00:05 +00:00
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $# -eq 0 ]]; then
|
|
|
|
help
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
IP_LIST=$1
|
|
|
|
shift
|
|
|
|
PEM_FLAG=""
|
|
|
|
KEYRING_PASSWORD=""
|
2024-05-03 15:14:04 +00:00
|
|
|
NETWORK="devnet"
|
2024-07-30 02:30:56 +00:00
|
|
|
TAG_OR_BRANCH="dev"
|
2024-05-01 09:00:05 +00:00
|
|
|
INIT_GENESIS_ENV=""
|
2024-07-30 02:30:56 +00:00
|
|
|
VESTING_ACCOUNT_END_TIME=0
|
2024-05-01 09:00:05 +00:00
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
|
|
|
-i)
|
|
|
|
PEM_FLAG="-i $2";
|
|
|
|
shift; shift
|
|
|
|
;;
|
|
|
|
-k)
|
|
|
|
KEYRING_PASSWORD=$2;
|
|
|
|
shift; shift
|
|
|
|
;;
|
|
|
|
-n)
|
|
|
|
NETWORK=$2
|
|
|
|
INIT_GENESIS_ENV="$INIT_GENESIS_ENV export ROOT_DIR=$2;"
|
|
|
|
shift; shift
|
|
|
|
;;
|
|
|
|
-c)
|
|
|
|
INIT_GENESIS_ENV="$INIT_GENESIS_ENV export CHAIN_ID=$2;"
|
|
|
|
shift; shift
|
|
|
|
;;
|
2024-07-30 02:30:56 +00:00
|
|
|
-v)
|
|
|
|
INIT_GENESIS_ENV="$INIT_GENESIS_ENV export VESTING_ACCOUNT_END_TIME=$2;"
|
|
|
|
shift; shift
|
|
|
|
;;
|
2024-05-01 09:00:05 +00:00
|
|
|
*)
|
|
|
|
help
|
|
|
|
echo "Unknown flag passed: \"$1\""
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
IFS=","; declare -a IPS=($IP_LIST); unset IFS
|
|
|
|
NUM_NODES=${#IPS[@]}
|
|
|
|
|
|
|
|
# Install dependent libraries and binary
|
|
|
|
for ((i=0; i<$NUM_NODES; i++)) do
|
2024-07-30 02:30:56 +00:00
|
|
|
ssh $PEM_FLAG ubuntu@${IPS[$i]} "rm -rf 0g-chain; git clone https://github.com/0glabs/0g-chain.git; cd 0g-chain; git checkout $TAG_OR_BRANCH; ./networks/$NETWORK/install.sh"
|
2024-05-01 09:00:05 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Create genesis config on node0
|
2024-07-30 02:30:56 +00:00
|
|
|
ssh $PEM_FLAG ubuntu@${IPS[0]} "cd 0g-chain/networks/$NETWORK; $INIT_GENESIS_ENV ./init-genesis.sh $IP_LIST $KEYRING_PASSWORD; tar czf ~/$NETWORK.tar.gz $NETWORK; rm -rf $NETWORK"
|
2024-05-01 09:00:05 +00:00
|
|
|
scp $PEM_FLAG ubuntu@${IPS[0]}:$NETWORK.tar.gz .
|
|
|
|
ssh $PEM_FLAG ubuntu@${IPS[0]} "rm $NETWORK.tar.gz"
|
|
|
|
|
|
|
|
# Copy genesis config to remote nodes
|
|
|
|
tar xzf $NETWORK.tar.gz
|
|
|
|
rm $NETWORK.tar.gz
|
|
|
|
cd $NETWORK
|
|
|
|
for ((i=0; i<$NUM_NODES; i++)) do
|
|
|
|
tar czf node$i.tar.gz node$i
|
|
|
|
scp $PEM_FLAG node$i.tar.gz ubuntu@${IPS[$i]}:~
|
2024-07-30 02:30:56 +00:00
|
|
|
ssh $PEM_FLAG ubuntu@${IPS[$i]} "rm -rf 0gchaind-$NETWORK; tar xzf node$i.tar.gz; rm node$i.tar.gz; mv node$i 0gchaind-$NETWORK"
|
2024-05-01 09:00:05 +00:00
|
|
|
rm node$i.tar.gz
|
|
|
|
done
|
|
|
|
|
|
|
|
echo -e "\n\nSucceeded to deploy on $NUM_NODES nodes!\n"
|