#!/bin/sh -e
##**************************************************************
##
## Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
## 
## 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.
##
##**************************************************************


CONFIGFILE=/etc/condor/condor_config

# Source debconf library
. /usr/share/debconf/confmodule
db_title 'Condor configuration'
db_version 2.0
db_capb backup

# read some existing config values
if [ -e $CONFIGFILE ]; then
	CM=`grep -e "^[ \t]*CONDOR_HOST" $CONFIGFILE |cut -d"=" -f2|tr -d " "`
	db_set condor/centralmanager $CM || true 
	ADMIN=`grep -e "^[ \t]*CONDOR_ADMIN" $CONFIGFILE |cut -d"=" -f2|tr -d " "`
	db_set condor/admin $ADMIN || true 
	UIDD=`grep -e "^[ \t]*UID_DOMAIN" $CONFIGFILE |cut -d"=" -f2|tr -d " "`
	db_set condor/uiddomain $UIDD || true 
	FSD=`grep -e "^[ \t]*FILESYSTEM_DOMAIN" $CONFIGFILE |cut -d"=" -f2|tr -d " "`
	db_set condor/filesystemdomain $FSD || true 
	RESERVEDMEM=`grep -e "^[ \t]*RESERVED_MEMORY" $CONFIGFILE |cut -d"=" -f2|tr -d " "`
	db_set condor/reservedmemory $RESERVEDMEM || true 
	HOSTALLOWWRITE=`grep -e "^[ \t]*HOSTALLOW_WRITE" $CONFIGFILE |cut -d"=" -f2|tr -d " "`
	db_set condor/hostallowmrite $HOSTALLOWWRITE || true 
fi

# start state machine
STATE=1
while [ "$STATE" != 0 -a "$STATE" != 8 ]; do
    case "$STATE" in
    1)
	db_input medium condor/personal || true
    ;;
    2)
	if [ "$ISPERSONAL" = "false" ]; then
		db_input medium condor/daemons || true
	fi
    ;;
    3)
	if [ "$ISPERSONAL" = "false" ]; then
		db_input medium condor/centralmanager || true
	fi
    ;;
    4)
	db_input medium condor/admin || true
    ;;
    5)
	if [ "$ISPERSONAL" = "false" ]; then
		db_input medium condor/uiddomain || true
	fi
    ;;
    6)
	if [ "$ISPERSONAL" = "false" ]; then
		db_input medium condor/filesystemdomain || true
	fi
    ;;
    7)
	if [ "$ISPERSONAL" = "false" ]; then
		db_input medium condor/hostallowwrite || true
	fi
    ;;
    8)
	db_input low condor/reservedmemory || true    
    esac

    if db_go; then
	if [ $STATE -eq 1 ]; then
		db_get condor/personal
		ISPERSONAL=$RET
	fi
	STATE=$(($STATE + 1))
    else
	STATE=$(($STATE - 1))
    fi
done
db_stop




