From 4d1030f1af181eedf4ff893271a490eda0680896 Mon Sep 17 00:00:00 2001 From: bilulib Date: Mon, 12 May 2025 22:55:43 +0200 Subject: [PATCH] add remove backups function befor creating a new one --- ct/huntarr.sh | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/ct/huntarr.sh b/ct/huntarr.sh index 2d07ab2..d951bfe 100644 --- a/ct/huntarr.sh +++ b/ct/huntarr.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash source <(curl -fsSL https://git.bila.li/Proxmox/proxmox-ve-install-scripts/raw/branch/dev/misc/build.func) # Copyright (c) 2021-2025 community-scripts ORG -# Author: BiluliB +# Author: [YourUserName] # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # Source: [SOURCE_URL] @@ -25,15 +25,15 @@ function update_script() { check_container_storage check_container_resources - # Check for Python app with hardcoded path - if [[ ! -f /opt/huntarr/main.py ]]; then + # Check if installation is present | -f for file, -d for folder + if [[ ! -f /opt/huntarr/huntarr ]]; then msg_error "No ${APP} Installation Found!" exit fi # Crawling the new version and checking whether an update is required RELEASE=$(curl -fsSL https://api.github.com/repos/plexguide/Huntarr.io/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3)}') - if [[ "${RELEASE}" != "$(cat /opt/huntarr_version.txt 2>/dev/null)" ]] || [[ ! -f /opt/huntarr_version.txt ]]; then + if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then # Stopping Services msg_info "Stopping $APP" systemctl stop huntarr @@ -41,18 +41,20 @@ function update_script() { # Creating Backup msg_info "Creating Backup" - tar -czf "/opt/huntarr_backup_$(date +%F).tar.gz" /opt/huntarr + # Remove any existing backups + if ls /opt/${APP}_backup_*.tar.gz &>/dev/null; then + rm -f /opt/${APP}_backup_*.tar.gz + msg_info "Removed previous backup" + fi + # Create new backup + tar -czf "/opt/${APP}_backup_$(date +%F).tar.gz" /opt/huntarr msg_ok "Backup Created" - # Execute Update for Python app + # Execute Update msg_info "Updating $APP to v${RELEASE}" - curl -fsSL -o "/opt/huntarr/${RELEASE}.zip" "https://github.com/plexguide/Huntarr.io/archive/refs/tags/${RELEASE}.zip" - unzip -q -o "/opt/huntarr/${RELEASE}.zip" -d /tmp - cp -rf "/tmp/Huntarr.io-${RELEASE}"/* /opt/huntarr/ - - # Update Python dependencies - cd /opt/huntarr || exit - /opt/huntarr/venv/bin/pip install -r requirements.txt + curl -fsSL -o "/opt/huntarr/huntarr_${RELEASE}_linux_amd64.tar.gz" "https://github.com/plexguide/Huntarr.io/releases/download/${RELEASE}/huntarr_${RELEASE}_linux_amd64.tar.gz" + tar -xzf "/opt/huntarr/huntarr_${RELEASE}_linux_amd64.tar.gz" -C /opt/huntarr + chmod +x /opt/huntarr/huntarr msg_ok "Updated $APP to v${RELEASE}" # Starting Services @@ -62,12 +64,11 @@ function update_script() { # Cleaning up msg_info "Cleaning Up" - rm -f "/opt/huntarr/${RELEASE}.zip" - rm -rf "/tmp/Huntarr.io-${RELEASE}" + rm -f /opt/huntarr/huntarr_"${RELEASE}"_linux_amd64.tar.gz msg_ok "Cleanup Completed" # Last Action - echo "${RELEASE}" >/opt/huntarr_version.txt + echo "${RELEASE}" >/opt/${APP}_version.txt msg_ok "Update Successful" else msg_ok "No update required. ${APP} is already at v${RELEASE}"