QuilibriumTools/update/update.sh
2024-10-11 21:39:04 +03:00

119 lines
3.8 KiB
Bash

#!/bin/bash
VERSION="2.0"
# Step 0: Welcome
echo "This script is made with ❤️ by 0xOzgur.eth @ https://quilibrium.space"
echo "⏳Enjoy and sit back while you are upgrading your Quilibrium Node to v$VERSION!"
echo "The script is prepared for Ubuntu machines. If you are using another operating system, please check the compatibility of the script."
echo "⏳Processing..."
sleep 5 # Add a 5-second delay
# Stop the ceremonyclient service
echo "Updating node..."
service ceremonyclient stop
# apt install cpulimit -y
# apt install gawk -y #incase it is not installed
# Download Binary
echo "⏳ Downloading New Release v$VERSION"
cd ~/ceremonyclient
git remote set-url origin https://github.com/QuilibriumNetwork/ceremonyclient.git
git checkout main
git branch -D release
git pull
git checkout release
# Determine the ExecStart line based on the architecture
ARCH=$(uname -m)
OS=$(uname -s)
# Determine the node binary name based on the architecture and OS
if [ "$ARCH" = "x86_64" ]; then
if [ "$OS" = "Linux" ]; then
NODE_BINARY="node-$VERSION-linux-amd64"
GO_BINARY="go1.22.4.linux-amd64.tar.gz"
QCLIENT_BINARY="qclient-1.4.19.1-linux-amd64"
elif [ "$OS" = "Darwin" ]; then
NODE_BINARY="node-$VERSION-darwin-amd64"
GO_BINARY="go1.22.44.linux-amd64.tar.gz"
QCLIENT_BINARY="qclient-1.4.19.1-darwin-arm64"
fi
elif [ "$ARCH" = "aarch64" ]; then
if [ "$OS" = "Linux" ]; then
NODE_BINARY="node-$VERSION-linux-arm64"
GO_BINARY="go1.22.4.linux-arm64.tar.gz"
elif [ "$OS" = "Darwin" ]; then
NODE_BINARY="node-$VERSION-darwin-arm64"
GO_BINARY="go1.22.4.linux-arm64.tar.gz"
QCLIENT_BINARY="qclient-1.4.19.1-linux-arm64"
fi
fi
# Step 4:Update qClient
echo "Updating qClient"
sleep 1 # Add a 1-second delay
cd ~/ceremonyclient/client
rm -f qclient
wget https://releases.quilibrium.com/$QCLIENT_BINARY
mv $QCLIENT_BINARY qclient
chmod +x qclient
# Get the current user's home directory
HOME=$(eval echo ~$HOME_DIR)
# Use the home directory in the path
NODE_PATH="$HOME/ceremonyclient/node"
EXEC_START="$NODE_PATH/release_autorun.sh"
# Re-Create Ceremonyclient Service
echo "⏳ Re-Creating Ceremonyclient Service"
sleep 2 # Add a 2-second delay
SERVICE_FILE="/lib/systemd/system/ceremonyclient.service"
if [ ! -f "$SERVICE_FILE" ]; then
echo "📝 Creating new ceremonyclient service file..."
if ! sudo tee "$SERVICE_FILE" > /dev/null <<EOF
[Unit]
Description=Ceremony Client Go App Service
[Service]
Type=simple
Restart=always
RestartSec=5s
WorkingDirectory=$NODE_PATH
ExecStart=$EXEC_START
KillSignal=SIGINT
TimeoutStopSec=30s
[Install]
WantedBy=multi-user.target
EOF
then
echo "❌ Error: Failed to create ceremonyclient service file." >&2
exit 1
fi
else
echo "🔍 Checking existing ceremonyclient service file..."
# Check if the required lines exist and if they are different
if ! grep -q "WorkingDirectory=$NODE_PATH" "$SERVICE_FILE" || ! grep -q "ExecStart=$EXEC_START" "$SERVICE_FILE"; then
echo "🔄 Updating existing ceremonyclient service file..."
# Replace the existing lines with new values
sudo sed -i "s|WorkingDirectory=.*|WorkingDirectory=$NODE_PATH|" "$SERVICE_FILE"
sudo sed -i "s|ExecStart=.*|ExecStart=$EXEC_START|" "$SERVICE_FILE"
else
echo "✅ No changes needed."
fi
fi
# Start the ceremonyclient service
echo "✅ Starting Ceremonyclient Service"
sleep 2 # Add a 2-second delay
sudo systemctl daemon-reload
sudo systemctl enable ceremonyclient
sudo service ceremonyclient start
# See the logs of the ceremonyclient service
echo "🎉 Welcome to Quilibrium Ceremonyclient v$VERSION"
echo "⏳ Please let it flow node logs at least 5 minutes then you can press CTRL + C to exit the logs."
sleep 5 # Add a 5-second delay
sudo journalctl -u ceremonyclient.service -f --no-hostname -o cat