Update sabnzbd.sh

This commit is contained in:
CanbiZ 2025-04-29 15:52:59 +02:00
parent 1d0cd6c446
commit fe76ba1709

View File

@ -28,11 +28,14 @@ function update_script() {
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
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}"
systemctl stop sabnzbd
cp -r /opt/sabnzbd /opt/sabnzbd_backup_$(date +%s)
@ -42,28 +45,22 @@ function update_script() {
cp -rf "${tmpdir}/SABnzbd-${RELEASE}/"* /opt/sabnzbd/
rm -rf "$tmpdir"
# Check if venv exists, else create with uv
if [[ ! -d /opt/sabnzbd/venv ]]; then
msg_info "Migrating SABnzbd to venv installation"
$STD python3 -m venv /opt/sabnzbd/venv
source /opt/sabnzbd/venv/bin/activate
$STD pip install --upgrade pip
if [[ -f /opt/sabnzbd/requirements.txt ]]; then
$STD pip install -r /opt/sabnzbd/requirements.txt
fi
deactivate
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 "Migrated SABnzbd to venv installation and updated Service"
msg_ok "Updated SABnzbd service to use uv venv"
fi
else
source /opt/sabnzbd/venv/bin/activate
$STD pip install --upgrade pip
$STD pip install -r /opt/sabnzbd/requirements.txt
deactivate
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
msg_ok "Updated ${APP} to ${RELEASE}"