#!/bin/sh
set -e
export LC_ALL=C
#set -x
exec > /var/log/opensvc.v3.postinst.log 2>&1

case "$1" in
    configure)
        if dpkg -s opensvc 2>/dev/null | grep ^Status | grep -q "deinstall ok config-files"; then
            echo "postinst: migration from opensvc to opensvc-server"
        fi
        if [ -f /var/lib/opensvc/migration.from.opensvc.v2 ]; then
            echo "postinst: migration from opensvc confirmed (witness file)"
            rm -f /var/lib/opensvc/migration.from.opensvc.v2
	    systemctl enable --now opensvc-server
        fi
	mkdir -p /usr/share/opensvc/bin
        if [ ! -f /usr/share/opensvc/bin/om ] || [ -L /usr/share/opensvc/bin/om ]; then
            echo "Creating compatibility symlink /usr/share/opensvc/bin/om -> /usr/bin/om"
            ln -sf /usr/bin/om /usr/share/opensvc/bin/om
        fi
        ;;
    *)
        echo "postinst: script argument : $1"
        ;;
esac

#DEBHELPER#

exit 0
