#!/bin/sh

set -e

case "$1" in
    install|upgrade)
        # If systemd getty@.service (serial-getty@.service) is running, we can have some conflicts.
        # So stop and disable them for ttyS0 and ttyS1.
        # Yeah, on each install|upgrade.
        if [ -e /bin/systemctl -a -d /usr/lib/systemd ]; then
            for g in getty serial-getty ; do
                for t in ttyS0 ttyS1 ; do
                    /bin/systemctl stop ${g}@${t}.service
                    if [ -e /etc/systemd/system/getty.target.wants/${g}@${t}.service ]; then
                        /bin/systemctl disable ${g}@${t}.service
                    fi
                done
            done
        fi
    ;;

    abort-upgrade)
    ;;

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

exit 0
