#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2026 The Dodobian authors
#
# On a first install (preinst left a mark), dpkg's vendor becomes Dodobian, whose parent is
# Debian, unless the administrator had pointed /etc/dpkg/origins/default somewhere other than
# Debian. No package owns that link: base-files only creates it when it is missing. An upgrade
# never touches it, so an administrator who set it back to Debian keeps that.
# systemd rereads units for the greetd drop-in; greetd itself is not restarted, as that would end
# a running session.
set -eu

pending=/var/lib/dodobian-desktop/vendor-pending

case "$1" in
	configure)
		if [ -e "$pending" ]; then
			link=/etc/dpkg/origins/default
			if [ ! -e "$link" ] && [ ! -L "$link" ]; then
				ln -s dodobian "$link"
			elif [ -L "$link" ] && [ "$(readlink "$link")" = debian ]; then
				ln -sfn dodobian "$link"
			fi
			rm -f "$pending"
			rmdir "${pending%/*}" 2>/dev/null || true
		fi
		if [ -d /run/systemd/system ]; then
			systemctl daemon-reload || true
		fi
		;;
esac

#DEBHELPER#

exit 0
