function post_install() {
#!/bin/sh
# Arch Linux post-install / post-upgrade script (used by nfpm).
# nfpm places this script inside both post_install() and post_upgrade() hooks,
# so no $1 argument check is needed — just run unconditionally.

APP_NAME="scmclient"
CONFIG_DIR="/etc/openscm"
KEYS_DIR="/etc/openscm/keys"
LOG_DIR="/var/log/openscm"

# Create directories if missing
mkdir -p "$CONFIG_DIR" "$KEYS_DIR" "$LOG_DIR"
chmod 755 "$CONFIG_DIR"
chmod 700 "$KEYS_DIR"
chmod 755 "$LOG_DIR"

# Reload and restart service
if [ -d /run/systemd/system ]; then
    systemctl --system daemon-reload >/dev/null 2>&1 || true
    systemctl enable  "$APP_NAME.service" >/dev/null 2>&1 || true
    systemctl restart "$APP_NAME.service" >/dev/null 2>&1 || true
fi

}

function post_remove() {
#!/bin/sh
# Arch Linux post-remove script (used by nfpm).
# Keys are preserved so reinstall does not require re-registration.

CONFIG_DIR="/etc/openscm"
LOG_DIR="/var/log/openscm"

rm -f "$CONFIG_DIR/scmclient.config"
rm -rf "$LOG_DIR"

if [ -d /run/systemd/system ]; then
    systemctl daemon-reload >/dev/null 2>&1 || true
fi

}

function pre_remove() {
#!/bin/sh
# Arch Linux pre-remove script (used by nfpm).

APP_NAME="scmclient"

if [ -d /run/systemd/system ]; then
    systemctl stop    "$APP_NAME.service" >/dev/null 2>&1 || true
    systemctl disable "$APP_NAME.service" >/dev/null 2>&1 || true
fi

}

