From c66fb807c8ccc63bef344d9f6613c49e7bd36508 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Tue, 29 Apr 2025 20:08:11 +0200 Subject: [PATCH] Refactor: sabnzbd (#4127) * Refactor: sabnzbd * update SABnzbd to uv * update to uv * Update sabnzbd.sh * Update sabnzbd.sh * Update sabnzbd-install.sh * Update sabnzbd.json * add .sabnzbd/ ini --- ct/sabnzbd.sh | 62 +++++++++++++++++++------------ frontend/public/json/sabnzbd.json | 10 ++--- install/sabnzbd-install.sh | 48 +++++++++++++----------- 3 files changed, 70 insertions(+), 50 deletions(-) diff --git a/ct/sabnzbd.sh b/ct/sabnzbd.sh index b67a18407..6cccda6f8 100644 --- a/ct/sabnzbd.sh +++ b/ct/sabnzbd.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) # Copyright (c) 2021-2025 tteck -# Author: tteck (tteckster) +# Author: tteck (tteckster) | Co-Author: MickLesk (CanbiZ) # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # Source: https://sabnzbd.org/ APP="SABnzbd" var_tags="${var_tags:-downloader}" var_cpu="${var_cpu:-2}" -var_ram="${var_ram:-4096}" -var_disk="${var_disk:-8}" +var_ram="${var_ram:-2048}" +var_disk="${var_disk:-5}" var_os="${var_os:-debian}" var_version="${var_version:-12}" var_unprivileged="${var_unprivileged:-1}" @@ -20,30 +20,43 @@ color catch_errors function update_script() { - header_info - check_container_storage - check_container_resources - if [[ ! -d /opt/sabnzbd ]]; then - msg_error "No ${APP} Installation Found!" - exit - fi - RELEASE=$(curl -fsSL https://api.github.com/repos/sabnzbd/sabnzbd/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') - if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then + header_info + check_container_storage + check_container_resources + + if [[ ! -d /opt/sabnzbd ]]; then + msg_error "No ${APP} Installation Found!" + exit + fi + RELEASE=$(curl -fsSL https://api.github.com/repos/sabnzbd/sabnzbd/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') + if [[ -f /opt/${APP}_version.txt ]] && [[ "${RELEASE}" == "$(cat /opt/${APP}_version.txt)" ]]; then + msg_ok "No update required. ${APP} is already at ${RELEASE}" + exit + fi msg_info "Updating $APP to ${RELEASE}" - rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED - systemctl stop sabnzbd.service - tar zxvf <(curl -fsSL https://github.com/sabnzbd/sabnzbd/releases/download/$RELEASE/SABnzbd-${RELEASE}-src.tar.gz) - cp -rf SABnzbd-${RELEASE}/* /opt/sabnzbd - rm -rf SABnzbd-${RELEASE} - cd /opt/sabnzbd - $STD python3 -m pip install -r requirements.txt + systemctl stop sabnzbd + cp -r /opt/sabnzbd /opt/sabnzbd_backup_$(date +%s) + temp_file=$(mktemp) + curl -fsSL "https://github.com/sabnzbd/sabnzbd/releases/download/${RELEASE}/SABnzbd-${RELEASE}-src.tar.gz" -o "$temp_file" + tar -xzf "$temp_file" -C /opt/sabnzbd --strip-components=1 + rm -f "$temp_file" + if [[ ! -d /opt/sabnzbd/venv ]]; then + msg_info "Migrating SABnzbd to uv virtual environment" + $STD uv venv /opt/sabnzbd/venv + msg_ok "Created uv venv at /opt/sabnzbd/venv" + + if grep -q "ExecStart=python3 SABnzbd.py" /etc/systemd/system/sabnzbd.service; then + sed -i "s|ExecStart=python3 SABnzbd.py|ExecStart=/opt/sabnzbd/venv/bin/python SABnzbd.py|" /etc/systemd/system/sabnzbd.service + systemctl daemon-reload + msg_ok "Updated SABnzbd service to use uv venv" + fi + fi + $STD uv pip install --upgrade pip --python=/opt/sabnzbd/venv/bin/python + $STD uv pip install -r /opt/sabnzbd/requirements.txt --python=/opt/sabnzbd/venv/bin/python echo "${RELEASE}" >/opt/${APP}_version.txt - systemctl start sabnzbd.service + systemctl start sabnzbd msg_ok "Updated ${APP} to ${RELEASE}" - else - msg_ok "No update required. ${APP} is already at ${RELEASE}" - fi - exit + exit } start @@ -54,3 +67,4 @@ msg_ok "Completed Successfully!\n" echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" echo -e "${INFO}${YW} Access it using the following URL:${CL}" echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:7777${CL}" + diff --git a/frontend/public/json/sabnzbd.json b/frontend/public/json/sabnzbd.json index 1ea34c4f3..27f631150 100644 --- a/frontend/public/json/sabnzbd.json +++ b/frontend/public/json/sabnzbd.json @@ -9,10 +9,10 @@ "updateable": true, "privileged": false, "interface_port": 7777, - "documentation": null, + "documentation": "https://sabnzbd.org/wiki/", "website": "https://sabnzbd.org/", - "logo": "https://raw.githubusercontent.com/sabnzbd/sabnzbd/develop/icons/logo-arrow.svg", - "config_path": "", + "logo": "https://raw.githubusercontent.com/selfhst/icons/refs/heads/main/svg/sabnzbd.svg", + "config_path": "/.sabnzbd/sabnzbd.ini", "description": "SABnzbd is a free, open-source software program for downloading binary files from Usenet newsgroups. It is designed to be easy to use, and provides a number of features to simplify the downloading process, such as automatic error detection and repair, download scheduling, and integration with other applications. SABnzbd is a binary newsreader, which means it is specifically designed for downloading binary files, such as images, music, and video, from Usenet newsgroups. With its user-friendly interface and powerful features, SABnzbd makes it easy to manage your Usenet downloads and keep your download queue organized.", "install_methods": [ { @@ -20,8 +20,8 @@ "script": "ct/sabnzbd.sh", "resources": { "cpu": 2, - "ram": 4096, - "hdd": 8, + "ram": 2048, + "hdd": 5, "os": "debian", "version": "12" } diff --git a/install/sabnzbd-install.sh b/install/sabnzbd-install.sh index d838b6a5e..49b396689 100644 --- a/install/sabnzbd-install.sh +++ b/install/sabnzbd-install.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Copyright (c) 2021-2025 tteck -# Author: tteck (tteckster) +# Author: tteck (tteckster) | Co-Author: MickLesk (CanbiZ) # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # Source: https://sabnzbd.org/ @@ -14,52 +14,58 @@ network_check update_os msg_info "Installing Dependencies" -$STD apt-get install -y par2 -$STD apt-get install -y p7zip-full +$STD apt-get install -y \ + par2 \ + p7zip-full +msg_ok "Installed Dependencies" + +msg_info "Setup uv" +setup_uv +msg_ok "Setup uv" + +msg_info "Setup Unrar" cat </etc/apt/sources.list.d/non-free.list deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware EOF $STD apt-get update $STD apt-get install -y unrar rm /etc/apt/sources.list.d/non-free.list -msg_ok "Installed Dependencies" - -msg_info "Setup Python3" -$STD apt-get install -y \ - python3-dev \ - python3-pip -$STD apt-get install -y python3-setuptools -rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED -msg_ok "Setup Python3" +msg_ok "Setup Unrar" msg_info "Installing SABnzbd" RELEASE=$(curl -fsSL https://api.github.com/repos/sabnzbd/sabnzbd/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') -$STD tar zxvf <(curl -fsSL https://github.com/sabnzbd/sabnzbd/releases/download/$RELEASE/SABnzbd-${RELEASE}-src.tar.gz) -mv SABnzbd-${RELEASE} /opt/sabnzbd -cd /opt/sabnzbd -$STD python3 -m pip install -r requirements.txt +mkdir -p /opt/sabnzbd +$STD uv venv /opt/sabnzbd/venv +temp_file=$(mktemp) +curl -fsSL "https://github.com/sabnzbd/sabnzbd/releases/download/${RELEASE}/SABnzbd-${RELEASE}-src.tar.gz" -o "$temp_file" +tar -xzf "$temp_file" -C /opt/sabnzbd --strip-components=1 +$STD uv pip install -r /opt/sabnzbd/requirements.txt --python=/opt/sabnzbd/venv/bin/python echo "${RELEASE}" >/opt/${APPLICATION}_version.txt msg_ok "Installed SABnzbd" msg_info "Creating Service" -service_path="/etc/systemd/system/sabnzbd.service" -echo "[Unit] +cat </etc/systemd/system/sabnzbd.service +[Unit] Description=SABnzbd After=network.target + [Service] WorkingDirectory=/opt/sabnzbd -ExecStart=python3 SABnzbd.py -s 0.0.0.0:7777 +ExecStart=/opt/sabnzbd/venv/bin/python SABnzbd.py -s 0.0.0.0:7777 Restart=always User=root + [Install] -WantedBy=multi-user.target" >$service_path -systemctl enable --now -q sabnzbd.service +WantedBy=multi-user.target +EOF +systemctl enable -q --now sabnzbd msg_ok "Created Service" motd_ssh customize msg_info "Cleaning up" +rm -f "$temp_file" $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned"