#!/bin/sh
# postinst script for bit-report

set -e

case "$1" in
    configure)
        a=/etc/default/bit-report
        if [ ! -e $a ] || grep -qi 'uuid=undefined' $a; then
            uuid=$(/usr/bin/perl -e 'use UUID;UUID::generate($a);UUID::unparse($a,$_);print')
            echo "Generated bit-report uuid '$uuid'"
            tmpf=$(/bin/mktemp)
            (if [ -e $a ]; then grep -vi "^uuid=" $a; fi; echo "uuid=$uuid") > $tmpf
            mv $tmpf $a; chmod 644 $a; chown root:root $a
            echo "Saved to $a"
        else
            . $a
            echo "This server is bit-report uuid '$uuid'!"
        fi 

        echo "Post install script running bit-report."
        /usr/bin/bit-report >/dev/null 2>&1
    ;;

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

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

#DEBHELPER#

exit 0
