#! /bin/sh -e

# $Id: postinst 436 2012-08-12 02:11:52Z joostvb $
# $URL: svn+ssh://svn.debian.org/svn/systraq/trunk/debian/trunk/debian/postinst $

# postinst script for systraq

# http://women.debian.org/wiki/English/MaintainerScripts

SYSTRAQUSER=debian-systraq
OLDVERSION=0.0.20050213-4 # etch ships       0.0.20050213-8
                          # lennie           0.0.20081217-1 (?)
                          # squeeze (stable) 0.0.20081217-1+squeeze2.1
                          # wheezy (testing) 0.0.20081217-3
                          # jessie (unstable)
MD5VERSION=0.0.20070301-4 # last version using md5sum by default

case "$1" in
  configure)
    if ! getent passwd $SYSTRAQUSER > /dev/null 2>&1
    then
        adduser --system --disabled-password --home /var/lib/systraq \
          --quiet --group $SYSTRAQUSER
    fi

    test -f /var/lib/systraq/.forward || echo root > /var/lib/systraq/.forward
    chown -R $SYSTRAQUSER:$SYSTRAQUSER /var/lib/systraq/.forward

    if ! test -d /var/lib/systraq/filetraq
    then
        mkdir /var/lib/systraq/filetraq
        chown $SYSTRAQUSER:$SYSTRAQUSER /var/lib/systraq/filetraq
    fi

    if ! getent group $SYSTRAQUSER > /dev/null 2>&1
    then
        cat <<EOT
You do have a debian-systraq user, but not a debian-systraq group
on your system. Your systraq user was not created by the systraq Debian package.
Please make sure your systraq user is a member of the debian-systraq group.
You can make this adjustment after this package is installed.
EOT
        addgroup --system --quiet $SYSTRAQUSER
    fi

    # deal with symlinks in /etc/systraq/systraq.d/
    LINKS=`ls /usr/share/systraq`

    # user can add links (or scripts), named AA-local
    # user can disable our links, by relinking to /bin/true
    #
    # initial install: create all our links
    # upgrade: 
    # fix broken links
    # see 10.7. Configuration files in debian-policy/policy.txt.gz

    for l in $LINKS
    do
        if test -L /etc/systraq/systraq.d/$l
        then
            if test ! -e /etc/systraq/systraq.d/$l
            then
                # broken symlink, fix it
                rm /etc/systraq/systraq.d/$l
                ln -s /usr/share/systraq/$l /etc/systraq/systraq.d/$l
            fi
        else
            ln -s /usr/share/systraq/$l /etc/systraq/systraq.d/$l
        fi
    done

    # Is systraq configured ?
    if ! test -f /etc/systraq/snapshot_pub.list
    then
        #cp /usr/share/doc/systraq/examples/systraq_is_unconfigured /etc/systraq/
        cp /etc/default/systraq.d/examples/systraq_is_unconfigured /etc/systraq/
    fi

    ;;

  failed-upgrade|abort-upgrade|abort-remove|abort-deconfigure|in-favour|removing)
    ;;

  *)
    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

