#!/bin/sh
# postinst script for da682c-base-system
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

MOD_FILE="/etc/modules"
case "$1" in
	configure)
	if ! grep -wq "i2c-dev" $MOD_FILE ;\
		then echo "i2c-dev" >> $MOD_FILE; fi
	if ! grep -wq "misc-moxa-da682c" $MOD_FILE ;\
		then echo "misc-moxa-da682c" >> $MOD_FILE; fi
	if ! grep -wq "hid-ft260" $MOD_FILE ;\
		then echo "hid-ft260" >> $MOD_FILE; fi
	if ! grep -wq "gpio-pca953x" $MOD_FILE ;\
		then echo "gpio-pca953x" >> $MOD_FILE; fi
	if ! grep -wq "it8786_wdt" $MOD_FILE;\
		 then echo "it8786_wdt" >> $MOD_FILE; fi
	if ! grep -wq "it87" $MOD_FILE;\
		 then echo "it87" >> $MOD_FILE; fi

	# fix failed to set xfermode (err_mask=0x40) error
	sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="quiet libata.force=noncq"/g' /etc/default/grub
	update-grub

	;;

	abort-upgrade|abort-remove|abort-deconfigure)
	;;

	*)
	echo "postinst called with unknown argument \`$1'" >&2
	exit 1
	;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

# Automatically added by dh_systemd_enable
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask da682c_platform_init.service >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled da682c_platform_init.service; then
	# Enables the unit on first installation, creates new
	# symlinks on upgrades if the unit file has changed.
	deb-systemd-helper enable da682c_platform_init.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 da682c_platform_init.service >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_systemd_start
if [ -d /run/systemd/system ]; then
	systemctl --system daemon-reload >/dev/null || true
	if [ -n "$2" ]; then
		_dh_action=try-restart
	else
		_dh_action=start
	fi
	deb-systemd-invoke $_dh_action da682c_platform_init.service >/dev/null || true
fi
# End automatically added section


exit 0
