#!/bin/sh
#
# @package      hubzero-submit-condor
# @file         preinst
# @copyright    Copyright (c) 2010-2020 The Regents of the University of California.
# @license      http://opensource.org/licenses/Apache-2.0 Apache2
#
# Copyright (c) 2010-2020 The Regents of the University of California.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# HUBzero is a registered trademark of The Regents of the University of California.
#

# preinst script for hubzero-submit-condor
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
# * <new-preinst> install
# * <new-preinst> install <old-version> <new-version>
# * <new-preinst> upgrade <old-version> <new-version>
# * <old-preinst> abort-upgrade <new-version>

case "$1" in
    install)
        # Actions to perform on fresh installation
        echo "Preparing system for fresh installation..."
        getent passwd condor > /dev/null || adduser --system --group \
                                                    --home /var/condor \
                                                    --shell /bin/bash \
                                                    --disabled-password \
                                                    --comment Condor condor
        ;;

    upgrade)
        # Actions to perform when upgrading from an older version ($2)
        echo "Preparing system for upgrade from version $2..."
        ;;

    abort-upgrade)
        # Error handling if the upgrade fails mid-way
        echo "Upgrade aborted. Backing out pre-install changes..."
        ;;

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