#!/bin/sh

set -e


case "$1" in
	configure|reconfigure)
		if [ ! -d /etc/vlmcsd/ ]; then
			mkdir -p /etc/vlmcsd/
		fi
		if [ ! -d /var/log/vlmcsd/ ]; then
			mkdir -p /var/log/vlmcsd/
			chown -R vlmcsd:vlmcsd /var/log/vlmcsd
		fi
		if [ ! -f /etc/vlmcsd/vlmcsd.ini ]; then
			cp /usr/share/vlmcsd/vlmcsd.ini /etc/vlmcsd/
		fi
		if [ ! -f /etc/vlmcsd/vlmcsd.kmd ]; then
			cp /usr/share/vlmcsd/vlmcsd.kmd /etc/vlmcsd/
		fi
		;;
	abort-upgrade|abort-remove|abort-deconfigure)
		exit 0
		;;
	*)
		echo "postinst called with unknown argument \`$1'" >&2
		exit 0
		;;
esac

# Automatically added by dh_systemd_enable/12.1.1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
	# This will only remove masks created by d-s-h on package removal.
	deb-systemd-helper unmask 'vlmcsd.service' >/dev/null || true

	# was-enabled defaults to true, so new installations run enable.
	if deb-systemd-helper --quiet was-enabled 'vlmcsd.service'; then
		# Enables the unit on first installation, creates new
		# symlinks on upgrades if the unit file has changed.
		deb-systemd-helper enable 'vlmcsd.service' >/dev/null || true
	else
		# Update the statefile to add new symlinks (if any), which need to be
		# cleaned up on purge. Also remove old symlinks.
		deb-systemd-helper update-state 'vlmcsd.service' >/dev/null || true
	fi
fi
# End automatically added section
# Automatically added by dh_installinit/12.1.1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
	if [ -x "/etc/init.d/vlmcsd" ]; then
		update-rc.d vlmcsd defaults >/dev/null
		if [ -n "$2" ]; then
			_dh_action=restart
		else
			_dh_action=start
		fi
		invoke-rc.d vlmcsd $_dh_action || exit 1
	fi
fi
# End automatically added section


exit 0
