post_install() {


	USER=ventoy
	HOME_DIR=/var/lib/ventoy
	CACHE_DIR=/var/cache/ventoy

	setup_user() {

		if ! getent passwd "${USER}" >/dev/null; then
			adduser --quiet\
				--system \
				--group \
				--gecos "ventoy" \
				--home "${HOME_DIR}" \
				--no-create-home \
				${USER}
		fi
	}


	ACTION="$1"
	OLD_VERSION="$2"

	if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
		if [ -x "/etc/init.d/ventoy" ]; then
			update-rc.d ventoy-web defaults >/dev/null
			invoke-rc.d ventoy-web start || exit 1
		fi
	fi
	if [ -f /etc/systemd/system/multi-user.target.wants/ventoy-web.service ] ; then
		rm /etc/systemd/system/multi-user.target.wants/ventoy-web.service
	fi
	ln -s /usr/lib/systemd/system/ventoy-web.service /etc/systemd/system/multi-user.target.wants/ventoy-web.service

	#deb-systemd-invoke start ventoy-web
	#systemctl --root="/" enable ventoy-web.service
	#systemctl --root="/" start ventoy-web.service
	if [ -d /run/systemd/system ] ; then
		sudo systemctl enable --now ventoy-web.service
	fi
	if [ -d /run/systemd/system ] ; then
		systemctl --system daemon-reload >/dev/null || true
	fi

}
pre_remove() {
	if [ -f /etc/systemd/system/multi-user.target.wants/ventoy-web.service ] ; then
		rm /etc/systemd/system/multi-user.target.wants/ventoy-web.service
	fi
}
post_remove() {
	if [ -d /run/systemd/system ] ; then
		systemctl --system daemon-reload >/dev/null || true
	fi
	exit 0
}
post_upgrade() {
	post_install
}
