#!/bin/sh -e
# postinst script for opennx
#
# see: dh_installdeb(1)

# 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>
#        * <postinst> `abort-remove'
#        * <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|triggered)
        # USBIP only
        #if ! getent group opennx >/dev/null ; then
        #    addgroup --quiet --system opennx
        #fi
        for l in smbclient cups opensc pulse ; do
            lp=`/sbin/ldconfig -p|awk '/lib'$l'[\.-]/ {print $4}'|head -1`
            if test -n "$lp" ; then
                bn=`echo $l|sed -e 's/[-0-9]//g'`
                ln -snf $lp /usr/lib/opennx/lib/lib$l.so
            fi
        done
        # Install icons
        cd /usr/share/opennx/icons
        SIZES="16 32 48 128 256"
        ICINST="xdg-icon-resource install --noupdate --novendor --mode system"
        for sz in $SIZES ; do
            case $sz in
                scalable)
                    subdir=$sz
                    ext=svg
                    ;;
                [0-9]*)
                    subdir=${sz}x${sz}
                    ext=png
                    ;;
            esac
            for ctx in apps mimetypes ; do
                (
                    cd $subdir/$ctx
                    for f in *.$ext ; do
                        $ICINST --context $ctx --size $sz $f
                    done
                )
            done
        done
        xdg-icon-resource forceupdate
        # Install menu entries
        cd /usr/share/opennx/applnk/xdg
        xdg-desktop-menu install --mode system *.directory *.desktop
        ;;

    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
