Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node updating script #938

Merged
merged 1 commit into from
Jun 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions scripts/public-node-updater.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/bash
# ChainofSecrets.org - Public Release.
# Set "mainnet" or "testnet"

NETWORK="mainnet";

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

install_jq () {
if command_exists apt-get; then
apt-get -y update
apt -y -q install jq
fi

if ! command_exists jq; then
echo "jq: command not found"
exit 1;
fi
}

install_secretd () {
if command_exists wget; then
wget "$GOLEVELDB_LINK"
sudo apt install -y ./secretnetwork_"$LATEST_VERSION"_"$NETWORK"_goleveldb_amd64.deb
fi

if ! command_exists secretd; then
echo "secretd: command not found"
exit 1;
fi
}

install_sgx () {

wget "https://raw.githubusercontent.com/SecretFoundation/docs/main/docs/node-guides/sgx"
sudo bash sgx
}

check_release () {

LATEST_VERSION=$(curl -sL https://api.github.com/repos/scrtlabs/secretnetwork/releases/latest | jq -r ".tag_name" | sed 's/v//');
GOLEVELDB_LINK=`curl -sL https://api.github.com/repos/scrtlabs/secretnetwork/releases/latest | jq -r ".assets[].browser_download_url" | grep "$NETWORK"_goleveldb_amd64.deb`;
ROCKSDB_LINK=`curl -sL https://api.github.com/repos/scrtlabs/secretnetwork/releases/latest | jq -r ".assets[].browser_download_url" | grep "$NETWORK"_rocksdb_amd64.deb`;

}

read_installation_method () {
echo "--------------------------------------------------------------------------------------------";
echo "This installation file is built for any version of secretd.";
echo "Note: Currently does not support SGX check then install, therefor will just install SGX again.";
echo "";
echo "This will automatically install a fresh secretd or update an old secretd to either rocksdb or golevel";
echo "depending on current running configuration.";
echo "";
echo "<3 from ChainofSecrets.org";
echo "--------------------------------------------------------------------------------------------";
echo "";
read -p "Install secretd [Y/N]? " choice
case "$choice" in
y|Y )
INSTALL="true";
;;

n|N )
exit 0;
;;

* )
echo "Please, enter Y or N to cancel";
;;
esac
}

if ! command_exists jq ; then
install_jq;
fi

check_release;
read_installation_method;
install_sgx;

if ! command_exists secretd ; then
install_secretd;
fi


if [ $(secretd version) = "$LATEST_VERSION" ]; then
echo 'Current Version '$LATEST_VERSION' - Updating not needed! Happy Nodeling - ChainofSecrets.org'
else
if [ $(awk -F \" '/^db_backend =/{print $2}' ~/.secretd/config/config.toml) = 'goleveldb' ]; then
echo "This is a golevelDB install"
sudo systemctl stop secret-node
wget "$GOLEVELDB_LINK"
sudo apt install -y ./secretnetwork_"$LATEST_VERSION"_"$NETWORK"_goleveldb_amd64.deb

else

echo "This is a Rocksdb install"
sudo systemctl stop secret-node
wget "$ROCKSDB_LINK"
sudo apt install -y ./secretnetwork_"$LATEST_VERSION"_"$NETWORK"_rocksdb_amd64.deb
fi


# .Restart the node & modify the service

perl -i -pe 's{^(ExecStart=).*}{ExecStart=\/usr\/local\/bin\/secretd start}' /etc/systemd/system/secret-node.service

systemctl daemon-reload

sudo systemctl start secret-node

fi