From 92a8c818636242794c6d40eb7400d3d2720f47fd Mon Sep 17 00:00:00 2001 From: 0xOzgur <29779769+0xOzgur@users.noreply.github.com> Date: Mon, 20 May 2024 19:46:15 +0300 Subject: [PATCH] . --- Quil_Balance_Checker/quil_balance_checker.sh | 22 ++++++ .../quil_balance_checker_installer.sh | 75 +++++++++++++++++++ install/install_binary.sh | 1 + install/install_docker.sh | 1 + install/install_quilibrium_service.sh | 2 + 5 files changed, 101 insertions(+) create mode 100644 Quil_Balance_Checker/quil_balance_checker.sh create mode 100644 Quil_Balance_Checker/quil_balance_checker_installer.sh diff --git a/Quil_Balance_Checker/quil_balance_checker.sh b/Quil_Balance_Checker/quil_balance_checker.sh new file mode 100644 index 0000000..bd8b0cb --- /dev/null +++ b/Quil_Balance_Checker/quil_balance_checker.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Navigate to the directory +cd /root/ceremonyclient/client || exit + +# Run the command and extract the token balance +balance=$(./qclient token balance | grep -oP '\b\d+(?=\.\d+\s+QUIL)') + +# Check if balance is not empty +if [ -n "$balance" ]; then + # Get the current date in the required format + current_date=$(date +"%d/%m/%Y") + + # Log the balance value in CSV format + echo "$current_date,$balance" >> /root/scripts/log/quil_balance.csv +else + # Get the current date in the required format + current_date=$(date +"%d/%m/%Y") + + # Log "error" in CSV format + echo "$current_date,error" >> /root/scripts/log/quil_balance.csv +fi diff --git a/Quil_Balance_Checker/quil_balance_checker_installer.sh b/Quil_Balance_Checker/quil_balance_checker_installer.sh new file mode 100644 index 0000000..4a3070a --- /dev/null +++ b/Quil_Balance_Checker/quil_balance_checker_installer.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# Step 1: Ensure /root/scripts and /root/scripts/log directories exist +echo "Checking if /root/scripts and /root/scripts/log directories exist..." +if mkdir -p /root/scripts/log; then + echo "Directories ensured successfully." +else + echo "Failed to ensure directories." >&2 + exit 1 +fi + +# Step 2: Create or overwrite quil_balance_checker.sh +echo "Creating or overwriting /root/scripts/quil_balance_checker.sh..." +if echo '#!/bin/bash' > /root/scripts/quil_balance_checker.sh; then + echo "File /root/scripts/quil_balance_checker.sh created successfully." +else + echo "Failed to create /root/scripts/quil_balance_checker.sh." >&2 + exit 1 +fi + +# Step 3: Paste the script content into quil_balance_checker.sh +echo "Adding script content to /root/scripts/quil_balance_checker.sh..." +if echo "#!/bin/bash + +# Navigate to the directory +cd /root/ceremonyclient/client || exit + +# Run the command and extract the token balance +balance=\$(./qclient token balance | grep -oP '\\b\\d+(?=\\.\\d+\\s+QUIL)') + +# Check if balance is not empty +if [ -n \"\$balance\" ]; then + # Get the current date in the required format + current_date=\$(date +\"%d/%m/%Y\") + + # Log the balance value in CSV format + echo \"\$current_date,\$balance\" >> /root/scripts/log/quil_balance.csv +else + # Get the current date in the required format + current_date=\$(date +\"%d/%m/%Y\") + + # Log \"error\" in CSV format + echo \"\$current_date,error\" >> /root/scripts/log/quil_balance.csv +fi +" > /root/scripts/quil_balance_checker.sh; then + echo "Script content added successfully." +else + echo "Failed to add script content." >&2 + exit 1 +fi + +# Step 4: Grant execute permissions +echo "Setting execute permissions for /root/scripts/quil_balance_checker.sh..." +if chmod +x /root/scripts/quil_balance_checker.sh; then + echo "Execute permissions set successfully." +else + echo "Failed to set execute permissions." >&2 + exit 1 +fi + +# Step 5: Create cronjob if not already existing +echo "Checking for existing cronjob..." +if crontab -l | grep -q 'quil_balance_checker.sh'; then + echo "Cronjob already exists." +else + echo "Creating new cronjob..." + if { crontab -l; echo '0 10 * * * export TZ="Europe/Rome" && /root/scripts/quil_balance_checker.sh'; } | crontab -; then + echo "Cronjob created successfully." + else + echo "Failed to create cronjob." >&2 + exit 1 + fi +fi + +echo "Installer script executed successfully!" diff --git a/install/install_binary.sh b/install/install_binary.sh index e0bc66e..51ed45d 100644 --- a/install/install_binary.sh +++ b/install/install_binary.sh @@ -1,5 +1,6 @@ #!/bin/bash +cd ~ # Step 0: Welcome echo "This script is prepared by 0xOzgur.eth" diff --git a/install/install_docker.sh b/install/install_docker.sh index 489cfdf..26af018 100644 --- a/install/install_docker.sh +++ b/install/install_docker.sh @@ -1,5 +1,6 @@ #!/bin/bash +cd ~ # Step 0: Welcome echo "This script is prepared by 0xOzgur.eth" diff --git a/install/install_quilibrium_service.sh b/install/install_quilibrium_service.sh index 03a4b73..a597cf4 100644 --- a/install/install_quilibrium_service.sh +++ b/install/install_quilibrium_service.sh @@ -1,5 +1,7 @@ #!/bin/bash -i +cd ~ + # Step 0: Welcome echo "This script is prepared by 0xOzgur.eth" echo "Enjoy and sit back while you are building your Quilibrium Node!"