#!/bin/sh
#
# Slack-Demon unpack v1.0
#
# Written by Ivan Beveridge <ivan@dreamtim.demon.co.uk>
#
# Copyright (C) 1995 Ivan Beveridge
# All rights reserved.
#
#
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
#
# This is part of the Slack-help package. It helps in with the configuration
# of Linux Slackware to connect to Demon Internet Ltd.
#
#
#
# TODO:
#	* Initiate running of package install scripts (once written).
#	* Modularise further
#
#


#
# Variable definition section
#
TITLE="Demon Slackware Setup"
ERROR="Error"
WARNING="Warning"
TEMP="./.Slack-Demon-tempfile"

# These are the various files to get installed
BASE="base-3.2.tar"
BIND="bind-3.1.tar"
CNEWS="cnews-3.1.tar"
INN="inn-0.62.tar"

# These are the base directory names created by the packages
# (to test for installation)
BASEDIR="base"
BINDDIR="bind"
CNEWSDIR="cnews"
INNDIR="inn"


#
# This checks that the user is ROOT user, otherwise the script is exited.
#

LoginWarn () {
if [ $LOGNAME != root ]
  then dialog --title "$TITLE" --msgbox \
	"	You must be root user to run this script.\n
This is done to enable file permissions to be set correctly." 7 64
  exit
fi
}	# LoginWarn ()


#
# This prints up a pretty banner.
#

Banner () {
dialog --infobox \
"Slackware / Demon installation package \n
                Version 3.0a\n\n\
Written by:
	John Phillips  <john@linux.demon.co.uk>
	Ivan Beveridge <ivan@dreamtim.demon.co.uk>" 9 56

sleep 3

}	# Banner ()


#
# Put up a little menu to give the user a choice.
#

Menu () {

while [ 0 ]; do		# Main loop so that menu returns after a selection.

dialog  --title "$TITLE" \
	--menu "Select what you want to do" 13 70 6 \
	"README" "Read the README file" \
	"BASE" "Unpackage PPP and SLIP package" \
	"BIND" "Unpackage the BIND package" \
	"CNEWS" "Unpackage the CNews package" \
	"INN" "Unpackage the INN package" \
	"EXIT" "" 2>$TEMP

# Test for Cancel box selected, or escape button pressed
 if [ $? = 1 -o $? = 255 ]; then
  reset
  exit
 fi


SELECTION=`cat $TEMP`

case $SELECTION in
	README)	if [ ! -e ./README ] ; then
		  dialog --title "$ERROR" --msgbox \
		  "README cannot be found" 5 40 
		  continue
		fi
		dialog --title "$TITLE" --textbox "./README" 22 78 ;;

	BASE)	if [ ! -e ./$BASE ] ; then
		  dialog --title "$ERROR" --msgbox \
		  "PPP & SLIP package unavailable for unpackaging" 5 60
		  continue
		fi
		if [ -e ./$BASEDIR ] ; then
		  dialog --title "$WARNING" \
			 --msgbox "PPP & SLIP package already installed" 5 60
		  continue
		fi
		tar xpf $BASE
		dialog --title "$TITLE" \
		       --msgbox "PPP & SLIP package installed" 5 50 ;;

	BIND)	if [ ! -e ./$BIND ] ; then
		  dialog --title "$ERROR" --msgbox \
		  "BIND package unavailable for unpackaging" 5 60
		  continue
		fi
		if [ -e ./$BINDDIR ] ; then
		  dialog --title "$WARNING" \
			 --msgbox "BIND package already installed" 5 60
		  continue
		fi
		tar xpf $BIND 
		dialog --title "$TITLE" \
		       --msgbox "BIND package installed" 5 50 ;;

	CNEWS)	if [ ! -e ./$CNEWS ] ; then
		  dialog --title "$ERROR" --msgbox \
		  "CNEWS package unavailable for unpackaging" 5 60
		  continue
		fi
		if [ -e ./$CNEWSDIR ] ; then
		  dialog --title "$WARNING" \
			 --msgbox "CNews package already installed" 5 60
		  continue
		fi
		tar xpf $CNEWS 
		dialog --title "$TITLE" \
		       --msgbox "CNews package installed" 5 50 ;;

	INN)	if [ ! -e ./$INN ] ; then
		  dialog --title "$ERROR" --msgbox \
		  "INN package unavailable for unpackaging" 5 60
		  continue
		fi
		if [ -e ./$INNDIR ] ; then
		  dialog --title "$WARNING" \
			 --msgbox "INN package already installed" 5 60
		  continue
		fi
		tar xpf $INN 
		dialog --title "$TITLE" \
		       --msgbox "INN package installed" 5 50 ;;

	EXIT)	reset
		break ;;
esac

done	# end of Menu loop

} 	# Menu ()


#
#
# This is the main part of the program
#
#

Banner
LoginWarn
Menu
if [ -e $TEMP ] ; then rm -f $TEMP ; fi