#!/usr/bin/env bash
#
# Copyright (C) 2003 VA Linux Systems Japan, K.K.
#
# LICENSE NOTICE
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program 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 General Public License for more details.
#

# $Id: 00ultrapossum-config,v 1.8 2004/04/02 02:34:28 taru Exp $

set -e

eval `ultrapossum-config init`
trap "find $SYSCONFDIR -name '*.extra' | xargs /bin/rm -f; eval `ultrapossum-config term`" 0

ultrapossum-config get
ultrapossum-config module
ultrapossum-config variable
ultrapossum-config status

## Config set test
ultrapossum-config remove . ORGANIZATION SUFFIX
eval `ultrapossum-config get ORGANIZATION`
oORGANIZATION=$ORGANIZATION
oSUFFIX=$SUFFIX

for v in SUFFIX ORGANIZATION
do
  for val in "hello" "hello world" "hello 'quoted'"
  do
    echo -n "Setting $v to $val ... "
    ultrapossum-config set . "$v=$val"
    eval `ultrapossum-config get $v`
    if test "x${!v}" != "x$val"; then
      echo "failed to set $v to $val (${!v})" 1>&2
      exit 1
    fi
    echo "ok"
  done
done


## Config remove test
echo -n "Removing ORGANIZATION, SUFFIX... "
ultrapossum-config remove . ORGANIZATION SUFFIX
eval `ultrapossum-config get ORGANIZATION SUFFIX`
if test "x$ORGANIZATION" != "x$oORGANIZATION"; then
  echo "failed to remove ORGANIZATION" 1>&2
  exit 1
fi
if test "x$SUFFIX" != "x$oSUFFIX"; then
  echo "failed to remove SUFFIX" 1>&2
  exit 1
fi
echo "ok"

## EXTRACONFSUFFIX test
for f in $SYSCONFDIR/ultrapossum.cf $SYSCONFDIR/secret.cf
do
  echo -n "Checking extra configuration for `basename $f`... "
  echo "SUFFIX=extrasuffix" > $f.extra
  eval `EXTRACONFSUFFIX=.extra ultrapossum-config get SUFFIX`
  if test "x$SUFFIX" != "xextrasuffix"; then
    echo "failed"
    exit 1
  fi
  echo "ok"
  /bin/rm -f $f.extra
done

