#!/bin/sh
# postinst script for fly-wm
#
# 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 http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
    configure)

#restore attrs after fly-syslog-monitor set it with 644, but now it is removed
if stat /var/log/syslog | grep 644 > /dev/null; then
    list=`grep /var/log /etc/rsyslog.conf | cut -f 3-7 | sed s/-//`
    for file in $list; do
      if [ -f $file ]; then chmod 640 $file; fi
    done
    list=`grep /var/log /etc/logrotate.d/* | cut -f 1 -d' ' | cut -f 2 -d':'`
    for file in $list; do
      if [ -f $file ]; then chmod 640 $file; fi
    done
fi

if ! test -L /usr/share/fly-wm/Pictures/SystemWallpapers; then
ln -s /usr/share/wallpapers /usr/share/fly-wm/Pictures/SystemWallpapers
fi

##alex: add it to have desktop for never logged users
if ! test -x /etc/skel/Desktop; then mkdir -p /etc/skel/Desktop; fi
if ! test -x /root/Desktop; then mkdir -p /root/Desktop; fi

if ! test -d /etc/xdg/autostart; then
    mkdir -p /etc/xdg/autostart
fi
    #to update user rc files
    find /usr/share/fly-wm -maxdepth 2 -name "*rc*" | xargs touch

    # register the alternatives of x-window-manager manually
    # because dh_installwm doesn't register manpage as slave yet.
    update-alternatives --install /usr/bin/x-window-manager \
        x-window-manager /usr/bin/fly-wm 70 \
        --slave /usr/share/man/man1/x-window-manager.1.gz \
        x-window-manager.1.gz /usr/share/man/man1/fly-wm.1
    update-alternatives --install /usr/bin/x-session-manager \
        x-session-manager /usr/bin/fly-wm 70 \
        --slave /usr/share/man/man1/x-session-manager.1.gz \
        x-session-manager.1.gz /usr/share/man/man1/fly-wm.1
    ;;
    *)
        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.



exit 0
