#!/bin/sh -e

# Magicpoint hat keine Priorität mehr
MAGICPOINTFONTS=no

# user-de gibt's gar nicht mehr und das scheint nicht mehr nötig zu sein
#if [ ! -L /etc/language ] ; then
#    if [ ! -e /etc/language-de ] ; then
#	echo "Package user-de seems to be broken"
#    else
#        ln -s language-de /etc/language
#    fi
#fi

MSTTFONTDIR=/usr/share/fonts/truetype/msttcorefonts

## This was for fixing broken MagicPoint fonts
## I stopped using MagicPoint because of several issues
## and this did not work anyway - so just do not do this here.
if [ "$MAGICPOINTFONTS" = "yes" ] ; then
    if [ -d ${MSTTFONTDIR} ] ; then
	cd ${MSTTFONTDIR}
	ttmkfdir -o fonts.scale
	head -1 fonts.scale > fonts.dir
	tail +2 fonts.scale | tac >> fonts.dir
	cp fonts.dir fonts.scale
	if [ -d /etc/X11/fonts/TrueType ] ; then
	    # sometimes this directory does not exist - don't know exactly what to do
	    # and what this means ...
	    cd /etc/X11/fonts/TrueType
	    cp -a ${MSTTFONTDIR}/fonts.dir .
	    /usr/share/andreas-privat/mkfontalias.py
	    grep 'iso8859-1"' fonts.alias > msttcorefonts.alias
	    rm -f fonts.dir fonts.alias
	fi
	update-fonts-alias TrueType
    fi
fi

case "$1" in
    configure)
	XPLUSER=xplanet
	CLOUDSDIR=/var/lib/xplanet
	## Add user ${XPLUSER} if not existent
	TESTUSER="`getent passwd ${XPLUSER}`" || true
	if [ -z "${TESTUSER}" ] ; then
	    /usr/sbin/adduser --home /var/lib/xplanet --system "${XPLUSER}" >/dev/null
	fi
	mkdir -p "$CLOUDSDIR"
	chown "${XPLUSER}": "$CLOUDSDIR"
	chmod 775 "$CLOUDSDIR"
	mkdir -p /media
	for dir in camera mp3 ; do
	    mkdir -p /media/$dir
	done
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

## set permissions for dchroot
#chown root:sys /usr/bin/dchroot
#chmod ug+s /usr/bin/dchroot

# ungetestet
if [ "$1" = "configure" ]; then
    update-alternatives --install /usr/bin/x-terminal-emulator \
			x-terminal-emulator /usr/bin/xterm 40 \
			--slave /usr/share/man/man1/x-terminal-emulator.1.gz \
			x-terminal-emulator.1.gz /usr/share/man/man1/xterm.1.gz
fi

if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] ; then
    for alt in x-www-browser gnome-www-browser; do
	update-alternatives --install /usr/bin/$alt \
    	    $alt /usr/bin/firefox 90 \
    	    --slave /usr/share/man/man1/$alt.1.gz \
    	    $alt.1.gz /usr/share/man/man1/firefox.1.gz
    done

fi

#DEBHELPER#
