#!/bin/sh
# postinst script for penguins-eggs_9.7.8-1
#
# 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
# echo ">>> $0 $1 $2 $3 $4<<<"

pkgname="penguins-eggs"

case "$1" in
    configure)
        # Adding bash-completion Debian/Devuan/Ubuntu /etc/bash_completion.d/
        if [ -d "/etc/bash_completion.d/" ]; then
            if [ -f "/usr/lib/$pkgname/scripts/eggs.bash" ]; then
                cp /usr/lib/$pkgname/scripts/eggs.bash /etc/bash_completion.d/
            fi
        fi    

        # Adding bash-completion elementary /usr/share/bash-completion/completions/
        if [ -d "/usr/share/bash-completion/completions/" ]; then
            if [ -f "/usr/lib/$pkgname/scripts/eggs.bash" ]; then
                cp /usr/lib/$pkgname/scripts/eggs.bash /usr/share/bash-completion/completions/
            fi
        fi    

        # Adding zsh-completion for eggs
        if [ -d "/usr/share/zsh/functions/Completion/Zsh/" ]; then
            if [ -f "/usr/lib/$pkgname/scripts/_eggs" ]; then
                cp /usr/lib/$pkgname/scripts/_eggs /usr/share/zsh/functions/Completion/Zsh/
            fi
        fi

        # Install man page
        if [ -f "/usr/lib/$pkgname/manpages/doc/man/eggs.1.gz" ]; then
            install -Dm644 /usr/lib/$pkgname/manpages/doc/man/eggs.1.gz /usr/share/man/man1
        fi


        # link to adapt
        if [ -f "/usr/lib/$pkgname/addons/eggs/adapt/bin/adapt" ]; then
            install /usr/lib/$pkgname/addons/eggs/adapt/bin/adapt /usr/bin
        fi

        # link to love
        if [ -f "/usr/lib/$pkgname/scripts/love" ]; then
            install /usr/lib/$pkgname/scripts/love /usr/bin
        fi

        # link to resy
        if [ -f "/usr/lib/$pkgname/scripts/resy" ]; then
            install /usr/lib/$pkgname/scripts/resy /usr/sbin
        fi

        # revitalize mom
        if [ -f "/usr/lib/$pkgname/scripts/mom.sh" ]; then  
            chmod +x /usr/lib/$pkgname/scripts/mom.sh
        fi

        # revitalize eui
        if [ -d "/usr/lib/$pkgname/eui" ]; then  
            chmod +x /usr/lib/$pkgname/eui/eui-create-image.sh
            chmod +x /usr/lib/$pkgname/eui/eui-start.sh
            chmod 0400 /usr/lib/$pkgname/eui/eui-users
        fi


        eggs config --nointeractive
        echo "penguins-eggs was installed..." 
    ;;

    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
