Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Update Validator Setup Scripts (#130)
Browse files Browse the repository at this point in the history
* updated validator setup script

* updated regen-ledger location

* added sleep

* added safety question

* added safety question

* added safety question

* added safety question

* added safety question

* added ascii

* added ascii

* fixed systemctl

* fixed systemctl

* added more peers

* added more peers

* fixed order of instructions

* remove go after install

* cleaned up go installation alerts
  • Loading branch information
dpdanpittman committed Jun 22, 2023
1 parent b4ed546 commit 80d4ca5
Showing 1 changed file with 213 additions and 93 deletions.
306 changes: 213 additions & 93 deletions scripts/mainnet-val-setup.sh
Original file line number Diff line number Diff line change
@@ -1,141 +1,261 @@
#!/bin/bash
set -e

command_exists () {
REGEN_HOME="${HOME}/.regen"
PERSISTENT_PEERS="69975e7afdf731a165e40449fcffc75167a084fc@104.131.169.70:26656,c4460b52c34ad4f12168d05807e998bb8e8b4812@3.22.22.248:26656,6eab01c9b75a1040ad3cda25a3e6c05d23b7e12c@3.23.48.152:26656"

function command_exists () {
type "$1" &> /dev/null ;
}

if command_exists go ; then
echo "Golang is already installed"
else
echo "Install dependencies"
sudo apt update
sudo apt install build-essential jq wget git -y

wget https://dl.google.com/go/go1.17.1.linux-amd64.tar.gz
tar -xvf go1.17.1.linux-amd64.tar.gz
sudo mv go /usr/local

echo "" >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
echo 'export GOBIN=$GOPATH/bin' >> ~/.bashrc
echo 'export PATH=$PATH:/usr/local/go/bin:$GOBIN' >> ~/.bashrc

fi
function required_go_version () {
current_go_version=$(go version | { read _ _ v _; echo "${v#go}"; })
minimum_go_version="1.19.6"
if [ "$(printf '%s\n' "$minimum_go_version" "$current_go_version" | sort -V | head -n1)" = "$minimum_go_version" ]; then
return 0
else
return 1
fi
}

source ~/.bashrc
clear

echo "CAUTION!"
echo "-- If Regen was previously installed, the following step will remove ~/.regen from your system. Are you sure you would like to continue?--"
echo " @@@@@"
echo " @@@@@@,"
echo " (@@@@@"
echo " @@@@*"
echo " @@@@"
echo " @@@, @@@ ,@@@@%"
echo " @@@ @@@ @@@ @@@@@@@@"
echo " ,@ .@@ @@@ @@@@@@@@@"
echo " @@@@ @ @ @@ @@@@@@"
echo " /@@@ @ @@@@%"
echo " &@ @@@"
echo " /"
echo ""
echo ""
echo " @@@@@@@@@@@@@@@@% @@@@@"
echo " @@@@@@@@@@@@@@@% %@@@"
echo ""
echo " @@@@@@"
echo " * @ @"
echo " @@@@@ %@@"
echo " @@@@ @@ @ @@@@@"
echo " @@@@ @ @ ,@ @@@@@@@"
echo " @@@@ ,@ .@@ @@@ ,@@@@@@@@/"
echo " @@@ @@@ @@@@ @@@@@@@@"
echo " @@@* ,@@ @@@#"
echo " @@@@"
echo " @@@@&"
echo " @@@@@"
echo " @@@@@@@"
echo " @@@@@"
echo ""
echo ""
echo ""
echo ""
echo ""
echo " @@@@@@@@@@ *@@@@@@@@@@@@ (@@@@( @@@@@@@@@@@@ @@@@# @@@@"
echo " @@@@@@@@@@@@@ *@@@@@@@@@@@@ %@@@@@@@@@@@@ @@@@@@@@@@@@ @@@@@@ @@@@"
echo " @@@@ @@@@ *@@@@ @@@@@ @ @@@@ @@@#@@@% @@@@"
echo " @@@@@@@@@@@@@ *@@@@@@@@@@ @@@@ @@@@@@@@ @@@@@@@@@@* @@@ @@@@ @@@@"
echo " @@@@ /@@@@ *@@@@ @@@@# ####@@@@ @@@@ @@@ @@@@@@@@"
echo " @@@@ @@@@@ *@@@@@@@@@@@@ @@@@@@ &@@@@@ @@@@@@@@@@@@/ @@@ @@@@@@"
echo " @@@@ #@@@@ *@@@@@@@@@@@@ /@@@@@@@ @@@ @@@@@@@@@@@@/ @@@ @@@@@"
echo ""
echo ""
echo ""
echo " @@ @@ @@@@@@@%@@@@@@@@@@@@ @@ *@ @@@@@@@ @@@@@@@ @@ @@"
echo " @ @@ @@ @ @@ @, @ @ @ @@ *@ @ @@ @@ @@"
echo " @ @ @@ @@@@@@ @@ @ @@ @ @% @& @@ @@@@@@@ @@@&@@"
echo " @ @@@@ @ @@ %@ @ @@*@ #@ @@ @ @@ @@ @@"
echo " @ @@ @@@@@@@@ @@ @@ @@ .@@@@@ @ /@ @@ @@"

select yn in "Yes" "No"; do
case $yn in
Yes ) rm -rf ~/.regen; break;;
No ) exit;;
esac
done
sleep 3
clear
echo "This script will install all of the necessary dependencies and perform node configurations for a Regen Network full-node"
sleep 3
clear

echo "Installing dependencies..."
sleep 3

DAEMON=regen
DENOM=uregen
CHAIN_ID=regen-1
PERSISTENT_PEERS="69975e7afdf731a165e40449fcffc75167a084fc@104.131.169.70:26656,d35d652b6cb3bf7d6cb8d4bd7c036ea03e7be2ab@116.203.182.185:26656,ffacd3202ded6945fed12fa4fd715b1874985b8c@3.98.38.91:26656"
sudo apt update
sudo apt install build-essential jq wget git -y

echo "install regen-ledger"
git clone https://github.com/regen-network/regen-ledger
cd ~/regen-ledger
sleep 3
clear

echo "Installing Go 1.19..."

if command_exists go && required_go_version; then
clear
echo "Go 1.19 already installed"
sleep 3
clear
else
sudo rm -rf /usr/local/go
wget https://dl.google.com/go/go1.19.6.linux-amd64.tar.gz
tar -xvf go1.19.6.linux-amd64.tar.gz
sudo mv go /usr/local
rm -rf go1.19.6.linux-amd64.tar.gz
sleep 5
clear
echo "
export GOPATH=$HOME/go
export GOROOT=/usr/local/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:/usr/local/go/bin:$GOBIN
" >> ~/.bashrc
source ~/.bashrc
clear
echo "Installed Go 1.19.6 and added it to your .bashrc"
sleep 5
clear
fi

export GOPATH=$HOME/go
export GOROOT=/usr/local/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:/usr/local/go/bin:$GOBIN

if [ -d "$REGEN_HOME" ]; then
echo "--------------- WARNING! ---------------"
echo "A home directory for the regen binary already exists."
echo "The following step will remove $REGEN_HOME from your system."
while true; do
read -rp $'Are you sure you would like to continue (y/n)?\n' yn
case $yn in
[yY][eE][sS]|[yY]) rm -rf "$REGEN_HOME"; break;;
[nN][oO]|[nN]) exit;;
* ) echo "Please answer yes or no.";;
esac
done
clear
fi

echo "Installing the regen binary (v1.0.0)..."
sleep 3
cd $HOME
rm -rf regen-ledger
git clone https://github.com/regen-network/regen-ledger
cd regen-ledger
git fetch
git checkout v1.0.0
make install

echo "Regen Ledger has been installed succesfully!"
echo ""
echo "-- Next we will need to set up your keys and moniker"
echo "-- Please choose a name for your key --"
read YOUR_KEY_NAME

echo "-- Please choose a moniker --"
read YOUR_NAME
sleep 5
clear
echo "The regen binary (v1.0.0) has been installed on your system"
sleep 5
clear
echo "Setting validator key and node moniker..."

echo "-- Your Key Name is $YOUR_KEY_NAME and your moniker is $YOUR_NAME. Is this correct?"

select yn in "Yes" "No" "Cancel"; do
while true; do
echo "Please enter a name for your key:"
read -r KEY_NAME
echo "Please enter a moniker for your node:"
read -r NODE_MONIKER
echo "Your key name is $KEY_NAME and your node moniker is $NODE_MONIKER."
read -rp $'Is this correct (y/n)?\n' yn
case $yn in
Yes ) break;;
No ) echo "-- Please choose a name for your key --";
read YOUR_KEY_NAME;
echo "-- Please choose a moniker --";
read YOUR_NAME; break;;
Cancel ) exit;;
[yY][eE][sS]|[yY]) break;;
[nN][oO]|[nN]) ;;
* ) echo "Please answer yes or no.";;
esac
done

echo "-- Your Key Name is $YOUR_KEY_NAME and your moniker is $YOUR_NAME. --"

echo "Creating keys"
$DAEMON keys add $YOUR_KEY_NAME

echo ""
echo "After you have copied the mnemonic phrase in a safe place,"
echo "press the space bar to continue."
read -s -d ' '
echo ""
while true; do
echo "Creating validator key..."
regen keys add $KEY_NAME
echo ""
echo "After you have copied the mnemonic phrase in a safe place, press [ENTER] to continue."
read -r -s -d $'\x0a'
read -rp $'Are you sure you copied your mnemonic phrase (y/n)?\n' yn
case $yn in
[yY][eE][sS]|[yY]) break;;
[nN][oO]|[nN]) ;;
* ) echo "Please answer yes or no.";;
esac
done

echo "----------Setting up your validator node------------"
$DAEMON init --chain-id $CHAIN_ID $YOUR_NAME
echo "------Downloading Regen Mainnet genesis--------"
curl -s https://raw.githubusercontent.com/regen-network/mainnet/main/regen-1/genesis.json > ~/.regen/config/genesis.json
sleep 5
clear

echo "----------Setting config for seed node---------"
sed -i 's#tcp://127.0.0.1:26657#tcp://0.0.0.0:26657#g' ~/.$DAEMON/config/config.toml
sed -i '/persistent_peers =/c\persistent_peers = "'"$PERSISTENT_PEERS"'"' ~/.$DAEMON/config/config.toml
echo "Initializing node..."
regen init --chain-id regen-1 $NODE_MONIKER
sleep 2
clear

DAEMON_PATH=$(which $DAEMON)
echo "Downloading Regen Mainnet genesis file..."
curl -s https://raw.githubusercontent.com/regen-network/mainnet/main/regen-1/genesis.json > $REGEN_HOME/config/genesis.json
sleep 2
clear

echo "Installing cosmovisor - an upgrade manager..."
echo "Configuring RPC address..."
sed -i 's#tcp://127.0.0.1:26657#tcp://0.0.0.0:26657#g' $REGEN_HOME/config/config.toml
sleep 2
clear

rm -rf $GOPATH/src/github.com/cosmos/cosmos-sdk
git clone https://github.com/cosmos/cosmos-sdk $GOPATH/src/github.com/cosmos/cosmos-sdk
cd $GOPATH/src/github.com/cosmos/cosmos-sdk
git checkout v0.40.0
cd cosmovisor
make cosmovisor
cp cosmovisor $GOBIN/cosmovisor
echo "Configuring seed nodes..."
sed -i '/persistent_peers =/c\persistent_peers = "'"$PERSISTENT_PEERS"'"' $REGEN_HOME/config/config.toml
sleep 2
clear

echo "Setting up cosmovisor directories"
mkdir -p ~/.regen/cosmovisor/genesis/bin
cp $GOBIN/regen ~/.regen/cosmovisor/genesis/bin
echo "Installing cosmovisor..."
go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.4.0
sleep 2
clear

echo "---------Creating system file---------"
echo "Setting up genesis binary..."
mkdir -p $REGEN_HOME/cosmovisor/genesis/bin
cp $GOBIN/regen $REGEN_HOME/cosmovisor/genesis/bin
sleep 2
clear

echo "Creating cosmovisor service file..."
echo "[Unit]
Description=Cosmovisor daemon
After=network-online.target
[Service]
Environment="DAEMON_NAME=regen"
Environment="DAEMON_HOME=${HOME}/.${DAEMON}"
Environment="DAEMON_RESTART_AFTER_UPGRADE=on"
Environment="DAEMON_HOME=${HOME}/.regen"
Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=false"
Environment="DAEMON_RESTART_AFTER_UPGRADE=true"
Environment="DAEMON_POLL_INTERVAL=300ms"
Environment="DAEMON_DATA_BACKUP_DIR=${HOME}/.regen"
Environment="UNSAFE_SKIP_BACKUP=false"
Environment="DAEMON_PREUPGRADE_MAX_RETRIES=0"
User=${USER}
ExecStart=${GOBIN}/cosmovisor start
ExecStart=${GOBIN}/cosmovisor run start
Restart=always
RestartSec=3
LimitNOFILE=4096
[Install]
WantedBy=multi-user.target
" >cosmovisor.service
sudo mv cosmovisor.service /etc/systemd/system/cosmovisor.service
sleep 3
clear

sudo mv cosmovisor.service /lib/systemd/system/cosmovisor.service
sudo -S systemctl daemon-reload
sudo -S systemctl start cosmovisor
echo "Starting cosmovisor service..."
sudo systemctl daemon-reload
sudo systemctl enable cosmovisor
sudo service cosmovisor start

sleep 5
clear

echo "Congratulations! You have successfully set up your node."
echo ""
echo "Check the status of you node by running the following command:"
echo ""
echo "--------------Congratulations---------------"
echo "regen status"
echo ""
echo "View your account address by typing your passphrase below."
$DAEMON keys show $YOUR_KEY_NAME -a
echo "In order to become a validator, you will first need to fund your new account:"
echo ""
echo "regen keys show $KEY_NAME -a"
echo ""
echo "Next you will need to fund the above wallet address. When finished, you can create your validator by customizing and running the following command"
echo "When finished, you can create your validator by customizing and running the following command:"
echo ""
echo "regen tx staking create-validator --amount 9000000000uregen --commission-max-change-rate \"0.1\" --commission-max-rate \"0.20\" --commission-rate \"0.1\" --details \"Some details about yourvalidator\" --from <keyname> --pubkey=\"$(regen tendermint show-validator)\" --moniker <your moniker> --min-self-delegation \"1\" --chain-id regen-1 --gas auto --fees 500uregen"
echo "regen tx staking create-validator --amount 9000000000uregen --commission-max-change-rate \"0.1\" --commission-max-rate \"0.20\" --commission-rate \"0.1\" --details \"Some details about your validator\" --from <keyname> --pubkey=\"$(regen tendermint show-validator)\" --moniker <your moniker> --min-self-delegation \"1\" --chain-id regen-1 --gas auto --fees 5000uregen"

0 comments on commit 80d4ca5

Please sign in to comment.