From 9a1fbe8bee84edb25fb35b3347b7a41a444d6f01 Mon Sep 17 00:00:00 2001 From: Gamerboy59 Date: Tue, 10 Sep 2024 21:59:34 +0200 Subject: [PATCH] Update DEB install scripts to use systemd scriptlets --- .build/DEB/postinst | 31 +++++++++++++++++++++++-------- .build/DEB/postrm | 21 +++++++++++++-------- .build/DEB/prerm | 10 ++++------ .build/rpxy-start.sh | 2 +- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/.build/DEB/postinst b/.build/DEB/postinst index b3f180e..0ec4552 100644 --- a/.build/DEB/postinst +++ b/.build/DEB/postinst @@ -1,20 +1,35 @@ -#!/bin/bash - +#!/bin/sh set -e +# Source debconf library +. /usr/share/debconf/confmodule + # Create rpxy user if it doesn't exist -if ! id rpxy >/dev/null 2>&1; then - useradd --system --no-create-home --shell /usr/sbin/nologin rpxy +if ! getent passwd rpxy > /dev/null; then + adduser --system --group --no-create-home --shell /usr/sbin/nologin rpxy fi -# Set correct user for config directory +# Set correct ownership for config directory if [ -d /etc/rpxy ]; then chown -R rpxy:rpxy /etc/rpxy fi # Reload systemd, enable and start the service -systemctl daemon-reload -systemctl enable rpxy -systemctl start rpxy +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + deb-systemd-helper unmask rpxy.service >/dev/null || true + if deb-systemd-helper --quiet was-enabled rpxy.service; then + deb-systemd-helper enable rpxy.service >/dev/null || true + else + deb-systemd-helper update-state rpxy.service >/dev/null || true + fi + if [ -d /run/systemd/system ]; then + systemctl --system daemon-reload >/dev/null || true + if [ -n "$2" ]; then + deb-systemd-invoke try-restart rpxy.service >/dev/null || true + else + deb-systemd-invoke start rpxy.service >/dev/null || true + fi + fi +fi exit 0 diff --git a/.build/DEB/postrm b/.build/DEB/postrm index b88f939..4cfa3ea 100644 --- a/.build/DEB/postrm +++ b/.build/DEB/postrm @@ -1,17 +1,22 @@ -#!/bin/bash - +#!/bin/sh set -e -# Remove the rpxy user and configuration directory only if purging the package if [ "$1" = "purge" ]; then - if id rpxy >/dev/null 2>&1; then - userdel rpxy + # Remove the rpxy user + if getent passwd rpxy >/dev/null; then + deluser --quiet --system rpxy >/dev/null || true fi # Remove config directory - if [ -d /etc/rpxy ]; then - rm -rf /etc/rpxy - fi + rm -rf /etc/rpxy + + # Remove systemd service state + deb-systemd-helper purge rpxy.service >/dev/null || true + deb-systemd-helper unmask rpxy.service >/dev/null || true +fi + +if [ -d /run/systemd/system ]; then + systemctl --system daemon-reload >/dev/null || true fi exit 0 diff --git a/.build/DEB/prerm b/.build/DEB/prerm index d4548d6..d088bc4 100644 --- a/.build/DEB/prerm +++ b/.build/DEB/prerm @@ -1,10 +1,8 @@ -#!/bin/bash - +#!/bin/sh set -e -# Stop and disable the service before removing -systemctl stop rpxy || true -systemctl disable rpxy || true -systemctl daemon-reload +if [ -d /run/systemd/system ] && [ "$1" = remove ]; then + deb-systemd-invoke stop rpxy.service >/dev/null || true +fi exit 0 diff --git a/.build/rpxy-start.sh b/.build/rpxy-start.sh index a4158bd..97800da 100644 --- a/.build/rpxy-start.sh +++ b/.build/rpxy-start.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh set -e