#!/bin/sh
# 
# Tested on Slackware 3.0, should work on 7.0 but not tested - reports welcome.
#
# Slackware 2.x (and presumably earlier versions too) used /var/adm as its admin
# directory rather than /var/log. If you're even more stone-age than me and
# you're still using Slack 2, you will need to set and export the variable
# ADMIN_DIR or alter this script. See the manual pages. -- SDK, 21.1.2000 
#
# Another change for this Slackware 3.0-ready version is that the scripts
# now check that a few necessary utilities are available before proceeding IF we
# are running off the boot disk. -- SDK, 28.12.95

APPLICATION="`basename "$0"`"
if [ "$APPLICATION" = "morepkgtools" ] ; then
	echo "Call as listcustompkgs, mkpkg, packagetools, pkgheader,
viewpackages, or viewscripts." 1>&2
	exit 1
fi

# packagetools version 1.3:
if echo $* | grep -wq "\-\-version" ; then
	{ [ "$APPLICATION" = "mkpkg" ] && echo "mkpkg version 2.3" 1>&2 ; } || echo "$APPLICATION version 1.3" 1>&2
	exit 0
fi

if echo $* | grep -wq "\-\-copyright" ; then
	cat <<EOF 1>&2
`sh "$0" --version`
Author: Stephen Kennedy (G0LRI), Gloucestershire, England.
<steve@sdk-software.com>, http://www.sdk-software.com/
Copyright (C) 1995-2000, S D K Software

All rights reserved.

Distribution and use of this script is permitted provided that the
following conditions are met:

 Distributions of this script must retain the above copyright
 notice, this list of conditions and the disclaimer below.
 If the script is modified it may be distributed provided this copyright
 notice is not removed and provided any changes you make are clearly marked.
 If the script is changed in any substantial way it should be distributed
 under a different name BUT with this copyright notice intact.
 Extracts of the script may be used in your work provided you include my
 copyright notice, list of conditions and disclaimer. The latter two may be
 omitted if your own conditions and disclaimer are substantially the same.

I also request, but do not insist, that the script is distributed together
with its manpage or, ideally, in its Slackware Package form as released by
me and that you send any suggested changes to me for inclusion in the
"official" version. I want people to use and improve this script, and changes
are best propogated by addition to the "official" version, that's all.

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.

Note: This is intended to be free software as currently defined,
available to all for use and distribution as they see fit, any
limitations herein are only to protect me from liability and to give me
proper credit as author.


Extracts from:
----------------------------------------------------------------------------
mkpkg script (package comprises mkpkg and pkginstall scripts)
version 1.0

Author : A. Davison
Copyright (C) 1994, Esonque Systems

This file may be distributed freely AS LONG AS this copyright message
remains in the distributed/derivative file.


<davison@cs.monash.edu.au>
----------------------------------------------------------------------------
pkgtool v2.2.0, makepkg v1.0, pkgtool.tty v5.0.0

Copyright 1993, 1994, 1998 Patrick Volkerding, Moorhead, Minnesota USA
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.
 [The disclaimer is *exactly* the same as the one above (the paragraph in
 block capitals]

<volkerdi@slackware.com>
----------------------------------------------------------------------------
EOF
	exit 0
fi

# First deal with scenarios which will result in a hasty exit, then those with
# limited options

# the interactive programs don't take piped stdin
if [ ! "$APPLICATION" = "pkgheader" -a ! -t 0 ] ; then
	echo "Sorry, $APPLICATION cannot read from piped stdin" 1>&2
	exit 1
fi


if [ "$APPLICATION" = "mkpkg" ] ; then
	if [ ! -d /usr/sbin ] || [ "$TARGET_DIR" -a "`echo "$TARGET_DIR" | tr -s /`" != "/" ] ; then
		echo "Mkpkg cannot be used from the boot disk, sorry."
		exit 2
	fi
	TARGET_DIR=/
else
# based on pkgtool 2.2.0 by Patrick Volkerding (see copyright notice above):
	if [ ! -d /usr/sbin ] ; then # we must be on the bootdisk
# if TARGET_DIR is already set we hope the user knows what (s)he is doing
		TARGET_DIR=${TARGET_DIR:=/mnt}
		if mount | fgrep "on /mnt" 1> /dev/null 2>&1 ; then # good
			PATH="$PATH:/mnt/usr/local/sbin"

# check that the root disk supports a couple of key utils:
			find / -maxdepth 1 >/dev/null 2>&1 || { echo "Bah. You don't have a working 'find' utility. Install one, or try the Slackware rescue root disk, and try again" ; exit 2; }
			which grep >/dev/null 2>&1 || { echo "Bah. You don't have a working 'grep' utility. Install one, or try the Slackware rescue root disk, and try again" ; exit 2; }
			which sed >/dev/null 2>&1 || { echo "Bah. You don't have a working 'sed' utility. Install one, or try the Slackware rescue root disk, and try again" ; exit 2; }

		else # bad
			cat <<EOF 1>&2


You can't run $APPLICATION from the rootdisk until you've mounted
your Linux partitions beneath /mnt. Here are some examples of this:

If your root partition is /dev/hda1, and is using ext2fs, you would type:
mount /dev/hda1 /mnt -t ext2

Then, supposing your /usr partition is /dev/hda2, you must do this:
mount /dev/hda2 /mnt/usr -t ext2

Please mount your Linux partitions and then run $APPLICATION again.

EOF
			exit
		fi
	else
		TARGET_DIR=${TARGET_DIR:=/}
	fi
fi

TMP=${TMP:="$TARGET_DIR/var/log/setup/tmp2"} # the "2" to make it totally impossible that we step on pkgtool's toes
TMP="`echo "$TMP/" | tr -s /`"

# Patch possible /tmp security holes
if [ ! -d "$TMP" ]; then # make a secure temp directory:
	rm -rf "$TMP" >/dev/null 2>&1
	mkdir -p "$TMP"
	chmod 700 "$TMP"
# end of pkgtool borrowing
else # is a directory, if we inherited an environment variable and the user still wants to use /tmp,
     # it's not very sociable to chmod it to 700 or delete files. We'll add a directory, and warn
     # about this in manpage
	if [ "$TMP" = "`echo "$TARGET_DIR/tmp/" | tr -s /`" ] ; then
		TMP="`echo $TMP/packagetools.tmp | tr -s /`"
		if [ ! -d "$TMP" ]; then rm -rf "$TMP" >/dev/null 2>&1 ; fi
		mkdir -p "$TMP"
	fi
	
	chmod 700 "$TMP"
fi

# check TMP:
if [ ! -d "$TMP" ] ; then # in view of the patch, we're not being so kind as we used to be in finding
# somewhere to store our files. If there's no temp dir, we don't try to find one, we exit.
	echo "\"$TMP\" is NOT a directory. I need to have somewhere to store my working files, sorry\!" 1>&2
	logger -t "$APPLICATION[$$]" "\"$TMP\" - no such directory"
	exit 1
fi

ADM_DIR=${ADM_DIR:="`echo "$TARGET_DIR/var/log" | tr -s /`"}
PACKAGES=${PACKAGES:="`echo "$ADM_DIR/packages" | tr -s /`"}
SCRIPTS=${SCRIPTS:="`echo "$ADM_DIR/scripts" | tr -s /`"}
OLDIFS="$IFS"
TEST="$TARGET_DIR/usr/bin/test"


if echo $* | grep -wq "\-\-html" ; then
	if [ "${BROWSER}" = "" ] ; then # variable not set, search for popular browsers
		if which netscape >/dev/null 2>&1 ; then
			BROWSER="netscape" #BROWSER=${BROWSER:=netscape}
		elif which Netscape >/dev/null 2>&1 ; then
			BROWSER="Netscape"
		elif which Mosaic >/dev/null 2>&1 ; then
			BROWSER="Mosaic"
		elif which mosaic >/dev/null 2>&1 ; then
			BROWSER="mosaic"
		elif which lynx >/dev/null 2>&1 ; then
			BROWSER="lynx"
		else
			BROWSER="cat" # now defaults to cat
		fi
	fi
	HTML=1
	HTMLHEADER="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
<HTML>
<HEAD>"
	
	# Jan 2000 I've renamed my simple man2html cgi because of an illustrious cousin with the same
	# name, but for now I'm leaving this as is - the inline function is most likely to be the one
	# caught anyway...
	which man2html >/dev/null 2>&1 || man2html() {
		cat <<EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE><A NAME="top">Man-cgi by Stephen Kennedy</A></TITLE>
</HEAD>
<BODY>
<H1>Manual page for $1</H1>
<PRE>
`man  "$1" 2>/dev/null | colcrt -`
<P>
<HR>
<P><A HREF="#top">Top</A>
<BR>Click on <B>Back</B> to return to the previous screen.
</BODY>
</HTML>
EOF
	}

	hyper_activities() {
		echo "<A HREF=\"file:$TMP/$$.man.html\">manual page for $APPLICATION</A>" >>"$TMP/$$.html"
		man2html "$APPLICATION" > "$TMP/$$.man.html"
		cat <<EOF >>"$TMP/$$.html"
<P><HR><P>
<B>$APPLICATION</B> is part of the <B>morepkgtools</B> package.
Its home site is <A HREF="http://www.sdk-software.com/">www.sdk-software.com</A>.
<P><HR>
</BODY>
</HTML>
EOF
		$BROWSER "$TMP/$$.html"
		rm -f "$TMP"/$$*html 2>/dev/null
	}
fi


# now deal with help requests
if echo $* | grep -wq "\-\-help" ; then
	case "$APPLICATION" in

		listcustompkgs) warnings() {
			if [ ! -d "$PACKAGES" -o ! -d "$SCRIPTS" -o ! -d "$ADM_DIR" ] ; then
				cat <<EOF


WARNING!
EOF
				[ ! -d "$PACKAGES" ] && echo "The PACKAGES variable is set to \"$PACKAGES\", which is not a directory"!
				[ ! -d "$SCRIPTS" ] && echo "The SCRIPTS variable is set to \"$SCRIPTS\", which is not a directory"!
				[ ! -d "$ADM_DIR" ] && echo "The ADM_DIR variable is set to \"$ADM_DIR\", which is not a directory"!
				cat <<EOF

Maybe you are using an old version of Slackware? If you are, type
'export ADM_DIR=/var/adm ; unset PACKAGES SCRIPTS' and try running
$APPLICATION again.
EOF
			fi
		}

		if [ $HTML ] ; then
			cat <<EOF >"$TMP/$$.html"
${HTMLHEADER}
<TITLE>Listcustompkgs (HTML) by Stephen Kennedy</TITLE>
</HEAD>
<BODY>
<H2>Listcustompkgs: list "custom" packages installed on your system</H2>

<PRE>
Options
--copyright
--help
--html			View in your favourite Web browser
--textonly
--version
--viewscripts,-s	View installation scripts

`warnings`
</PRE>
EOF
			hyper_activities
			exit 0

		else
			cat <<EOF
`sh "$0" --version 2>&1`: list "custom" packages installed on your system

Options
--copyright
--help
--html			View in your favourite Web browser
--textonly
--version
--viewscripts,-s	View installation scripts
EOF
			warnings
			exit 0
		fi ;;

		viewscripts|viewpackages) echo "Usage: $APPLICATION [--html] [--removed,-r] [--copyright] [--version]"
		exit 0 ;;

		packagetools) echo "Usage: packagetools [--textonly] [--copyright] [--version]"
		exit 0 ;;

# all other basenames should have exited
		pkgheader|mkpkg) warnings() {
			if [ $INSANE_P ] || [ ! -d "$SCRIPTS" -o ! -d "$ADM_DIR" ] ; then
				cat <<EOF


WARNING!
EOF
				[ $INSANE_P ] && echo "The PACKAGES variable is set to \"$INSANE_P\", which is not a directory"!
				[ ! -d "$SCRIPTS" ] && echo "The SCRIPTS variable is set to \"$SCRIPTS\", which is not a directory"!
				[ ! -d "$ADM_DIR" ] && echo "The ADM_DIR variable is set to \"$ADM_DIR\", which is not a directory"!
				cat <<EOF

Maybe you are using an old version of Slackware? If you are, type
'export ADM_DIR=/var/adm ; unset PACKAGES SCRIPTS' and try running
$APPLICATION again.
EOF
			fi
		}

		if [ ! -d "$PACKAGES" ] ; then
			INSANE_P="$PACKAGES"
			PACKAGES="the Slackware packages directory"
		fi

		echo
		if [ "$APPLICATION" = "pkgheader" ] ; then
			echo "`sh "$0" --version 2>&1`: Adds Slackware-compatible headers to a list file"
		else
			echo "`sh "$0" --version 2>&1`: Create a Slackware pkgtool style description file for any
\"package\" which you would normally install using \"make install\""
		fi
		cat <<EOF

Basic usage: $APPLICATION [options] package-name ...

Options:
--copyright
--desc,-D DESCRIPTION		Enter package DESCRIPTION
--descfile,-F FILE		Package description is in FILE
$(if [ "$APPLICATION" = "pkgheader" ] ; then echo "--dir,-d DIRECTORY		Package contents file is in DIRECTORY" ; else echo "--exit,-e			Exit if make reports an error, otherwise prompt
				user" ; fi)
--help
--quiet				Suppress information-only messages
--textonly
--version
--zdd,-z			Compress any document files in the package

EOF
		if [ "$APPLICATION" = "pkgheader" ] ; then echo "This script takes as its input custom package names and, for each package,
creates a Slackware pkgtool-compliant package description file in
$PACKAGES. See the manpage, pkgheader(8), for more information.
"
		fi
		warnings
		exit 0 ;;

		*) echo "hmm... who are you? are we here??"
		exit 3 ;;

	esac
fi
#


unset a temp DESCFILE TEXTONLY check

# before going any further we need to know whether we can use ncurses or not
if [ ! -t 0 ] || echo $* | grep -wq "\-\-textonly" || echo $* | grep -wq "\-\-quiet"
then
	TEXTONLY=1
# If no `dialog` switch to TEXTONLY:
elif [ `which dialog >/dev/null 2>&1 ; echo $?` != 0 ] ; then
	if [ "$APPLICATION" = "packagetools" ] ; then
		echo "\`dialog\` not found - exiting" 1>&2
		exit 2
	else
		echo "\`dialog\` not found - switching to \"--textonly\" mode" 1>&2
		TEXTONLY=1
	fi
fi

is_scripts_sane() {
	if [ ! -d "$SCRIPTS" ] ; then
		cat <<EOF 1>&2
The SCRIPTS variable is set to "$SCRIPTS", and that is NOT a directory!!

Maybe you are using an old version of Slackware? If you are, type
'export ADM_DIR=/var/adm ; unset PACKAGES SCRIPTS' and try running
$APPLICATION again.

If you're still stuck read the manpage or ask a Unix wizard to help you :-).
EOF
		logger -t "$APPLICATION[$$]" "\"$SCRIPTS\" - no such directory"
		exit 1
	fi
}

is_packages_sane() {
	if [ ! -d "$PACKAGES" ] ; then
		cat <<EOF 1>&2
The PACKAGES variable is set to "$PACKAGES", and that is NOT a directory!!

Maybe you are using an old version of Slackware? If you are, type
'export ADM_DIR=/var/adm ; unset PACKAGES SCRIPTS' and try running
$APPLICATION again.

If you're still stuck read the manpage or ask a Unix wizard to help you :-).
EOF
		logger -t "$APPLICATION[$$]" "\"$PACKAGES\" - no such directory"
		exit 1
	fi
}

# if ls produces colour output its a killer
if /bin/ls --no-colour / >/dev/null 2>&1 ; then
	ls() {
		/bin/ls --no-colour "$@"
	}
else
	ls() {
		/bin/ls "$@"
	}
fi


# Next we deal with our listcustompkgs and similar customers
if [ "$APPLICATION" = "listcustompkgs" -o "$APPLICATION" = "viewscripts" -o "$APPLICATION" = "viewpackages" ]
then

	is_qth_empty() {
# if the directory is empty we bomb out (otherwise view_with_dialog freezes up)
		find "$QTH" -xtype f -maxdepth 1 >"$TMP/tmp.$$"
		if [ ! -s "$TMP/tmp.$$" ] ; then
			if [ $HTML ] ; then
				printf "${HTMLHEADER}
<TITLE>$APPLICATION (HTML) by Stephen Kennedy</TITLE>
</HEAD>
<BODY>
<H1>Nothing to do</H1>There are no files in \"$QTH\".<P> Perhaps you would like to read the " >"$TMP/$$.html"
				hyper_activities
			else
				dialog --title "$APPLICATION" --msgbox "Nothing to do! There are no files in \"$QTH\"." 5 70
			fi
			rm -f "$TMP/tmp.$$" 2>/dev/null
# this might or might not be an error, we'll exit 2
			exit 2
		fi
		rm -f "$TMP/tmp.$$" 2>/dev/null
	}

	look_for_custom_packages() {
		IFS='
'
		local ACDC Bon=0
		rm -f "$TMP/grep.$$" 2>/dev/null
		for ACDC in `grep -il "disk\*" "$PACKAGES"/* 2>/dev/null ; IFS="$OLDIFS"` ; do
			Bon=1
			echo `basename "$ACDC"` >>"$TMP/grep.$$"
		done
		if [ $Bon = 0 ] ; then
			if [ $HTML ] ; then
				printf "<TITLE>$APPLICATION (HTML) by Stephen Kennedy</TITLE><H1>Nothing to do</H1>I can't find any custom packages.<P>" >"$TMP/$$.html"
				hyper_activities
			else
				dialog --title "$APPLICATION" --msgbox "Nothing to do! I can't find any custom packages." 6 70
			fi
			exit 2
		fi
	}

	view_with_dialog() {
# taken (with changes) from pkgtool 2.2.0 by P Volkerding (see copyright
# notice above):
		is_qth_empty
		if [ "$APPLICATION" = "viewscripts" ] ; then
			dialog --title "SCANNING" --infobox "Please wait while viewscripts scans your system for package installation scripts and prepares a list for you. This will take 1.`date +"%S"`E+`date +"%M"` BogoMipSeconds." 8 40
			echo 'dialog --menu "Please select the script you wish to view." 15 55 8 \' > "$TMP/viewscr"
			ls "$QTH" | sed -e 's/.*/"&" "" \\/' >> "$TMP/viewscr"
		elif [ "$APPLICATION" = "viewpackages" ] ; then
			dialog --title "SCANNING" --infobox "Please wait while viewpackages scans your system for package description files and prepares a list for you. This will take 1.`date +"%S"`E+`date +"%M"` BogoMipSeconds." 8 40
			echo 'dialog --menu "Please select the package you wish to view." 15 55 8 \' > "$TMP/viewscr"
			ls "$QTH" | sed -e 's/.*/"&" "" \\/' >> "$TMP/viewscr"
		else
			dialog --title "SCANNING" --infobox "Please wait while listcustompkgs scans your system to determine which custom packages you have installed and prepares a list for you. This will take 1.`date +"%S"`E+`date +"%M"` BogoMipSeconds." 8 40
			echo 'dialog --menu "Please select the package you wish to view." 15 55 8 \' > "$TMP/viewscr"
			if [ $listscript ] ; then
				Listscript
				if [ ! "$check" ] ; then
					dialog --title "liscustompkgs -viewscripts" --msgbox "Nothing to do! There are no script files for custom packages. I would have expected to find at least a script for morepkgtools, so maybe something went wrong." 7 70
					rm -f "$TMP/viewscr" 2>/dev/null
					exit 2
				fi
				cat "$TMP/Listscript.$$" | sed -e 's/.*/"&" "" \\/' >> "$TMP/viewscr"
				rm -f "$TMP/Listscript.$$" 2>/dev/null
			else
				look_for_custom_packages
				cat "$TMP/grep.$$" | sed -e 's/.*/"&" "" \\/' >> "$TMP/viewscr"
				rm -f "$TMP/grep.$$" 2>/dev/null
			fi
		fi
		echo "2> "$TMP/return"" >> "$TMP/viewscr"

		while [ 0 ] ; do
			. "$TMP/viewscr"
			if [ ! "`cat "$TMP"/return`" = "" ]; then
				dialog --title "$TEXT: `cat "$TMP"/return`" --textbox "$QTH/`cat "$TMP/return"`" 22 74 2> /dev/null
			else # tidy up and leave
				rm -f "$TMP/return" "$TMP/viewscr"
				chmod 755 /
				chmod 1777 "$TMP"
				exit 0
			fi
		done
	}
# end of pkgtool borrowing

	Listscript() {
		look_for_custom_packages
		rm -f "$TMP/Listscript.$$" 2>/dev/null
		IFS='
'
		for g in `cat "$TMP/grep.$$" ; IFS="$OLDIFS"`
		do
			if "$TEST" -e "$SCRIPTS/$g" ; then
				check=1
				echo $g >>"$TMP/Listscript.$$"
			fi
		done
		rm -f "$TMP/grep.$$" 2>/dev/null
	}


# viewscripts takes only "--html" or "--removed"
	if [ "$APPLICATION" = "viewscripts" ] ; then

		if echo $* | grep -qE '\-\-removed\>|\-r\>' ; then
			REMOVED_SCRIPTS=${REMOVED_SCRIPTS:="$ADM_DIR/removed_scripts"}
			if [ ! -d "$REMOVED_SCRIPTS" ] ; then
				echo "The variable \$REMOVED_SCRIPTS is set to \"$REMOVED_SCRIPTS\" which is NOT a directory."
				exit 1
			fi
			QTH="$REMOVED_SCRIPTS"
		else
			is_scripts_sane
			QTH="$SCRIPTS"
		fi
		is_qth_empty
	
		if [ $HTML ] ; then
			cat <<EOF >"$TMP/$$.html"
${HTMLHEADER}
<TITLE>Viewscripts (HTML) by Stephen Kennedy</TITLE>
</HEAD>
<BODY>
<H2>Slackware Installation Scripts at `hostname`</H2>
To view a script click on the hyperlink.<P>
<UL>
EOF
			for z in "$QTH"/*
			do
				echo "<LI><A HREF=\"file:$z\">`basename "$z"`</A>" >>"$TMP/$$.html"
			done
			echo "</UL>" >>"$TMP"/$$.html
			hyper_activities
			exit 0
		else
			TEXT="INSTALLATION SCRIPT FOR PACKAGE"
			view_with_dialog
		fi

# if "listcustompkgs --viewscripts" is detected we use ncurses or "--html" and
# don't process any other options:
	elif echo $* | grep -Eq '\-\-viewscripts\>|\-s\>' && [ "$APPLICATION" = "listcustompkgs" ] ; then

		is_scripts_sane
		QTH="$PACKAGES"
		is_qth_empty
		QTH="$SCRIPTS"
		is_qth_empty

		if [ $HTML ] ; then
			cat <<EOF >"$TMP"/$$.html
${HTMLHEADER}
<TITLE>Listcustompkgs --viewscripts (HTML) by Stephen Kennedy</TITLE>
</HEAD>
<BODY>
<H2>Installation scripts for "custom packages" at `hostname`</H2>
To view a script click on the hyperlink.<P>
<UL>
EOF
			Listscript
			if [ ! "$check" ] ; then
				printf "${HTMLHEADER}
<TITLE>Listcustompkgs --viewscripts (HTML) by Stephen Kennedy</TITLE>
</HEAD>
<BODY>
<H1>Nothing to do</H1>I can't find any scripts for custom packages. I would have expected to find at least a script for morepkgtools, so maybe something went wrong.<P>Perhaps you would like to read the " >"$TMP"/$$.html
				rm -f "$TMP"/Listscript.$$ 2>/dev/null
				hyper_activities
				exit 2
			else
				IFS='
'
				for z in `cat "$TMP"/Listscript.$$`
				do
					echo "<LI><A HREF=\"file:$SCRIPTS/$z\">$z</A>" >>"$TMP"/$$.html
				done
				rm -f "$TMP"/Listscript.$$ 2>/dev/null
				echo "</UL>" >>"$TMP"/$$.html
				hyper_activities
				exit 0
			fi

		else
# look for custom packages and then check for scripts
			listscript=1
			TEXT="INSTALLATION SCRIPT FOR PACKAGE"
			view_with_dialog
		fi

	elif [ "$APPLICATION" = "viewpackages" ] ; then

		if echo $* | grep -Eq '\-\-removed\>|\-r\>' ; then
			REMOVED_PACKAGES=${REMOVED_PACKAGES:="$ADM_DIR/removed_packages"}
			if [ ! -d "$REMOVED_PACKAGES" ] ; then
				echo "The variable \$REMOVED_PACKAGES is set to \"$REMOVED_PACKAGES\" which is NOT a directory."
				exit 1
			fi
			QTH="$REMOVED_PACKAGES"
		else
			is_packages_sane
			QTH="$PACKAGES"
		fi
		is_qth_empty

		if [ $HTML ] ; then
			cat <<EOF >"$TMP"/$$.html
${HTMLHEADER}
<TITLE>Viewpackages (HTML) by Stephen Kennedy</TITLE>
</HEAD>
<BODY>
<H2>Slackware packages at `hostname`</H2>
To view a package description file click on the hyperlink.<P>
<UL>
EOF
			for z in "$QTH"/* ; do
				echo "<LI><A HREF=\"file:$z\">`basename "$z"`</A>" >>"$TMP"/$$.html
			done
			echo "</UL>" >>"$TMP"/$$.html
			hyper_activities
			exit 0
		else
			TEXT="CONTENTS OF PACKAGE"
			view_with_dialog
		fi


	else
# listcustompkgs
		is_packages_sane
		QTH="$PACKAGES"

		if [ $TEXTONLY ] ; then
			PAGER=${PAGER:="less -s -E"}
			grep -il "disk\*" "$PACKAGES"/* | $PAGER
			exit
		fi

		is_qth_empty
		look_for_custom_packages

		if [ $HTML ] ; then
			cat <<EOF >"$TMP"/$$.html
${HTMLHEADER}
<TITLE>Listcustompkgs (HTML) by Stephen Kennedy</TITLE>
</HEAD>
<BODY>
<H2>"Custom packages" at `hostname`</H2>
To view a package description file click on the hyperlink.<P>
<UL>
EOF
			IFS='
'
			for z in `cat "$TMP/grep.$$" ; IFS="$OLDIFS"` ; do
				echo "<LI><A HREF=\"file:$PACKAGES/$z\">$z</A>" >>"$TMP/$$.html"
			done
			echo "</UL>" >>"$TMP/$$.html"
			hyper_activities
			rm -f "$TMP/grep.$$" 2>/dev/null
			exit 0

		else
			QTH="$PACKAGES"
			TEXT="CONTENTS OF PACKAGE"
			view_with_dialog
			rm -f "$TMP/grep.$$" 2>/dev/null

		fi
	fi
fi
#

temp5=0

give_a_package_name() {
	if [ "$TEXTONLY" ] ; then
		printf "
What is the name of this package?
> "
		read PACKAGE_NAME
	else
		dialog --title "$APPLICATION" --inputbox "What is the name of this package?" 7 70 2>"$TMP/PACKAGE_NAME.$$" || { rm -f "$TMP/PACKAGE_NAME.$$"; exit; }
		PACKAGE_NAME=`cat "$TMP/PACKAGE_NAME.$$"`
		rm -f "$TMP/PACKAGE_NAME.$$" 2>/dev/null
	fi
	if [ ! "$PACKAGE_NAME" ] ; then
		if [ "$NOARGS" ] ; then
			[ ! "$QUIET" ] && echo Done
			exit 0
		else
			temp5=`expr $temp5 + 1`
			if [ $temp5 -gt 1 ] ; then
				if [ $TEXTONLY ] ; then
					echo "No package name given. Exiting." 1>&2
				else
					dialog --title "$APPLICATION" --infobox "No package name given. Exiting." 4 70
				fi
				exit 1
			else
				if [ $TEXTONLY ] ; then
					echo "No package name given. Try again."
				else
					dialog --title "$APPLICATION" --msgbox "No package name given. Try again." 6 70 || exit
				fi
				give_a_package_name
			fi
		fi
	fi
}


if [ "$APPLICATION" = "pkgheader" -o "$APPLICATION" = "mkpkg" ] ; then

# now we'll parse all the other options for the folks who are staying with us
# I could make this much nicer if I only had to support bash
	get_opts() {
		IFS="$OLDIFS"
		local OPTION
		while getopts d:ezF:D:qt OPTION ; do
			case $OPTION in

				e) if [ "$APPLICATION" = "mkpkg" ] ; then
					EXIT_ON_ERROR=1
				else
					sh "$0" --help 1>&2
					exit 1
				fi ;;

				t) TEXTONLY=1 ;; # TEXTONLY should already be set, but no harm in making sure!

				F) temp=1 # we want to exit after just one run
				DESCFILE="$OPTARG" ;;

				D) temp=1 # we want to exit after just one run:
				a="`printf "$OPTARG\\n"`" ;;

				q) QUIET=1
				TEXTONLY=1 ;; # quiet ncurses operation would be pointless methinks!

				z) if which zdd >/dev/null 2>&1 ; then
					ZDD=1
					export TARGET_DIR TMP ADM_DIR PACKAGES SCRIPTS OLDTMP="$TMP"
				else
					if [ $TEXTONLY ] ; then
						[ ! "$QUIET" ] && echo "Sorry, the \"--zdd\" option cannot be processed because I can't find the zdd program on your system."
					else
						dialog --title "$APPLICATION" --msgbox "Sorry, the \"--zdd\" option cannot be processed because I can't find the zdd program on your system." 7 60 || exit
					fi
				fi ;;

				d) if [ "$APPLICATION" = "mkpkg" ] ; then
					sh "$0" --help 1>&2
					exit 1
				else
					FILES="$OPTARG"
				fi ;;

				*) sh "$0" --help 1>&2
				exit 1 ;;

			esac
		done
	}

	IFS='
'
# -q and -t are undocumented and unsupported
	get_opts $(for GET_OPTS in "$@" ; do echo $GET_OPTS | sed -e 's/--desc=\|--desc\>/-D/' -e 's/--descfile=\|--descfile\>/-F/' -e 's/--dir=\|--dir\>/-d/' -e 's/--exit\>/-e/' -e 's/--quiet\>/-q/' -e 's/--textonly\>/-t/' -e 's/--zdd\>/-z/' ; done)
	shift $(expr $OPTIND - 1)
	unset get_opts GET_OPTS



# bomb out now if taking stdin and no arguments (not options) have been given
# (already bombed out if mkpkg is taking stdin)
	if [ ! -t 0 -a $# = 0 ] ; then
		cat <<EOF 1>&2
You must specify one package name as an argument when using stdin!:
`sh "$0" --help`
EOF
		exit 1
	fi

	temp6=0
# now we've sorted the wheat from the chaff lets declare some functions:
	where_files() {
		if [ -t 0 ] ;  then
			if [ ! "$FILES" ] ; then
				if [ "$TEXTONLY" ] ; then
					printf "\\nWhich directory contains the package list file(s)?\\n> "
					read FILES
				else
					dialog --title "pkgheader" --inputbox "Which directory contains the package list files?" 13 70 2> "$TMP/pkgheader.$$" || { rm -f "$TMP/pkgheader.$$"; exit; }
					FILES="`cat "$TMP"/pkgheader.$$`"
					rm -f "$TMP/pkgheader.$$"
				fi
				if [ ! "$FILES" ] ; then
					temp6=`expr $temp6 + 1`
					if [ $temp6 -gt 1 ] ; then
						if [ $TEXTONLY ] ; then
							echo "No directory name given. Exiting." 1>&2
						else
							dialog --title "$APPLICATION" --infobox "No directory name given. Exiting." 4 70
						fi
						exit 1
					else
						if [ $TEXTONLY ] ; then
							echo "No directory name given. Try again." 1>&2
						else
							dialog --title "$APPLICATION" --msgbox "No directory name given. Try again." 6 70 || exit
						fi
						where_files 
					fi
				fi
			fi
			if [ ! -d "$FILES" ] ; then
				if [ $TEXTONLY ] ; then
					echo "Sorry, \"$FILES\" does not appear to be a directory" 1>&2
				else
					dialog --title "$APPLICATION" --infobox "Sorry, \"$FILES\" does not appear to be a directory" 4 70
				fi
				exit 1
			fi
		fi
	}

	input_method() {
		if [ ! "$FILES" -a -t 0 ] ; then
			if [ "$TEXTONLY" ] ; then
				happy_mondays() {
					cat <<EOF
Please select one of the following:

  1	Read the file list for the package(s) from file
  2	Read the file list from user input (keyboard)
  3	Exit

EOF
					local option
					read option
					case "`echo $option | tr A-Z a-z`" in
						2|*standard*|*std*) STDIN=1 ;;
						1|*file*) where_files ;;
						3|exit) exit ;;
						*) tput clear
						happy_mondays ;;
					esac
				}
				happy_mondays
			else
				dialog --title "pkgheader" --menu "Please select one of the following:\n" 12 75 3 \
1 "Read the file list for the package(s) from file" \
2 "Read the file list from standard input (keyboard)" \
3 "Exit" 2>"$TMP/OPTION" || { rm -f "$TMP/OPTION"; exit; }
				case `cat "$TMP/OPTION" ; rm -f "$TMP/OPTION" 2>/dev/null` in
					1) where_files ;;
					2) STDIN=1 ;;
					3) exit ;;
				esac
			fi
		fi
	}

# function which makes install script, loosely based on function of same name
# from `makepkg` version 1.0
# Copyright 1994, Patrick Volkerding, Moorhead, Minnesota USA
# All rights reserved - see copyright notice above
	make_install_script() {
		IFS='
'
		for LINE in `cat "$TMP/script.$PACKAGE_NAME" ; IFS="$OLDIFS"` ; do
			local TemP=0
			IFS='$'
			for OUT in `echo $LINE | sed -n 's/ -> /$/p' | cat -E ; IFS="$OLDIFS"` ; do
				TemP=`expr $TemP + 1`
				if [ $TemP = 1 ] ; then
					LINKGOESIN="`dirname "$OUT"`"
					LINKNAMEIS="`basename "$OUT"`"
					if echo "$OUT" | grep -q " " ; then
						echo "$LINKGOESIN" | grep -q " " && LINKGOESIN="\"$LINKGOESIN\""
						echo "$LINKNAMEIS" | grep -q " " && LINKNAMEIS="\"$LINKNAMEIS\""
					fi
				elif [ $TemP = 2 ] ; then
					if echo "$OUT" | grep -q " " ; then
						LINKPOINTSTO="\"$OUT\""
					else
						LINKPOINTSTO="$OUT"
					fi
				fi
			done
			cat <<EOF
( cd $LINKGOESIN ; rm -rf $LINKNAMEIS )
( cd $LINKGOESIN ; ln -sf $LINKPOINTSTO $LINKNAMEIS )
EOF
		done
	}

# strip leading slashes and remove '/./' sequences
	strip_search() {
		{ [ "`echo $1 | cut -b 1`" = "/" ] && echo $1 | tr -s / | cut -b 2- | sed 's/\(\/\.\/\)\(\.\/\)*/\//g' ; } || echo $1 | tr -s / | sed 's/\(\/\.\/\)\(\.\/\)*/\//g'
	}

	strip_n_link() {
		if [ -L "$TARGET_DIR/$1" ] ; then
			cd "/$TARGET_DIR"
			ls -l "`strip_search "$1"`" | cut -b56- >> "$TMP/script.$PACKAGE_NAME"
		else
			if [ "$ZDD" ] ; then
				strip_search "$1">>"$TMP/filelist.$PACKAGE_NAME"
			else
				strip_search "$1">>"$TMP/pkg.$PACKAGE_NAME"
			fi
		fi 
	}


	I_like_to_move_it_move_it() {
		[ ! "$QUIET" ] && echo "
Moving $TYPE file for \"$PACKAGE_NAME\" to \"$QTH\""

		if "$TEST" -e "$QTH/$PACKAGE_NAME" ; then
			if "$TEST" -e "$QTH/$PACKAGE_NAME.bak" ; then
				if [ ! "$QUIET" ] && [ $TEXTONLY ] ; then
					cat <<EOF
*******************************************************
A $TYPE file for "$PACKAGE_NAME" already exists
AND "$PACKAGE_NAME.bak" exists. "$PACKAGE_NAME" will not be processed -
please tidy up your filesystem and try again! :-)
(Saved as "$TEMPFILE")
*******************************************************
EOF
				elif [ ! "$TEXTONLY" ] ; then
					dialog --title "$APPLICATION" --msgbox "A $TYPE file for \"$PACKAGE_NAME\"
already exists, AND \"$PACKAGE_NAME.bak\" exists.
\"$PACKAGE_NAME\" will not be processed - please tidy
up your filesystem and try again! :-)
(Saved as \"$TEMPFILE\")" 9 50 || exit
				fi
			else
				if [ ! "$QUIET" ] ; then
					if [ $TEXTONLY ] ; then
						cat <<EOF
*******************************************************
A $TYPE file for "$PACKAGE_NAME" already exists 
Backing up old file to "$PACKAGE_NAME.bak"
*******************************************************
EOF
					else
						dialog --title "$APPLICATION" --msgbox "A $TYPE file for \"$PACKAGE_NAME\"\\nalready exists.\\nBacking up old file to \"$PACKAGE_NAME.bak\"" 7 50 || exit
					fi
					mv -v "$QTH/$PACKAGE_NAME" "$QTH/$PACKAGE_NAME.bak"
					mv -v "$TEMPFILE" "$QTH/$PACKAGE_NAME"
				else
					mv "$QTH/$PACKAGE_NAME" "$QTH/$PACKAGE_NAME.bak"
					mv "$TEMPFILE" "$QTH/$PACKAGE_NAME"
				fi
			fi
		else
			if [ ! "$QUIET" ] ; then
				mv -v "$TEMPFILE" "$QTH/$PACKAGE_NAME"
			else
				mv "$TEMPFILE" "$QTH/$PACKAGE_NAME"
			fi
		fi
	}


	pkgheader_function() {
		unset NOTthisTIME
		if echo "$PACKAGE_NAME" | grep -wq "/" ; then
			PACKAGE_NAME="`basename "$PACKAGE_NAME"`"
			[ ! "$QUIET" ] && echo Warning: package-name cannot include a path\!\! \(slash ignored\)
		fi
		cat <<EOF >"$TMP/pkg.$PACKAGE_NAME"
PACKAGE NAME:	$PACKAGE_NAME
PACKAGE SIZE:	0 K
PACKAGE LOCATION:	disk*
PACKAGE DESCRIPTION:
EOF

		if [ -t 0 ] && [ ! "$a" ] && [ ! "$DESCFILE" ] ; then
#
			if [ $TEXTONLY ] ; then
				cat <<EOF

"$PACKAGE_NAME"
Type a short description of this package. Terminate the description
with a blank line.
EOF
			else
				dialog --title "$APPLICATION" --infobox "\"$PACKAGE_NAME\"\\nType a short description of this package. Terminate the\\ndescription with a blank line." 7 70
			fi

			a=a
			while [ "$a" ] ; do
				printf "> "
				read a
				echo $PACKAGE_NAME":	"$a >> "$TMP/pkg.$PACKAGE_NAME"
			done
		else

			if [ "$a" ] ; then
# replace "\n" with "\n$PACKAGE_NAME:" 
# Conversion to `join` (and other small changes in the script) by g0lgs:

				printf "$a" > "$TMP/pkgdesc.$$"
				printf $PACKAGE_NAME":            " | join -j 100 - "$TMP/pkgdesc.$$" | colrm 1 1 >> "$TMP/pkg.$PACKAGE_NAME"
				rm -f "$TMP/pkgdesc.$$"

			elif [ $DESCFILE ] ; then

				printf $PACKAGE_NAME":            "  | join -j 100 - "$DESCFILE" | colrm 1 1 >> "$TMP/pkg.$PACKAGE_NAME"

			fi
		fi
##

		echo "FILE LIST:" >> "$TMP/pkg.$PACKAGE_NAME"

# here we take the list of files from a make install, stdin or file (cool!) :-)

		if [ "$APPLICATION" = "mkpkg" ] ; then
# mkpkg version 2.xx, for use with pkginstall v3.xx
# mkpkg calls up make which calls up pkginstall which calls up install...
			make install > "$TMP/.make.$$" 2>&1 ; temp3=$?
			MAKE="`head -n1 "$TMP/.make.$$"`"
			[ ! "$QUIET" ] && cat "$TMP/.make.$$"
			if [ $temp3 != 0 ] || echo "$MAKE" | grep -qiE 'Nothing to be done|up to date' ; then
				[ $temp3 != 0 ] && logger -t mkpkg[$$] error reported by \"make install\"
				if [ "$EXIT_ON_ERROR" ] ; then
					[ "$QUIET" ] || echo "Something went wrong... exiting" 1>&2
					rm -f "$TMP/.make.$$" 2>/dev/null
					exit 1
				elif [ $TEXTONLY ] ; then
					echo "hmm... I've noticed an error with \"make\"."
					while : ; do
						printf "\\n[c]ontinue with mkpkg, [v]iew transcript, [e]xit\\n> "
						read temp4
						case "`echo "$temp4" | tr A-Z a-z`" in
							c|continue) break ;;

							e|exit) rm -f "$TMP/.make.$$" 2>/dev/null
							exit 1 ;;

							v|view) "$PAGER" "$TMP/.make.$$" ;;

							*) echo "Invalid input. Try again" ;;
						esac
					done
				else
					while : ; do
						dialog --title "mkpkg" --menu "hmm... I've noticed an error with \"make\"." 12 75 3 \
1 "Continue with mkpkg" \
2 "Exit" \
3 "View transcript" 2>"$TMP/continue_or_no" || { rm -f "$TMP/.make.$$" 2>/dev/null ; exit 1 ; }
						case `cat "$TMP/continue_or_no" ; rm -f "$TMP/continue_or_no" 2>/dev/null` in
							1) break ;;
							2) rm -f "$TMP/.make.$$" 2>/dev/null
							exit 1 ;;
							3) "$PAGER" "$TMP/.make.$$"
							echo "Press enter to continue"
							read NULL ;;
						esac
					done
				fi
			fi
			rm -f "$TMP/.make.$$" 2>/dev/null
			unset temp4 temp3
			IFS='
'
			for d in `cat "$MAKE_FILELIST" ; IFS="$OLDIFS"` ; do
				strip_n_link "$d"
			done
			rm -f "$MAKE_FILELIST"
# exit after one run:
			temp=1

		elif [ ! -t 0 ] ; then
			IFS='
'
			for d in `cat -` ; do
				strip_n_link "$d"
			done
# exit after one run:
			temp=1

		elif [ "$STDIN" ] ; then
			if [ $TEXTONLY ] ; then
				printf "Input the file list for package \"$PACKAGE_NAME\".\\nTerminate the list with a blank line:\\n\\n"
			else
				dialog --title "pkgheader" --infobox "Input the file list for package \"$PACKAGE_NAME\".\\nTerminate the list with a blank line:\\n" 4 70
			fi
			FILEINPUT=x
			while [ "$FILEINPUT" ] ; do
				printf "> "
				read FILEINPUT
				strip_n_link "$FILEINPUT"
			done

		elif [ `"$TEST" -e "$FILES/$PACKAGE_NAME" ; echo $?` != 0 ] ; then
			NOTthisTIME=1
			if [ ! "$QUIET" ] && [ $TEXTONLY ] ; then
				cat <<EOF
There does not appear to be a file list for "$PACKAGE_NAME".
You will need to add the list of files to "$PACKAGES/$PACKAGE_NAME" manually.

EOF
			elif [ ! "$TEXTONLY" ] ; then
				dialog --title "pkgheader" --msgbox "There does not appear to be a file list for\\n\"$PACKAGE_NAME\".\\nYou will need to add the list of files to\\n\"$PACKAGES/$PACKAGE_NAME\" manually." 9 50 || exit
			fi

		elif [ -s "$FILES/$PACKAGE_NAME" ] ; then
			IFS='
'
			for d in `cat "$FILES/$PACKAGE_NAME"; IFS="$OLDIFS"` ; do
				strip_n_link "$d"
			done

		else
			NOTthisTIME=1
			if [ ! "$QUIET" ] && [ $TEXTONLY ] ; then
				cat <<EOF
The file list for "$PACKAGE_NAME" appears to be null.
You will need to add the list of files to "$PACKAGES/$PACKAGE_NAME" manually.

EOF
			elif [ ! "$TEXTONLY" ] ; then
				dialog --title "pkgheader" --msgbox "The file list for \"$PACKAGE_NAME\" appears to be null.\\nYou will need to add the list of files to\\n\"$PACKAGES/$PACKAGE_NAME\"\\nmanually." 9 50 || exit
			fi
		fi

# call make_install_script if required:
		if [ -s "$TMP/script.$PACKAGE_NAME" ] ; then
			if [ ! "$QUIET" ] ; then
				echo "Making symbolic link creation script:"
				make_install_script | tee "$TMP/doinst.sh.$PACKAGE_NAME"
				echo
			else
				make_install_script > "$TMP/doinst.sh.$PACKAGE_NAME"
			fi
			rm -f "$TMP/script.$PACKAGE_NAME"
			move_script=1
			if [ "$ZDD" ] ; then
# we've made a script and --zdd was parsed: (there should be no way
# we could get here AND have $NOTthisTIME set)
				touch "$TMP/filelist.$PACKAGE_NAME"
				if [ "$QUIET" ] ; then
					zdd --quiet --pkgheader "$TMP/pkg.$PACKAGE_NAME" "$TMP/filelist.$PACKAGE_NAME" "$PACKAGE_NAME" "$TMP/doinst.sh.$PACKAGE_NAME"
				elif [ "$TEXTONLY" ] ; then
					zdd --textonly --pkgheader "$TMP/pkg.$PACKAGE_NAME" "$TMP/filelist.$PACKAGE_NAME" "$PACKAGE_NAME" "$TMP/doinst.sh.$PACKAGE_NAME"
				else
					zdd --pkgheader "$TMP/pkg.$PACKAGE_NAME" "$TMP/filelist.$PACKAGE_NAME" "$PACKAGE_NAME" "$TMP/doinst.sh.$PACKAGE_NAME"
				fi
			fi

		else
			if [ "$ZDD" ] ; then
# "--zdd" was parsed, and we have no installation script to deal with:
				if [ "$NOTthisTIME" ] ; then
					if [ ! "$QUIET" ] && [ "$TEXTONLY" ] ; then
						echo "Not processing \"--zdd\" for \"$PACKAGE_NAME\" because there is no file list."
					elif [ ! "$TEXTONLY" ] ; then
						dialog --title "$APPLICATION" --infobox "Not processing \"--zdd\" for \"$PACKAGE_NAME\" because there is no file list." 4 60
						sleep 1
					fi
				else
					touch "$TMP/filelist.$PACKAGE_NAME"
					if [ "$QUIET" ] ; then
						zdd --quiet --pkgheader "$TMP/pkg.$PACKAGE_NAME" "$TMP/filelist.$PACKAGE_NAME" "$PACKAGE_NAME"
					elif [ "$TEXTONLY" ] ; then
						zdd --textonly --pkgheader "$TMP/pkg.$PACKAGE_NAME" "$TMP/filelist.$PACKAGE_NAME" "$PACKAGE_NAME"
					else
						zdd --pkgheader "$TMP/pkg.$PACKAGE_NAME" "$TMP/filelist.$PACKAGE_NAME" "$PACKAGE_NAME"
					fi
				fi
			fi
		fi

		TYPE=Package
		QTH="$PACKAGES"
		TEMPFILE="$TMP/pkg.$PACKAGE_NAME"
		I_like_to_move_it_move_it

		if [ "$move_script" ] ; then
			chown root "$TMP/doinst.sh.$PACKAGE_NAME"
			chmod u=rx,go=r "$TMP/doinst.sh.$PACKAGE_NAME"
			if [ ! -d "$SCRIPTS" ] ; then
				logger -t "$APPLICATION[$$]" "\"$SCRIPTS\" - no such directory"
# we won't exit even if $SCRIPTS is not a directory
				if [ ! "$QUIET" ] ; then
					cat <<EOF
Warning! "$SCRIPTS" is not a directory.
Your script file has been saved in "$TMP/doinst.sh.$PACKAGE_NAME"
EOF
				fi
			else
				TYPE=Script
				QTH="$SCRIPTS"
				TEMPFILE="$TMP/doinst.sh.$PACKAGE_NAME"
				I_like_to_move_it_move_it
			fi
			unset move_script
		fi

# exit if taken list from stdin or if "-desc*" options parsed
		if [ $temp ] ; then
			if [ ! "$QUIET" ] ; then
				echo
				echo "Done"
			fi
			exit 0
		fi
	}
# end of pkgheader function


	introducing() {
		if [ ! "$QUIET" -a ! "$EXIT_ON_ERROR" ] ; then
			if [ "$TEXTONLY" ] ; then
				cat <<EOF

$APPLICATION: $WHATITDOES
By Stephen Kennedy, 1995-2000

Incorporates mkpkg v1 by A Davison & extracts from P Volkerding's pkgtools
Copyright (C) 1993-2000 S D K Software, Esonque Systems, P Volkerding
--------------------------------------------------------------------------------

EOF
			else
				dialog --title "$APPLICATION" --msgbox "By Stephen Kennedy, 1995-2000\\n\\n$WHATITDOES\\n\\nIncorporates mkpkg v1 by A Davison & extracts from P Volkerding's pkgtools\\n\\nCopyright (C) 1993-2000 SDK Software, Esonque Systems, P Volkerding." 11 78 || exit
			fi
		fi
	}


# down to business
	is_packages_sane

	if [ "$APPLICATION" = "mkpkg" ] ; then
		WHATITDOES="Slackware-friendly supplement for make install"
		introducing
		if [ $# = 0 ] ; then
			give_a_package_name
		else
			PACKAGE_NAME="$1"
		fi
		export MAKE_FILELIST="$TMP/$PACKAGE_NAME.tmp.$$"
		pkgheader_function

	elif [ $# = 0 ] ; then
		WHATITDOES="Adds Slackware-compatible headers to a list file"
		introducing
		PACKAGE_NAME=xxx
		input_method
		while [ "$PACKAGE_NAME" ] ; do
			give_a_package_name
			pkgheader_function
			NOARGS=1
		done

	else
		WHATITDOES="Adds Slackware-compatible headers to a list file"
		introducing
		input_method
		while [ "$1" ] ; do
			PACKAGE_NAME="$1"
			pkgheader_function
			shift
		done
	fi
# end of pkgheader/mkpkg


else # packagetools menu

	backup-text() {
		cat <<EOF
Previously, when you wanted to install a new Slackware package you needed to
delete the old one first, and thereby lose configuration files (or manually
backup, a tedious process). Now you can keep a backup of an entire old
package, including any modifications you have made. [Ideally this option
would be incorporated into pkgtool].

EOF

		if [ "$TEXTONLY" ] ; then
			echo "Press Enter to list the packages installed on your system..."
		else
			cat <<EOF
Please select the package[s] you wish to backup. Use the spacebar to select
packages to backup, and the UP/DOWN arrow keys to scroll up and down through
the entire list.
EOF
		fi
	}

	Backup() {
		if [ "$TEXTONLY" ] ; then
			backup-text
			read NULL
			tput clear
			(cd "$PACKAGES" && ls)
			echo
			echo "Input the package names you wish to backup, one per line. Terminate the list
with a blank line:"
			rm -f "$TMP/return" >/dev/null 2>&1
			BJORK=xxx
			while [ "$BJORK" ] ; do
				printf "> "
				read BJORK
				echo "$BJORK" >> "$TMP/return"
			done
		else
# taken (with changes) from pkgtool 2.2.0 by P Volkerding:
			dialog --title "SCANNING" --infobox "Please wait while packagetools scans \
your system to determine  which packages you have installed and prepares \
a list for you. This will take 3.`date +"%S"`E+`date +"%M"` \
BogoMipSeconds." 7 40
			cat << EOF > "$TMP/rmscript"
dialog --checklist "`backup-text`" 24 80 10 \\
EOF
			for PACKAGE_NAME in "$PACKAGES"/* ; do
				PACKAGE_NAME="`basename "$PACKAGE_NAME"`"
				BLURB="`sed -n \"/$PACKAGE_NAME:/{s/\\"//g;p;q;}\" "$PACKAGES/$PACKAGE_NAME" | cut -b10-45`"
				echo "\"$PACKAGE_NAME\" \"$BLURB\" off \\" >> "$TMP/rmscript"
			done
			echo "2> \"$TMP/return\" || return 2" >> "$TMP/rmscript"
# end of pkgtool borrowing
			. "$TMP/rmscript"
			rm -f "$TMP/rmscript" >/dev/null 2>&1
		fi

		if [ "`cat "$TMP/return"`" ]; then
			BACKUPS=${BACKUPS:="`echo "$ADM_DIR/backups" | tr -s /`"}
			mkdir -p "$BACKUPS" >/dev/null 2>&1
			[ -d "$BACKUPS" ] || (echo "Error: can't make backups directory." ; sleep 4 ; return 2 )
			DATE="`date | tr : _`"
			if [ "$TEXTONLY" ] ; then
				IFS='
'
			else
				IFS="\""
			fi
			for PACKAGE_NAME in `if [ "$TEXTONLY" ]
then cat "$TMP/return"
else { cat "$TMP/return" | cut -b2- | sed 's/\" //'; }
fi
IFS="$OLDIFS"` ; do
				if [ "`echo "$PACKAGE_NAME" | tr -d ' '`" ] ; then
					if [ "$TEXTONLY" ] ; then
						echo "Backing up package \"$PACKAGE_NAME\""
					else
						dialog --title "packagetools" --infobox "Backing up package:
\"$PACKAGE_NAME\"" 4 60
					fi
					lovely_bjork | grep -vEx '.*/' > "$TMP/2tar.$$"
					cd "$TARGET_DIR" || { echo "Error: can't change to target directory" ; return 3; }
					IFS='
'
					for JDJ in `cat "$TMP/2tar.$$" ; IFS="$OLDIFS"` ; do
						[ -d "$JDJ" ] || echo "$JDJ" >> "$TMP/2tar2.$$"
					done
					echo "$PACKAGES/$PACKAGE_NAME" >> "$TMP/2tar2.$$"
					"$TEST" -e "$SCRIPTS/$PACKAGE_NAME" && echo "$SCRIPTS/$PACKAGE_NAME" >> "$TMP/2tar2.$$"
					tar --preserve -cf - -T "$TMP/2tar2.$$" 2>/dev/null | gzip -9 - >"$BACKUPS/$PACKAGE_NAME.$DATE.tgz"
					rm -f "$TMP/csplit$$.1" "$TMP/2tar.$$" "$TMP/2tar2.$$" >/dev/null 2>&1
				fi
			done
			if [ "$TEXTONLY" ] ; then
				cat <<EOF

Done.

If you wish you can now remove the packages by selecting 'pkgtool' from the
packagetools menu.
EOF
			else
				dialog --title "packagetools" --msgbox "Done. If you wish you can now remove the packages by selecting 'pkgtool' from the packagetools menu." 7 70
			fi
		fi
		rm -f "$TMP/return" >/dev/null 2>&1
		unset JDJ BLURB BJORK
		return 0
	}

	strip_search() {
		{ [ "`echo $1 | cut -b 1`" = "/" ] && echo $1 | tr -s / | cut -b 2- ; } || echo $1 | tr -s /
	}

	lovely_bjork() {
# taken, with changes, from pkgtool v2.2.0 by P Volkerding:
		if fgrep "./" "$PACKAGE_NAME" > /dev/null 2>&1 ; then
# as borrowed this didn't work properly:
			TRIGGER="\.\/"
		else
			TRIGGER="FILE LIST:"
		fi
# end of pkgtool borrowing

# this and nip() based on zdd v0.51 by SDK:
		csplit -kn1 -qf "$TMP/csplit$$." "$PACKAGES/$PACKAGE_NAME" /"$TRIGGER"/+1 >/dev/null 2>&1
		touch "$TMP/csplit$$.1"
		rm -f "$TMP/csplit$$.0" >/dev/null 2>&1

		if grep -qxE '/.*|.*//.*' "$TMP/csplit$$.1" ; then
			IFS='
'
			for LINE in `cat "$TMP/csplit$$.1"; IFS="$OLDIFS"` ; do
				strip_search "$LINE"
			done
		else
			cat "$TMP/csplit$$.1"
		fi
	}

	nip() { # find files Not In Packages
		echo "Please wait..."

		OLDIFS="$IFS"
		OUTPUTFILE="$TMP/nip.$$"
		OUTPUTFILE2="$TMP/nip2.$$"

		cd "$PACKAGES"
		IFS='
'
		for PACKAGE_NAME in `find -maxdepth 1 -xtype f | cut -b 3- ; IFS="$OLDIFS"` ; do
			lovely_bjork
			rm -f "$TMP/csplit$$.1" >/dev/null 2>&1
		done | sort -u >> "$OUTPUTFILE2"

# CHANGE THIS TO {IN,EX}CLUDE FILESYSTEM TYPES FROM THE SEARCH: 
		(cd "$TARGET_DIR" && find . -path './proc' -prune , ! -fstype proc ! -fstype iso9660 ! -fstype smbfs ! -fstype nfs ! -fstype msdos ! -fstype hpfs ! -fstype vfat 2>/dev/null) | grep -vxE '.*/tmp/.*' | cut -b3- | sort -u | comm -23 - "$OUTPUTFILE2" >> "$OUTPUTFILE"

		rm -f "$OUTPUTFILE2" >/dev/null 2>&1
	}

	if echo $* | grep -wq "\-\-textonly" ; then
		TEXTONLY=1
		tput clear
		mega_menu() {
			cat <<EOF
`sh "$0" --version 2>&1` mega-menu

Please select one of the following options:

1	pkgheader		- Create a Slackware package description file
2	listcustompkgs		- List the custom packages installed
3	pkgtool			- Install or remove packages
4	backup			- Backup a package (see manpage for caveats)
5	setup			- Slackware system setup tool
6	mkpkg			- Run instead of make install at the current
				  dir level
7	makepkg			- Make a package from the contents of the pwd &
				  below
8	nip			- Search for files not listed in package files
9	nip2file		- Output the search to file
10	manpkgheader		- Read the manual entry for pkgheader
11	manlistcustompkgs	- Read the manual entry for listcustompkgs
12	manpkgtool		- Read the manual entry for pkgtool
13	mansetup		- Read the manual entry for setup
14	manmkpkg		- Read the manual entry for mkpkg
15	manmakepkg		- Read the manual entry for makepkg
16	about			- About packagetools
17	exit			- Exit packagetools

EOF
			local REPLY
			printf "> "
			read REPLY
			case "`echo $REPLY | tr A-Z a-z`" in
				1|pkgh*) sh pkgheader --textonly --zdd ;;
				2|listcustomp*) sh listcustompkgs --textonly ;;
				3|pkgt*) sh pkgtool.tty ;;
				4|backup) Backup ;;
				5|s*) sh setup.tty ;;
				6|mk*) sh mkpkg --textonly --zdd ;;
				7|mak*)  give_a_package_name
				makepkg "$PACKAGE_NAME" ;;
				8|nip) nip
				tput clear
				echo "space to scroll, q when done"
				less "$OUTPUTFILE"
				rm -f "$OUTPUTFILE" >/dev/null 2>&1 ;;
				9|nip2*) nip
				cat <<EOF

The file list is "$OUTPUTFILE". It can be made
into a package file by piping it into pkgheader, for example as follows:
cat "$OUTPUTFILE" | pkgheader --desc "<description>" package-name
EOF
				;;
				10|man*pkgh*) man pkgheader ;;
				11|man*l*) man listcustompkgs ;;
				12|man*pkgt*) man pkgtool ;;
				13|man*s*) man setup ;;
				14|man*mk*) man mkpkg ;;
				15|man*ma*) man makepkg ;;
				16|a*) cat <<EOF

`sh "$0" --version 2>&1`
"mega-menu": (c) 1995-2000 SDK Software, interface to tools written by
S Kennedy, P Volkerding, A Davison and others.

morepkgtools package: incorporates pkgheader, mkpkg, listcustompkgs,
zdd, viewscripts, and viewpackages, by S Kennedy et al

EOF
				;;
				17|e*) exit 0 ;;
				*) echo "Invalid input. Try again."
				mega_menu ;;
			esac
		}
		while [ 0 ] ; do
			mega_menu
			echo
			echo "Press Enter to return to $APPLICATION menu"
			read null
			unset null 
		done

	else
		while [ 0 ] ; do
			dialog --title "$APPLICATION mega-menu" --menu "Select one of the following options:\n\n[The options extend below the screen - use the arrow keys to scroll]" 25 80 16 \
Pkgheader "Create a Slackware package description file" \
Listcustompkgs "List and view the custom packages installed" \
Listcustomscripts "List and view scripts from custom packages installed" \
Viewpackages "View packages installed on your system" \
Viewscripts "View scripts for packages installed on your system" \
Pkgtool "Install, remove or view packages" \
Backup "Backup a package (see manpage for caveats)" \
Setup "Slackware system setup tool" \
Mkpkg "Run instead of make install at the current dir level" \
Makepkg "Make a package from the contents of the pwd & below" \
Zdd "Gzip the files below \$DOCDIR and update package files" \
Nip "Search for files not listed in package files" \
Nip2file "Output the search to file" \
Pkggrep "Search for regular expression in package files" \
ManPkgheader "Read the manual entry for pkgheader" \
ManListcustompkgs "Read the manual entry for listcustompkgs" \
ManViewscripts "Read the manual entry for viewscripts" \
ManViewpackages "Read the manual entry for viewpackages" \
ManPkgtool "Read the manual entry for pkgtool" \
ManSetup "Read the manual entry for setup" \
ManMkpkg "Read the manual entry for mkpkg" \
ManMakepkg "Read the manual entry for makepkg" \
ManZdd "Read the manual entry for zdd" \
About "About packagetools" \
Exit "Exit $APPLICATION" 2>"$TMP/reply" || { rm -f "$TMP/reply" 2>/dev/null; exit; }
			case `cat "$TMP/reply" ; rm -f "$TMP/reply" 2>/dev/null` in
				Nip) nip
				dialog --title "packagetools" --textbox "$OUTPUTFILE" 22 80
				rm -f "$OUTPUTFILE" >/dev/null 2>&1 ;;
				Nip2file) nip
				dialog --msgbox "The file list is \"$OUTPUTFILE\". It can be made
into a package file by piping it into pkgheader,
for example as follows:
cat \"$OUTPUTFILE\" | pkgheader --desc \"<description>\" package-name" 8 80 ;;
				Pkggrep) printf "
Type in the expression you want to search for:
> "
				read PKGGREP
				pkggrep "$PKGGREP"
				unset PKGGREP ;;
				Pkgheader) sh pkgheader --zdd ;;
				Listcustompkgs) sh listcustompkgs ;;
				Listcustomscripts) sh listcustompkgs --viewscripts ;;
				Viewscripts) sh viewscripts ;;
				Viewpackages) sh viewpackages ;;
				Pkgtool) pkgtool ;;
				Backup) Backup ;;
				Setup) setup ;;
				Mkpkg) sh mkpkg --zdd ;;
				Makepkg) give_a_package_name
				makepkg "$PACKAGE_NAME"
				echo
				echo "Press Enter to return to $APPLICATION menu"
				read null
				unset null ;;
				Zdd) dialog --title "$APPLICATION mega-menu" --menu "Select one of the following zdd options:\n" 17 80 5 \
 All "Compress all files below \$DOCDIR" \
 Allpackages "Compress all files below \$DOCDIR that are listed in \$ADM_DIR" \
 Package "Compress the files below \$DOCDIR from one package" \
 Exit "Exit $APPLICATION" 2>"$TMP/reply" || { rm -f "$TMP/reply" 2>/dev/null; exit; }
 				export TARGET_DIR TMP ADM_DIR PACKAGES SCRIPTS
 				case `cat "$TMP/reply" ; rm -f "$TMP/reply" 2>/dev/null` in
 					All) sh zdd --all --notlinks ;;
 					Allpackages) sh zdd --allpackages --notlinks ;;
 					Package) give_a_package_name
 					sh zdd --notlinks "$PACKAGE_NAME" ;;
 					*) exit 0 ;;
 				esac ;;
				ManListcustompkgs) man listcustompkgs ;;
				ManPkgheader) man pkgheader ;;
				ManViewscripts) man viewscripts ;;
				ManViewpackages) man viewpackages ;;
				ManPkgtool) man pkgtool ;;
				ManSetup) man setup ;;
				ManMkpkg) man mkpkg ;;
				ManMakepkg) man makepkg ;;
				ManZdd) man zdd ;;
				About) dialog --title "packagetools mega-menu" --msgbox "\"mega-menu\": (c) 1995-2000 SDK Software, interface to tools written by\\nS Kennedy, P Volkerding, A Davison and others.\\n\\nmorepkgtools package: incorporates pkgheader, mkpkg, listcustompkgs,\\nzdd, viewscripts, and viewpackages, by S Kennedy et al." 10 78  || exit ;;
				*) exit 0 ;;
			esac
		done
	fi
fi

# au revoir mon amis
if [ ! "$QUIET" ] ; then
	echo
	echo Done
fi
exit 0

# ROCK N ROLL :-)
