#!/bin/bash

set -e

#
# Make sure this file gets installed with the correct permissions
#
if ( ! dpkg-statoverride --list /etc/sudoers.d/sympl > /dev/null ) ; then
  dpkg-statoverride --add root root 0440 /etc/sudoers.d/sympl
fi

case "$1" in
    install)
      # If theres a /etc/symbiosis directory, move everything to /etc/sympl
      if [ -d /etc/symbiosis ]; then
        if [ "x$( readlink /etc/symbiosis )" == "x/etc/sympl" ]; then
          echo "I: /etc/symbiosis already symlinked to /etc/sympl"
        elif [ "x$( readlink /etc/symbiosis )" == "x"]; then
          # Definatelty a directory and not an odd symlink
          echo "I: Moving /etc/symbiosis to /etc/sympl"
          mkdir -p /etc/sympl
          mv /etc/symbiosis/* /etc/sympl/
          rmdir /etc/symbiosis
          ln -s /etc/sympl /etc/symbiosis
        fi
      else
        # If not, create a symlink for compatability
        echo "I: Created /etc/symbiosis symlink for compatability"
        mkdir -p /etc/sympl
        ln -s /etc/sympl /etc/symbiosis
      fi
    ;;

    upgrade)
      # do nothing
    ;;

    abort-upgrade)
    ;;

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

#DEBHELPER#

exit 0
