#!/usr/sbin/gtkdialog3 -e
#(c) Copyright Barry Kauler 2009
#This is a GUI frontend for Woof.
#100617 add support for slackware .txz pkgs.
#100730 fix for pet pkg search order.
#100912 checkbox to choose simple or traditional filenames.
#110422 DISTRO_VERSION variable now has dotted format. note, also now using full dotted version# in puppy filenames.
#110608 simplify pet pkg search order.
#110821 updates.
#120522 wary 5.3: 'pidof woof_gui' no longer works! but, busybox applet does.
#120719 support raspbian.
#121102 file DISTRO_SPECS has new variable DISTRO_DB_SUBNAME. ex: for 14.0-based slacko, DISTRO_DB_SUBNAME=slacko14
#121102 Packages-puppy-${DISTRO_FILE_PREFIX}- (or Packages-puppy-${DISTRO_COMPAT_VERSION}-) is now Packages-puppy-${DISTRO_DB_SUBNAME}-. refer /etc/DISTRO_SPECS.
#121105 restore other variables that may have been in prior DISTRO_SPECS.
#130306 arch linux: gz now xz. maybe only 'DISTRO_COMPAT_REPOS-arch'. more arch stuff.

if [ "`busybox pidof woof_gui`" = "" ];then
 echo "Please run 'woof_gui' script"
 exit
fi

DEFAULTTABNUM="0"
[ $1 ] && DEFAULTTABNUM="$1"

#Specifications
[ ! -f DISTRO_SPECS ] && exit
. ./DISTRO_SPECS
[ ! "$DISTRO_DB_SUBNAME" ] && DISTRO_DB_SUBNAME="$DISTRO_COMPAT_VERSION" #121102 fallback if DISTRO_DB_SUBNAME not defined in file DISTRO_SPECS.
. ./support/HISTORY_DISTRO_SPECS
. ./DISTRO_PET_REPOS
DCRFILE=''
if [ -f ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then
. ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
 DCRFILE="DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}" #130306
else
. ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT} #130306
 DCRFILE="DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}"
fi
if [ -f ./DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then
. ./DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
 DPSFILE="DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}"
else
. ./DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}
 DPSFILE="DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}"
fi
. ./support/HISTORY_3builddistro

[ ! "$DISTRO_NAME" ] && DISTRO_NAME='Puppy'
[ ! "$DISTRO_FILE_PREFIX" ] && DISTRO_FILE_PREFIX='pup'
[ "$DISTRO_VERSION" = "" ] && DISTRO_VERSION='5.0' 
[ ! "$DISTRO_COMPAT_VERSION" ] && DISTRO_COMPAT_VERSION='5'
[ ! "$DISTRO_BINARY_COMPAT" ] && DISTRO_BINARY_COMPAT='puppy'
#110422[ ! $DISTRO_MINOR_VERSION ] && DISTRO_MINOR_VERSION=00

BINARIES='deb' #download to packages-deb.
[ "$DISTRO_BINARY_COMPAT" = "t2" ] && BINARIES="bz2" #download to packages-bz2-${DISTRO_COMPAT_VERSION}.
[ "$DISTRO_BINARY_COMPAT" = "slackware" ] && BINARIES="tgz_txz" #100617 download to packages-tgz_txz-${DISTRO_COMPAT_VERSION}.
[ "$DISTRO_BINARY_COMPAT" = "debian" ] && BINARIES="deb" #download to packages-deb-${DISTRO_COMPAT_VERSION}.
[ "$DISTRO_BINARY_COMPAT" = "arch" ] && BINARIES="tar_xz" #download to packages-tar_gz-${DISTRO_COMPAT_VERSION}. 130306
[ "$DISTRO_BINARY_COMPAT" = "puppy" ] && BINARIES="pet" #built entirely from pet pkgs.
[ "$DISTRO_BINARY_COMPAT" = "scientific" ] && BINARIES="rpm" #110523 Iguleder: download to packages-rpm-${DISTRO_COMPAT_VERSION}.
[ "$DISTRO_BINARY_COMPAT" = "mageia" ] && BINARIES="rpm" #110615
[ "$DISTRO_BINARY_COMPAT" = "gentoo" ] && BINARIES="gentoo" #120515 download to packages-gentoo-gap6
[ "$DISTRO_BINARY_COMPAT" = "raspbian" ] && BINARIES="deb_raspbian" #download to packages-deb_raspbian-${DISTRO_COMPAT_VERSION}.
BINARIES="${BINARIES}-${DISTRO_COMPAT_VERSION}"

#run this stuff at first entry only...
ALLPS="`ps`"
if [ "`echo "$ALLPS" | grep 'gtkdialog -i ./woof_gui_tabs'`" = "" ];then
 #if [ -f /usr/sbin/gtkdialog3 ];then #110813
 # ln -s gtkdialog3 /usr/sbin/gtkdialog
 #else
 # ln -s gtkdialog /usr/sbin/gtkdialog3
 #fi
 touch support/HISTORY_DISTRO_SPECS
 echo "$DISTRO_NAME" > /tmp/woof_gui_dn
 echo "$DISTRO_FILE_PREFIX" > /tmp/woof_gui_dfp
 echo "$DISTRO_COMPAT_VERSION" > /tmp/woof_gui_dcv
 echo "$PET_REPOS" | sed -e 's% $%%' | tr ' ' '\n' > /tmp/woof_gui_pet_repos
 xPET_REPOS="$PET_REPOS"
 echo "$PKG_DOCS_PET_REPOS" | sed -e 's% $%%' | tr ' ' '\n' > /tmp/woof_gui_pkg_docs_pet_repos
 xPKG_DOCS_PET_REPOS="$PKG_DOCS_PET_REPOS"
 echo "$REPOS_DISTRO_COMPAT" | sed -e 's% $%%' | tr ' ' '\n' > /tmp/woof_gui_compat_repos
 COMPAT_REPOS="$REPOS_DISTRO_COMPAT" #alternate name used in this script.
 xCOMPAT_REPOS="$COMPAT_REPOS"
 echo "$PKG_DOCS_DISTRO_COMPAT" | sed -e 's% $%%' | tr ' ' '\n' > /tmp/woof_gui_pkg_docs_compat_repos
 PKG_DOCS_COMPAT_REPOS="$PKG_DOCS_DISTRO_COMPAT" #alternative name used in this script.
 xPKG_DOCS_COMPAT_REPOS="$PKG_DOCS_COMPAT_REPOS"
fi
xDISTRO_KERNEL_PET="$DISTRO_KERNEL_PET" #100514

########Specifications tab#######
update_distro_specs_func() {
# if [ "$xHISTORY_DISTRO_SPECS_TEMPLATE" != "$HISTORY_DISTRO_SPECS_TEMPLATE" ];then
 if [ "$xHISTORY_DISTRO_SPECS_TEMPLATE" != "settings as above" ];then
  HDSTpostfix="`echo -n "$xHISTORY_DISTRO_SPECS_TEMPLATE" | tr ' ' '_'`"
  #change all the variables to template values...
. support/HISTORY_DISTRO_SPECS_TEMPLATE_${HDSTpostfix}
  xDISTRO_NAME="$DISTRO_NAME"
  xDISTRO_VERSION="$DISTRO_VERSION"
  xDISTRO_BINARY_COMPAT="$DISTRO_BINARY_COMPAT"
  xDISTRO_FILE_PREFIX="$DISTRO_FILE_PREFIX"
  xDISTRO_COMPAT_VERSION="$DISTRO_COMPAT_VERSION"
  xDISTRO_KERNEL_PET="$DISTRO_KERNEL_PET" #100514
  xDISTRO_XORG_AUTO="DISTRO_XORG_AUTO" #110821
 fi

# if [ "$xDISTRO_BINARY_COMPAT" = "puppy" ];then
#  case $xDISTRO_COMPAT_VERSION in
#   2|3|4|5|6|7|8|9)
#    echo
#   ;;
#   *)
#    xmessage -center -bg red "ERROR:
#When the compatible-distro is 'puppy', the 'compatible-distro-version' must be
#set to a single-digit number, ex '4' (to build from the Puppy 4.x PET packages)"
#    return
#   ;;
#  esac
# fi

 nDFP=`echo -n "$xDISTRO_FILE_PREFIX" | wc -c`
# [ $nDFP -gt 4 ] && xmessage -center -bg pink "WARNING:
#DISTRO_FILE_PREFIX=${xDISTRO_FILE_PREFIX}, but recommend this be four characters or less,
#if you want to keep the Puppy files such as ${xDISTRO_FILE_PREFIX}-${xDISTRO_VERSION}.sfs within the
#MSDOS-compatible 8+3 filename limit (recommended in some boot situations)"

 DPSFILE=''
 if [ -f DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION} ];then
  DPSFILE="DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}"
 else
  [ -f DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT} ] && DPSFILE="DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}"
 fi
 if [ "$DPSFILE" = "" ];then
  xmessage -center -bg red "ERROR:
The 'Packages' and later tabs need a configuration file named 'DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}',
which does not exist. This file has a table of what packages are to be included in the
build of Puppy. 
If there is a similarly-named file, 'DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}-<something>',
a good starting point is to make a copy of it, named 'DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}'.

Aborting changes to file DISTRO_SPECS"
  return
 fi
 DCRFILE=''
 if [ -f DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION} ];then
  DCRFILE="DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}"
 else
  [ -f DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT} ] && DCRFILE="DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}"
 fi
 if [ "$DCRFILE" = "" ];then #130306
  xmessage -center -bg red "ERROR:
The 'Compat repos' and later tabs need a configuration file named 'DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}',
which does not exist. This file specifies the URLs where the compatible-distro packages
can be downloaded from. 
If there is a similarly-named file, 'DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}-<something>',
a good starting point is to make a copy of it, named 'DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}'.

Aborting changes to file DISTRO_SPECS"
  return
 fi
 cp -f DISTRO_SPECS /tmp/DISTRO_SPECS-backup
 cp -f support/HISTORY_DISTRO_SPECS /tmp/HISTORY_DISTRO_SPECS-backup
 HISTORY_DISTRO_NAME="`echo "$HISTORY_DISTRO_NAME" | head -n 10 | grep -v "^${xDISTRO_NAME}$"`"
 HISTORY_DISTRO_NAME="$xDISTRO_NAME
$HISTORY_DISTRO_NAME"
 echo "HISTORY_DISTRO_NAME='${HISTORY_DISTRO_NAME}'" > support/HISTORY_DISTRO_SPECS
 echo '#One or more words that identify this distribution:' > DISTRO_SPECS
 echo "DISTRO_NAME='${xDISTRO_NAME}'" >> DISTRO_SPECS
 echo '#version number of this distribution:' >> DISTRO_SPECS
 echo "DISTRO_VERSION=${xDISTRO_VERSION}" >> DISTRO_SPECS
 #echo '#A two-digit numeric value, minor-version number of this distribution:' >> DISTRO_SPECS
 #echo "DISTRO_MINOR_VERSION=${xDISTRO_MINOR_VERSION}" >> DISTRO_SPECS
 echo '#The distro whose binary packages were used to build this distribution:' >> DISTRO_SPECS
 echo "DISTRO_BINARY_COMPAT='${xDISTRO_BINARY_COMPAT}'" >> DISTRO_SPECS
 echo '#Prefix for some filenames: exs: '"${xDISTRO_FILE_PREFIX}save.2fs, ${xDISTRO_FILE_PREFIX}-${xDISTRO_VERSION}.sfs" >> DISTRO_SPECS
 HISTORY_DISTRO_FILE_PREFIX="`echo "$HISTORY_DISTRO_FILE_PREFIX" | head -n 10 | grep -v "^${xDISTRO_FILE_PREFIX}$"`"
 HISTORY_DISTRO_FILE_PREFIX="$xDISTRO_FILE_PREFIX
$HISTORY_DISTRO_FILE_PREFIX"
 echo "HISTORY_DISTRO_FILE_PREFIX='${HISTORY_DISTRO_FILE_PREFIX}'" >> support/HISTORY_DISTRO_SPECS
 echo "DISTRO_FILE_PREFIX='${xDISTRO_FILE_PREFIX}'" >> DISTRO_SPECS
 echo '#The version of the distro whose binary packages were used to build this distro:' >> DISTRO_SPECS
 HISTORY_DISTRO_COMPAT_VERSION="`echo "$HISTORY_DISTRO_COMPAT_VERSION" | head -n 10 | grep -v "^${xDISTRO_COMPAT_VERSION}$"`"
 HISTORY_DISTRO_COMPAT_VERSION="$xDISTRO_COMPAT_VERSION
$HISTORY_DISTRO_COMPAT_VERSION"
 echo "HISTORY_DISTRO_COMPAT_VERSION='${HISTORY_DISTRO_COMPAT_VERSION}'" >> support/HISTORY_DISTRO_SPECS
 echo "DISTRO_COMPAT_VERSION='${xDISTRO_COMPAT_VERSION}'" >> DISTRO_SPECS
 if [ "$xDISTRO_KERNEL_PET" ];then #100514
  echo '#the kernel pet package used:' >> DISTRO_SPECS
  #echo "DISTRO_KERNEL_PET='${CHOICE_KERNELPKG}'" >> support/HISTORY_DISTRO_SPECS
  echo "DISTRO_KERNEL_PET='${CHOICE_KERNELPKG}'" >> DISTRO_SPECS
 fi
 if [ "$xDISTRO_XORG_AUTO" ];then #110821
  echo '#read by /usr/bin/xwin to bypass Xorg Wizard at first boot:' >> DISTRO_SPECS
  echo "DISTRO_XORG_AUTO='$xDISTRO_XORG_AUTO'" >> DISTRO_SPECS
 fi
 #echo '#Earlier DISTRO_SPECS than was built in Woof:' >> support/HISTORY_DISTRO_SPECS
 #echo "HISTORY_DISTRO_SPECS_TEMPLATE='${xHISTORY_DISTRO_SPECS_TEMPLATE}'" >> support/HISTORY_DISTRO_SPECS
# echo "HISTORY_DISTRO_SPECS_TEMPLATES='${HISTORY_DISTRO_SPECS_TEMPLATES}'" >> support/HISTORY_DISTRO_SPECS
 #export XDIALOG_HIGH_DIALOG_COMPAT=1

 #121105 restore other variables that may have been in prior DISTRO_SPECS...
 for ONEDISTROVAR in `grep -o '^DISTRO_[^# =]*' /tmp/DISTRO_SPECS-backup | tr '\n' ' '`
 do
  odvPTN="^${ONEDISTROVAR}="
  if [ "`grep "$odvPTN" ./DISTRO_SPECS`" == "" ];then
   grep "$odvPTN" /tmp/DISTRO_SPECS-backup >> ./DISTRO_SPECS
  fi
 done

 Xdialog --center --title "DISTRO_SPECS" --backtitle "This is now the content of file 'DISTRO_SPECS'. Click OK button to continue" --no-cancel --textbox ./DISTRO_SPECS 0 0
}

ITEMSCOMP="<item>${DISTRO_BINARY_COMPAT}</item>"
for ONECHOICE in arch debian mageia puppy raspbian scientific slackware t2 ubuntu
do
 [ "$ONECHOICE" = "$DISTRO_BINARY_COMPAT" ] && continue
 ITEMSCOMP="${ITEMSCOMP}<item>${ONECHOICE}</item>"
done

echo -n "" > /tmp/woof_gui_items_hdn
echo "$HISTORY_DISTRO_NAME" |
while read ONECHOICE
do
 echo -n "<item>${ONECHOICE}</item>" >> /tmp/woof_gui_items_hdn
done
ITEMS_HDN="`cat /tmp/woof_gui_items_hdn`"

echo -n "" > /tmp/woof_gui_items_hdfp
echo "$HISTORY_DISTRO_FILE_PREFIX" |
while read ONECHOICE
do
 echo -n "<item>${ONECHOICE}</item>" >> /tmp/woof_gui_items_hdfp
done
ITEMS_HDFP="`cat /tmp/woof_gui_items_hdfp`"

echo -n "" > /tmp/woof_gui_items_hdcv
echo "$HISTORY_DISTRO_COMPAT_VERSION" |
while read ONECHOICE
do
 echo -n "<item>${ONECHOICE}</item>" >> /tmp/woof_gui_items_hdcv
done
ITEMS_HDCV="`cat /tmp/woof_gui_items_hdcv`"

HISTORY_DISTRO_SPECS_TEMPLATES="`ls -1 support/HISTORY_DISTRO_SPECS_TEMPLATE_* | sed -e 's%.*TEMPLATE_%%' -e 's%_% %g'`"
#echo -n "<item>${HISTORY_DISTRO_SPECS_TEMPLATE}</item>" > /tmp/woof_gui_items_hdst
echo -n "<item>settings as above</item>" > /tmp/woof_gui_items_hdst
echo "$HISTORY_DISTRO_SPECS_TEMPLATES" |
while read ONECHOICE
do
 #[ "$HISTORY_DISTRO_SPECS_TEMPLATE" = "$ONECHOICE" ] && continue
 echo -n "<item>${ONECHOICE}</item>" >> /tmp/woof_gui_items_hdst
done
ITEMS_HDST="`cat /tmp/woof_gui_items_hdst`"


########PET repos tab##########
edit_pet_repos_func() {
 cp -a -f /tmp/woof_gui_pet_repos /tmp/woof_gui_pet_repos2
 defaulttextviewer /tmp/woof_gui_pet_repos
 prDIFF="`diff -q /tmp/woof_gui_pet_repos /tmp/woof_gui_pet_repos2`"
 if [ "$prDIFF" != "" ];then
  prADD_LINE="`diff /tmp/woof_gui_pet_repos /tmp/woof_gui_pet_repos2 | grep '^< ' | head -n 1`"
  if [ "$prADD_LINE" != "" ];then
   prERR=''
   prADD_fc=`echo -n "$prADD_LINE" | sed -e 's%[^|]%%g' | wc -c`
   [ $prADD_fc -ne 2 ] && prERR="ERROR: wrong number of '|' delimiters in new entry. Aborting edit"
   prADD_PKGDB="`echo -n "$prADD_LINE" | cut -f 3 -d '|'`"
   [ "`echo "$prADD_PKGDB" | grep '^Packages-puppy-'`" = "" ] && prERR="ERROR: ${prADD_PKGDB} is named incorrectly. See Help button. Aborting change"
   if [ "$prERR" != "" ];then
    xmessage -center -bg red "$prERR"
    cp -a -f /tmp/woof_gui_pet_repos2 /tmp/woof_gui_pet_repos
    return
   fi
  fi
  xPET_REPOS="`cat /tmp/woof_gui_pet_repos | tr -s '\n' | tr '\n' ' ' | tr -s ' ' | sed -e 's% $%%'`"
  echo "$xPET_REPOS" | tr ' ' '\n' > /tmp/woof_gui_pet_repos
 fi
}

edit_pkg_docs_pet_repos_func() {
 cp -a -f /tmp/woof_gui_pkg_docs_pet_repos /tmp/woof_gui_pkg_docs_pet_repos2
 defaulttextviewer /tmp/woof_gui_pkg_docs_pet_repos
 prDIFF="`diff -q /tmp/woof_gui_pkg_docs_pet_repos /tmp/woof_gui_pkg_docs_pet_repos2`"
 if [ "$prDIFF" != "" ];then
  prADD_LINE="`diff /tmp/woof_gui_pkg_docs_pet_repos /tmp/woof_gui_pkg_docs_pet_repos2 | grep '^< ' | head -n 1`"
  prERR=''
  prADD_fc=`echo -n "$prADD_LINE" | sed -e 's%[^|]%%g' | wc -c`
  [ $prADD_fc -ne 2 ] && prERR="ERROR: wrong number of '|' delimiters in new entry. Aborting edit"
  prADD_PKGDB="`echo -n "$prADD_LINE" | cut -f 3 -d '|'`"
  [ "`echo "$prADD_PKGDB" | grep '^Packages-puppy-'`" = "" ] && prERR="ERROR: ${prADD_PKGDB} is named incorrectly. See Help button. Aborting change"
  if [ "$prERR" != "" ];then
   xmessage -center -bg red "$prERR"
   cp -a -f /tmp/woof_gui_pkg_docs_pet_repos2 /tmp/woof_gui_pkg_docs_pet_repos
   return
  fi
  xPKG_DOCS_PET_REPOS="`cat /tmp/woof_gui_pkg_docs_pet_repos | tr -s '\n' | tr '\n' ' ' | tr -s ' ' | sed -e 's% $%%'`"
  echo "$xPKG_DOCS_PET_REPOS" | tr ' ' '\n' > /tmp/woof_gui_pkg_docs_pet_repos
 fi
}

update_distro_pet_repos_func() {
 cp -f DISTRO_PET_REPOS /tmp/DISTRO_PET_REPOS-backup
 echo '#PKG_DOCS_PET_REPOS
#where to download the pet pkgs databases from.
#first field is for testing the url.
#second field is full URI of the database file.
#third field is name of db file when local and after being processed into standard format
# (in the case of PET databases, the names are the same and no processing is required)' > DISTRO_PET_REPOS
 xPKG_DOCS_PET_REPOS="`cat /tmp/woof_gui_pkg_docs_pet_repos | tr '\n' ' ' | tr -s ' ' | sed -e 's% $%%'`"
 echo "PKG_DOCS_PET_REPOS='${xPKG_DOCS_PET_REPOS}'" >> DISTRO_PET_REPOS
 echo  >> DISTRO_PET_REPOS
 echo '#PET_REPOS
#first field is for testing the url.
#second field is full URI of the repo
#third field is the name of db-file(s) associated with that repo. it may have glob wildcards.
# ex: Packages-puppy-4-official (note, url paths are in the database)'  >> DISTRO_PET_REPOS
 xPET_REPOS="`cat /tmp/woof_gui_pet_repos | tr '\n' ' ' | tr -s ' ' | sed -e 's% $%%'`"
 echo "PET_REPOS='${xPET_REPOS}'" >> DISTRO_PET_REPOS
 
# case $xDISTRO_BINARY_COMPAT in
#  puppy)
#   #w478 2/3: append Packages-puppy-4-official as a fallback, for some arch-independent pkgs...
#   case $xDISTRO_COMPAT_VERSION in #100730 110608
#    2) xPACKAGELISTS_PET_ORDER="Packages-puppy-common-official Packages-puppy-2-official Packages-puppy-4-official" ;;
#    3) xPACKAGELISTS_PET_ORDER="Packages-puppy-common-official Packages-puppy-3-official Packages-puppy-4-official" ;;
#    4) xPACKAGELISTS_PET_ORDER="Packages-puppy-common-official Packages-puppy-4-official Packages-puppy-3-official" ;;
#    *) xPACKAGELISTS_PET_ORDER="Packages-puppy-${xDISTRO_COMPAT_VERSION}-official Packages-puppy-common-official Packages-puppy-quirky-official Packages-puppy-4-official" ;;
#   esac
#  ;;
#  *)
#   xPACKAGELISTS_PET_ORDER="Packages-puppy-common-official Packages-puppy-quirky-official Packages-puppy-4-official"
#  ;;
# esac
# echo >> DISTRO_PET_REPOS
# echo '#this defines where Woof looks first and second (and third, etc.) for pet pkgs' >> DISTRO_PET_REPOS
# echo "PACKAGELISTS_PET_ORDER='${xPACKAGELISTS_PET_ORDER}'" >> DISTRO_PET_REPOS

 #110608 simplify search order...
 xPACKAGELISTS_PET_ORDER='Packages-puppy-common-official Packages-puppy-4-official'
 #exs of DISTRO_COMPAT_VERSION: wary5, lucid, 4
 [ "$xDISTRO_COMPAT_VERSION" != "4" ] && [ -f Packages-puppy-${xDISTRO_COMPAT_VERSION}-official ] && xPACKAGELISTS_PET_ORDER="Packages-puppy-${xDISTRO_COMPAT_VERSION}-official ${xPACKAGELISTS_PET_ORDER}"
 echo "PACKAGELISTS_PET_ORDER='${xPACKAGELISTS_PET_ORDER}'" >> DISTRO_PET_REPOS

 Xdialog --center --title "DISTRO_PET_REPOS" --backtitle "This is now the content of file 'DISTRO_PET_REPOS'. Click OK button to continue" --no-cancel --textbox ./DISTRO_PET_REPOS 0 0
}

#########Compat repos tab#####
edit_compat_repos_func() {
 cp -a -f /tmp/woof_gui_compat_repos /tmp/woof_gui_compat_repos2
 defaulttextviewer /tmp/woof_gui_compat_repos
 prDIFF="`diff -q /tmp/woof_gui_compat_repos /tmp/woof_gui_compat_repos2`"
 if [ "$prDIFF" != "" ];then
  prADD_LINE="`diff /tmp/woof_gui_compat_repos /tmp/woof_gui_compat_repos2 | grep '^< ' | head -n 1`"
  if [ "$prADD_LINE" != "" ];then
   prERR=''
   prADD_fc=`echo -n "$prADD_LINE" | sed -e 's%[^|]%%g' | wc -c`
   [ $prADD_fc -ne 2 ] && prERR="ERROR: wrong number of '|' delimiters in new entry. Aborting edit"
   prADD_PKGDB="`echo -n "$prADD_LINE" | cut -f 3 -d '|'`"
   [ "`echo "$prADD_PKGDB" | grep '^Packages-'`" = "" ] && prERR="ERROR: ${prADD_PKGDB} is named incorrectly. See Help button. Aborting change"
   if [ "$prERR" != "" ];then
    xmessage -center -bg red "$prERR"
    cp -a -f /tmp/woof_gui_compat_repos2 /tmp/woof_gui_compat_repos
    return
   fi
  fi
  xCOMPAT_REPOS="`cat /tmp/woof_gui_compat_repos | tr -s '\n' | tr '\n' ' ' | tr -s ' ' | sed -e 's% $%%'`"
  echo "$xCOMPAT_REPOS" | tr ' ' '\n' > /tmp/woof_gui_compat_repos
 fi
}

edit_pkg_docs_compat_repos_func() {
 cp -a -f /tmp/woof_gui_pkg_docs_compat_repos /tmp/woof_gui_pkg_docs_compat_repos2
 defaulttextviewer /tmp/woof_gui_pkg_docs_compat_repos
 prDIFF="`diff -q /tmp/woof_gui_pkg_docs_compat_repos /tmp/woof_gui_pkg_docs_compat_repos2`"
 if [ "$prDIFF" != "" ];then
  prADD_LINE="`diff /tmp/woof_gui_pkg_docs_compat_repos /tmp/woof_gui_pkg_docs_compat_repos2 | grep '^< ' | head -n 1`"
  prERR=''
  prADD_fc=`echo -n "$prADD_LINE" | sed -e 's%[^|]%%g' | wc -c`
  [ $prADD_fc -ne 2 ] && prERR="ERROR: wrong number of '|' delimiters in new entry. Aborting edit"
  prADD_PKGDB="`echo -n "$prADD_LINE" | cut -f 3 -d '|'`"
  [ "`echo "$prADD_PKGDB" | grep '^Packages-'`" = "" ] && prERR="ERROR: ${prADD_PKGDB} is named incorrectly. See Help button. Aborting change"
  if [ "$prERR" != "" ];then
   xmessage -center -bg red "$prERR"
   cp -a -f /tmp/woof_gui_pkg_docs_compat_repos2 /tmp/woof_gui_pkg_docs_compat_repos
   return
  fi
  xPKG_DOCS_COMPAT_REPOS="`cat /tmp/woof_gui_pkg_docs_compat_repos | tr -s '\n' | tr '\n' ' ' | tr -s ' ' | sed -e 's% $%%'`"
  echo "$xPKG_DOCS_COMPAT_REPOS" | tr ' ' '\n' > /tmp/woof_gui_pkg_docs_compat_repos
 fi
}

update_distro_compat_repos_func() {
 #cp -f DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} /tmp/DISTRO_COMPAT_REPOS-backup
 cp -f $DCRFILE /tmp/DISTRO_COMPAT_REPOS-backup #130306
 echo '#PKG_DOCS_DISTRO_COMPAT
#where to download the compatible-distro pkgs databases from.
#first field is for testing the url.
#second field is full URI of the database file.
#third field is name of db file when local and after being processed into standard format' > $DCRFILE #130306 DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
 xPKG_DOCS_COMPAT_REPOS="`cat /tmp/woof_gui_pkg_docs_compat_repos | tr '\n' ' ' | tr -s ' ' | sed -e 's% $%%'`"
 echo "PKG_DOCS_DISTRO_COMPAT='${xPKG_DOCS_COMPAT_REPOS}'" >> $DCRFILE #130306 DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
 #echo 'PKG_DOCS_DISTRO_COMPAT="$PKG_DOCS_COMPAT_REPOS" #older equiv. name.' >> DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
 echo  >> $DCRFILE #130306 DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
 echo '#REPOS_DISTRO_COMPAT
#first field is for testing the url.
#second field is full URI of the repo
#third field is the name of db-file(s) associated with that repo. it may have glob wildcards.'  >> $DCRFILE #130306 DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
 xCOMPAT_REPOS="`cat /tmp/woof_gui_compat_repos | tr '\n' ' ' | tr -s ' ' | sed -e 's% $%%'`"
 echo "REPOS_DISTRO_COMPAT='${xCOMPAT_REPOS}'" >> $DCRFILE #130306 DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
 #echo 'REPOS_DISTRO_COMPAT="$COMPAT_REPOS" #older equiv. name.' >> DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
 Xdialog --center --title "${DCRFILE}" --backtitle "This is now the content of file '${DCRFILE}'. Click OK button to continue" --no-cancel --textbox ./${DCRFILE} 0 0 #130306
}

#####Download dbs######
PET_REPOS_LIST_ONLINE="`echo "$PKG_DOCS_PET_REPOS" | tr ' ' '\n' | cut -f 3 -d '|' | sort -u`"
PET_REPOS_LIST_LOCAL="`ls -1 Packages-puppy-*`"
echo -n "" > /tmp/PET_REPOS_LIST_LOCAL
for ONE_DB in $PET_REPOS_LIST_LOCAL
do
 [ "`echo "$PET_REPOS_LIST_ONLINE" | grep "^${ONE_DB}$"`" != "" ] && echo "$ONE_DB" >> /tmp/PET_REPOS_LIST_LOCAL
done
PET_REPOS_LIST_LOCAL="`cat /tmp/PET_REPOS_LIST_LOCAL`"
PKG_DOCS_DISTRO_COMPAT_LIST_ONLINE="`echo "$PKG_DOCS_DISTRO_COMPAT" | tr ' ' '\n' | cut -f 3 -d '|' | sort -u`"
echo -n "" > /tmp/PKG_DOCS_DISTRO_COMPAT_LIST_LOCAL
for ONE_DB in $PKG_DOCS_DISTRO_COMPAT_LIST_ONLINE
do
 [ -f $ONE_DB ] && echo "$ONE_DB" >> /tmp/PKG_DOCS_DISTRO_COMPAT_LIST_LOCAL
done
PKG_DOCS_DISTRO_COMPAT_LIST_LOCAL="`cat /tmp/PKG_DOCS_DISTRO_COMPAT_LIST_LOCAL`"
#in some cases, the "online" db is not available online. Then 1st and 2nd fields are empty...
PKG_DOCS_DISTRO_COMPAT_LIST_ONLINE="`echo "$PKG_DOCS_DISTRO_COMPAT" | tr ' ' '\n' | grep -v '||' | cut -f 3 -d '|' | sort -u`"

report_0setup_func() {
 if [ ! -f /var/woof/0setup_fail_report_no ];then
  xmessage -center -bg red "ERROR: Must run 'UPDATE' first"
  return
 fi
 xmessage -center -bg pink "`cat /var/woof/0setup_fail_report_no`"
}

########Choose pkgs#######
#has 2 variables, FALLBACKS_COMPAT_VERSIONS and PKGS_SPECS_TABLE
if [ ! -f /tmp/CHOSEN_PET_PKGS -o ! -f /tmp/CHOSEN_COMPAT_PKGS ];then
 xmessage -center -bg orange -buttons "" "Please wait, processing..." &
 WAITPID=$!
 CHOSEN_PET_PKGS="`echo "$PKGS_SPECS_TABLE" | grep '^yes' | grep '||' | cut -f 2 -d '|'`"
 #add a description...
 echo -n "" > /tmp/CHOSEN_PET_PKGS
 for ONE_CPP in $CHOSEN_PET_PKGS
 do
  ocppPATTERN='|'"$ONE_CPP"'|'
  ocppDESCR="`cat $PACKAGELISTS_PET_ORDER | grep "$ocppPATTERN" | head -n 1 | cut -f 10 -d '|'`"
  echo "${ONE_CPP}|${ocppDESCR}" >> /tmp/CHOSEN_PET_PKGS
 done
 #add a description...
 echo -n "" > /tmp/CHOSEN_COMPAT_PKGS
 if [ "$DISTRO_BINARY_COMPAT" = "puppy" ];then
  CHOSEN_COMPAT_PKGS="`echo "$PKGS_SPECS_TABLE" | grep '^yes' | grep -v '||' | cut -f 2 -d '|'`"
  PACKAGELISTS_COMPAT="`echo "$PKG_DOCS_DISTRO_COMPAT" | tr ' ' '\n' | cut -f 3 -d '|' | tr '\n' ' '`"
  for ONE_CCP in $CHOSEN_COMPAT_PKGS
  do
   occpPATTERN='|'"$ONE_CCP"'|'
   occpDESCR="`cat $PACKAGELISTS_COMPAT | grep "$occpPATTERN" | head -n 1 | cut -f 10 -d '|'`"
   echo "${ONE_CCP}|${occpDESCR}" >> /tmp/CHOSEN_COMPAT_PKGS
  done
 else
  CHOSEN_COMPAT_PKGS="`echo "$PKGS_SPECS_TABLE" | grep '^yes' | grep -v '||' | cut -f 2,3 -d '|'`"
  PACKAGELISTS_COMPAT="`echo "$PKG_DOCS_DISTRO_COMPAT" | tr ' ' '\n' | cut -f 3 -d '|' | tr '\n' ' '`"
  for ONE_CCP in $CHOSEN_COMPAT_PKGS
  do
   ccpCOMPAT="`echo -n "$ONE_CCP" | cut -f 2 -d '|' | cut -f 1 -d ','`"
   ccpGENERIC="`echo -n "$ONE_CCP" | cut -f 1 -d '|'`"
   occpPATTERN='|'"$ccpGENERIC"'|'
   ccpcPATTERN='|'"$ccpCOMPAT"'|'
   occpDESCR="`cat $PACKAGELISTS_COMPAT | grep "$occpPATTERN" | head -n 1 | cut -f 10 -d '|'`"
   [ "$occpDESCR" = "" ] && occpDESCR="`cat $PACKAGELISTS_COMPAT | grep "$ccpcPATTERN" | head -n 1 | cut -f 10 -d '|'`"
   echo "${ccpGENERIC}|${occpDESCR}" >> /tmp/CHOSEN_COMPAT_PKGS
  done
 fi
 #echo "$CHOSEN_COMPAT_PKGS" > /tmp/CHOSEN_COMPAT_PKGS
 echo "$PACKAGELISTS_COMPAT" > /tmp/PACKAGELISTS_COMPAT
 kill $WAITPID
fi

add_remove_pet_pkgs_func() {
 xmessage -center -bg orange -buttons "" "Please wait, processing..." &
 WAITPID=$!
 ./findwoofinstalledpkgs >/dev/null #writes db entries to /tmp/woof-installed-packages-pet and /tmp/woof-installed-packages-compat
 #ex: bash-3.0.16-1|bash|3.0.16-1||BuildingBlock|498K|pet_packages-woof|bash-3.0.16-1.pet|+ncurses|Bash shell|puppy|412|woof|
 CHOSEN_ENTRIES="`cat /tmp/woof-installed-packages-pet | tr -d '"' | sed -e 's%|% %' -e 's%|% on "%' -e 's%$%"%'`" #'geany
 #...ex: bash-3.0.16-1 bash on "3.0.16-1||BuildingBlock|498K|pet_packages-woof|bash-3.0.16-1.pet|+ncurses|Bash shell|puppy|412|woof|"
 cppPATTERNS="`cat /tmp/CHOSEN_PET_PKGS | cut -f 1 -d '|' | sed -e 's%^%|%' -e 's%$%|%'`"
 echo "$cppPATTERNS" > /tmp/cppPATTERNS
 grep --file=/tmp/cppPATTERNS -v $PACKAGELISTS_PET_ORDER > /tmp/NOT_CHOSEN_PETS_DB_RAW #note: grep prepends <filename>: on each line.
 NOT_CHOSEN_ENTRIES="`cat /tmp/NOT_CHOSEN_PETS_DB_RAW | cut -f 2-9 -d ':' | tr -d '"' | sed -e 's%|% %' -e 's%|% off "%' -e 's%$%"%'`" #'geany
 #...ex: bash-3.0.16-1 bash off "3.0.16-1||BuildingBlock|498K|pet_packages-woof|bash-3.0.16-1.pet|+ncurses|Bash shell|puppy|412|woof|"
 kill $WAITPID
 EXECME="Xdialog --backtitle \"The right pane has the chosen PET packages, left pane has unchosen pkgs. Note that mouseover displays further database details\" --title \"Choose PET packages\" --left --stdout --separator \" \" --item-help --buildlist \"\" 0 0 8 ${CHOSEN_ENTRIES} ${NOT_CHOSEN_ENTRIES} >/tmp/cpp_rettags.txt"
 eval $EXECME
 if [ $? -eq 0 ];then
  rtPATTERNS="`cat /tmp/cpp_rettags.txt | tr ' ' '\n' | sed -e 's%^%^%' -e 's%$%|%'`"
  echo "$rtPATTERNS" > /tmp/rtPATTERNS
  NEW_CHOSEN_GENERICNAMES="`cat $PACKAGELISTS_PET_ORDER | grep --file=/tmp/rtPATTERNS | cut -f 2 -d '|' | sort -u`"
  OLD_CHOSEN_GENERICNAMES="`cat /tmp/woof-installed-packages-pet | cut -f 2 -d '|' | sort -u`"
  echo "$NEW_CHOSEN_GENERICNAMES" > /tmp/NEW_CHOSEN_GENERICNAMES
  echo "$OLD_CHOSEN_GENERICNAMES" > /tmp/OLD_CHOSEN_GENERICNAMES
  rtDIFF="`diff /tmp/OLD_CHOSEN_GENERICNAMES /tmp/NEW_CHOSEN_GENERICNAMES`"
  PET_ADDED="`echo "$rtDIFF" | grep '^> ' | cut -f 2 -d ' '`"   #generic names only, one each line.
  PET_REMOVED="`echo "$rtDIFF" | grep '^< ' | cut -f 2 -d ' '`" # "
  if [ "$PET_REMOVED" != "" ];then
   prPATTERNS="`echo "$PET_REMOVED" | sed -e 's%^%|%' -e 's%$%|%'`"
   echo "$prPATTERNS" > /tmp/prPATTERNS
   PKGS_SPECS_TABLE="`echo "$PKGS_SPECS_TABLE" | grep --file=/tmp/prPATTERNS -v`"
  fi
  ####for now, create new entry 'yes|<genericname>||exe'
  ####but need to ask about the last field....
  echo "$PKGS_SPECS_TABLE" > /tmp/PKGS_SPECS_TABLE
  if [ "$PET_ADDED" != "" ];then
   NEW_ENTRIES="`echo "$PET_ADDED" | sed -e 's%^%yes|%' -e 's%$%||exe%'`"
   echo "$NEW_ENTRIES" >> /tmp/PKGS_SPECS_TABLE
   #important note, order is important. ex, seamonkey must come before the seamonkey_addon pkgs,
   #as former has symlink /usr/lib/seamonkey, latter have it as an actual directory. The param
   #'--key=2,2' takes care of the seamonkey case, sort on field 2 only...
   PKGS_SPECS_TABLE="`sort --key=2,2 --field-separator='|' --unique /tmp/PKGS_SPECS_TABLE`"
   echo "$PKGS_SPECS_TABLE" > /tmp/PKGS_SPECS_TABLE
  fi
  #update for gui...
  echo -n "" > /tmp/CHOSEN_PET_PKGS
  for ONE_CPP in $NEW_CHOSEN_GENERICNAMES
  do
   ocppPATTERN='|'"$ONE_CPP"'|'
   ocppDESCR="`cat $PACKAGELISTS_PET_ORDER | grep "$ocppPATTERN" | head -n 1 | cut -f 10 -d '|'`"
   echo "${ONE_CPP}|${ocppDESCR}" >> /tmp/CHOSEN_PET_PKGS
  done
  #update DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}...
  echo 'Fallbacks when looking for pkgs (space-separated list of distro versions)...' > ${DPSFILE}
  echo "FALLBACKS_COMPAT_VERSIONS='$FALLBACKS_COMPAT_VERSIONS'" >> ${DPSFILE}
  echo '
#PKGS_SPECS_TABLE table format:
#will pkg be in puppy-build.
#    Generic name for pkg. Note: PET packages, if exist, use this name.
#            Comma-separated list of compatible-distro pkg(s). "-" prefix, exclude.
#            Must be exact name-only of pkg, else "*" on end is wildcard to search full name.
#            Empty field, then use PET pkg.
#                                    How the package will get split up in woof (optional redirection ">" operator).
#                                    Missing field, it goes into exe. Can also redirect >null, means dump it.
#yes|abiword|iceword,iceword-plugins|exe,dev,doc,nls
#example showing wildcard. finds all full pkg names with "gcc-4.3*",
#but, exclude any "gcc-4.3-doc*" matches...
#yes|gcc|gcc,gcc-4.3*,-gcc-4.3-doc*|exe,dev,doc,nls
' >> ${DPSFILE}
  echo "PKGS_SPECS_TABLE='$PKGS_SPECS_TABLE'" >> ${DPSFILE}
  Xdialog --center --title "PET selection change" --msgbox "These PET packages have been added:\n
${PET_ADDED}\n
These PET packages have been removed:\n
${PET_REMOVED}\n
The changes have been made to variable 'PKGS_SPECS_TABLE'\n
in file ${DPSFILE}" 0 0
 fi
}

add_remove_compat_pkgs_func() {
 if [ "$DISTRO_BINARY_COMPAT" != "puppy" ];then
  xmessage -center -bg pink "SORRY, currently this must be done manually."
  return
 fi
 xmessage -center -bg orange -buttons "" "Please wait, processing..." &
 WAITPID=$!
 ./findwoofinstalledpkgs >/dev/null #writes db entries to /tmp/woof-installed-packages-pet and /tmp/woof-installed-packages-compat
 #ex: abiword_2.6.6|abiword|2.6.6|0ubuntu1|Document|7808K|pool/main/a/abiword|abiword_2.6.6-0ubuntu1_i386.deb|+libaiksaurus-1.2-0c2a,+libaiksaurusgtk-1.2-0c2a,+libart-2.0-2,+libatk1.0-0,+libc6,+libcairo2,+libenchant1c2a,+libexpat1,+libfontconfig1,+libfreetype6,+libfribidi0,+libgcc1,+libglade2-0,+libglib2.0-0,+libgnomecanvas2-0,+libgnomeprint2.2-0,+libgnomeprintui2.2-0,+libgsf-1-114,+libgtk2.0-0,+libice6,+libidn11,+libjpeg62,+libloudmouth1-0,+libncurses5,+libots0,+libpango1.0-0,+libpng12-0,+libpopt0,+libreadline5,+librsvg2-2,+libsm6,+libstdc++6,+libwmf0.2-7,+libwpd8c2a,+libwpg-0.1-1,+libwv-1.2-3|efficient featureful word processor with collaboration|
 CHOSEN_ENTRIES="`cat /tmp/woof-installed-packages-compat | tr -d '"' | sed -e 's%|% %' -e 's%|% on "%' -e 's%$%"%'`" #'geany
 #...ex: abiword_2.6.6 abiword on "2.6.6|0ubuntu1|Document|7808K|pool/main/a/abiword|abiword_2.6.6-0ubuntu1_i386.deb|+libaiksaurus-1.2-0c2a,+libaiksaurusgtk-1.2-0c2a,+libart-2.0-2,+libatk1.0-0,+libc6,+libcairo2,+libenchant1c2a,+libexpat1,+libfontconfig1,+libfreetype6,+libfribidi0,+libgcc1,+libglade2-0,+libglib2.0-0,+libgnomecanvas2-0,+libgnomeprint2.2-0,+libgnomeprintui2.2-0,+libgsf-1-114,+libgtk2.0-0,+libice6,+libidn11,+libjpeg62,+libloudmouth1-0,+libncurses5,+libots0,+libpango1.0-0,+libpng12-0,+libpopt0,+libreadline5,+librsvg2-2,+libsm6,+libstdc++6,+libwmf0.2-7,+libwpd8c2a,+libwpg-0.1-1,+libwv-1.2-3|efficient featureful word processor with collaboration|"
 ccpPATTERNS="`cat /tmp/CHOSEN_COMPAT_PKGS | cut -f 1 -d '|' | sed -e 's%^%|%' -e 's%$%|%'`"
 echo "$ccpPATTERNS" > /tmp/ccpPATTERNS
 PACKAGELISTS_COMPAT="`cat /tmp/PACKAGELISTS_COMPAT`"
 grep --file=/tmp/ccpPATTERNS -v $PACKAGELISTS_COMPAT > /tmp/NOT_CHOSEN_COMPATS_DB_RAW #note: grep prepends <filename>: on each line.
 
 ####UNCHOSEN ENTRIES MAY BE TOO BIG!#####
 ####may need to add category filtering, plus for debian get rid of those language pkgs####
# #w091018 ubuntu/debian not-chosen list is too long for Xdialog. for now, until i can think of anything better...
# nceFIRST="`Xdialog --title "Choose compat-repo pkgs by alphabet" --left --stdout --no-tags --no-cancel --radiolist "Some package repos are enormous (ex: Ubuntu/Debian) and the Xdialog\n
#tool used for the GUI cannot handle a long list of all of them.\n
#Until I think of a better way of doing it, this cumbersome method\n
#is used -- choose by first character. For example, if you want to\n
#add 'sylpheed' to Puppy, choose 's' here..." 0 0 0 0-9 0-9 off aA a on bB b off cC c off dD d off eE e off fF f off gG g off hH h off iI i off jJ j off kK k off lL l off mM m off nN n off oO o off pP p off qQ q off rR r off sS s off tT t off uU u off vV v off wW w off xX x off yY y off zZ z off`"
# [ "$nceFIRST" = "" -o $? -ne 0 ] && nceFIRST='aA'
# ncePATTERN="^[${nceFIRST}]"
# #and add ncePATTERN here to extract alphabetical pkgs only...
# NOT_CHOSEN_ENTRIES="`cat /tmp/NOT_CHOSEN_COMPATS_DB_RAW | cut -f 2-9 -d ':' | grep "$ncePATTERN" | tr -d '"' | sed -e 's%|% %' -e 's%|% off "%' -e 's%$%"%'`" #'geany
 
 NOT_CHOSEN_ENTRIES="`cat /tmp/NOT_CHOSEN_COMPATS_DB_RAW | cut -f 2-9 -d ':' | tr -d '"' | sed -e 's%|% %' -e 's%|% off "%' -e 's%$%"%'`" #'geany
 #...ex: abiword_2.6.6 abiword off "2.6.6|0ubuntu1|Document|7808K|pool/main/a/abiword|abiword_2.6.6-0ubuntu1_i386.deb|+libaiksaurus-1.2-0c2a,+libaiksaurusgtk-1.2-0c2a,+libart-2.0-2,+libatk1.0-0,+libc6,+libcairo2,+libenchant1c2a,+libexpat1,+libfontconfig1,+libfreetype6,+libfribidi0,+libgcc1,+libglade2-0,+libglib2.0-0,+libgnomecanvas2-0,+libgnomeprint2.2-0,+libgnomeprintui2.2-0,+libgsf-1-114,+libgtk2.0-0,+libice6,+libidn11,+libjpeg62,+libloudmouth1-0,+libncurses5,+libots0,+libpango1.0-0,+libpng12-0,+libpopt0,+libreadline5,+librsvg2-2,+libsm6,+libstdc++6,+libwmf0.2-7,+libwpd8c2a,+libwpg-0.1-1,+libwv-1.2-3|efficient featureful word processor with collaboration|"
 #xNOT_CHOSEN_ENTRIES="`echo "$NOT_CHOSEN_ENTRIES" | tr '\n' ' '`"
 #xCHOSEN_ENTRIES="`echo "$CHOSEN_ENTRIES" | tr '\n' ' '`"
 kill $WAITPID
 EXECME="Xdialog --backtitle \"The right pane has the chosen packages, left pane has unchosen pkgs. Note that mouseover displays further database details\" --title \"Choose compat-distro packages\" --left --stdout --separator \" \" --item-help --buildlist \"\" 0 0 8 ${CHOSEN_ENTRIES} ${NOT_CHOSEN_ENTRIES} >/tmp/ccp_rettags.txt"
 echo "$EXECME" > /tmp/woof_gui_not_chosen_items #TEST
 eval $EXECME
 if [ $? -eq 0 ];then
  rtPATTERNS="`cat /tmp/ccp_rettags.txt | tr ' ' '\n' | sed -e 's%^%^%' -e 's%$%|%'`"
  echo "$rtPATTERNS" > /tmp/rtPATTERNS
  NEW_CHOSEN_GENERICNAMES="`cat $PACKAGELISTS_COMPAT | grep --file=/tmp/rtPATTERNS | cut -f 2 -d '|' | sort -u`"
  OLD_CHOSEN_GENERICNAMES="`cat /tmp/woof-installed-packages-compat | cut -f 2 -d '|' | sort -u`"
  echo "$NEW_CHOSEN_GENERICNAMES" > /tmp/NEW_CHOSEN_GENERICNAMES
  echo "$OLD_CHOSEN_GENERICNAMES" > /tmp/OLD_CHOSEN_GENERICNAMES
  rtDIFF="`diff /tmp/OLD_CHOSEN_GENERICNAMES /tmp/NEW_CHOSEN_GENERICNAMES`"
  COMPAT_ADDED="`echo "$rtDIFF" | grep '^> ' | cut -f 2 -d ' '`"   #generic names only, one each line.
  COMPAT_REMOVED="`echo "$rtDIFF" | grep '^< ' | cut -f 2 -d ' '`" # "
  if [ "$COMPAT_REMOVED" != "" ];then
   prPATTERNS="`echo "$COMPAT_REMOVED" | sed -e 's%^%[|,]%' -e 's%$%[|,]%'`" #finds an entry in 3rd field of PKGS_SPECS_TABLE
   echo "$prPATTERNS" > /tmp/prPATTERNS
   PKGS_SPECS_TABLE="`echo "$PKGS_SPECS_TABLE" | grep --file=/tmp/prPATTERNS -v`"
  fi
  ####for now, create new entry 'yes|<genericname>|<genericname>|exe,dev,doc,nls'
  ####but need to ask about the last field....
  ####also for debian/ubuntu many pkgs are split into smaller pkgs, may want to bring them together.
  ####if compat-distro=puppy, merge _DEV into any pre-existing entry (?)
  echo "$PKGS_SPECS_TABLE" > /tmp/PKGS_SPECS_TABLE
  if [ "$COMPAT_ADDED" != "" ];then
   #NEW_ENTRIES="`echo "$COMPAT_ADDED" | sed -e 's%^%yes|%' -e 's%$%||exe%'`"
   #echo "$NEW_ENTRIES" >> /tmp/PKGS_SPECS_TABLE
   for ONE_CA in $COMPAT_ADDED
   do
    echo "yes|${ONE_CA}|${ONE_CA}|exe,dev,doc,nls" >> /tmp/PKGS_SPECS_TABLE
   done
   #important note, order is important. ex, seamonkey must come before the seamonkey_addon pkgs,
   #as former has symlink /usr/lib/seamonkey, latter have it as an actual directory. The param
   #'--key=2,2' takes care of the seamonkey case, sort on field 2 only...
   PKGS_SPECS_TABLE="`sort --key=2,2 --field-separator='|' --unique /tmp/PKGS_SPECS_TABLE`"
   echo "$PKGS_SPECS_TABLE" > /tmp/PKGS_SPECS_TABLE
  fi

  #update for gui...
  echo -n "" > /tmp/CHOSEN_COMPAT_PKGS
  for ONE_CCP in $NEW_CHOSEN_GENERICNAMES
  do
   occpPATTERN='|'"$ONE_CCP"'|'
   occpDESCR="`cat $PACKAGELISTS_COMPAT | grep "$occpPATTERN" | head -n 1 | cut -f 10 -d '|'`"
   echo "${ONE_CCP}|${occpDESCR}" >> /tmp/CHOSEN_COMPAT_PKGS
  done
  #update DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}...
  echo "FALLBACKS_COMPAT_VERSIONS='$FALLBACKS_COMPAT_VERSIONS'" > ${DPSFILE}
  echo "PKGS_SPECS_TABLE='$PKGS_SPECS_TABLE'" >> ${DPSFILE}
  Xdialog --center --title "Compat-distro package selection change" --msgbox "These packages have been added:\n
${COMPAT_ADDED}\n
These packages have been removed:\n
${COMPAT_REMOVED}\n
The changes have been made to variable 'PKGS_SPECS_TABLE'\n
in file ${DPSFILE}" 0 0
 fi
}

check_dependencies_func() {
 xmessage "COMING SOON"
}

#######Download pkgs#####
download_summary_func() {
 xmessage "COMING SOON"
}

########Build pkgs########
CHOSEN_GENERICNAMES="`echo "$PKGS_SPECS_TABLE" | grep -v '^#' | grep '^yes' | cut -f 2 -d '|'`"
if [ -s /var/cache/woof/2createpackages_history_builds-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then
 ITEMS_CG="<item>CHANGED_ONLY</item><item>ALL_PACKAGES</item>" #091211
else
 ITEMS_CG="<item>ALL_PACKAGES</item>"
fi
ITEMS_CG="${ITEMS_CG} `echo "$CHOSEN_GENERICNAMES" | sed -e 's%^%<item>%' -e 's%$%</item>%' | tr '\n' ' '`"

createpackages_summary_func() {
 xmessage "COMING SOON"
}

#######Build distro#######
AVAILKERNELS="`ls -1 packages-pet/linux_kernel-*.pet`"
ITEMS_AK=""
[ "$DISTRO_KERNEL_PET" ] && ITEMS_AK='<item>'"$DISTRO_KERNEL_PET"'</item>' #should be in DISTRO_SPECS.
for ONE_AK in $AVAILKERNELS
do
 BASE_AK="`basename $ONE_AK`"
 [ "$BASE_AK" = "$DISTRO_KERNEL_PET" ] && continue
 ITEMS_AK="${ITEMS_AK}<item>${BASE_AK}</item>"
done

ITEMS_SCSI0='<item>'"$HISTORY_wantscsi"'</item>' #see support/HISTORY_3builddistro
ITEMS_SCSI="${ITEMS_SCSI0}`echo 'Erase_SCSI Keep_SCSI Boot_SCSI' | tr ' ' '\n' | grep -v "$HISTORY_wantscsi" | sed -e 's%^%<item>%' -e 's%$%</item>%'`"

ITEMS_BIGMODEM0='<item>'"$HISTORY_bigmodem"'</item>' #see support/HISTORY_3builddistro
ITEMS_BIGMODEM="${ITEMS_BIGMODEM0}`echo 'Erase_big_modems Keep_big_modems Zdrv_big_modems' | tr ' ' '\n' | grep -v "$HISTORY_bigmodem" | sed -e 's%^%<item>%' -e 's%$%</item>%'`"

CHK_FB_DEFAULT="$HISTORY_CHK_FB_STATE"

CHK_EXOTIC_DEFAULT="$HISTORY_CHK_EXOTIC_STATE"
CHK_RADICAL_DEFAULT="$HISTORY_CHK_RADICAL_STATE"
CHK_SIMPLE_FILENAMES_DEFAULT="$HISTORY_CHK_SIMPLE_FILENAMES_STATE" #100912

save_builddistro_options_func() {
 cp -f support/HISTORY_3builddistro /tmp/HISTORY_3builddistro-backup1
 echo "
HISTORY_KERNELPKG='${CHOICE_KERNELPKG}'
HISTORY_wantscsi='${CHOICE_SCSI}'
HISTORY_bigmodem='${CHOICE_BIGMODEM}'
HISTORY_CHK_FB_STATE='${CHK_FB_STATE}'
HISTORY_CHK_EXOTIC_STATE='${CHK_EXOTIC_STATE}'
HISTORY_CHK_RADICAL_STATE='${CHK_RADICAL_STATE}'
HISTORY_CHK_SIMPLE_FILENAMES_STATE='${CHK_SIMPLE_FILENAMES_STATE}'" > support/HISTORY_3builddistro #100912
 #100514 if defined in file DISTRO_SPECS, update...
 dkpPATTERN="s%^DISTRO_KERNEL_PET.*%DISTRO_KERNEL_PET='${CHOICE_KERNELPKG}'%"
 sed -i -e "$dkpPATTERN" ./DISTRO_SPECS
}

export MAIN_DIALOG="
<window title=\"Woof: the Puppy builder\" icon-name=\"gtk-preferences\" >
<vbox>
  <notebook page=\"${DEFAULTTABNUM}\" labels=\"Specifications|PET repos|Compat repos|Download dbs|Choose pkgs|Download pkgs|Build pkgs|Kernel options|Build distro\">
    
    <vbox>
      <hbox>
      <text use-markup=\"true\"><label>\"<b>These are the highest-level settings for building Puppy</b>\"</label></text>
      <text><label>Note, where appropriate, older choices are in a drop-down list on the right. Choose and click the left-arrow button for speedy selection of an older choice</label></text>
      </hbox>
      <hbox>
        <text><label>A title for this build:</label></text>
        <entry>
          <input>cat /tmp/woof_gui_dn</input>
          <variable>xDISTRO_NAME</variable>
        </entry>
        <text><label>\"(Any title, one to three words)\"</label></text>
        <button><input file stock=\"gtk-go-back\"></input><action>echo \$xHISTORY_DISTRO_NAME > /tmp/woof_gui_dn</action><action type=\"refresh\">xDISTRO_NAME</action></button>
        <combobox><variable>xHISTORY_DISTRO_NAME</variable>${ITEMS_HDN}</combobox>
      </hbox>
      <hbox>
        <text><label>Puppy version number:</label></text>
        <entry>
          <default>${DISTRO_VERSION}</default>
          <variable>xDISTRO_VERSION</variable>
        </entry>
        <text><label>(use dots to separate: major.minor[.subminor...] ex: 5.1.23)</label></text>
        <text><label>\"                     \"</label></text>
      </hbox>
      <hbox>
        <text><label>File prefix:</label></text>
        <entry>
          <input>cat /tmp/woof_gui_dfp</input>
          <variable>xDISTRO_FILE_PREFIX</variable>
        </entry>
        <text><label>\"(one to four characters only)\"</label></text>
        <button><input file stock=\"gtk-go-back\"></input><action>echo \$xHISTORY_DISTRO_FILE_PREFIX > /tmp/woof_gui_dfp</action><action type=\"refresh\">xDISTRO_FILE_PREFIX</action></button>
        <combobox><variable>xHISTORY_DISTRO_FILE_PREFIX</variable>${ITEMS_HDFP}</combobox>
      </hbox>
      <hbox>
        <text>
          <label>Compatible-distro:</label>
        </text>
	    <combobox>
          <variable>xDISTRO_BINARY_COMPAT</variable>
          ${ITEMSCOMP}
        </combobox>
        <text><label>(this the distro where to get the binary pkgs from)</label></text>
        <text><label>\"                     \"</label></text>
      </hbox>
      <hbox>
        <text><label>Compatible-distro version:</label></text>
        <entry>
          <input>cat /tmp/woof_gui_dcv</input>
          <variable>xDISTRO_COMPAT_VERSION</variable>
        </entry>
        <text><label>\"(a word or number)\"</label></text>
        <button><input file stock=\"gtk-go-back\"></input><action>echo \$xHISTORY_DISTRO_COMPAT_VERSION > /tmp/woof_gui_dcv</action><action type=\"refresh\">xDISTRO_COMPAT_VERSION</action></button>
        <combobox><variable>xHISTORY_DISTRO_COMPAT_VERSION</variable>${ITEMS_HDCV}</combobox>
      </hbox>
      <text><label>\" \"</label></text>

      <hbox>
        <text><label>The available kernels are PET packages, located in directory 'packages-pet'. Choose which one is to be in the live-CD:</label></text>
        <combobox><variable>CHOICE_KERNELPKG</variable>${ITEMS_AK}</combobox>
      <text><label>\"                                                                                \"</label></text>
      </hbox>

      <hbox>
        <text><label>\"                      \"</label></text>
        <frame Previous templates>
          <hbox>
          <text><label>If you are even slightly confused by the above choices, this section makes it easy. Choose a configuration that has previously been built in Woof (and will likely just-work):</label></text>
          <combobox><variable>xHISTORY_DISTRO_SPECS_TEMPLATE</variable>${ITEMS_HDST}</combobox>
          </hbox>
        </frame>
      </hbox>
      <hbox>
        <text><label>Welcome! Each of these tabs is a GUI frontend for a single configuration file or script. This first tab is a GUI for configuration file 'DISTRO_SPECS'. This file has the overall specifications for your proposed build of Puppy.</label></text>
        <text use-markup=\"true\"><label>\"<b>If any changes made above, click 'UPDATE' button to save changes:</b>\"</label></text>
      </hbox>
      <hbox>
        <button><label>Help: Introduction</label><action>defaulttextviewer ./README.txt & </action></button>
        <button><label>UPDATE OVERALL SPECS</label><action>update_distro_specs_func</action><action type=\"exit\">UPDATE_DS</action></button>
      </hbox>
    </vbox>
    
    <vbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>These are the online repositories of PET packages</b>\"</label></text>
        <text><label>Even if you are building Puppy from some other compatible-distro, still many PET packages are required</label></text>
        <button><label>Edit</label><action>edit_pet_repos_func</action><action type=\"refresh\">TREE_PET_REPOS</action></button>
      </hbox>
      <tree>
        <label>URL|Local database file(s)</label>
        <input>cat /tmp/woof_gui_pet_repos | tr '\n' ' ' | sed -e 's%\n$%%' | tr ' ' '\n' | cut -f 2,3 -d '|'</input>
        <variable>TREE_PET_REPOS</variable>
      </tree>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>Online PET database files</b>\"</label></text>
        <text><label>The up-to-date PET database files are online, for Woof to download</label></text>
        <button><label>Edit</label><action>edit_pkg_docs_pet_repos_func</action><action type=\"refresh\">TREE_PKG_DOCS_PET_REPOS</action></button>
      </hbox>
      <tree>
        <label>URL of online database file|Local database file</label>
        <input>cat /tmp/woof_gui_pkg_docs_pet_repos | tr '\n' ' ' | sed -e 's%\n$%%' | tr ' ' '\n' | cut -f 2,3 -d '|'</input>
        <variable>TREE_PKG_DOCS_PET_REPOS</variable>
      </tree>
      <text><label>\" \"</label></text>
      <hbox>
        <text><label>This tab is a GUI for configuration file 'DISTRO_PET_REPOS'.</label></text>
        <text use-markup=\"true\"><label>\"<b>If any changes made above, click 'UPDATE' button to save:</b>\"</label></text>
      </hbox>
      <hbox>
        <button><label>Help: Repositories</label><action>defaulthtmlviewer /usr/local/petget/README-add-repo.htm & </action></button>
        <button><label>UPDATE PET REPOS</label><action>update_distro_pet_repos_func</action><action type=\"exit\">UPDATE_PR</action></button>
      </hbox>
    </vbox>
    
    <vbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>These are the online repositories of compatible-distro (${DISTRO_BINARY_COMPAT}) packages</b>\"</label></text>
        <text><label>This tab specifies the URLs for downloading the binary packages of ${DISTRO_BINARY_COMPAT}, release ${DISTRO_COMPAT_VERSION}, that you want to build Puppy from.</label></text>
        <button><label>Edit</label><action>edit_compat_repos_func</action><action type=\"refresh\">TREE_COMPAT_REPOS</action></button>
      </hbox>
      <tree>
        <label>URL|Local database file(s)</label>
        <input>cat /tmp/woof_gui_compat_repos | tr '\n' ' ' | sed -e 's%\n$%%' | tr ' ' '\n' | cut -f 2,3 -d '|'</input>
        <variable>TREE_COMPAT_REPOS</variable>
      </tree>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>Online compat-distro database files</b>\"</label></text>
        <text><label>The up-to-date compat-distro database files are online, for Woof to download</label></text>
        <button><label>Edit</label><action>edit_pkg_docs_compat_repos_func</action><action type=\"refresh\">TREE_PKG_DOCS_COMPAT_REPOS</action></button>
      </hbox>
      <tree>
        <label>URL of online database file|Local database file</label>
        <input>cat /tmp/woof_gui_pkg_docs_compat_repos | tr '\n' ' ' | sed -e 's%\n$%%' | tr ' ' '\n' | cut -f 2,3 -d '|'</input>
        <variable>TREE_PKG_DOCS_COMPAT_REPOS</variable>
      </tree>
      <text><label>\" \"</label></text>
      <hbox>
        <text><label>This tab is a GUI for configuration file '${DCRFILE}'.</label></text>
        <text use-markup=\"true\"><label>\"<b>If any changes made above, click 'UPDATE' button to save:</b>\"</label></text>
      </hbox>
      <hbox>
        <button><label>Help: Repositories</label><action>defaulthtmlviewer /usr/local/petget/README-add-repo.htm & </action></button>
        <button><label>UPDATE COMPAT-DISTRO REPOS</label><action>update_distro_compat_repos_func</action><action type=\"exit\">UPDATE_CR</action></button>
      </hbox>
    </vbox>
    
    <vbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>This tab is for downloading the package databases</b>\"</label></text>
        <text><label>The databases of PET and compat-distro (${DISTRO_BINARY_COMPAT}, release ${DISTRO_COMPAT_VERSION}) are online and need to be downloaded and converted to Puppy Standard Format.</label></text>
      </hbox>
      <hbox>
        <frame PET pkg online databases><text><label>\"${PET_REPOS_LIST_ONLINE}\"</label></text></frame>
        <frame PET pkg local databases><text><label>\"${PET_REPOS_LIST_LOCAL}\"</label></text></frame>
        <text><label>This shows the PET package database files available online and what is local. If local files are incomplete or you want to update them, click the 'UPDATE' button. Note: the online files are already in Puppy Standard Format, so only need to be downloaded.</label></text>
      </hbox>
      <hbox>
        <frame compat-distro pkg online databases><text><label>\"${PKG_DOCS_DISTRO_COMPAT_LIST_ONLINE}\"</label></text></frame>
        <frame compat-distro pkg local databases><text><label>\"${PKG_DOCS_DISTRO_COMPAT_LIST_LOCAL}\"</label></text></frame>
        <text><label>The left frame shows the database files as they would be named after downloading and converting to Puppy Standard Format (the actual online files are named differently). The right frame shows what is actually available locally -- if any are missing, or you want to update them, click the UPDATE button</label></text>
      </hbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>WARNING: If you click 'UPDATE', the download and conversion will take a long time</b>\"</label></text>
        <text><label>For any compat-distro other than a Puppy-release, it is the conversion to Puppy Standard Format that takes a long time. This is because it is currently written in Bash script -- one day I'll get around to rewriting it in C or Genie.</label></text>
      </hbox>
      <text><label>\" \"</label></text>
      <hbox>
        <text><label>This tab is a frontend for script '0setup'</label></text>
        <text use-markup=\"true\"><label>\"<b>Click 'UPDATE' if any files missing in right panes, or need updating:</b>\"</label></text>
        <text use-markup=\"true\"><label>\"<b>Report on last update:</b>\"</label></text>
      </hbox>
      <hbox>
        <button><label>Help: Standard DB Format</label><action>defaulthtmlviewer http://puppylinux.com/woof/pkg-db-format.htm & </action></button>
        <button><label>UPDATE LOCAL DB FILES</label><action type=\"exit\">UPDATE_DB</action></button>
        <button><label>REPORT</label><action>report_0setup_func</action></button>
      </hbox>
    </vbox>
    
    
    <vbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>This tab is for choosing what packages you want to have in the Puppy build</b>\"</label></text>
        <text><label>You can choose either PET packages or from the compat-distro (${DISTRO_BINARY_COMPAT}, release ${DISTRO_COMPAT_VERSION}). Of course, if you choose a Puppy-release as the compat-distro then they will also be PET packages.</label></text>
      </hbox>
      <hbox>
        <tree><label>Chosen PET packages|Descriptions</label><input>cat /tmp/CHOSEN_PET_PKGS</input><height>180</height><variable>TREE_CHOSEN_PET_PKGS</variable></tree>
        <text><label>These are packages that are going to be in most builds of Puppy, regardless which compat-distro you choose. They are essential infrastructure pkgs, or architecture-independent pkgs, or packages that are not available in the compat-distro (or the pkg in the compat-distro is in some way unsuitable)</label></text>
      </hbox>
      <hbox>
        <tree><label>Chosen compat-distro packages|Descriptions</label><input>cat /tmp/CHOSEN_COMPAT_PKGS</input><height>180</height><variable>TREE_CHOSEN_COMPAT_PKGS</variable></tree>
        <text><label>These are binary packages available in the compatible-distro '${DISTRO_BINARY_COMPAT}', release '${DISTRO_COMPAT_VERSION}'.</label></text>
      </hbox>
      <text><label>This tab is a frontend for config file '${DPSFILE}'</label></text>
      <hbox>
        <button><label>ADD/REMOVE PET PKGS</label><action>add_remove_pet_pkgs_func</action><action type=\"refresh\">TREE_CHOSEN_PET_PKGS</action></button>
        <button><label>ADD/REMOVE COMPAT-DISTRO PKGS</label><action>add_remove_compat_pkgs_func</action><action type=\"refresh\">TREE_CHOSEN_COMPAT_PKGS</action></button>
        <button><label>CHECK DEPENDENCIES</label><action>check_dependencies_func</action></button>
      </hbox>
    </vbox>
    
    <vbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>This tab is for downloading the PET and compat-distro packages needed to build the Puppy live-CD</b>\"</label></text>
        <text><label>Assuming that at some prior stage the package database files were downloaded (see 'Download dbs' tab), the packages can now be downloaded. The PET packages will be downloaded to directory 'packages-pet' and the compat-distro packages to 'packages-${BINARIES}'.</label></text>
      </hbox>
      <hbox>
        <text><label>Click the button to download packages. Note that if packages already exist in those directories, they will not be re-downloaded, so you can click this button to download any packages that have been added in the 'Choose pkgs' tab since the last download...</label></text>
        <vbox>
          <button><label>DOWNLOAD PACKAGES</label><action>rxvt -title \"Downloading packages\" -bg yellow -e ./1download</action><action>xmessage -bg green -center \"Download finished. Click 'REPORT' button (in 'Download pkgs' tab) for download summary\"</action><action type=\"exit\">UPDATE_DP</action></button>
        </vbox>
      </hbox>
      <hbox>
        <text><label>Click 'REPORT' button after downloading, for a summary. Sometimes things can go wrong, like the package no longer being available online, or the repository servers are offline, so it is wise to check. Note, sometimes clicking the 'DOWNLOAD' button again will succeed in getting missed pkgs.</label></text>
        <vbox>
          <button><label>REPORT</label><action>download_summary_func</action></button>
        </vbox>
      </hbox>
      <text><label>\" \"</label></text>
      <text><label>NOTE: It is allowed to manually copy a pkg into those directories. If you have a package that you have already added via 'Choose pkgs', you can manually place a PET package into 'packages-pet' and a compat-distro package into 'packages-${BINARIES}'. In that case, no need to click the above buttons.</label></text>
      <text><label>\" \"</label></text>
      <text><label>This tab is a frontend for script '1download'</label></text>
    </vbox>
    
    <vbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>This tab is for creating the cut-down packages needed to build a Puppy live-CD</b>\"</label></text>
        <text><label>You must have previously downloaded all the packages, see 'Download pkgs' tab. Now, they need to be processed into a cut-down and Puppy-compatible format. The resulting packages are created in directory 'packages-${DISTRO_FILE_PREFIX}'</label></text>
      </hbox>
      <hbox>
        <text><label>'ALL_PACKAGES' means all chosen packages (see 'Choose pkgs' tab) are processed, directory 'packages-${DISTRO_FILE_PREFIX}' is wiped and all packages re-created. 'CHANGED_ONLY' will automatically process only packages that have changed or added since last time 2createpackages was run. Or, if only one package has been added or modified in the 'Choose pkgs' tab, then it can be explicitly selected here to process just that one:</label></text>
        <combobox><variable>CHOICE_CREATEPACKAGES</variable>${ITEMS_CG}</combobox>
      </hbox>
      <hbox>
        <text><label>Click this button to build all the packages in directory 'packages-${DISTRO_FILE_PREFIX}', or the single package selected above:</label></text>
        <vbox>
          <button><label>CREATE PACKAGES</label><action>rxvt -title \"Creating packages\" -bg yellow -e ./2createpackages \$CHOICE_CREATEPACKAGES</action><action>xmessage -bg green -center \"Finished. Click 'REPORT' button for a summary.\"</action></button>
        </vbox>
      </hbox>
      <hbox>
        <text><label>Click 'REPORT' button afterward, for a summary. This can be useful to check that the right 'raw' binary packages were processed:</label></text>
        <vbox>
          <button><label>REPORT</label><action>createpackages_summary_func</action></button>
        </vbox>
      </hbox>
      <text><label>\" \"</label></text>
      <text><label>This tab is a frontend for script '2createpackages'</label></text>
    </vbox>
    
    <vbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>This tab is to choose the kernel config and module options</b>\"</label></text>
        <text><label>Building '${DISTRO_NAME}' version '${DISTRO_VERSION}', from the packages of compatible-distro '${DISTRO_BINARY_COMPAT}', version ${DISTRO_COMPAT_VERSION}. The compat-distro is designed to work with a certain minimum kernel version, do not choose anything older.</label></text>
      </hbox>

      <frame Kernel modules options >
        <hbox>
          <vbox>
            <text><label>What do you want to do with the SCSI drivers? Some network server PCs had these, 10-20 years ago, and they are quite rare now, so choosing 'Erase' to get rid of them is a reasonable choice. If you decide to leave them in, they will add about 1.1MB to the live-CD. There are two options if you leave them in: 'Boot' places them into the initrd so Puppy can boot from a SCSI drive, whereas 'Keep' enables SCSI drives to be recognised and mounted but not booted from.</label></text>
            <hbox><combobox><variable>CHOICE_SCSI</variable>${ITEMS_SCSI}</combobox></hbox>
          </vbox>
          <vbox>
            <text><label>The kernel has some very large drivers for Internet dialup analog modems, these can add up to 9MB to the live-CD. If you choose 'Erase', the biggest will be deleted, so you won't have support for many Intel, Conexant and Agere modems -- but there are many others that will still be supported, and of course true hardware modems will be supported. Alternatively, you can choose to move them to a 'zdrv' and optionally bundle that on the live-CD.</label></text>
            <hbox><combobox><variable>CHOICE_BIGMODEM</variable>${ITEMS_BIGMODEM}</combobox></hbox>
          </vbox>
        </hbox>
        <hbox>
          <vbox>
            <text><label>The kernel is configured with the 'vesafb' driver builtin, which is usually ok if it is ever required to boot in framebuffer video mode. The other framebuffer modules take up 1.4MB uncompressed and are not normally required.</label></text>
            <checkbox><label>Tick to erase framebuffer modules</label><default>${CHK_FB_DEFAULT}</default><variable>CHK_FB_STATE</variable></checkbox>
          </vbox>
          <vbox>
            <text><label>There are some modules that are unlikely to be needed, and it is normally ok to remove them (see variable CHK_EXOTIC_STATE in 3builddistro for details). If you want the smallest possible live-CD, 5-9MB off, there is more radical culling of less-commonly required modules (see CHK_RADICAL_STATE in 3builddistro).</label></text>
            <checkbox><label>Tick to erase exotic modules</label><default>${CHK_EXOTIC_DEFAULT}</default><variable>CHK_EXOTIC_STATE</variable></checkbox>
            <checkbox><label>Tick for radical culling of modules</label><default>${CHK_RADICAL_DEFAULT}</default><variable>CHK_RADICAL_STATE</variable></checkbox>
          </vbox>
        </hbox>
        
      </frame>
      <hbox>
        <text><label>This tab and the next are frontends for script '3builddistro'.</label></text>
        <text use-markup=\"true\"><label>\"<b>Choose the kernel and module options above, then go onto the 'Build distro' tab...</b>\"</label></text>
      </hbox>
    </vbox>

    <vbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>This tab is for building the live-CD and 'devx' file</b>\"</label></text>
        <text><label>'${DISTRO_NAME}' version '${DISTRO_VERSION}' live-CD will be created, built from the packages of compatible-distro '${DISTRO_BINARY_COMPAT}' (release ${DISTRO_COMPAT_VERSION}).</label></text>
      </hbox>
      <text><label>\" \"</label></text>
      
      <hbox>
        <text><label>Choose simple or traditional Puppy filenames (this will be variable CHK_SIMPLE_FILENAMES in 3builddistro). Simple names: vmlinuz, initrd.gz, puppy.sfs, zdrv.sfs, devx.sfs. Example traditional names: vmlinuz, initrd.gz, wary_071.sfs, zw071335.sfs, wary_devx_071.sfs</label></text>
        <vbox>
          <checkbox><label>Tick for simplified filenames</label><default>${CHK_SIMPLE_FILENAMES_DEFAULT}</default><variable>CHK_SIMPLE_FILENAMES_STATE</variable></checkbox>
          <button><label>help</label><action>defaulthtmlviewer `pwd`/support/help_filenames.htm & </action></button>
        </vbox>
      </hbox>
      <text><label>\" \"</label></text>
      
      <text><label>MORE STUFF HERE SOON</label></text>
      <text><label>\" \"</label></text>
      <text><label>This tab is a frontend for script '3builddistro'</label></text>
      <hbox>
        <text><label>After making appropriate choices above, click here to build live-CD:</label></text>
        <button><label>BUILD DISTRO</label><action>save_builddistro_options_func</action><action>rxvt -title \"Building distro\" -bg yellow -e ./3builddistro \$CHOICE_KERNELPKG \$CHOICE_SCSI \$CHOICE_BIGMODEM \$CHK_FB_STATE \$CHK_EXOTIC_STATE \$CHK_RADICAL_STATE \$CHK_SIMPLE_FILENAMES_STATE </action></button>
      </hbox>
    </vbox>

  </notebook>

</vbox>
</window>"

#gtkdialog3 --program=MAIN_DIALOG

