#!/bin/sh

###############################################################################
# Script : maketag
# Author : Stuart Winter <mozes@armedslack.org>
#          Based on the original Slackware maketag scripts by Patrick Volkerding
# Version: 1.0 
# Date...: 01-Jan-2006
###############################################################################

#item   ####description                                      ###on off ###

TMP=/var/log/setup/tmp
if [ ! -d $TMP ]; then
   mkdir -p $TMP
fi

# Need to add in a 'current series' file into a temp file for us to
# parse it. then cd into the current series dir to produce the menu.

# Blank temporary tag file:
cp -f /dev/null $TMP/SeTnewtag
TMPMENU=$TMP/menu.script

# Determine the title for this menu by looking in the 
# pkgseriesinfo.txt file contained within the series' directory.
if [ -s pkgseriesinfo.txt ]; then
   MENUTITLE="$( cat pkgseriesinfo.txt )"
 else
   MENUTITLE="THIS SERIES"
fi

# Build the menu:
 echo 'dialog \
         --backtitle "Slackware installer: Select packages" \
         --title "SELECTING PACKAGES FROM $MENUTITLE" \
         --checklist "Please select the packages you wish to install \
from series A. Use the \
UP/DOWN keys to scroll through the list, and the SPACE key to select \
the packages you wish to install. Certain important packages have \
already been selected for you, and you are cautioned against unselecting \
these packages. However, it's your system. :-)  
Press ENTER when you are done.\n" 21 76 8 \' > $TMPMENU
cat maketag.pkglist >> $TMPMENU

# Execute the menu and grab the selection and return code:
exec 3>&1
( /bin/bash $tempfile 2>&1 1>&3 ) > $TMP/SeTpkgs
menu_retval=$?
exec 3>&-

# If the user pressed on 'Cancel' or something bad happened, we'll mark
# each package as "Skipped" and we'll bail out of this package series.
if [ $menu_retval = 1 -o $menu_retval = 255 ]; then
 rm -f $TMP/SeTpkgs
 cp -f /dev/null $TMP/SeTnewtag
 # Mark each package as being skipped:
 for pkg in \
  aaa_base aaa_elflibs acpid apmd bash bin bzip2 coreutils cpio cups cxxlibs dcron devs e2fsprogs elvis etc findutils floppy gawk genpower gettext getty-ps glibc-solibs gpm grep gzip hdparm hotplug pkgtools kernel-ide isapnptools jfsutils kbd less lilo loadlin logrotate minicom mkinitrd kernel-modules module-init-tools openssl-solibs pciutils pcmcia-cs procps reiserfsprogs sed shadow slocate smartmontools sysklogd syslinux sysvinit tar tcsh umsdos-progs udev usbutils utempter util-linux infozip glibc-zoneinfo xfsprogs \
  ; do
  echo "$pkg: SKP" >> $TMP/SeTnewtag
 done
 exit
fi


cat /dev/null > $TMP/SeTnewtag
for PACKAGE in \
 aaa_base aaa_elflibs acpid apmd bash bin bzip2 coreutils cpio cups cxxlibs dcron devs e2fsprogs elvis etc findutils floppy gawk genpower gettext getty-ps glibc-solibs gpm grep gzip hdparm hotplug pkgtools kernel-ide isapnptools jfsutils kbd less lilo loadlin logrotate minicom mkinitrd kernel-modules module-init-tools openssl-solibs pciutils pcmcia-cs procps reiserfsprogs sed shadow slocate smartmontools sysklogd syslinux sysvinit tar tcsh umsdos-progs udev usbutils utempter util-linux infozip glibc-zoneinfo xfsprogs \
 ; do
 if fgrep \"$PACKAGE\" $TMP/SeTpkgs 1> /dev/null 2> /dev/null ; then
  echo "$PACKAGE: ADD" >> $TMP/SeTnewtag
 else
  echo "$PACKAGE: SKP" >> $TMP/SeTnewtag
 fi
done
rm -f $TMP/SeTpkgs
