Last active
December 2, 2023 11:39
-
-
Save 0x3639/05c6e2ba6b7f0c2a502a6bb4da6f4746 to your computer and use it in GitHub Desktop.
NoM Restore Script
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 | |
# Ensure the user runs the script with root permissions | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
# Check and install wget and unzip if necessary | |
for cmd in wget unzip; do | |
if ! command -v $cmd &> /dev/null; then | |
echo "$cmd is not installed. Installing $cmd..." | |
apt-get update | |
apt-get install -y $cmd | |
fi | |
done | |
DEFAULT_URL="http://hypercore.nyc3.digitaloceanspaces.com/bootstrap/2023-12-02/bootstrap-20231202111921.zip" | |
# Ask the user for the bootstrap file's URL | |
read -p "Enter the URL for the bootstrap file (default is $DEFAULT_URL): " bootstrap_url | |
bootstrap_url=${bootstrap_url:-$DEFAULT_URL} | |
hash_url="${bootstrap_url%.*}.hash" | |
# Check if the directory exists | |
if [[ ! -d "/root/.znn" ]]; then | |
echo "/root/.znn directory does not exist" | |
exit 1 | |
fi | |
# Move to destination directory | |
cd /root/.znn | |
zip_file_name=$(basename "$bootstrap_url") | |
hash_file_name=$(basename "$hash_url") | |
# Download the bootstrap and hash files using wget | |
wget "$bootstrap_url" -O "$zip_file_name" | |
wget "$hash_url" -O "$hash_file_name" | |
# Function to compare checksum | |
function compare_checksum() { | |
if [[ ! -f "$zip_file_name" || ! -f "$hash_file_name" ]]; then | |
return 1 | |
fi | |
local_downloaded_hash=$(sha256sum "$zip_file_name" | awk '{print $1}') | |
local_stored_hash=$(cat "$hash_file_name") | |
if [[ "$local_downloaded_hash" == "$local_stored_hash" ]]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# Start checksum comparison | |
compare_checksum | |
if [[ $? -eq 0 ]]; then | |
echo "Download complete and checksum verified!" | |
else | |
echo "Checksum verification failed." | |
exit 1 | |
fi | |
# Stop the service after successful download and hash check | |
systemctl stop go-zenon | |
# Sleep for 10 seconds to ensure everything is fully stopped | |
sleep 10 | |
# Unzip the bootstrap file | |
unzip "$zip_file_name" | |
# Rename existing folders by appending the current datetime to their names | |
datetime_suffix=$(date +"%Y%m%d%H%M%S") | |
mv nom/ "nom_$datetime_suffix/" | |
mv network/ "network_$datetime_suffix/" | |
mv consensus/ "consensus_$datetime_suffix/" | |
# Check if backup subdirectories exist before moving | |
if [[ -d "backup/nom.bak" ]]; then | |
mv backup/nom.bak/ nom/ | |
else | |
echo "backup/nom.bak/ does not exist!" | |
fi | |
if [[ -d "backup/network.bak" ]]; then | |
mv backup/network.bak/ network/ | |
else | |
echo "backup/network.bak/ does not exist!" | |
fi | |
if [[ -d "backup/consensus.bak" ]]; then | |
mv backup/consensus.bak/ consensus/ | |
else | |
echo "backup/consensus.bak/ does not exist!" | |
fi | |
# Cleanup the backup directory if it exists | |
if [[ -d "backup" ]]; then | |
rm -r backup/ | |
else | |
echo "backup/ directory does not exist!" | |
fi | |
# Start the service again | |
systemctl start go-zenon | |
echo "Restore process completed. go-zenon has been started!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment