#!/bin/sh
# postrm for velox (local test build). See packaging/README.md.
set -e

NM_MANIFEST_NAME=com.velox.host.json

real_users() {
    getent passwd | awk -F: '$3 >= 1000 && $3 < 60000 && $6 != "" {print $1":"$6}'
}

# Undoes exactly what postinst's install_per_user_manifests() did — never anything
# beyond that file. In particular this never touches a user's Velox data
# ($XDG_DATA_HOME/velox, i.e. normally ~/.local/share/velox — the task database and
# any settings) on either `remove` or `purge`: per-user, root-owned deletion across
# every account on the system is exactly the kind of destructive multi-user operation
# that deserves its own careful design and testing, not a first cut bolted onto this
# local test package. Documented as a deliberate simplification in
# packaging/README.md, not a silent gap.
remove_per_user_manifests() {
    real_users | while IFS=: read -r user home; do
        f="$home/.mozilla/native-messaging-hosts/$NM_MANIFEST_NAME"
        [ -e "$f" ] && rm -f "$f"
    done
}

case "$1" in
    remove|purge)
        remove_per_user_manifests
        ;;
esac

#DEBHELPER#

exit 0
