#!/bin/sh
# postinst script for serialportassistant
#
# 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>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package

INSTALL_DIR=/opt/SerialPortAssistant

function_config()
{
    if [ ! -f /usr/share/applications/SerialPortAssistant.desktop ]; then
        ln -s ${INSTALL_DIR}/share/applications/SerialPortAssistant.desktop /usr/share/applications/SerialPortAssistant.desktop
    fi
    if [ ! -f /usr/share/pixmaps/SerialPortAssistant.png ]; then
        if [ ! -d /usr/share/pixmaps ]; then
            mkdir -p /usr/share/pixmaps
        fi
        ln -s ${INSTALL_DIR}/share/pixmaps/SerialPortAssistant.png /usr/share/pixmaps/SerialPortAssistant.png
    fi
    echo "${INSTALL_DIR}/lib" > /etc/ld.so.conf.d/SerialPortAssistant.conf
    echo "${INSTALL_DIR}/bin" >> /etc/ld.so.conf.d/SerialPortAssistant.conf
    export QT_VERSION_DIR=
    if [ -n "${QT_VERSION_DIR}" ]; then
        echo "/opt/qt${QT_VERSION_DIR}/lib" >> /etc/ld.so.conf.d/SerialPortAssistant.conf
    fi
    ldconfig
}

case "$1" in
    configure)
        if [ -d ${INSTALL_DIR} ]; then
            function_config
        fi
    ;;

    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
