#!/bin/sh
#
# @package      hubzero-cms
# @file         postinst
# @author       Nicholas J. Kisseberth <nkissebe@purdue.edu>
# @copyright    Copyright (c) 2010-2011 Purdue University. All rights reserved.
# @license      http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
#
# Copyright (c) 2010-2011 Purdue University
# All rights reserved.
#
# This file is part of: The HUBzero(R) Platform for Scientific Collaboration
#
# The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
# software: you can redistribute it and/or modify it under the terms of
# the GNU Lesser General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# HUBzero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# HUBzero is a registered trademark of Purdue University.
#
# postinst script for hubzero-cms
#
# 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

USER="www-data"
CHOWN="/bin/chown"
CHMOD="/bin/chmod"
#USERDEL="/usr/sbin/userdel"
ADDUSER="/usr/sbin/adduser"
ID="/usr/bin/id"
GROUPMOD="/usr/sbin/groupmod"
#GROUPDEL="/usr/sbin/groupdel"

make_dir() {
	if [ $# != 4 ]; then 
           echo "Invalid number of parameters to make_dir(): $@"
           return 1
        fi

        if ! test -d $1; then
            rm -rf $1;
            mkdir $1
        fi
        $CHOWN -R $2:$3 $1
	$CHMOD $4 $1
}

make_file() {
	if [ $# != 4 ]; then 
           echo "Invalid number of parameters to make_file(): $@"
           return 1
        fi

        if ! test -f $1; then
            rm -rf $1;
            touch $1
        fi
        $CHOWN $2:$3 $1
	$CHMOD $4 $1
}


case "$1" in
    configure)

        make_dir  "/var/log/hubzero" "root" "www-data" "0775"
        make_dir  "/var/log/hubzero/daily" "root" "www-data" "0770"
        make_dir  "/var/log/hubzero/daily/imported" "root" "www-data" "0770"

    ;;

    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


