Last active
June 5, 2024 21:56
-
-
Save 0x3639/979e2b0d2b0acea31dfd30849a524d4a to your computer and use it in GitHub Desktop.
Deploy Go-Zenon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Large ASCII Art for Zenon Network | |
echo " | |
███████╗███████╗███╗░░██╗░█████╗░███╗░░██╗ ███╗░░██╗███████╗████████╗░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗ | |
╚════██║██╔════╝████╗░██║██╔══██╗████╗░██║ ████╗░██║██╔════╝╚══██╔══╝░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝ | |
░░███╔═╝█████╗░░██╔██╗██║██║░░██║██╔██╗██║ ██╔██╗██║█████╗░░░░░██║░░░░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░ | |
██╔══╝░░██╔══╝░░██║╚████║██║░░██║██║╚████║ ██║╚████║██╔══╝░░░░░██║░░░░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░ | |
███████╗███████╗██║░╚███║╚█████╔╝██║░╚███║ ██║░╚███║███████╗░░░██║░░░░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗ | |
╚══════╝╚══════╝╚═╝░░╚══╝░╚════╝░╚═╝░░╚══╝ ╚═╝░░╚══╝╚══════╝░░░╚═╝░░░░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝ | |
▀█▀ █░█ █▀▀ █▄░█ █▀▀ ▀█▀ █░█░█ █▀█ █▀█ █▄▀ █▀█ █▀▀ █▀▄▀█ █▀█ █▀▄▀█ █▀▀ █▄░█ ▀█▀ █░█ █▀▄▀█ | |
░█░ █▀█ ██▄ █░▀█ ██▄ ░█░ ▀▄▀▄▀ █▄█ █▀▄ █░█ █▄█ █▀░ █░▀░█ █▄█ █░▀░█ ██▄ █░▀█ ░█░ █▄█ █░▀░█ | |
" | |
# Display starting message | |
echo "Starting Zenon Network setup script..." | |
# Function to deploy go-zenon | |
deploy_go_zenon() { | |
# Download Go | |
wget -O go1.21.4.linux-amd64.tar.gz https://go.dev/dl/go1.21.4.linux-amd64.tar.gz | |
# Check if /usr/local/go exists | |
if [ -d "/usr/local/go" ]; then | |
# Remove any previous Go installation | |
rm -rf /usr/local/go | |
fi | |
# Extract the Go tarball | |
tar -C /usr/local -xzf go1.21.4.linux-amd64.tar.gz | |
# Check if /usr/local/go/bin is in the PATH | |
if ! echo "$PATH" | grep -q "/usr/local/go/bin"; then | |
# Add /usr/local/go/bin to the PATH environment variable | |
echo "export PATH=\$PATH:/usr/local/go/bin" >> $HOME/.profile | |
fi | |
# Apply the changes immediately | |
source $HOME/.profile | |
# Verify that Go is installed | |
go version | |
# Check if make is installed | |
if ! command -v make &> /dev/null; then | |
echo "make could not be found" | |
echo "Installing make..." | |
apt-get update | |
apt-get install -y make | |
fi | |
# Check if gcc is installed | |
if ! command -v gcc &> /dev/null; then | |
echo "gcc could not be found" | |
echo "Installing gcc..." | |
apt-get update | |
apt-get install -y gcc | |
fi | |
# Check if go-zenon directory exists | |
if [ -d "go-zenon" ]; then | |
rm -rf go-zenon | |
fi | |
# Check if /usr/local/bin/znnd exists and back it up | |
if [ -f /usr/local/bin/znnd ]; then | |
timestamp=$(date +%Y%m%d%H%M%S) | |
cp /usr/local/bin/znnd /usr/local/bin/znnd.bak.$timestamp | |
fi | |
echo "Please enter the URL of the version of go-zenon you would like to install. Press enter to use the default URL." | |
read -r -p "URL (default: https://github.com/zenon-network/go-zenon.git): " go_zenon_url | |
go_zenon_url=${go_zenon_url:-https://github.com/zenon-network/go-zenon.git} | |
# Clone the repository to get the branches | |
git clone --bare $go_zenon_url temp_go_zenon | |
echo "Available branches:" | |
branches=$(git --git-dir=temp_go_zenon for-each-ref --format='%(refname:short)' refs/heads/) | |
PS3="Please select a branch: " | |
select branch in $branches; do | |
if [ -n "$branch" ]; then | |
go_zenon_branch=$branch | |
break | |
else | |
echo "Invalid selection. Please try again." | |
fi | |
done | |
# Clean up temporary repository | |
rm -rf temp_go_zenon | |
echo "Selected branch: $go_zenon_branch" | |
echo "Installing go-zenon from $go_zenon_url branch $go_zenon_branch..." | |
git clone -b $go_zenon_branch $go_zenon_url go-zenon | |
if [ $? -ne 0 ]; then | |
echo "Error: Failed to clone the repository. Please check the URL and branch name." | |
exit 1 | |
fi | |
cd go-zenon | |
make znnd | |
if [ $? -ne 0 ]; then | |
echo "Error: Failed to build znnd. Please check the Makefile and dependencies." | |
exit 1 | |
fi | |
cp build/znnd /usr/local/bin/ | |
echo "Setting up go-zenon.service..." | |
if [ ! -e /etc/systemd/system/go-zenon.service ]; then | |
cat << EOF > /etc/systemd/system/go-zenon.service | |
[Unit] | |
Description=znnd service | |
After=network.target | |
[Service] | |
LimitNOFILE=32768 | |
User=root | |
Group=root | |
Type=simple | |
SuccessExitStatus=SIGKILL 9 | |
ExecStart=/usr/local/bin/znnd | |
ExecStop=/usr/bin/pkill -9 znnd | |
Restart=on-failure | |
TimeoutStopSec=10s | |
TimeoutStartSec=10s | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
systemctl daemon-reload | |
systemctl enable go-zenon.service | |
echo "go-zenon.service is setup." | |
else | |
echo "go-zenon.service already exists. Skipping setup." | |
fi | |
# Start go-zenon | |
systemctl start go-zenon | |
echo "go-zenon started successfully." | |
} | |
# Function to restore go-zenon from bootstrap | |
restore_go_zenon() { | |
# Download and run the restore.sh script | |
wget -O temp_restore.sh "https://gist.githubusercontent.com/0x3639/05c6e2ba6b7f0c2a502a6bb4da6f4746/raw/ff4343433b31a6c85020c887256c0fd3e18f01d9/restore.sh" | |
chmod +x temp_restore.sh | |
./temp_restore.sh | |
# Cleanup the temporary restore script | |
rm temp_restore.sh | |
} | |
# Function to restart go-zenon | |
restart_go_zenon() { | |
systemctl restart go-zenon | |
echo "go-zenon restarted successfully." | |
} | |
# Function to stop go-zenon | |
stop_go_zenon() { | |
systemctl stop go-zenon | |
echo "go-zenon stopped successfully." | |
} | |
# Function to start go-zenon | |
start_go_zenon() { | |
systemctl start go-zenon | |
echo "go-zenon started successfully." | |
} | |
# Present a menu of options in a loop | |
while true; do | |
echo "Please choose an option:" | |
echo "1) Deploy go-zenon" | |
echo "2) Restore go-zenon from Bootstrap" | |
echo "3) Restart go-zenon" | |
echo "4) Stop go-zenon" | |
echo "5) Start go-zenon" | |
echo "6) Quit" | |
read -r -p "Enter your choice [1-6]: " choice | |
case $choice in | |
1) | |
deploy_go_zenon | |
;; | |
2) | |
restore_go_zenon | |
;; | |
3) | |
restart_go_zenon | |
;; | |
4) | |
stop_go_zenon | |
;; | |
5) | |
start_go_zenon | |
;; | |
6) | |
echo "Exiting script." | |
exit 0 | |
;; | |
*) | |
echo "Invalid option. Please try again." | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment