#!/bin/sh

case $1 in 
    start)
        echo "check for uni-klu network environment ..."
        CHECK="$(nmap -p 389 ldap-unix.uni-klu.ac.at | grep 389 | grep open)"
        if [ -z "$CHECK" ]; then
            # no uniklu environment, revert to offline configuration
            echo "deactivating uni-klu network configuration"
            files=$(dpkg -L uniklu-config)
            for f in $files; do
                F=${f%.uniklu}
                if [ "$f" != "$F" ]; then
                    if [ -f "$F.ubuntu" ]; then
                        cp -p $F.ubuntu $F
                    fi
                fi
            done
        else
            # uniklu environment, activate network settings
            echo "activating uni-klu network configuration"
            files=$(dpkg -L uniklu-config)
            for f in $files; do
                F=${f%.uniklu}
                if [ "$f" != "$F" ]; then
                    if [ -f "$F" ]; then
                        cp -p $f $F
                    fi
                fi
            done
        fi
        /etc/init.d/nscd stop
        rm -f /var/cache/nscd/*
        /etc/init.d/nscd start
        ;;
    *)
        ;;
esac
