PKGBUILDs/aur/sabnzbd/sabnzbd.install
2012-09-09 10:11:13 -04:00

104 lines
3.2 KiB
Text

## arg 1: the new package version
post_install() {
. /etc/conf.d/sabnzbd
# add x-nzb mimetype
xdg-mime install --mode system "${SABNZBD_DIR}/x-nzb.xml"
xdg-icon-resource install --context mimetypes --size 64 "${SABNZBD_DIR}/nzb-2.png" application-x-nzb
post_upgrade
cat << "EOM"
==> Don't forget to edit /etc/conf.d/sabnzbd or /etc/conf.d/sabnzbd_systemd!
==> Add your Session key and if necessary your username and password to ensure a proper shutdown.
==> If you want to associate .nzb-files with SABnzbd, run 'xdg-mime default sabnzbd.desktop applications/x-nzb'
EOM
}
## arg 1: the new package version
## arg 2: the old package version
pre_upgrade() {
PID="$(pgrep -f SABnzbd.py)"
if [ -f /run/daemons/sabnzbd ]; then
/etc/rc.d/sabnzbd stop # kill the daemon
fi
if [[ -d "/run/sabnzbd/" && "$(ls -A /run/sabnzbd/)" ]]; then
systemctl stop sabnzbd.service
fi
if [ -n "${PID}" ];then
kill "${PID}" # kill the daemon finaly
fi
}
## arg 1: the new package version
## arg 2: the old package version
post_upgrade() {
. /etc/conf.d/sabnzbd
if [ "${USE_SYSTEM_IDS}" == "1" ]; then
if grep -q "^sabnzbd:" /etc/group &> /dev/null; then
if grep -q "^SABNZBD_GID=" /etc/conf.d/sabnzbd &> /dev/null; then
groupmod -g "${SABNZBD_GID}" -n sabnzbd sabnzbd &> /dev/null
else
groupmod -r -n sabnzbd sabnzbd &> /dev/null
fi
else
if grep -q "^SABNZBD_GID=" /etc/conf.d/sabnzbd &> /dev/null; then
groupadd -g "${SABNZBD_GID}" sabnzbd &> /dev/null
else
groupadd -r sabnzbd &> /dev/null
fi
fi
if grep -q "^SABNZBD_AGROUP=" /etc/conf.d/sabnzbd &> /dev/null; then
SABNZBD_GS="-G ${SABNZBD_AGROUP}"
else
SABNZBD_GS=""
fi
if grep -q "^sabnzbd:" /etc/passwd 2> /dev/null; then
if grep -q "^SABNZBD_UID=" /etc/conf.d/sabnzbd &> /dev/null; then
usermod -s /sbin/nologin -c "SABnzbd user" -d "${SABNZBD_DIR}" \
-u "${SABNZBD_UID}" -g sabnzbd ${SABNZBD_GS} sabnzbd &> /dev/null
else
usermod -s /sbin/nologin -c "SABnzbd user" -d "${SABNZBD_DIR}" \
-g sabnzbd ${SABNZBD_GS} -r sabnzbd &> /dev/null
fi
else
if grep -q "^SABNZBD_UID=" /etc/conf.d/sabnzbd &> /dev/null; then
useradd -s /sbin/nologin -c "SABnzbd user" -d "${SABNZBD_DIR}" \
-u ${SABNZBD_UID} -g sabnzbd "${SABNZBD_GS}" -r sabnzbd &> /dev/null
else
useradd -s /sbin/nologin -c "SABnzbd user" -d "${SABNZBD_DIR}" \
-g sabnzbd ${SABNZBD_GS} -r sabnzbd &> /dev/null
fi
fi
fi
chown -R "${SABNZBD_USER}:${SABNZBD_GROUP}" "${SABNZBD_DIR}"
if command -v "systemd-tmpfiles" &> /dev/null; then
systemd-tmpfiles --create /usr/lib/tmpfiles.d/sabnzbd.conf
fi
}
## arg 1: the old package version
pre_remove() {
. /etc/conf.d/sabnzbd
pre_upgrade
xdg-mime uninstall --mode system "${SABNZBD_DIR}/x-nzb.xml"
xdg-icon-resource uninstall --context mimetypes --size 64 application-x-nzb
}
## arg 1: the old package version
post_remove() {
userdel sabnzbd &> /dev/null
groupdel sabnzbd &> /dev/null || /bin/true
echo "==> There may be some files left in /opt/sabnzbd."
}
# vim:set ts=2 sw=2 et: