#!/bin/bash
#
# postinst script for linuxmuster-client
#
# Thomas Schmitt <schmitt@lmz-bw.de>
# 18.12.2009
#
# 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>
#        * <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
#

case "$1" in

    configure)

        # determine client ip
        clientip=`ifconfig  | grep 255.240.0.0 | awk '{print $2}' | awk -F: '{print $2}'`
        clientname=`host $clientip | awk '{print $5}' | cut -d. -f1`
        # determine servername
        fqsn=`host -v $clientip | grep -A1 AUTHORITY | grep in.addr | awk '{print $5}'`
        # determine serverip
        serverip=`host $fqsn | awk '{print $4}'`


        if [ -z "$serverip" ]; then
            echo "Cannot get the ip for the cifs server! Skipping configuration!"
            exit 0
        fi


        # patching configuration files
        echo "Patching configuration ..."
        cd /var/lib/linuxmuster-client-shares/templates
            find -type f | xargs -i -t sh -c \
            "sed -e 's%@@serverip@@%${serverip}%g' {} > /{}" 2> /dev/null 1> /dev/null
        cd ../../
        ;;

    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.

#DEBHELPER#


exit 0

