2024-04-21 12:06:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function help() {
|
|
|
|
echo "Usage: deploy.sh IP1,IP2,IP3 [options]"
|
|
|
|
echo ""
|
|
|
|
echo " -i Identity file"
|
|
|
|
echo " -k Keyring password to create key (for Linux only)"
|
|
|
|
echo " -n Network (default: testnet)"
|
2024-04-21 12:09:34 +00:00
|
|
|
echo " -c Chain ID (default: \"zgtendermint_16600-1\")"
|
2024-04-21 12:06:41 +00:00
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $# -eq 0 ]]; then
|
2024-04-21 12:09:34 +00:00
|
|
|
help
|
|
|
|
exit 1
|
2024-04-21 12:06:41 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
IP_LIST=$1
|
|
|
|
shift
|
|
|
|
PEM_FLAG=""
|
|
|
|
KEYRING_PASSWORD=""
|
|
|
|
NETWORK="testnet"
|
|
|
|
INIT_GENESIS_ENV=""
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
2024-04-21 12:09:34 +00:00
|
|
|
case $1 in
|
|
|
|
-i)
|
|
|
|
PEM_FLAG="-i $2";
|
2024-04-21 12:06:41 +00:00
|
|
|
shift; shift
|
2024-04-21 12:09:34 +00:00
|
|
|
;;
|
|
|
|
-k)
|
|
|
|
KEYRING_PASSWORD=$2;
|
2024-04-21 12:06:41 +00:00
|
|
|
shift; shift
|
2024-04-21 12:09:34 +00:00
|
|
|
;;
|
2024-04-21 12:06:41 +00:00
|
|
|
-n)
|
|
|
|
NETWORK=$2
|
2024-04-21 12:09:34 +00:00
|
|
|
INIT_GENESIS_ENV="$INIT_GENESIS_ENV export ROOT_DIR=$2;"
|
2024-04-21 12:06:41 +00:00
|
|
|
shift; shift
|
2024-04-21 12:09:34 +00:00
|
|
|
;;
|
2024-04-21 12:06:41 +00:00
|
|
|
-c)
|
2024-04-21 12:09:34 +00:00
|
|
|
INIT_GENESIS_ENV="$INIT_GENESIS_ENV export CHAIN_ID=$2;"
|
2024-04-21 12:06:41 +00:00
|
|
|
shift; shift
|
2024-04-21 12:09:34 +00:00
|
|
|
;;
|
|
|
|
*)
|
2024-04-21 12:06:41 +00:00
|
|
|
help
|
|
|
|
echo "Unknown flag passed: \"$1\""
|
2024-04-21 12:09:34 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
2024-04-21 12:06:41 +00:00
|
|
|
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-05-01 08:11:39 +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 patch_testnet_1; ./networks/testnet/install.sh"
|
2024-04-21 12:06:41 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Create genesis config on node0
|
|
|
|
ssh $PEM_FLAG ubuntu@${IPS[0]} "cd 0g-chain/networks/testnet; $INIT_GENESIS_ENV ./init-genesis.sh $IP_LIST $KEYRING_PASSWORD; tar czf ~/$NETWORK.tar.gz $NETWORK; rm -rf $NETWORK"
|
|
|
|
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-05-01 08:11:39 +00:00
|
|
|
ssh $PEM_FLAG ubuntu@${IPS[$i]} "rm -rf 0gchaind-prod; tar xzf node$i.tar.gz; rm node$i.tar.gz; mv node$i 0gchaind-prod"
|
2024-04-21 12:06:41 +00:00
|
|
|
rm node$i.tar.gz
|
|
|
|
done
|
|
|
|
|
|
|
|
echo -e "\n\nSucceeded to deploy on $NUM_NODES nodes!\n"
|