Updated with script links to protect compatibility

This commit is contained in:
0xOzgur 2024-06-12 19:58:22 +03:00
parent 31f88060c4
commit 4d3631d487

View File

@ -31,361 +31,44 @@ elif [ "$ARCH" = "aarch64" ]; then
fi
fi
# URLs for scripts
UPDATE_URL="https://raw.githubusercontent.com/0xOzgur/QuilibriumTools/main/update.sh"
PREREQUISITES_URL="https://raw.githubusercontent.com/0xOzgur/QuilibriumTools/main/install/Install_prerequisites.sh"
NODE_INSTALL_URL="https://raw.githubusercontent.com/0xOzgur/QuilibriumTools/main/install/install_quilibrium_service.sh"
GRPCURL_CONFIG_URL="https://raw.githubusercontent.com/0xOzgur/QuilibriumTools/main/configuration/config.sh"
NODE_UPDATE_URL="https://raw.githubusercontent.com/0xOzgur/QuilibriumTools/main/update.sh"
CHECK_VISIBILITY_URL="https://raw.githubusercontent.com/0xOzgur/QuilibriumTools/main/visibility_check.sh"
# Function for each menu option
install_prerequisites() {
echo "Installing prerequisites..."
sleep 1 # Add a 1-second delay
echo "Updating the machine"
echo "⏳Processing..."
sleep 1 # Add a 1-second delay
# Fof DEBIAN OS - Check if sudo and git is installed
# Step 1.1: Prepare Machine
if ! command -v sudo &> /dev/null
then
echo "sudo could not be found"
echo "Installing sudo..."
su -c "apt update && apt install sudo -y"
else
echo "sudo is installed"
fi
# ınstall git if not installed
if ! command -v git &> /dev/null
then
echo "git could not be found"
echo "Installing git..."
su -c "apt update && apt install git -y"
else
echo "git is installed"
fi
# Update the machine
sudo apt update
sudo apt upgrade -y
# Install cpu limit and gawk
apt install cpulimit -y
apt install gawk -y #incase it is not installed
# Download and install Go
wget https://go.dev/dl/$GO_BINARY || { echo "Failed to download Node! Exiting..."; exit_message; exit 1; }
sudo tar -xvf $GO_BINARY || { echo "Failed to extract Go! Exiting..."; exit_message; exit 1; }
sudo rm -rf /usr/local/go || { echo "Failed to remove existing Go! Exiting..."; exit_message; exit 1; }
sudo mv go /usr/local || { echo "Failed to move go! Exiting..."; exit_message; exit 1; }
sudo rm $GO_BINARY || { echo "Failed to remove downloaded archive! Exiting..."; exit_message; exit 1; }
# Set Go environment variables
echo "⏳Setting Go environment variables..."
sleep 2 # Add a 2-second delay
# Check if GOROOT is already set
if grep -q 'GOROOT=/usr/local/go' ~/.bashrc; then
echo "GOROOT already set in ~/.bashrc."
else
echo 'GOROOT=/usr/local/go' >> ~/.bashrc
echo "GOROOT set in ~/.bashrc."
fi
# Check if GOPATH is already set
if grep -q "GOPATH=$HOME/go" ~/.bashrc; then
echo "GOPATH already set in ~/.bashrc."
else
echo "GOPATH=$HOME/go" >> ~/.bashrc
echo "GOPATH set in ~/.bashrc."
fi
# Check if PATH is already set
if grep -q 'PATH=$GOPATH/bin:$GOROOT/bin:$PATH' ~/.bashrc; then
echo "PATH already set in ~/.bashrc."
else
echo 'PATH=$GOPATH/bin:$GOROOT/bin:$PATH' >> ~/.bashrc
echo "PATH set in ~/.bashrc."
fi
# Source .bashrc to apply changes
echo "⏳Sourcing .bashrc to apply changes"
source ~/.bashrc
sleep 2 # Add a 2-second delay
# Check GO Version
go version
sleep 2 # Add a 2-second delay
# Install gRPCurl
echo "⏳Installing gRPCurl"
sleep 1 # Add a 1-second delay
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
echo ""
echo "⌛️ Preparing server with necessary apps and settings..."
wget --no-cache -O - "$PREREQUISITES_URL" | bash
}
# Install Node
install_node() {
echo "Installing node..."
# Adjust network buffer sizes
echo "Adjusting network buffer sizes..."
if grep -q "^net.core.rmem_max=600000000$" /etc/sysctl.conf; then
echo "net.core.rmem_max=600000000 found inside /etc/sysctl.conf, skipping..."
else
echo -e "\n# Change made to increase buffer sizes for better network performance for ceremonyclient\nnet.core.rmem_max=600000000" | sudo tee -a /etc/sysctl.conf > /dev/null
fi
if grep -q "^net.core.wmem_max=600000000$" /etc/sysctl.conf; then
echo "net.core.wmem_max=600000000 found inside /etc/sysctl.conf, skipping..."
else
echo -e "\n# Change made to increase buffer sizes for better network performance for ceremonyclient\nnet.core.wmem_max=600000000" | sudo tee -a /etc/sysctl.conf > /dev/null
fi
sudo sysctl -p
# Check if directory ~/ceremonyclient exists, download from github
if [ -d ~/ceremonyclient ]; then
# Check if backup directory ~/backup/qnode_keys exists, if not create it
if [ ! -d ~/backup/qnode_keys ]; then
mkdir -p ~/backup/qnode_keys
fi
# Check if files exist, then backup
if [ -f ~/ceremonyclient/node/.config/keys.yml ]; then
cp ~/ceremonyclient/node/.config/keys.yml ~/backup/qnode_keys/
echo "✅ Backup of keys.yml created in ~/backup/qnode_keys folder"
fi
if [ -f ~/ceremonyclient/node/.config/config.yml ]; then
cp ~/ceremonyclient/node/.config/config.yml ~/backup/qnode_keys/
echo "✅ Backup of config.yml created in ~/backup/qnode_keys folder"
fi
fi
# Download Ceremonyclient
echo "⏳Downloading Ceremonyclient"
sleep 1 # Add a 1-second delay
cd ~
if [ -d "ceremonyclient" ]; then
echo "Directory ceremonyclient already exists, skipping git clone..."
else
until git clone https://source.quilibrium.com/quilibrium/ceremonyclient.git || git clone https://git.quilibrium-mirror.ch/agostbiro/ceremonyclient.git; do
echo "Git clone failed, retrying..."
sleep 2
done
fi
cd ~/ceremonyclient/
git remote set-url origin https://source.quilibrium.com/quilibrium/ceremonyclient.git || git remote set-url origin https://git.quilibrium-mirror.ch/agostbiro/ceremonyclient.git
git checkout release-cdn
# 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"
# Create Ceremonyclient Service
echo "⏳ Creating Ceremonyclient Service"
sleep 2 # Add a 2-second delay
# Check if the file exists before attempting to remove it
if [ -f "/lib/systemd/system/ceremonyclient.service" ]; then
# If the file exists, remove it
rm /lib/systemd/system/ceremonyclient.service
echo "ceremonyclient.service file removed."
else
# If the file does not exist, inform the user
echo "ceremonyclient.service file does not exist. No action taken."
fi
sudo tee /lib/systemd/system/ceremonyclient.service > /dev/null <<EOF
[Unit]
Description=Ceremony Client Go App Service
[Service]
Type=simple
Restart=always
RestartSec=5s
WorkingDirectory=$NODE_PATH
ExecStart=$EXEC_START
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable ceremonyclient
# Start the ceremonyclient service
echo "✅Starting Ceremonyclient Service"
sleep 1 # Add a 1-second delay
sudo service ceremonyclient start
# See the logs of the ceremonyclient service
echo "🎉Welcome to Quilibrium Ceremonyclient"
echo ""
echo "⌛️ Installing node as a service..."
wget --no-cache -O - "$NODE_INSTALL_URL" | bash
}
configure_grpcurl() {
echo "Configuring grpcurl..."
line_exists() {
grep -qF "$1" "$2"
}
# Enable gRPC
echo "Enabling gRPC..."
cd "$HOME/ceremonyclient/node" || { echo "Failed to change directory to ~/ceremonyclient/node! Exiting..."; exit 1; }
# Check if the line listenGrpcMultiaddr: /ip4/127.0.0.1/tcp/8337 exists
if ! line_exists "listenGrpcMultiaddr: /ip4/127.0.0.1/tcp/8337" .config/config.yml; then
# Check if the line listenGrpcMultiaddr: "" exists
if line_exists "listenGrpcMultiaddr: \"\"" .config/config.yml; then
# Substitute listenGrpcMultiaddr: "" with listenGrpcMultiaddr: /ip4/127.0.0.1/tcp/8337
sudo sed -i 's#^listenGrpcMultiaddr:.*$#listenGrpcMultiaddr: /ip4/127.0.0.1/tcp/8337#' .config/config.yml || { echo "Failed to enable gRPC! Exiting..."; exit 1; }
else
# Add listenGrpcMultiaddr: /ip4/127.0.0.1/tcp/8337
echo "listenGrpcMultiaddr: /ip4/127.0.0.1/tcp/8337" | sudo tee -a .config/config.yml > /dev/null || { echo "Failed to enable gRPC! Exiting..."; exit 1; }
fi
else
echo "gRPC already enabled."
fi
# Check if the line listenRESTMultiaddr: /ip4/127.0.0.1/tcp/8338 exists
if ! line_exists "listenRESTMultiaddr: /ip4/127.0.0.1/tcp/8338" .config/config.yml; then
# Check if the line listenRESTMultiaddr: "" exists
if line_exists "listenRESTMultiaddr: \"\"" .config/config.yml; then
# Substitute listenRESTMultiaddr: "" with listenRESTMultiaddr: /ip4/127.0.0.1/tcp/8338
sudo sed -i 's#^listenRESTMultiaddr:.*$#listenRESTMultiaddr: /ip4/127.0.0.1/tcp/8338#' .config/config.yml || { echo "Failed to enable gRPC! Exiting..."; exit 1; }
else
# Add listenRESTMultiaddr: /ip4/127.0.0.1/tcp/8338
echo "listenRESTMultiaddr: /ip4/127.0.0.1/tcp/8338" | sudo tee -a .config/config.yml > /dev/null || { echo "Failed to enable gRPC! Exiting..."; exit 1; }
fi
else
echo "gRPC already enabled."
fi
# Enable Stats Collection
echo "Enabling Stats Collection..."
if ! line_exists " statsMultiaddr: \"/dns/stats.quilibrium.com/tcp/443\"" .config/config.yml; then
sudo sed -i '/^ *engine:/a\ statsMultiaddr: "/dns/stats.quilibrium.com/tcp/443"' .config/config.yml || { echo "Failed to enable Stats Collection! Exiting..."; exit 1; }
else
echo "Stats Collection already enabled."
fi
# Check if both lines were added successfully
if line_exists "listenGrpcMultiaddr: /ip4/127.0.0.1/tcp/8337" .config/config.yml && line_exists " statsMultiaddr: \"/dns/stats.quilibrium.com/tcp/443\"" .config/config.yml; then
echo "Success: The script successfully edited your config.yml file."
else
echo "ERROR: The script failed to correctly edit your config.yml file."
echo "You may want to follow the online guide to do it manually."
exit 1
fi
echo "gRPC calls setup was successful."
echo ""
echo "⌛️ Configuring grpCurl..."
wget --no-cache -O - "$GRPCURL_CONFIG_URL" | bash
}
update_node() {
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://source.quilibrium.com/quilibrium/ceremonyclient.git || git remote set-url origin https://git.quilibrium-mirror.ch/agostbiro/ceremonyclient.git
git pull
git checkout release-cdn
# 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
[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 ""
echo "⌛️ Updating node..."
wget --no-cache -O - "$NODE_UPDATE_URL" | bash
}
check_visibility() {
echo "⏳Processing..."
sleep 2 # Add a 2-second delay
# Bootstrap peer list
bootstrap_peers=(
"EiDpYbDwT2rZq70JNJposqAC+vVZ1t97pcHbK8kr5G4ZNA=="
"EiCcVN/KauCidn0nNDbOAGMHRZ5psz/lthpbBeiTAUEfZQ=="
"EiDhVHjQKgHfPDXJKWykeUflcXtOv6O2lvjbmUnRrbT2mw=="
"EiDHhTNA0yf07ljH+gTn0YEk/edCF70gQqr7QsUr8RKbAA=="
"EiAnwhEcyjsHiU6cDCjYJyk/1OVsh6ap7E3vDfJvefGigw=="
"EiB75ZnHtAOxajH2hlk9wD1i9zVigrDKKqYcSMXBkKo4SA=="
"EiDEYNo7GEfMhPBbUo+zFSGeDECB0RhG0GfAasdWp2TTTQ=="
"EiCzMVQnCirB85ITj1x9JOEe4zjNnnFIlxuXj9m6kGq1SQ=="
)
# Run the grpcurl command and capture its output
output=$(grpcurl -plaintext localhost:8337 quilibrium.node.node.pb.NodeService.GetNetworkInfo)
# Check if any of the specific peers are in the output
visible=false
for peer in "${bootstrap_peers[@]}"; do
if [[ $output == *"$peer"* ]]; then
visible=true
echo "You see $peer as a bootstrap peer"
else
echo "Peer $peer not found"
fi
done
if $visible ; then
echo "Great, your node is visible!"
else
echo "Sorry, your node is not visible. Please restart your node and try again."
fi
echo ""
echo "⌛️ Checking visibility..."
wget --no-cache -O - "$CHECK_VISIBILITY_URL" | bash
}
node_info() {
@ -397,7 +80,6 @@ node_info() {
node_logs() {
echo "Getting node logs..."
sudo journalctl -u ceremonyclient.service -f --no-hostname -o cat
# sudo journalctl -u ceremonyclient.service -n 100 --no-hostname -o cat
}
restart_node() {