#!/bin/sh
#
# @package      hubzero-mw2-client
# @file         preinst
# @copyright    Copyright (c) 2010-2020 The Regents of the University of California.
# @license      http://opensource.org/licenses/MIT MIT
#
# Copyright (c) 2010-2020 The Regents of the University of California.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# HUBzero is a registered trademark of The Regents of the University of California.
#

# preinst script for hubzero-mw-client
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
    install|upgrade)
		if [ ! -d /etc/mw-client ]
		then
			mkdir /etc/mw-client
			if [ -d /etc/mw-client ]
			then
				chown root:root /etc/mw-client
				chmod 0775 /etc/mw-client
			fi
		fi

		# upgrading from versions (0.9.1-1) with support files in /etc/hubzero/


		if [ ! -f /etc/mw-client/mw-client.conf ]
		then 
			if [ -f /etc/hubzero/maxwell.conf ] 
			then
				cp /etc/hubzero/maxwell.conf /etc/mw-client/mw-client.conf
			fi
		fi
		if [ ! -f /etc/mw-client/notify.key ]
		then 
			if [ -f /etc/hubzero/notify.key ] 
			then
				cp /etc/hubzero/notify.key /etc/mw-client/notify.key
			fi
		fi
		if [ ! -f /etc/mw-client/notify.key.pub ]
		then 
			if [ -f /etc/hubzero/notify.key.pub ] 
			then
				cp /etc/hubzero/notify.key.pub /etc/mw-client/notify.key.pub
			fi
		fi

		# upgrading from versions (0.8.0-1) with support files in /etc/mw/

		if [ ! -f /etc/mw-client/mw-client.conf ]
		then 
			if [ -f /etc/mw/maxwell.conf ] 
			then
				cp /etc/mw/maxwell.conf /etc/mw-client/mw-client.conf
			fi
		fi
		if [ ! -f /etc/mw-client/notify.key ]
		then 
			if [ -f /etc/mw/notify.key ] 
			then
				cp /etc/mw/notify.key /etc/mw-client/notify.key
			fi
		fi
		if [ ! -f /etc/mw-client/notify.key.pub ]
		then 
			if [ -f /etc/mw/notify.key.pub ] 
			then
				cp /etc/mw/notify.key.pub /etc/mw-client/notify.key.pub
			fi
		fi
    ;;

    abort-upgrade)
    ;;

    *)
        echo "preinst 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
