#!/bin/sh
#(c) Copyright Barry Kauler 2006 www.puppylinux.com
#2007 Lesser GPL licence v2 (/usr/share/doc/legal/lgpl-2.1.txt)
# BK july 2007:
#/usr/sbin/puppyinstaller-217 is heavily modified by Dougal (based on
# puppyinstaller from v2.14). Was used in 216 and 217.
#/usr/sbin/puppyinstaller-bk is the v2.14 one with minimal mods. for 2.17.1+
#aug 2007 updated for 2.20: 'root=/dev/ram0' removed as using initramfs.
#v3.94 BK dec 2007: no longer any hd* drives.
#v3.95 BK jan 2008: handle Classmate laptop.
#v3.96 BK jan 2008: improvements for full hd install, warning about drive nums.
#v3.97 BK feb 2008: fully support /dev/hd* notation for ide drives.
#v3.97 BK feb 2008: fix mbr recognition error in flash pen drive.
#v3.97 BK feb 2008: new ComboFormat installation for Flash drives.
#v3.98 BK mar 2008: bugfix for install to idehd or satahd.
#v4.02 /lib/modules/firmware.dep.<kern>,DOTconfig-K<kern> moved to /etc/modules. ...um, no mods this script.
#v404 usb install, now have 'pfix=copy'. bugfix extlinux now needs '-i'.
#v412 /etc/DISTRO_SPECS, renamed pup_xxx.sfs, pup_save.2fs etc.
#w013, w015 march 2009: updated for Woof.
#w460 zdrv has new name format, ex zu500269.sfs.
#w464, w478 checking /etc/puppyversion is history.
#w482 fix handling if separate zdrv file.
#w482 copy modules from 'initrd' folder to full hd install.
#v423 kirk: ext4 support.
#v424 coolpup: removed the '*' from ${DISTRO_FILE_PREFIX}-${NEWVER}*.sfs, tidyup pidof.
#v425 tentative support for install to scsi hd.
#v430 full hd install, wipe all, rc.update was not running properly.
#091211 modified to work with GRUB4DOS and shinobar's grub4dosconfig.
#100113 TARGETEXES has files that got copied from initrd. ditto /lib/keymaps, /lib/consolefonts.
#100207 gecko edubook, disktype sees internal sd as both partitions and a superfloppy.
#100321 Now have boot menu for installations that use Syslinux/Extlinux.
#100412 Fix from EdV: prevent display irrelevant partitions.
#100719 warning frugal, do not install to folder if want save session to entire partition.
#100720 removed 'nosmp' kernel boot param.
#100913 new simplified puppy filenames.
#100916 no longer have DISTRO_DEVXSFS in /etc/DISTRO_SPECS.(it was only there briefly)
#100916 a second help screen at bootup, file help2.msg.
#101107 fix frugal install, puppy now searches 2-deep.
#101221 yaf-splash fix.

# i18n by rodin.s 
#export LANG=C
#NEWVER="`cat /etc/puppyversion`"

TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=puppyinstaller
export TEXTDOMAINDIR
export TEXTDOMAIN
# 3jan11 shinobar
export OUTPUT_CHARSET=UTF-8
#. gettext.sh
eval_gettext () {
  local myMESSAGE=$(gettext "$1")
  eval echo \"$myMESSAGE\"
}
# shinobar end

KERNELVER="`uname -r`"

. /etc/rc.d/PUPSTATE
. /etc/DISTRO_SPECS
NEWVER="$DISTRO_VERSION"

#PREFIX1CHAR="`echo -n "$DISTRO_FILE_PREFIX" | cut -c 1`"
#KERNEL3CHARS="`echo -n "$KERNELVER" | tr -d '.' | tr -d '\-' | tr -d '[a-z]' | rev | cut -c 1,2,3 | rev`"
#ZDRVSFS="z${PREFIX1CHAR}${DISTRO_VERSION}${KERNEL3CHARS}.sfs"

fsfunc() { #f.s. type param passed in
 case $1 in
 Ext2)     FSTYPE="ext2" ;;
 ReiserFS) FSTYPE="reiserfs" ;;
 Ext3)     FSTYPE="ext3" ;;
 Ext4)     FSTYPE="ext4" ;;
 FAT16)    FSTYPE="vfat" ;;
 FAT32)    FSTYPE="vfat" ;;
 NTFS)     FSTYPE="ntfs" ;;
 ISO9660)  FSTYPE="iso9660" ;;
 JFS)      FSTYPE="jfs" ;;
 XFS)      FSTYPE="xfs" ;;
 *)        FSTYPE="" ;; #100412
 esac 
}

ispupfunc() { #two params: fstype partition
 #returns version of already-installed Puppy, if any.
 PUPSFS=""
 PUPVEROLD=0
 [ ! $2 ] && return 0
 mkdir -p /mnt/$2
 ISPUPMNTPT="`mount | grep "^/dev/$2" | tr -s " " | cut -f 3 -d " "`"
 if [ "$ISPUPMNTPT" = "" ];then
  ISPUPMNTPT="/mnt/$2"
  mount -t $1 /dev/$2 /mnt/$2
  [ $? -ne 0 ] && return 0
 fi
 #check for ancient puppy...
 [ -f $ISPUPMNTPT/usr_cram.fs ] && PUPVEROLD=108
 #puppy 2,3,4 has format pup_412.sfs ...
 ISFILE="`ls -1 ${ISPUPMNTPT}/${DISTRO_FILE_PREFIX}_[0-9][0-9][0-9].sfs 2>/dev/null | head -n 1`"
 [ "$ISFILE" != "" ] && PUPVEROLD=`basename $ISFILE | rev | cut -c 5,6,7 | rev`
 #puppy built by earlier woof has format distroprefix-500.sfs (ex: upup-500.sfs) ...
 ISFILE="`ls -1 ${ISPUPMNTPT}/${DISTRO_FILE_PREFIX}-[0-9][0-9][0-9].sfs 2>/dev/null | head -n 1`"
 [ "$ISFILE" != "" ] && PUPVEROLD=`basename $ISFILE | rev | cut -c 5,6,7 | rev`
 #100913 new naming scheme...
 if [ "$PUPVEROLD" = "" ];then
  #should really search subdirs also...
  #ISFILE="`ls -1 ${ISPUPMNTPT}/${DISTRO_PUPPYSFS} 2>/dev/null | head -n 1`"
  ISFILE="`find ${ISPUPMNTPT} -maxdepth 2 -type f -name ${DISTRO_PUPPYSFS} | head -n 1`"
  if [ "$ISFILE" != "" ];then
   #version number is contained in the id-string appended to puppy.sfs file...
   FULLSIZE=`stat -c %s ${ISFILE}`
   ORIGSIZE=`expr $FULLSIZE - 16`
   PUPVEROLD="`dd if=${ISFILE} bs=1 skip=${ORIGSIZE} 2>/dev/null | cut -b 2,3,4 | sed -e 's%[^0-9]%%g'`"
  fi
 fi
 #check for a full install to the partition...
 [ -f $ISPUPMNTPT/etc/puppyversion ] && PUPVEROLD=`cat $ISPUPMNTPT/etc/puppyversion` #old pre-w464 install.
 [ -f $ISPUPMNTPT/etc/DISTRO_SPECS ] && PUPVEROLD=`grep '^DISTRO_VERSION' ${ISPUPMNTPT}/etc/DISTRO_SPECS | cut -f 2 -d '=' | cut -f 1 -d ' '` #w464 w478
 umount /dev/$2 2>/dev/null
 return $PUPVEROLD
}

gpartedfixfunc() { #params: $DRVSEL
 GPDRV="$1"
 gparted /dev/$GPDRV &
 sleep 2
 gxmessage -bg '#ba55d3' -center -title "`gettext \"Puppy Universal Installer\"`" "`gettext \"GParted is a partition manager, available in Puppy, a very simple tool
for deleting, creating and resizing partitions.

Regarding 'ntfs' or 'vfat', of course do not change these to ext2 or ext3 if the
partition has Windows or DOS installed on it! In the case of USB Flash drives,
these normally come with a 'fat16' partition which is okay, but you will be
restricted to saving to a '${DISTRO_FILE_PREFIX}save' file. This is fine and most people opt for
this, particularly as the drive can be used also to save and transfer files with
Windows. However, a Flash drive can be changed to ext2/3 and still boots fine,
with the advantage that the entire partition can be used to save to, rather than
a '${DISTRO_FILE_PREFIX}save' file. If in doubt, stay with 'vfat'.

WARNING: changing the filesystem will wipe everything in the partition!

One more thing. When you run GParted, right-click on the partition and you will
see a menu option to 'Manage flags'. Make sure the 'boot' flag is set -- don't
forget that!

If you have a USB Flash 'key' drive that you have installed Puppy to but it will
not boot, it may be that the partition(s) is confusing the PC's BIOS.
Personally, I was able to fix such a USB drive by wiping the existing partition
and then create it again using GParted.
The steps to do this are very simple: when GParted is running,
 1. delete all partitions on the USB device. 
 2. Create a new primary FAT16 partition, to fill the entire drive.
 3. Click the 'Apply' button to write changes to the USB drive.
 4. Set the 'boot' configuration flag (right-click on partition, 
    choose 'manage flags'). 

If GParted is installed, it is now running and you can do the above.
Quiting GParted will return you to the Puppy Universal Installer...

One final note for USB: after exiting GParted, do a mouse-over the desktop drive
icon(s) -- if it(they) has not updated, unplug then replug the USB drive.\"`" & # transl-1
 MSGID=$!
 while [ 1 ];do
  [ "`pidof gparted`" = "" ] && break #v424
  sleep 1
 done
 [ ! "`which gparted`" = "" ] && kill $MSGID 2>/dev/null
 #w015 need to refresh desktop drive icons(s)...
 #/tmp/pup_event_frontend_block_request is used in /sbin/pup_event_frontend_d to refresh drv...
 sync
 echo "$GPDRV" > /tmp/pup_event_frontend_block_request
}

fixusbfunc() { #params: $DESTPART $DESTFS
 echo '#!/bin/sh
DESTPART="$1" #partition being installed to
DESTFS="$2"   #filesystem of destination partition
echo "This little section of the Puppy Universal Installer is currently only"
echo "for fixing USB Flash or CF-card-in-IDE-adaptor, after you have gone thru"
echo "all the steps but it still will not boot."
echo
echo "You are trying to install to $DESTPART, but it is not booting..."
echo "Well, I am assuming that the BIOS in your PC is able to boot from USB."
echo "-- for CF-IDE the drive looks like an ordinary hard drive, so that should"
echo "   be okay for any BIOS."
echo
echo "This is the first release of this script, and it is a bit limited..."
echo "and only handles a partition with a msdos/vfat filesystem."
if [ "$DESTFS" = "vfat" ];then
 echo "...which is okay, $DESTPART does have a $DESTFS filesystem."
 echo "   But, we will now wipe it and recreate it."
else
 echo "...currently $DESTPART has a $DESTFS filesystem."
 echo "   This script is not yet designed for that, so cannot continue."
 echo
 echo -n "Press ENTER key to exit: "
 read nogo
 exit
fi
echo
echo "Please be sure that you are wiping the right partition!!!"
echo "Everything in $DESTPART is going to be wiped. If you do not want that,"
echo "press any letter on the keyboard then ENTER key, or"
echo -n "Press ENTER key only to continue script: "
read querygo
echo
echo "Recreating msdos filesystem on $DESTPART..."
mkdosfs /dev/$DESTPART
sync
echo "Fixing the Master Boot Record (MBR)..."
DESTDRV="`echo -n "$DESTPART" | cut -b 1-3`"
dd if=/usr/lib/syslinux/mbrfat.bin of=/dev/$DESTDRV
sync
echo "...done"
echo
echo "Okay, we can now go back to the main part of the Puppy Universal"
echo "Installer and install Puppy to the $DESTPART partition."
echo -n "Press ENTER key to continue: "
read yesgo
' > /tmp/fixusb.sh
 chmod 755 /tmp/fixusb.sh
 rxvt -bg "pink" -title "`gettext \"Puppy Universal Installer\"`" -geometry 80x25 -e /tmp/fixusb.sh # transl-2
}

unmountcdfunc() {
 if [ ! "$CDDRIVE" = "" ];then
  if [ ! "`mount | grep "/dev/$CDDRIVE"`" = "" ];then
   rox -D "`mount | grep "/dev/$CDDRIVE" | tr -s " " | cut -f 3 -d " "`"
   #do not kill any processes
   sync
   umount /dev/$CDDRIVE 2> /dev/null
   #mount > /etc/mtab  #v2.10 remove.
   [ "`mount | grep "/dev/$CDDRIVE"`" = "" ] && eject /dev/$CDDRIVE
  fi
 fi
}

locate_puppy_src_files() {
SRCPATH=""
CDDRIVE=""
rm -f /tmp/srcpath.txt
mount | tr -s " " | cut -f 3 -d " " |
while read ONEDIR
do
 INCYES=0
 [ -f ${ONEDIR}/${DISTRO_PUPPYSFS} ] && INCYES=`expr $INCYES + 1` #v3.01 v424 100913
 [ -f $ONEDIR/vmlinuz ] && INCYES=`expr $INCYES + 1`
 [ -f $ONEDIR/initrd.gz ] && INCYES=`expr $INCYES + 1`
 if [ $INCYES -eq 3 ];then
  echo -n "$ONEDIR" > /tmp/srcpath.txt
  break
 fi
done
[ -f /tmp/srcpath.txt ] && SRCPATH="`cat /tmp/srcpath.txt`"
if [ "$SRCPATH" = "" ];then
 Xdialog --wmclass "gtkdialog2" --left --buttons-style text --title "`gettext \"Puppy universal installer\"`" --ok-label "CD" --cancel-label "`gettext \"DIRECTORY\"`" --yesno "`eval_gettext \"Puppy consists of 2 to 4 files:\nvmlinuz      The Linux kernel\ninitrd.gz    The initial ramdisk.\n\\\${DISTRO_PUPPYSFS}  This has all the Puppy files (sometimes inside initrd.gz).\n             (if built inside initrd.gz then only initrd.gz is required)\n\\\${DISTRO_ZDRVSFS} Extra kernel drivers and firmware (optional).\n             (most builds have a usable selection of drivers in \\\${DISTRO_PUPPYSFS})\nIf you booted Puppy from a live-CD, those files will be on it.\nOtherwise, they are in the .iso file and can be extracted -- in that\ncase, just click on the .iso file and it will be mounted (opened) in\na directory (do not forget to click on the file later to unmount it!)\n\nWhere are the Puppy files?...\"`" 0 0 #transl-3
 RETVAL=$?
 if [ $RETVAL -eq 0 ];then #CD
  CDDRIVE="`readlink /dev/cdrom`"
  CDDRIVE="`basename $CDDRIVE`"
  CDDRVINFO="`probedisk2 | grep "/dev/$CDDRIVE" | cut -f 3 -d '|'`"
  Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy universal installer\"`" --msgbox "`eval_gettext \"Please insert the Puppy live-CD (if not already) into the drive.\nNote, in case your PC has two CD/DVD drives, Puppy is expecting\nthe live-CD to be inserted into \\\$CDDRIVE, which is described as:\n \\\$CDDRVINFO \n\nAfter inserting live-CD, click OK button...\"`" 0 0 # transl-4
  mkdir /mnt/$CDDRIVE 2> /dev/null
  mount -t iso9660 /dev/$CDDRIVE /mnt/$CDDRIVE
  if [ -f /mnt/$CDDRIVE/initrd.gz ];then
   SRCPATH="/mnt/$CDDRIVE"
  else
   Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy universal installer: ERROR\"`" --msgbox "`gettext \"Sorry, Puppy is not on the CD.\nPlease mount the CD using one of the mount programs\n(see File Managers menu) then click OK button...\"`" 0 0 # transl-5
   RETVAL=1
  fi 
 fi
 if [ ! $RETVAL -eq 0 ];then #DIRECTORY
  SRCFPATH="$(Xdialog --wmclass "gtkdialog2" --left --backtitle "`eval_gettext \"Please find the latest Puppy files\nvmlinuz, initrd.gz and \\\${DISTRO_PUPPYSFS},\nTHEN HIGHLIGHT ANY ONE OF THEM\nand click the OK button\"`" --title "`gettext \"Puppy universal installer\"`" --stdout --no-buttons --no-cancel --fselect "*" 0 0)" #transl-6
  [ ! $? -eq 0 ] && exit
  SRCPATH="`dirname $SRCFPATH`"
 fi
fi
#sanity check...
if [ ! -f ${SRCPATH}/${DISTRO_PUPPYSFS} ];then #v3.01 v424 100913
 Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy universal installer: ERROR\"`" --msgbox "`eval_gettext \"Oh dear, a 'sanity check' has failed.\nThis file: \\\$SRCPATH/\\\${DISTRO_PUPPYSFS}\ndoes not exist.\nThe above is supposed to be path-to-where-puppy-files-are/\\\${DISTRO_PUPPYSFS}\nClick OK button to quit...\"`" 0 0 # transl-7
 exit
fi
} #end locate_puppy_src_files function.


PMEDIA="$(Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --no-tags --stdout --menubox "`gettext \"Welcome to the Puppy Universal Installer!\nIf you wish to install Puppy to a removable media, such as a USB Flash\nor hard drive, CD/DVD disc, Zip disk or LS-120 disk, please insert it\nright now, before proceeding.\n\nINSERT MEDIA NOW\nThen, choose the media that you want to install Puppy to:\"`" 0 0 10 usbflash "`gettext \"USB Flash drive\"`" usbhd "`gettext \"USB hard drive\"`" usb2ataflash "`gettext \"USB CF Flash drive, later move CF card to IDE/SATA internal adaptor\"`" iusbflash "`gettext \"Internal USB Flash drive (ex: uDiskOnChip)\"`" ataflash "`gettext \"Internal IDE/SATA Flash drive (ex: CF card in IDE adaptor)\"`" atazip "`gettext \"Internal ZIP or LS120 drive\"`" atahd "`gettext \"Internal (IDE or SATA) hard drive\"`" scsihd "`gettext \"Ancient true-SCSI hard drive\"`" cd "`gettext \"CD drive\"`")" # transl-8
[ ! $? -eq 0 ] && exit
[ "$PMEDIA" = "" ] && exit

TAGPMEDIA="$PMEDIA" #remember the tag chosen above.
[ "$TAGPMEDIA" = "iusbflash" ] && PMEDIA="usbflash"
FINALPMEDIA="$PMEDIA"
if [ "$PMEDIA" = "usb2ataflash" ];then
 PMEDIA="usbflash"
 FINALPMEDIA="ataflash"
fi

############BIG LOOP###############
while [ 1 ];do #BIG LOOP

PROBEDISK="`probedisk2 2> /tmp/probediskerr.txt`"
case $PMEDIA in
 usbflash)
  USBDRIVES="`echo "$PROBEDISK" | grep '|usbdrv|' | cut -f 3 -d '/' | cut -f 1 -d '|' | tr "\n" " "`"
  SELECTIONS=""
  for ONEUSB in $USBDRIVES
  do
   [ "$ATADRIVES" != "" ] && [ "`echo "$ATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #eliminate ide/sata drives.
   [ "$SATADRIVES" != "" ] && [ "`echo "$SATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #for old kernel.
   [ "$TAGPMEDIA" = "usbflash" ] && [ "`cat /sys/block/$ONEUSB/removable`" != "1" ] && continue
   [ "$TAGPMEDIA" = "iusbflash" ] && [ "`cat /sys/block/$ONEUSB/removable`" != "0" ] && continue
   USBINFO="`echo "$PROBEDISK" | grep "/dev/$ONEUSB" | head -n 1 | cut -f 3 -d '|' | tr '$' " " | tr ',' ' ' | tr -s " " | sed -e 's/ $//'`"
   USBSIZE="`disktype /dev/$ONEUSB | grep "Block device" | cut -f 2 -d ',' | tr -s " " | cut -f 1-4 -d " "`"
   SELECTIONS="${SELECTIONS} $ONEUSB \"${USBINFO}, ${USBSIZE}\""
  done
 ;;
 usbhd)
  USBDRIVES="`echo "$PROBEDISK" | grep '|usbdrv|' | cut -f 3 -d '/' | cut -f 1 -d '|' | tr "\n" " "`"
  SELECTIONS=""
  for ONEUSB in $USBDRIVES
  do
   [ "$ATADRIVES" != "" ] && [ "`echo "$ATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #eliminate ide/sata drives.
   [ "$SATADRIVES" != "" ] && [ "`echo "$SATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #for old kernel.
   [ "`cat /sys/block/$ONEUSB/removable`" != "0" ] && continue
   USBINFO="`echo "$PROBEDISK" | grep "/dev/$ONEUSB" | head -n 1 | cut -f 3 -d '|' | tr '$' " " | tr -s " " | sed -e 's/ $//g'`"
   USBSIZE="`disktype /dev/$ONEUSB | grep "Block device" | cut -f 2 -d ',' | tr -s " " | cut -f 1-4 -d " "`"
   SELECTIONS="${SELECTIONS} $ONEUSB \"${USBINFO}, ${USBSIZE}\""
  done
 ;;
 cd)
  #find cd drives... 
  CDDRIVES="`echo "$PROBEDISK" | grep '|optical|' | cut -f 3 -d '/' | cut -f 1 -d '|' | tr "\n" " "`"
  SELECTIONS=""
  for ONEHD in $CDDRIVES
  do
   HDINFO="`echo "$PROBEDISK" | grep "/dev/$ONEHD" | head -n 1 | cut -f 3 -d '|' | tr '$' " " | tr -s " " | sed -e 's/ $//'`"
   HDSIZE="`disktype /dev/$ONEHD | grep "Block device" | cut -f 2 -d ',' | tr -s " " | cut -f 1-4 -d " "`"
   SELECTIONS="${SELECTIONS} $ONEHD \"${HDINFO}, ${HDSIZE}\""
  done
  Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --ok-label "`gettext \"QUIT\"`" --msgbox "`eval_gettext \"Your computer has these CD/DVD drives:\n\\\$SELECTIONS \n\nHowever, you cannot install Puppy to a CD/DVD in the same way as a\nhard drive, USB Flash drive or Zip drive, as the CD/DVD is not\ndirectly writable. For the CD/DVD, you need to do what is called\n'remastering' and Puppy has a program for this, called 'Remaster\nPuppy live-CD', found in the Setup menu. This program enables\nyou to create your own custom live-CD/DVD.\nNote, you will need a new blank CD-R or DVD-R (not +R).\n\nClick button to quit...\"`" 0 0 #transl-9
  exit
 ;;
 atazip)
  HDDRIVES="`echo "$PROBEDISK" | grep '|floppy|' | cut -f 3 -d '/' | cut -f 1 -d '|' | tr "\n" " "`"
  SELECTIONS=""
  for ONEHD in $HDDRIVES
  do
   HDINFO="`echo "$PROBEDISK" | grep "/dev/$ONEHD" | head -n 1 | cut -f 3 -d '|' | tr '$' " " | tr -s " " | sed -e 's/ $//'`"
   HDSIZE="`disktype /dev/$ONEHD | grep "Block device" | cut -f 2 -d ',' | tr -s " " | cut -f 1-4 -d " "`"
   SELECTIONS="${SELECTIONS} $ONEHD \"${HDINFO}, ${HDSIZE}\""
  done
 ;;
 atahd|ataflash|scsihd) #v425 added scsihd
  #at bootup, init script creates ATADRIVES='' in /etc/rc.d/PUPSTATE...
  HDDRIVES="$ATADRIVES"
  if [ -e /proc/ide ];then #old kernel.
    IDEDRIVES="`echo "$PROBEDISK" | grep '|drive|' | grep '/dev/hd' | cut -f 3 -d '/' | cut -f 1 -d '|' | tr "\n" " "`"
    HDDRIVES="$IDEDRIVES $SATADRIVES"
  fi
  for ONEHD in $HDDRIVES
  do
   HDINFO="`echo "$PROBEDISK" | grep "/dev/$ONEHD" | head -n 1 | cut -f 3 -d '|' | tr '$' " " | tr -s " " | sed -e 's/ $//'`"
   HDSIZE="`disktype /dev/$ONEHD | grep "Block device" | cut -f 2 -d ',' | tr -s " " | cut -f 1-4 -d " "`"
   SELECTIONS="${SELECTIONS} $ONEHD \"${HDINFO}, ${HDSIZE}\""
  done
 ;;
 *)
  gxmessage "`gettext \"Not yet implemented\"`" #transl-10
  exit
 ;;
esac

if [ "$SELECTIONS" = "" ];then
 Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --ok-label "`gettext \"QUIT\"`" --msgbox "`gettext \"Nothing to choose. If a plugin device, did you plug it in?\"`" 0 0 #transl-11
 exit
fi

echo '#!/bin/sh' > /tmp/dlg1
echo -n 'Xdialog --wmclass "gtkdialog2" --title "Puppy Universal Installer" --no-cancel --stdout --menubox "Choose which drive to install to:" 10 60 0' >> /tmp/dlg1
echo -n "$SELECTIONS" >> /tmp/dlg1
echo ' > /tmp/retval'  >> /tmp/dlg1
echo 'exit $?' >> /tmp/dlg1

chmod 755 /tmp/dlg1

/tmp/dlg1
[ $? -ne 0 ] && exit
 
DRVSEL="`cat /tmp/retval`"
[ "$DRVSEL" = "" ] && exit

#old kernel, distinguish between ide and sata...
if [ -e /proc/ide ];then
 substPATTERN='s/^ata/ide/'
 if [ "$SATADRIVES" != "" ];then
  [ "`echo "$SATADRIVES" | grep "$DRVSEL"`" != "" ] && substPATTERN='s/^ata/sata/'
 fi
 PMEDIA="`echo -n "$PMEDIA" | sed -e "$substPATTERN"`"
 FINALPMEDIA="`echo -n "$FINALPMEDIA" | sed -e "$substPATTERN"`"
fi

DRVINFO="`disktype /dev/$DRVSEL`"
SUPERFS="" #100207 need extra test on gecko edubook...
[ "`echo "$DRVINFO" | grep '^Partition 1: '`" = "" ] && SUPERFS="`echo "$DRVINFO" | grep "file system" | grep "^[a-zA-Z]" | tr -s " " | cut -f 1 -d " "`"
DRVSIZE="`echo "$DRVINFO" | grep "Block device" | cut -f 2 -d ',' | tr -s " " | cut -f 1-4 -d " "`"
DRVSIZM="`echo "$DRVSIZE" | cut -f 3 -d " "`"
[ "`echo "$DRVSIZE" | grep "GiB"`" != "" ] && DRVSIZM="`LANG=C; dc $DRVSIZM 1000 \* p`" # change for russian locale
IDRVSIZM="`echo -n "$DRVSIZM" | cut -f 1 -d '.'`" #truncate to integer.

DRVMSG=""
PUPINST=""
if [ "$SUPERFS" ];then
 fsfunc $SUPERFS #returns FSTYPE
 ispupfunc $FSTYPE $DRVSEL #returns PUPVEROLD
 [ $? -ne 0 ] && PUPINST=", Puppy version $PUPVEROLD installed" # transl-12 отменен
 DRVMSG="${DRVSEL}:  ${FSTYPE}, ${DRVSIZE}${PUPINST}
"
else
 #has mbr and partitions...
 echo -n "" > /tmp/pidrvmsg.txt
 echo "$DRVINFO" |
 while read ONELINE
 do
  #100207 edubook: after showing partitions, shows a superfloppy, ignore...
  if [ "`echo "$ONELINE" | grep 'file system' | grep '^[a-zA-Z]'`" != "" ];then #100207
   [ "`echo "$DRVINFO" | grep "$ONELINE"  | grep '^[a-zA-Z]'`" != "" ] && break #need any leading spaces.
  fi
  xPARTNUM="`echo "$ONELINE" | grep '^Partition ' | tr -s " " | cut -f 1 -d ':' | cut -f 2 -d " "`"
  [ ! "$xPARTNUM" = "" ] && PARTNUM="$xPARTNUM"
  [ ! "$xPARTNUM" = "" ] && PARTSIZE="`echo "$ONELINE" | cut -f 2 -d ':' | tr -s " " | cut -f 2-3 -d " "`"
  PARTITIONFS="`echo "$ONELINE" | grep "file system" | cut -f 1 -d " "`"
  if [ "$PARTITIONFS" ];then
   fsfunc $PARTITIONFS #sets FSTYPE.
   #find out if partition has puppy, or has ${DISTRO_PUPPYSFS} file...
   if [ "$FSTYPE" ];then #100412 fix from EdV.
    PUPINST=""
    ispupfunc $FSTYPE ${DRVSEL}${PARTNUM} #returns PUPVEROLD
    [ $? -ne 0 ] && PUPINST=", Puppy version $PUPVEROLD installed" # transl-13 отменен
    echo "${DRVSEL}${PARTNUM}: ${FSTYPE}, size ${PARTSIZE}${PUPINST}" >> /tmp/pidrvmsg.txt
   fi
  fi
 done
 DRVMSG="`cat /tmp/pidrvmsg.txt`"
fi

DLGTXT=""
CHOICES="`echo "$DRVMSG" | grep ':' | cut -f 1 -d ':' | tr "\n" " "`"
for ONECHOICE in $CHOICES
do
 DLGTXT="$DLGTXT
   <hbox>
    <text><label>`gettext \"Install Puppy to\"` ${ONECHOICE}:</label></text> 
    <button>
     <input file>/usr/local/lib/X11/mini-icons/mini-dog.xpm</input>
     <action>Exit:${ONECHOICE}</action>
    </button>
   </hbox>
" # transl-14
done
if [ "$FINALPMEDIA" = "usbflash" ];then
 MSGex1="<text><label>`gettext \"IMPORTANT: If you use GParted, after creating the partition be sure to set the 'boot' flag (right-click: Manage flags). Also, for a USB Flash drive choose fat16 filesystem as easier to boot from (than fat32) -- however a ext2 or ext3 partition will also work.\"`</label></text> 
<text><label>Extra note: Gparted may show invalid partitions on the drive, marked with a '!' icon -- delete it/them and recreate a partition (and make it bootable)</label></text>" # transl-15
else
 MSGex1="<text><label>`gettext \"IMPORTANT: If you use GParted, after creating the partition be sure to set the 'boot' flag (right-click: Manage flags).\"`</label></text>
<text><label>`gettext \"Extra note: Gparted may show invalid partitions on the drive, marked with a '!' icon -- delete it/them and recreate a partition (and make it bootable)\"`</label></text>" # transl-16
fi
if [ "$DLGTXT" = "" ];then
 DLGTXT="<hbox>
 <text><label>`gettext \"No partitions on drive ${DRVSEL}! It is recommended that you run GParted now to create a partition:\"`</label></text>
    <button>
     <input file>/usr/local/lib/X11/mini-icons/mini-hdisk.xpm</input>
     <label>GParted</label>
     <action>Exit:RUNGPARTED</action>
    </button>
</hbox>
$MSGex1
<text><label>\" \"</label></text>
" # transl-17
fi

DLGEXT=""

if [ "`echo "$DRVMSG" | cut -f 1 -d ':' | grep "[a-zA-Z]$"`" = "" ];then
 #ask if want superfloppy install...
 DLGEXT="$DLGEXT
   <frame `gettext \"Filesystem in partition\"`>
    <hbox>
     <text><label>`eval_gettext \"WARNING: Notice the filesystem in the intended destination, is that what you want? In particular, if the f.s. is 'vfat' or 'ntfs' you might want to replace these with a Linux ext2 or ext3 f.s. if the partition can be taken over totally for Puppy's use. If you are installing to an internal drive of a PC, it is highly recommended that the f.s. be a Linux ext2 or ext3. Puppy can install to vfat/ntfs but limited to 'frugal' with '\\\${DISTRO_FILE_PREFIX}save' only. Ntfs is particularly limited, slow and also has severe bootup options, so get rid of it if at all possible. Click the button to run GParted, which will enable you to examine and modify the partitions.\"`</label></text>
     <vbox>
      <button>
       <input file>/usr/local/lib/X11/mini-icons/gparted.xpm</input>
       <action>Exit:RUNGPARTED</action>
      </button>
     </vbox>
    </hbox>
   </frame>
   <frame `gettext \"Superfloppy\"`>
   <hbox>
    <text><label>`eval_gettext \"WARNING: NOT NORMALLY RECOMMENDED. Do you want to install Puppy in Superfloppy mode, that is, no MBR and no partitions? ...in that case, the drive will be accessed as /dev/\\\$DRVSEL, without a partition number. This may be a good choice for booting USB Flash drive from PC with a quirky BIOS. Click button if yes:\"`</label></text>
    <vbox>
     <button>
      <input file>/usr/local/lib/X11/mini-icons/mini-dog.xpm</input>
      <action>Exit:REFORMAT_${DRVSEL}</action>
     </button>
    </vbox>
   </hbox>
   </frame>
" # transl-18,19,20,21
else #drive is a superfloppy.
 DLGEXT="$DLGEXT
   <frame `gettext \"Superfloppy\"`>
   <hbox>
    <text><label>`eval_gettext \"The drive is currently in Superfloppy mode and has no MBR and no partitions. It is accessed as /dev/\\\$DRVSEL, without a partition number (this may be a good choice for booting USB Flash drive from PC with a quirky BIOS). Do you want to partition the drive so that it has a /dev/\\\${DRVSEL}1 partition, in which Puppy can be installed? If so, click button:\"`</label></text>
    <vbox>
     <button>
      <input file>/usr/local/lib/X11/mini-icons/mini-dog.xpm</input>
      <action>Exit:REFORMAT_${DRVSEL}1</action>
     </button>
    </vbox>
   </hbox>
   </frame>
" # transl-22,23
fi

DLG2="
 <wtitle>`gettext \"Puppy Universal Installer\"`</wtitle>
 <vbox>
  <text><label>`gettext \"Here is what Puppy has found out about the chosen drive:\"`</label></text>
  <text><label>\"${DRVMSG}\"</label></text>
$DLGTXT
$DLGEXT
  <hbox>
   <button>
    <label>`gettext \"Go back and choose a different drive\"`</label>
    <action>Exit:GOBACK</action>
   </button>
   <button cancel></button>
  </hbox>
 </vbox>
" # transl-24.25

RETTXT="`echo "$DLG2" | gtkdialog2 --stdin`"

#returns EXIT="Cancel" or EXIT="abort"...
[ "`echo "$RETTXT" | grep 'EXIT' | grep -E 'Cancel|abort'`" != "" ] && exit

if [ "`echo "$RETTXT" | grep 'RUNGPARTED'`" != "" ];then
 gpartedfixfunc $DRVSEL #w015
 continue #BIG LOOP
fi

[ "`echo "$RETTXT" | grep 'EXIT:GOBACK'`" != "" ] && continue

#when arrive here, have
#RETTXT="EXIT:sda1", DRVMSG="sda1: vfat, size 122.1 MiB, Puppy version 108 installed" (has all parts fnd)

#sanity check...
SANITYPART="`echo -n "$RETTXT" | grep 'EXIT' | cut -f 2 -d ':' | cut -f 2 -d '_'`"
SANITYMNTPT="`mount | grep "/dev/$SANITYPART" | tr -s " " | cut -f 3 -d " "`"

if [ ! "$SANITYMNTPT" = "" ];then
 SANITYMSG1="$SANITYPART currently mounted, need to unmount it!!!"
 SANITYMSG2="$SANITYPART currently mounted read-write."
 SANITYMSG3="$SANITYPART does not have ${DISTRO_FILE_PREFIX}save.3fs file in it."
 SANITYRORW="`mount | grep "/$SANITYPART" | tr -s " " | cut -f 6 -d " "`"
 [ ! "`echo -n "$SANITYMNTPT" | grep "/initrd/"`" = "" ] && SANITYMSG1="$SANITYPART cannot be unmounted!"
 [ "$SANITYRORW" = "(ro)" ] && SANITYMSG2="$SANITYPART is mounted read-only!"
 [ -f $SANITYMNTPT/${DISTRO_FILE_PREFIX}save.3fs ] && SANITYMSG3="$SANITYPART has personal file ${DISTRO_FILE_PREFIX}save.3fs in it!"
 Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy universal installer: SANITY CHECK\"`" --ok-label "`gettext \"CONTINUE\"`" --cancel-label "`gettext \"QUIT\"`" --yesno "`eval_gettext \"A partition sanity check before continuing:\n\\\$SANITYMSG1 \n\\\$SANITYMSG2 \n\\\$SANITYMSG3 \n\nIf the above report is that the partition is mounted, you need to unmount it\nright now, but if report is it cannot be unmounted, then there may be install\ndifficulties -- certainly, in the case of install to hard drive you will only\nbe able to do an \"option1\" install (explained further on).\nIf the partition has \\\${DISTRO_FILE_PREFIX}save.3fs in it, that is the reason it cannot be\nunmounted -- it is currently in use by Puppy. If booting Puppy from live-CD,\nif \\\${DISTRO_FILE_PREFIX}save.3fs does not exist then Puppy will run totally in RAM, which will\nsolve the problem -- but you should not delete or rename \\\${DISTRO_FILE_PREFIX}save.3fs right\nnow as it is in use. Instead, boot some other OS then rename the file, then\nboot Puppy live-CD.\n\nBottom-line, unmount the partition now, if you can, otherwise CONTINUE script\nwith the restricted install choice, or QUIT script now and try to fix the\nproblem of the partition getting mounted...\"`" 0 0 # transl-25
 [ ! $? -eq 0 ] && exit
fi

if [ ! "`echo "$RETTXT" | grep 'EXIT:REFORMAT'`" = "" ];then
 #RETTXT will have "EXIT:REFORMAT_sda" or "EXIT:REFORMAT_sda1", depending whether
 #we want to format in superfloppy mode or with a MBR and a partition...
 DESTPART="`echo "$RETTXT" | grep 'EXIT:REFORMAT' | cut -f 2 -d ':' | cut -f 2 -d '_'`"
 if [ "`echo "$DESTPART" | grep "[0-9]$"`" = "" ];then
  #want superfloppy...
  DLG3="
 <wtitle>`gettext \"Puppy Universal Installer\"`</wtitle>
 <vbox>
   <text><label>`eval_gettext \"You have chosen to format /dev/\\\${DESTPART} as a Superfloppy. You now need to choose whether to create a vfat or a ext3 filesystem on the drive. Ext3 is the most flexible (and recommended) choice, however if you need to be able to read the drive from Windows then choose vfat. Note, however, there are tools for accessing ext2/3 drives in Windows.\"`</label></text>
   <text><label>`eval_gettext \"A further clarification: if you choose ext3, then the entire drive will be immediately available for personal data storage, whereas if you choose vfat this installer will have to create a file with a ext3 filesystem inside it (\\\${DISTRO_FILE_PREFIX}save.3fs) -- that file will contain all your personal files. Press FORMAT_ext3 or FORMAT_vfat button to commence formatting...\"`</label></text>
  <hbox>
   <button>
    <label>`gettext \"FORMAT_ext3\"`</label>
    <action>Exit:ext3</action>
   </button>
   <button>
    <label>`gettext \"FORMAT_vfat\"`</label>
    <action>Exit:vfat</action>
   </button>
  </hbox>
 </vbox>
" # transl-26,27,28,29,30
  RETTXT="`echo "$DLG3" | gtkdialog2 --stdin`"

  [ ! "`echo "$RETTXT" | grep 'abort'`" = "" ] && exit
  DESTFS="`echo "$RETTXT" | grep 'EXIT:' | cut -f 2 -d ':'`"
  echo '#!/bin/sh' > /tmp/formatsuper.sh
  echo -e "echo -n \"SANITY CHECK: formatting /dev/${DRVSEL}, ENTER to continue or CTRL-C to quit: \""  >> /tmp/formatsuper.sh
  echo 'read mooo'  >> /tmp/formatsuper.sh
  #echo 'echo "Zeroising the entire drive..."'  >> /tmp/formatsuper.sh
  #echo 'echo "(please be very patient, this could take awhile)"'  >> /tmp/formatsuper.sh
  ##echo "dd if=/dev/zero bs=1024 | $BAR -of /dev/$DRVSEL -s ${IDRVSIZM}m" >> /tmp/formatsuper.sh
  #echo "dd if=/dev/zero of=/dev/$DRVSEL" >> /tmp/formatsuper.sh
  #no, will just zeroise the mbr section...
  echo "dd if=/dev/zero of=/dev/$DRVSEL bs=512 count=1" >> /tmp/formatsuper.sh
  echo 'sync'  >> /tmp/formatsuper.sh
  if [ "$DESTFS" = "ext3" ];then
   echo 'echo "Creating an ext3 filesystem on the drive..."'   >> /tmp/formatsuper.sh
   echo -e "echo \"y\" | mke2fs -j -m 0 /dev/$DRVSEL"   >> /tmp/formatsuper.sh
  else #vfat
   echo 'echo "Creating a vfat filesystem on the drive..."'   >> /tmp/formatsuper.sh
   echo "mkdosfs -I /dev/$DRVSEL" >> /tmp/formatsuper.sh
  fi
  echo 'sync'  >> /tmp/formatsuper.sh
  echo 'echo -n "Press ENTER key to continue: "'   >> /tmp/formatsuper.sh
  echo 'read moo'   >> /tmp/formatsuper.sh
  chmod 755 /tmp/formatsuper.sh
  rxvt -bg "orange" -title "`gettext \"Puppy Universal Installer\"`" -geometry 80x10 -e /tmp/formatsuper.sh # transl-31
  DESTSIZM="$DRVSIZM"
  IDESTSIZM="$IDRVSIZM"
  DESTVER="" #previous version, n.a.
  #w015 need to refresh desktop drive icons(s)...
  #/tmp/pup_event_frontend_block_request is used in /sbin/pup_event_frontend_d to refresh drv...
  sync
  echo "$DRVSEL" > /tmp/pup_event_frontend_block_request
 else
  #want to partition with partition 1...
  DLG3="
 <wtitle>`gettext \"Puppy Universal Installer\"`</wtitle>
 <vbox>
   <text><label>`eval_gettext \"You have chosen to format /dev/\\\${DRVSEL} with a MBR and a partition. You now need to choose whether to create a vfat or a ext3 filesystem on the partition. Ext3 is the most flexible (and recommended) choice, however if you need to be able to read the drive from Windows then choose vfat. Note, however, there are tools for accessing ext2/3 drives in Windows.\"`</label></text>
   <text><label>`eval_gettext \"A further clarification: if you choose ext3, then the entire partition will be immediately available for personal data storage, whereas if you choose vfat then Puppy will have to create a file with a ext2 filesystem inside it (\\\${DISTRO_FILE_PREFIX}save.2fs) -- that file will contain all your personal files.\"`</label></text>
   <text><label>`gettext \"USB Flash drives: it is most common to create a vfat (fat16) partition on these, for Windows interchangeability and some older BIOSes boot only if see a fat16 f.s.\"`</label></text>
   <text><label>\" \"</label></text>
   <text><label>`gettext \"Click button to run GParted...\"`</label></text>
  <hbox>
   <button>
    <label>Run GParted</label>
    <action>Exit:gparted</action>
   </button>
   <button cancel>
   </button>
  </hbox>
 </vbox>
" # transl-32,33,34,35,36
  RETTXT="`echo "$DLG3" | gtkdialog2 --stdin`"
  MYACTION="`echo "$RETTXT" | grep 'EXIT:' | cut -f 2 -d ':'`"
  if [ "$MYACTION" = "gparted" ];then
   #w015 if a superfloppy, first need to create a disk label, else gparted is upset...
   if [ "`echo "$DRVMSG" | cut -f 1 -d ':' | grep "[a-zA-Z]$"`" != "" ];then
    dd if=/dev/zero of=/dev/$DRVSEL bs=512 count=1
    parted --script /dev/sdb mklabel msdos
    sync
   fi
   #exec gparted /dev/$DRVSEL
   gpartedfixfunc $DRVSEL #w015
   continue #BIG LOOP
  fi
  #exit
  
 fi
else
 DESTPART="`echo "$RETTXT" | grep 'EXIT:' | cut -f 2 -d ':'`"
 DESTFS="`echo "$DRVMSG" | grep "$DESTPART" | cut -f 1 -d ',' | tr -s " " | cut -f 2 -d " "`"
 DESTSIZE="`echo "$DRVMSG" | grep "$DESTPART" | tr -s " " | cut -f 4-5 -d " "`"
 DESTSIZM="`echo -n "$DESTSIZE" | cut -f 1 -d " "`"
 if [ ! "`echo "$DESTSIZE" | grep "GiB"`" = "" ];then
  DESTSIZM="`LANG=C; dc $DESTSIZM 1000 \* p`" # change for russian locale
 fi
 IDESTSIZM="`echo -n "$DESTSIZM" | cut -f 1 -d '.'`" #truncate to integer.
 DESTVER="`echo "$DRVMSG" | grep "$DESTPART" | tr -s " " | grep "installed" | cut -f 8 -d " "`"
fi

break
done #BIG LOOP
###########END BIG LOOP###############



if [ "`echo "$DESTPART" | grep "[0-9]$"`" = "" ];then
 #superfloppy
 DLG4="
 <wtitle>`gettext \"Puppy Universal Installer\"`</wtitle>
 <vbox>
  <text><label>`gettext \"You have chosen to install Puppy to the entire drive, which is what we call Superfloppy mode, in which there is no MBR (Master Boot Record) and no partitions. This may be a good choice for Flash memory, especially USB Flash, that the PC BIOS has trouble booting from.\"`</label></text>
  <text><label>`eval_gettext \"The target drive is \\\${DESTPART}, which has a \\\${DESTFS}, of size \\\${DESTSIZM}M. Press OK button to install Puppy to the drive...\"`</label></text>
  <hbox><button ok></button><button cancel></button></hbox>
 </vbox>
" # transl-37,38,39
 RETTXT="`echo "$DLG4" | gtkdialog2 --stdin`"
else
 DLG4="
 <wtitle>`gettext \"Puppy Universal Installer\"`</wtitle>
 <vbox>
  <text><label>`eval_gettext \"You have chosen to install Puppy to partition /dev/\\\${DESTPART}, which has a \\\${DESTFS} filesystem and the size is \\\${DESTSIZM}M.\"`</label></text>
  <text><label>`gettext \"Press OK button to install Puppy (note, there will be one or two more dialog windows before you have to commit to the actual install)...\"`</label></text>
  <hbox><button ok></button><button cancel></button></hbox>
 </vbox>
" # transl-40,41,42
 RETTXT="`echo "$DLG4" | gtkdialog2 --stdin`"
fi

[ ! $? -eq 0 ] && exit
[ "`echo "$RETTXT" | grep 'OK'`" = "" ] && exit



#get latest Puppy files....
locate_puppy_src_files


#find out if puppy already on dest...
ispupfunc $DESTFS $DESTPART
#...sets PUPVEROLD.

#now to do the actual install...
case $FINALPMEDIA in
 usbflash|usbhd|ataflash|atazip) #removable media, install with syslinux/extlinux

  #26mar06 JustGreg fix mbr...
  if [ "`echo "$DESTPART" | grep '[0-9]$'`" != "" ];then #superfloppy mode has no mbr.
   #DESTPART is a partition (not superfloppy).
   DESTDRV="`echo -n "$DESTPART" | cut -b 1-3`"
   DESTNUM="`echo -n "$DESTPART" | cut -b 4-5`"
   dd if=/dev/$DESTDRV of=/tmp/mbr446.bin bs=446 count=1
   sync
   
   #v3.95
   ALPHADUMP="`hexdump -C /tmp/mbr446.bin | cut -f 2 -d '|' | tr '\n' ' ' | tr -d ' '`"
   #this will be =1 if mbr has 'GRUB' in it, else =0...
   FLAGGRUB="`echo "$ALPHADUMP" | grep 'GRUB' | wc -l`"
   
   #v3.97 have a case where normal bootable flash vfat pen drive has the
   #string 'GRUB.Geom.HardDisk.Read.Error' in the mbr...
   [ "$FLAGGRUB" = "1" ] && [ "`echo "$ALPHADUMP" | grep 'GRUB.Geom.HardDisk.Read.Error'`" != "" ] && FLAGGRUB="0"
   
   if [ "`hexdump -x /tmp/mbr446.bin | tr -s " " | cut -f 2-9 -d " " | grep '[1-9a-zA-Z]'`" = "" -o "$FLAGGRUB" = "1" ];then
    MBRCHOICE="$(Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --no-cancel --stdout --menubox "`gettext \"The bootstrap loader code is missing from the MBR (Master Boot Record),\nmeaning that the USB drive will not boot. Please choose one of the\nfollowing to fix this. Personally, I have had success with mbr.bin.\"`" 0 0 4 sys-nopart.mbr "`gettext \"Bootstrap loader code, created by JustGreg\"`" mbr.bin "`gettext \"From the Syslinux package\"`" mbrfat.bin "`gettext \"From the makebootfat package\"`" spb2_mbr.bin "`gettext \"From spblinux, created by Christian Ostheimer\"`" )" # transl-43
   else
    MBRCHOICE="$(Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --no-cancel --stdout --menubox "`eval_gettext \"The MBR (Master Boot Record) in the USB drive is probably okay as-is, so choose\nthe first option. However, if you cannot get the drive to boot, and you are\nsure that the BIOS settings are not to blame and the PC is capable of booting\nfrom USB, then try one of these alternative MBRs.\nNote, if you choose to change the MBR, the old first 446 bytes (the\nbootstrap loader part) of the MBR will be backed up to /tmp/oldmbr.bin\nNote, you can install these MBRs directly, without running this\nInstaller program again: they are located in /usr/lib/syslinux,\nand you can use the dd program to copy them.\nExample: dd if=spb2_mbr.bin of=/dev/\\\${DESTDRV}\nNote, personally I have had success with mbr.bin.\"`" 0 0 5 default "`gettext \"DO NOTHING, leave current MBR alone\"`" sys-nopart.mbr "`gettext \"Bootstrap loader code, created by JustGreg\"`" mbr.bin "`gettext \"From the Syslinux package\"`" mbrfat.bin "`gettext \"From the makebootfat package\"`" spb2_mbr.bin "`gettext \"From spblinux, created by Christian Ostheimer\"`" )" # transl-44
   fi
   rm /tmp/mbr446.bin
   if [ ! "$MBRCHOICE" = "" ];then
    if [ ! "$MBRCHOICE" = "default" ];then
     dd if=/dev/$DESTDRV of=/tmp/oldmbr.bin bs=446 count=1
     sync
     dd if=/usr/lib/syslinux/$MBRCHOICE of=/dev/$DESTDRV
     sync
    fi
   fi
   
   #check that partition has 'boot' flag set...
   QPATTERN="^Partition ${DESTNUM}:"
   if [ "`disktype /dev/$DESTDRV | grep "$QPATTERN" | grep 'bootable'`" = "" ];then
    Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --no-cancel --stdout --ok-label "GParted" --cancel-label "`gettext \"bypass\"`" --yesno "`eval_gettext \"Slight problem. It seems that partition \\\${DESTPART} does not have it's 'boot'
flag set, which is required to make it bootable. Recommended to click the
'GParted' button now to run GParted, then right-click on the partition and
choose 'Manage flags' then set 'boot' flag.
After exiting from GParted, this Puppy Universal Installer will continue.

Click 'GParted' (recommended) to run GParted...
Click 'bypass' to bypass GParted...\"`" 0 0 # transl-45
    [ $? -eq 0 ] && gparted /dev/$DESTDRV
   fi
  fi

  case $DESTFS in
   vfat)
     if [ ! "`echo "$DESTPART" | grep '[0-9]$'`" = "" ];then
      PARTCHOICE="$(Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --no-cancel --stdout --menubox "`gettext \"Please just accept the default here, 'JUST KEEP GOING'.\nPLEASE MAKE SURE TOP ENTRY HIGHLIGHTED THEN CLICK OK BUTTON\n\nHowever, if you have tried this Puppy Universal Installer\nbut Puppy will not boot, you can try one of the other choices here.\n\nPersonally, I have had success with using GParted to wipe and\nrecreate the partition...\"`" 0 0 4 default "`gettext \"JUST KEEP GOING\"`" GParted "`gettext \"Wipe and recreate USB/IDE-CF partition using GParted\"`" syslinux "`gettext \"Make USB or IDE-CF msdos/vfat partition bootable\"`")" # transl-46
      [ "$PARTCHOICE" = "syslinux" ] && fixusbfunc $DESTPART $DESTFS
      [ "$PARTCHOICE" = "GParted" ] && gpartedfixfunc $DRVSEL
     fi
    #params passed in: $DESTPART "$SRCPATH" $FINALPMEDIA
    echo '#!/bin/sh
DESTPART="$1"
SRCPATH="$2"
FINALPMEDIA="$3"
DISTRO_FILE_PREFIX="$4"
DISTRO_PUPPYSFS="$5"
DISTRO_ZDRVSFS="$6"
#DISTRO_DEVXSFS="$7"
PREFIX1CHAR="`echo -n "$DISTRO_FILE_PREFIX" | cut -c 1`"
echo "ABSOLUTE FINAL SANITY CHECK!"
echo "You are about to install Puppy to /dev/$DESTPART, with boot parameter"
echo "pmedia=$FINALPMEDIA. The files vmlinuz, initrd.gz, ${DISTRO_PUPPYSFS}, syslinux.cfg"
echo "(and maybe the ${DISTRO_ZDRVSFS} if it exists. ${DISTRO_PUPPYSFS} may be inside initrd.gz)"
echo "will be written to /dev/$DESTPART and Syslinux will be used to make it bootable."
echo
echo -n "Press ENTER key to continue, CTRL-C to abort: "
read goforit

#v3.95...
mount -t vfat /dev/$DESTPART /mnt/data
echo
echo "Do you want to wipe all files in /dev/$DESTPART? This is currently mounted"
echo "on /mnt/data so you can look at what is there before answering. You would"
echo "normally answer no if upgrading Puppy, or yes for a fresh install and"
echo "you want to get rid of old files that are just taking up space."
echo "Note, you can also manually prune files in /mnt/data then choose no here."
echo "Note, if you choose no here, this script will still do some basic deleting"
echo "of any files of an earlier Puppy installation (not the ${DISTRO_FILE_PREFIX}save though!)."
echo
echo "No, press ENTER only to not wipe all files, or"
echo -n "Yes, press any alpha or numeric char then ENTER to wipe all files: "
read WIPEALL
if [ "$WIPEALL" != "" ];then
 echo
 echo "Deleting everything in /mnt/data..."
 rm -rf /mnt/data/*
else
 #well, minimum to get rid of...
 rm -f /mnt/data/image.gz 2> /dev/null
 rm -f /mnt/data/usr_cram.fs 2> /dev/null #old name.
 rm -f /mnt/data/pup_[0-9]*.sfs 2>/dev/null #old name.
 rm -f /mnt/data/${DISTRO_FILE_PREFIX}-*.sfs 2>/dev/null
 rm -f /mnt/data/devx_*.sfs 2>/dev/null
 rm -f /mnt/data/${DISTRO_FILE_PREFIX}z*.sfs 2>/dev/null #old name.
 rm -f /mnt/data/z${PREFIX1CHAR}*.sfs 2>/dev/null
 rm -f /mnt/data/${DISTRO_PUPPYSFS} 2>/dev/null #100913
 rm -f /mnt/data/${DISTRO_ZDRVSFS} 2>/dev/null #100913
 #rm -f /mnt/data/${DISTRO_DEVXSFS} 2>/dev/null #100913
fi
sync
umount /mnt/data

echo
echo "Making $DESTPART bootable..."
syslinux  /dev/$DESTPART
sync

mount -t vfat /dev/$DESTPART /mnt/data
echo
echo "Copying vmlinuz..."
cp -f $SRCPATH/vmlinuz /mnt/data/
sync
echo "Creating syslinux.cfg..."
FCOPY=""
echo "Would you like syslinux.cfg to have 'pfix=copy' boot parameter?"
echo "this will cause ${DISTRO_PUPPYSFS} to be copied into RAM at bootup, which slows"
echo "bootup but speeds application startup slightly."
echo "Probably good to answer yes here if PC has 256MB or more RAM."
echo "(you can edit syslinux.cfg later to change the choice made here)"
echo "(note, Puppy will override this and not copy if there is insufficient RAM)"
echo -n "ENTER key only for no, else any char then ENTER for yes: "
read FCOPY
[ "$FCOPY" != "" ] && FCOPY=" pfix=copy"

#100321 big assumption here, that current running kernel matches one being installed...
if [ -e /proc/ide ];then
 NODMA="ide=nodma" #old kernel
else
 #old 'ide=nodma' does not work, need 'libata.dma=3' this enables DMA for Disk and CD/DVD but NOT for CF.
 NODMA="libata.dma=3"
fi
if [ ! -f $SRCPATH/boot.msg ];then #100321
 if [ "$FINALPMEDIA" = "ataflash" ];then
  echo "default vmlinuz initrd=initrd.gz ${NODMA} pmedia=${FINALPMEDIA}${FCOPY}" > /mnt/data/syslinux.cfg
 else
  echo "default vmlinuz initrd=initrd.gz pmedia=$FINALPMEDIA$FCOPY" > /mnt/data/syslinux.cfg
 fi
else
 #100321 want a boot menu...
 if [ "$FINALPMEDIA" = "ataflash" ];then
  echo "default puppy
display boot.msg
prompt 1
timeout 50

F1 boot.msg
F2 help.msg
F3 help2.msg

label puppy
kernel vmlinuz
append initrd=initrd.gz ${NODMA} pmedia=${FINALPMEDIA}${FCOPY}" > /mnt/data/syslinux.cfg
 else
  echo "default puppy
display boot.msg
prompt 1
timeout 50

F1 boot.msg
F2 help.msg
F3 help2.msg

label puppy
kernel vmlinuz
append initrd=initrd.gz pmedia=${FINALPMEDIA}${FCOPY}" > /mnt/data/syslinux.cfg
 fi
 cp -f $SRCPATH/boot.msg /mnt/data/
 cp -f $SRCPATH/help*.msg /mnt/data/
 cp -f $SRCPATH/logo.16 /mnt/data/
 sync
fi

echo ""
echo "Creating marker file for wakepup boot floppy..."
[ "$FINALPMEDIA" = "usbflash" ] && touch /mnt/data/USBFLASH
[ "$FINALPMEDIA" = "ataflash" ] && touch /mnt/data/IDEFLASH
[ "$FINALPMEDIA" = "usbhd" ] && touch /mnt/data/USBHD
[ "$FINALPMEDIA" = "atazip" ] && touch /mnt/data/IDEZIP
sync
echo "Copying initrd.gz..."
cp -f $SRCPATH/initrd.gz /mnt/data/
sync
echo "Copying .sfs files..."
cp -f $SRCPATH/${DISTRO_PUPPYSFS} /mnt/data/ 2>/dev/null
sync
cp -f $SRCPATH/${DISTRO_ZDRVSFS} /mnt/data/ 2>/dev/null
sync
#cp -f $SRCPATH/${DISTRO_DEVXSFS} /mnt/data/ 2>/dev/null
#sync
umount /mnt/data
echo -n "Finished, press ENTER key to continue: "
read moo
' > /tmp/installpup.sh
    chmod 755 /tmp/installpup.sh
    rxvt -bg "orange" -title "`gettext \"Puppy Universal Installer\"`" -geometry 80x10 -e /tmp/installpup.sh $DESTPART $SRCPATH $FINALPMEDIA $DISTRO_FILE_PREFIX $DISTRO_PUPPYSFS $DISTRO_ZDRVSFS #$DISTRO_DEVXSFS # transl-47
    ;;
   ext2|ext3|ext4)
    #params passed in: $DESTPART "$SRCPATH" $FINALPMEDIA
    echo '#!/bin/sh
DESTPART="$1"
SRCPATH="$2"
FINALPMEDIA="$3"
DESTFS="$4"
DISTRO_FILE_PREFIX="$5"
DISTRO_PUPPYSFS="$6"
DISTRO_ZDRVSFS="$7"
#DISTRO_DEVXSFS="$8"
PREFIX1CHAR="`echo -n "$DISTRO_FILE_PREFIX" | cut -c 1`"
echo "ABSOLUTE FINAL SANITY CHECK!"
echo "You are about to install Puppy to /dev/$DESTPART, with boot parameter"
echo "pmedia=$FINALPMEDIA. The files vmlinuz, initrd.gz, ${DISTRO_PUPPYSFS}, extlinux.conf"
echo "(and maybe ${DISTRO_ZDRVSFS} if it exists. ${DISTRO_PUPPYSFS} may be inside initrd.gz)"
echo "will be written to /dev/$DESTPART and Extlinux will be used to make it bootable."
echo
echo -n "Press ENTER key to continue, CTRL-C to abort: "
read goforit
mount -t $DESTFS /dev/$DESTPART /mnt/data
if [ ! $? -eq 0 ];then #v3.95
 dpPATTERN="^/dev/$DESTPART "
 if [ "`mount | grep "$dpPATTERN"`" = "" ];then
  echo
  echo "/dev/$DESTPART failed to mount on /mnt/data ...nothing else mounted on"
  echo "/mnt/data? One known case for this failure is when installing to the"
  echo "internal Flash drive of a Intel Classmate laptop. Well, you can attempt"
  echo "to fix this problem by creating a new $DESTFS filesystem in $DESTPART (which"
  echo "will of course wipe anything previously there -- which will not matter"
  echo "if you have already backed up the previous operating system)."
  echo "Press ENTER only to abort installation, or"
  echo "press any char then ENTER to create a new f.s. then proceed with install: "
  read NEWFS
  [ "$NEWFS" = "" ] && exit
  DFPARAM=""
  [ "$DESTFS" = "ext3" ] && DFPARAM="-j"
  echo "y" | mke2fs $DFPARAM -m 0 /dev/$DESTPART
  sync
  mount -t $DESTFS /dev/$DESTPART /mnt/data
  if [ ! $? -eq 0 ];then
   echo -n "Sorry, still cannot mount $DESTPART partition. Press ENTER to quit: "
   read NOWQUIT
   exit
  fi
 fi
fi
echo
echo "Do you want to wipe all files in /dev/$DESTPART? This is currently mounted"
echo "on /mnt/data so you can look at what is there before answering. You would"
echo "normally answer no if upgrading Puppy, or yes for a fresh install and"
echo "you want to get rid of old files that are just taking up space."
echo "Note, you can also manually prune files in /mnt/data then choose no here."
echo "Note, if you choose no here, this script will still do some basic deleting"
echo "of any files of an earlier Puppy installation (not the ${DISTRO_FILE_PREFIX}save though!)."
echo
echo "No, press ENTER only to not wipe all files, or"
echo -n "Yes, press any alpha or numeric char then ENTER to wipe all files: "
read WIPEALL
if [ "$WIPEALL" != "" ];then
 echo
 echo "Deleting everything in /mnt/data..."
 rm -rf /mnt/data/*
else
 #well, minimum to get rid of...
 rm -f /mnt/data/image.gz 2> /dev/null
 rm -f /mnt/data/usr_cram.fs 2> /dev/null
 rm -f /mnt/data/pup_[0-9]*.sfs 2>/dev/null
 rm -f /mnt/data/${DISTRO_FILE_PREFIX}-*.sfs 2>/dev/null
 rm -f /mnt/data/devx_*.sfs 2>/dev/null
 rm -f /mnt/data/z${PREFIX1CHAR}*.sfs 2>/dev/null
 rm -f /mnt/data/${DISTRO_PUPPYSFS} 2>/dev/null #100913
 rm -f /mnt/data/${DISTRO_ZDRVSFS} 2>/dev/null #100913
 #rm -f /mnt/data/${DISTRO_DEVXSFS} 2>/dev/null #100913
fi
sync
echo
echo "Making $DESTPART bootable..."
if [ ! "`echo "$DESTPART" | grep '[0-9]$'`" = "" ];then
 extlinux -i /mnt/data #i think only use -z for superfloppy.
else
 extlinux -i -z /mnt/data
fi
sync
echo "Copying vmlinuz..."
cp -f $SRCPATH/vmlinuz /mnt/data/
sync
echo "Creating extlinux.conf..."
FCOPY=""
echo "Would you like extlinux.cfg to have 'pfix=copy' boot parameter?"
echo "this will cause ${DISTRO_PUPPYSFS} to be copied into RAM at bootup, which slows"
echo "bootup but speeds application startup slightly."
echo "Probably good to answer yes here if PC has 256MB or more RAM."
echo "(you can edit extlinux.conf later to change the choice made here)"
echo "(note, Puppy will override this and not copy if there is insufficient RAM)"
echo -n "ENTER key only for no, else any char then ENTER for yes: "
read FCOPY
[ "$FCOPY" != "" ] && FCOPY=" pfix=copy"

#100321 big assumption here, that current running kernel matches one being installed...
if [ -e /proc/ide ];then
 NODMA="ide=nodma" #old kernel
else
 #old 'ide=nodma' does not work, need 'libata.dma=3' this enables DMA for Disk and CD/DVD but NOT for CF.
 NODMA="libata.dma=3"
fi
if [ ! -f $SRCPATH/boot.msg ];then #100321
 if [ "$FINALPMEDIA" = "ataflash" ];then
  echo "default vmlinuz initrd=initrd.gz ${NODMA} pmedia=${FINALPMEDIA}${FCOPY}" > /mnt/data/extlinux.conf
 else
  echo "default vmlinuz initrd=initrd.gz pmedia=$FINALPMEDIA$FCOPY" > /mnt/data/extlinux.conf
 fi
else
 #100321 want a boot menu...
 if [ "$FINALPMEDIA" = "ataflash" ];then
  echo "default puppy
display boot.msg
prompt 1
timeout 50

F1 boot.msg
F2 help.msg
F3 help2.msg

label puppy
kernel vmlinuz
append initrd=initrd.gz ${NODMA} pmedia=${FINALPMEDIA}${FCOPY}" > /mnt/data/extlinux.conf
 else
  echo "default puppy
display boot.msg
prompt 1
timeout 50

F1 boot.msg
F2 help.msg
F3 help2.msg

label puppy
kernel vmlinuz
append initrd=initrd.gz pmedia=${FINALPMEDIA}${FCOPY}" > /mnt/data/extlinux.conf
 fi
 cp -f $SRCPATH/boot.msg /mnt/data/
 cp -f $SRCPATH/help*.msg /mnt/data/
 cp -f $SRCPATH/logo.16 /mnt/data/
 sync
fi

#note do not create wakepup marker file as it only boots msdsos/vfat.
echo "Copying initrd.gz..."
cp -f $SRCPATH/initrd.gz /mnt/data/
sync
echo "Copying .sfs files..."
cp -f $SRCPATH/${DISTRO_PUPPYSFS} /mnt/data/ 2>/dev/null
sync
cp -f $SRCPATH/${DISTRO_ZDRVSFS} /mnt/data/ 2>/dev/null
sync
#cp -f $SRCPATH/${DISTRO_DEVXSFS} /mnt/data/ 2>/dev/null
#sync
umount /mnt/data
echo -n "Finished, press ENTER key to continue: "
read moo
' > /tmp/installpup.sh
    chmod 755 /tmp/installpup.sh
    rxvt -bg "orange" -title "`gettext \"Puppy Universal Installer\"`" -geometry 80x10 -e /tmp/installpup.sh $DESTPART $SRCPATH $FINALPMEDIA $DESTFS $DISTRO_FILE_PREFIX $DISTRO_PUPPYSFS $DISTRO_ZDRVSFS #$DISTRO_DEVXSFS # transl-48
    ;;
   *)
    gxmessage "`eval_gettext \"Your \\\$DESTPART has a \\\$DESTFS filesystem. Currently only install
to external vfat (FAT16/32) or ext2/ext3 filesystems is supported.
Click OK to quit...\"`" # transl-49
    exit
    ;;
  esac
  ;;
 scsihd|atahd|idehd|satahd) #internal media, boot with boot-disk or grub. #v3.98
  #arrive here with DESTPART & DESTFS where installing to, PMEDIA boot param FINALPMEDIA,
  #SRCPATH where to get vmlinuz, initrd, ${DISTRO_PUPPYSFS}, PUPVEROLD is old puppy version in
  #format 200 (without dots) =0 if no prior installed puppy,
  #NEWVER is new puppy version, DESTSIZM is size of dest partition in Mb (real number),
  DESTMNTPT="`mount | grep "/dev/$DESTPART" | tr -s " " | cut -f 3 -d " "`"
  #v2.02 ntfs-3g needs this...
  #[ "$DESTMNTPT" = "" ] && DESTMNTPT="`ps -e | grep -o ntfs\-3g.* | grep "/dev/$DESTPART" | sed -e 's/[^a-zA-Z0-9/._\-]/ /g' | tr -s ' ' | tr ' ' "\n" | grep '^/mnt/'`"
  
   [ "$DESTMNTPT" = "" ] && DESTMNTPT="`ps -e | grep -o 'ntfs\-3g.*' | grep "/dev/$DESTPART" | tr '\t' ' ' | tr -s ' ' | tr ' ' "\n" | grep '^/mnt/'`"

  if [ "$DESTMNTPT" = "" ];then
   mkdir /mnt/$DESTPART 2> /dev/null
   mount -t $DESTFS /dev/$DESTPART /mnt/$DESTPART
   DESTMNTPT="/mnt/$DESTPART"
  fi

  #choose option1 or option2 install...
  #option1: files vmlinuz, initrd.gz, ${DISTRO_PUPPYSFS}, to dest partition.
  #option2: file vmlinuz to partition, contents of ${DISTRO_PUPPYSFS} to partition.
  if [ $PUPVEROLD -eq 0 ];then
   PREVPUPMSG="`gettext \"It appears that this is a new installation.\"`" # transl-50
  else
   PREVPUPMSG="`eval_gettext \"There appears to be an existing installation of Puppy, version \\\$PUPVEROLD,
and you may choose to upgrade or totally replace.\"`" # transl-51
  fi
  INSTOPTION="1"
  if [ ! "$DESTFS" = "vfat" ];then
   Xdialog --wmclass "gtkdialog2" --left --buttons-style text --title "`gettext \"Puppy Universal Installer\"`" --ok-label "`gettext \"FRUGAL\"`" --cancel-label "`gettext \"FULL\"`" --yesno "`eval_gettext \"You have chosen to install to /dev/\\\$DESTPART, which appears to be an internal
hard drive (\\\$FINALPMEDIA).
\\\$PREVPUPMSG 

There are two ways to install Puppy to the partition:

1. FRUGAL (recommended)
Copies the files vmlinuz, initrd.gz, \\\${DISTRO_PUPPYSFS} and \\\${DISTRO_ZDRVSFS} to the
partition, saving your personal settings inside a \\\${DISTRO_FILE_PREFIX}save file (like when
running from CD) and leaving the previous contents of the partition
untouched. PROS:
- Can coexist with another distro installed to the same partition.
- Can install to a non-Linux FAT or NTFS partition (former preferred).
- Easier to upgrade: just download the new .iso file and replace the above
  files with their newer versions (mount the .iso to access the files).
  (Note: A .iso can easily be mounted in puppy just by clicking on it)
- Enables the use of .sfs addons (application combo-packs).
- Can save to entire partition if Linux f.s. and no need to coexist.

2. FULL
A \"normal\" Linux installation, requiring usage of the entire partition by Puppy.

Note: FRUGAL option, if install to a FAT or NTFS partition, there is an
extra boot option: \"WakePup2\", using a floppy disk. Otherwise, GRUB is
the normal method, booting from floppy, USB or internal hard drive.

Click FRUGAL for coexist install (recommended)...
Click FULL for conventional install...
Click window close box to quit...\"`" 0 0 # transl-52
   RET_VAL=$?
   [ $RET_VAL -eq 255 ] && exit
   [ $RET_VAL -eq 1 ] && INSTOPTION="2"
  fi

  #info for creating a grub entry...
  DRV_TYPE="`echo -n "$DESTPART" | cut -b 1-3`" #ex: hda
  GRUB_DRVN=0
  for ONE_TYPE in `fdisk -l | grep "^Disk /dev/" | cut -d' ' -f2 | cut -d':' -f1 | tr '\n' ' '`
  do
   [ "/dev/$DRV_TYPE" = "$ONE_TYPE" ] && break
   GRUB_DRVN=`expr $GRUB_DRVN + 1`
  done
  GRUB_PARTN=`echo -n "$DESTPART" | cut -b 4-5`
  if [ $GRUB_PARTN ];then
   GRUB_PARTN=`expr $GRUB_PARTN - 1`
   GRUB_PARTN=",$GRUB_PARTN"
  fi
   
  #INSTOPTION, install puppy to DESTPART...
  if [ "$INSTOPTION" = "1" ];then #frugal.
  
   case $DESTFS in #100719
    ext2|ext3|ext4|reiserfs|minix|btrfs)
     Xdialog --stdout --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --msgbox "`eval_gettext \"You have chosen a frugal installation. As you are installing Puppy to a
partition with a Linux filesystem (\\\${DESTFS}), the first time that you run
Puppy and shutdown you will be offered to save the session to either a single
file or to the entire partition.

A single file has convenience for backup and there can be multiple session
files, both for this installation of Puppy and for other installations of
Puppy. Saving the session to the entire partition has the advantage of all
the space available in that partition, however this is a warning for the
next dialog in this Puppy Universal Installer...

The next dialog will ask if you want to install Puppy into a sub-directory.
If you intend to, or might want to, save the session to entire partition, do
NOT install to a sub-directory, leave the folder field empty...\"`" 0 0 # transl-53
    ;;
   esac
   
   #101107 fix msg, puppy now searches 2-deep...
   Xdialog --stdout --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --fixed-font --no-cancel --inputbox "`eval_gettext \"Puppy is going to be installed to partition \\\${DESTPART}, which is currently
mounted on path \\\${DESTMNTPT}. As this will be a frugal install, you can
choose to place the Puppy files in a folder. This is very convenient if you
want to have more than one installation of Puppy. Even if you only have one
installation, it may be good to have all the Puppy files in their own folder
and so not causing any potential conflicts with other files at the top '/'
level (ex: a pre-existing full Linux install may have 'initrd.gz' at '/').

Enter a unique name for the folder. Note, Puppy will search 2-deep, so this
(for example) 'puppyfiles/pup\\\${NEWVER}' is okay. Or, a folder at the top
level, 'pup\\\${NEWVER}' is okay (of course, do not type the '). Type a string
without any spaces, or leave blank if you want to install Puppy at '/'.
The folders will be created if don't exist...\"`" 0 0 "puppy${NEWVER}" >/tmp/NEWPSUBDIR # transl-54
   [ $? -ne 0 ] && exit
   NEWPSUBDIR="`cat /tmp/NEWPSUBDIR | sed -e 's%^/%%' -e 's%/$%%' -e 's%[^/a-zA-Z0-9]%%g'`" #101107
   NEWPSUBCNT=`echo -n "$NEWPSUBDIR" | sed -e 's%[^/]%%g' | wc -c` #101107
   [ $NEWPSUBCNT -gt 2 ] && NEWPSUBDIR="`echo -n "$NEWPSUBDIR" | sed -e 's%/%%g'`" #101107 too many '/' chars.
   
   yaf-splash -outline 0 -margin 4 -bg orange -text "`eval_gettext \"Please wait, copying files to \\\$DESTPART, in folder \\\$NEWPSUBDIR...\"`" & # transl-55
   XPID=$!
   mkdir -p $DESTMNTPT/$NEWPSUBDIR
   cp -f $SRCPATH/vmlinuz $DESTMNTPT/$NEWPSUBDIR/
   sync
   cp -f $SRCPATH/initrd.gz $DESTMNTPT/$NEWPSUBDIR/
   sync
   cp -f ${SRCPATH}/${DISTRO_PUPPYSFS} $DESTMNTPT/$NEWPSUBDIR/ #v424
   sync
   [ -f $SRCPATH/${DISTRO_ZDRVSFS} ] && cp -f $SRCPATH/${DISTRO_ZDRVSFS} $DESTMNTPT/$NEWPSUBDIR/
   sync
   #[ -f $SRCPATH/${DISTRO_DEVXSFS} ] && cp -f $SRCPATH/${DISTRO_DEVXSFS} $DESTMNTPT/$NEWPSUBDIR/ #100913
   sync
   FPCAPS="`echo -n "$FINALPMEDIA" | tr [a-z] [A-Z]`"
   touch $DESTMNTPT/$NEWPSUBDIR/$FPCAPS #needed by WakePup
   sync
   kill $XPID
   umount /dev/$DESTPART
   
   if [ "`echo -n "$DESTFS" | grep -E 'msdos|vfat'`" != "" ];then
   
    Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --ok-label "`gettext \"CREATE_BOOT_DISK\"`" --cancel-label "`gettext \"NO_BOOT_DISK\"`" --yesno "`gettext \"
A floppy disk can be used to boot Puppy.
Currently we are offering WakePup2, a generic boot floppy
that scans the PC and finds where Puppy is installed.

Note, after this, you will be informed how to configure the
Grub bootloader.\"`" 0 0 # transl-56
    if [ $? -eq 0 ];then
     /usr/sbin/wakepup2
    fi
    
   fi
   xNEWPSUBDIR=""
   OPTIONPSUBDIR=""
   if [ "$NEWPSUBDIR" != "" ];then
    xNEWPSUBDIR="/$NEWPSUBDIR"
    OPTIONPSUBDIR=" psubdir=${NEWPSUBDIR}"
   fi
   if [ -e /proc/ide ];then #v3.97
    grubEXTRAMSG=""
   else
    grubEXTRAMSG="`eval_gettext \"
WARNING: If your PC has a mix of IDE and SATA hard drives, then (hd\\\${GRUB_DRVN}\\\${GRUB_PARTN})
may be wrong. GRUB numbers drives as hd<drive>,<partition> where
<drive> and <partition> numbering starts from zero. The problem is
that GRUB sees IDE drives first (hd0,), whereas if you look at Pmount
you may see it listed second (hd1,). The Uni. Installer uses the
ordering as reported by Pmount, which may be wrong for GRUB!
(EX: if an IDE drive is hd1,0 (sdb1), may need to be changed to hd0,0)\"`" # transl-57
   fi

   #091211...
   echo "`gettext \"If you have GRUB installed, find the 'menu.lst' file (usually in /boot
in the partition in which GRUB is installed) and insert this:\"`
" > /tmp/NEWGRUBTEXT # transl-58
   echo "title Puppy Linux ${NEWVER} frugal in ${DESTPART} dir ${NEWPSUBDIR}
rootnoverify (hd${GRUB_DRVN}${GRUB_PARTN})
kernel ${xNEWPSUBDIR}/vmlinuz pmedia=${FINALPMEDIA}${OPTIONPSUBDIR}
initrd ${xNEWPSUBDIR}/initrd.gz
" >> /tmp/NEWGRUBTEXT
   echo "`gettext \"If you have GRUB4DOS installed, find the 'menu.lst' file (usually in /
in the partition in which GRUB4DOS is installed) and insert this:\"`
" >> /tmp/NEWGRUBTEXT # transl-59
   echo "title Puppy Linux ${NEWVER} frugal in ${DESTPART} dir ${NEWPSUBDIR}
  find --set-root --ignore-floppies ${xNEWPSUBDIR}/initrd.gz
  kernel ${xNEWPSUBDIR}/vmlinuz pmedia=${FINALPMEDIA}${OPTIONPSUBDIR}
  initrd ${xNEWPSUBDIR}/initrd.gz" >> /tmp/NEWGRUBTEXT

   nohup defaulttextviewer /tmp/NEWGRUBTEXT &
   sleep 3

   Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --msgbox "`eval_gettext \"Now you can manually setup your GRUB, GRUB4DOS, LILO or other boot system.

Partition \\\$DESTPART has the files vmlinuz, initrd.gz and \\\${DISTRO_PUPPYSFS}
on it, where vmlinuz is the kernel, initrd.gz is the initial ramdisk and
\\\${DISTRO_PUPPYSFS} is all the Puppy-files.

If you already have GRUB or GRUB4DOS installed, see the text editor
window for text that can be inserted into 'menu.lst'.

If you do NOT have GRUB or GRUB4DOS (or any other boot manager) installed,
just click the 'OK' button to finish the installation, then go to the
'System' menu and run the GRUB or GRUB4DOS installer (you probably will
not need the text in the text editor window, as the installers will probe
your PC for all installations of Puppy and other operating systems).
\\\${grubEXTRAMSG}\"`" 0 0 # transl-60
   
   #finished. could put up a final dlg here, then quit script.
   Xdialog --wmclass "gtkdialog2" --title "`gettext \"Puppy Universal Installer\"`" --msgbox "`gettext \"Okay, all done!\"`" 0 0 # transl-61
   exit
  else #h.d. install option2
   #upgrade, ask if want delete partition...
   if [ ! $PUPVEROLD -eq 0 ];then
    Xdialog --wmclass "gtkdialog2" --left --buttons-style text --title "`gettext \"Puppy Universal Installer\"`" --ok-label "`gettext \"UPGRADE\"`" --cancel-label "`gettext \"WIPE\"`" --yesno "`eval_gettext \"There is already a version of Puppy installed in \\\$DESTPART.\nDo you want to upgrade, or totally wipe the partition?\n\nFINAL SANITY CHECK: ARE YOU SURE \\\$DESTPART IS THE RIGHT PARTITION?\n(note, \\\$DESTPART is currently mounted on \\\$DESTMNTPT -- okay?)\n\nSelect UPGRADE button to upgrade...\nSelect WIPE button to wipe partition...\nClick window Close box to quit...\"`" 0 0 # transl-62
    RET_VAL=$?
    if [ $RET_VAL -eq 255 ];then
     rox -D "$DESTMNTPT"
     sync
     umount $DESTMNTPT 2>/dev/null
     exit
    fi
    if [ $RET_VAL -eq 1 ];then #no
     Xdialog --wmclass "gtkdialog2" --title "`gettext \"Puppy Universal Installer\"`" --no-buttons --infobox "`eval_gettext \"Please wait, wiping all files in \\\$DESTPART...\"`" 0 0 200000 & # transl-63
     XPID=$!
     sleep 3
     rm -rf $DESTMNTPT/*
     sync
     kill $XPID
     PUPVEROLD=`expr $DISTRO_VERSION - 1` #v430
    fi
   fi
   Xdialog --wmclass "gtkdialog2" --title "`gettext \"Puppy Universal Installer\"`" --no-buttons --infobox "`eval_gettext \"Please wait, copying Puppy files to \\\$DESTPART...\"`" 0 0 120000 & # transl-64
   XPID=$!
   sleep 1
   #loop-device mount ${DISTRO_PUPPYSFS} in DESTPART, copy contents of ${DISTRO_PUPPYSFS} to DESTPART...
   #SFSPATTERN="^${DISTRO_PUPPYSFS}" #100913
   #xSFSNAME="`ls -1 $SRCPATH/ | grep "$SFSPATTERN" | head -n 1`" #v3.01
   ##losetup-FULL /dev/loop2 $SRCPATH/${DISTRO_FILE_PREFIX}-$NEWVER.sfs
   #losetup-FULL /dev/loop2 $SRCPATH/$xSFSNAME #v3.01
   losetup-FULL /dev/loop2 $SRCPATH/$DISTRO_PUPPYSFS #100913
   mkdir $DESTMNTPT/srcmntpt
   mount -r -t squashfs /dev/loop2 $DESTMNTPT/srcmntpt
   cp -a -u --remove-destination $DESTMNTPT/srcmntpt/bin $DESTMNTPT/
   cp -a -u --remove-destination $DESTMNTPT/srcmntpt/dev $DESTMNTPT/
   cp -a -u --remove-destination $DESTMNTPT/srcmntpt/etc $DESTMNTPT/
   cp -a -u --remove-destination $DESTMNTPT/srcmntpt/lib $DESTMNTPT/
   cp -a -u --remove-destination $DESTMNTPT/srcmntpt/mnt $DESTMNTPT/
   cp -a -u --remove-destination $DESTMNTPT/srcmntpt/proc $DESTMNTPT/
   cp -a -u --remove-destination $DESTMNTPT/srcmntpt/root $DESTMNTPT/
   cp -a -u --remove-destination $DESTMNTPT/srcmntpt/sbin $DESTMNTPT/
   cp -a -u --remove-destination $DESTMNTPT/srcmntpt/tmp $DESTMNTPT/
   cp -a -u --remove-destination $DESTMNTPT/srcmntpt/usr $DESTMNTPT/
   cp -a -u --remove-destination $DESTMNTPT/srcmntpt/var $DESTMNTPT/
   [ -d $DESTMNTPT/srcmntpt/opt ] && cp -a -u --remove-destination $DESTMNTPT/srcmntpt/opt $DESTMNTPT/ #v2.11
   
   #v2.12 external modules file...
   #w482 fix handling if separate zdrv file...
   [ -f $SRCPATH/${DISTRO_ZDRVSFS} ] && cp -af $SRCPATH/${DISTRO_ZDRVSFS} $DESTMNTPT/
   [ -f /${DISTRO_ZDRVSFS} ] && cp -af /${DISTRO_ZDRVSFS} $DESTMNTPT/
   if [ -f $DESTMNTPT/${DISTRO_ZDRVSFS} ];then #w482
    mkdir -p $DESTMNTPT/data
    mount -t squashfs -o loop $DESTMNTPT/${DISTRO_ZDRVSFS} $DESTMNTPT/data
    cp -a -f --remove-destination $DESTMNTPT/data/* $DESTMNTPT/
    depmod -b $DESTMNTPT
    sync
    umount $DESTMNTPT/data
    rm -f $DESTMNTPT/${DISTRO_ZDRVSFS}
   fi
   #w482 put these modules back into the normal places...
   if [ -d /lib/modules/$KERNELVER/initrd ];then
    #note, important to not have 'initrd' folder in full hd installation, messes up rc.sysinit.
    cp -af /lib/modules/$KERNELVER/initrd/* $DESTMNTPT/lib/modules/$KERNELVER/
    depmod -b $DESTMNTPT
   fi

   ##100913 do same for devx...
   #[ -f $SRCPATH/${DISTRO_DEVXSFS} ] && cp -af $SRCPATH/${DISTRO_DEVXSFS} $DESTMNTPT/
   #[ -f /${DISTRO_DEVXSFS} ] && cp -af /${DISTRO_DEVXSFS} $DESTMNTPT/
   #if [ -f $DESTMNTPT/${DISTRO_DEVXSFS} ];then #w482
   # mkdir -p $DESTMNTPT/data
   # mount -t squashfs -o loop $DESTMNTPT/${DISTRO_DEVXSFS} $DESTMNTPT/data
   # cp -a -f --remove-destination $DESTMNTPT/data/* $DESTMNTPT/
   # sync
   # umount $DESTMNTPT/data
   # rm -f $DESTMNTPT/${DISTRO_DEVXSFS}
   #fi
   
   #100113 /bin/TARGETEXES has list of executables that were copied from initrd (and not in main f.s.)...
   if [ -f /bin/TARGETEXES ];then
    for ONEEXE in `cat /bin/TARGETEXES` #ex: sbin/e2fsck
    do
     DIREXE="`dirname $ONEEXE`"
     cp -a -f --remove-destination /${ONEEXE} ${DESTMNTPT}/${DIREXE}/
    done
   fi
   #same thing here...
   if [ -d /lib/keymaps ];then
    mkdir -p ${DESTMNTPT}/lib/keymaps
    cp -a -f /lib/keymaps/* ${DESTMNTPT}/lib/keymaps/
    mkdir -p ${DESTMNTPT}/lib/consolefonts
    cp -a -f /lib/consolefonts/* ${DESTMNTPT}/lib/consolefonts/
   fi

   
   mkdir $DESTMNTPT/sys 2>/dev/null
   rm -f $DESTMNTPT/var/log/modprobes.log 2>/dev/null #v2.13 see /sbin/modprobe script.
   #...not necessary, not using this any more.
   #v3.96 /etc/rc.d/PUPSTATE only has 'PUPMODE=2', add this...
   if [ -e /proc/ide ];then
    echo "SATADRIVES='$SATADRIVES'" >> $DESTMNTPT/etc/rc.d/PUPSTATE
   else
    echo '#NEWS: IDE hd* drives are now also sd*. ATADRIVES is both ide and sata...' >> $DESTMNTPT/etc/rc.d/PUPSTATE
    echo "ATADRIVES='$ATADRIVES'" >> $DESTMNTPT/etc/rc.d/PUPSTATE
   fi
   sync
   kill $XPID
   #fix space optimisation links into initrd...
    #TODO
   #chroot to DESTPART, set DISTRO_VERSION back to $PUPVEROLD, run rc.update
   Xdialog --wmclass "gtkdialog2" --title "`gettext \"Puppy Universal Installer\"`" --no-buttons --infobox "`gettext \"Please wait, executing rc.update script...\"`" 0 0 60000 & # transl-65
   XPID=$!
   sleep 2
   
   if [ -f $DESTMNTPT/etc/puppyversion ];then #historical file, old installations.
    echo -n "$PUPVEROLD" > $DESTMNTPT/etc/puppyversion #set it back to what it was.
   fi
   if [ -f $DESTMNTPT/etc/DISTRO_SPECS ];then
    vPATTERN="s%^DISTRO_VERSION=.*%DISTRO_VERSION=${PUPVEROLD}%"
    sed -e "$vPATTERN" $DESTMNTPT/etc/DISTRO_SPECS > /tmp/distro_specs_old
    cp -f /tmp/distro_specs_old $DESTMNTPT/etc/DISTRO_SPECS #set DISTRO_VERSION back to what it was.
   fi
   
   #chroot $DESTMNTPT -c /etc/rc.d/rc.update option2hdinstall
   #busybox chroot does not have -c ...
   chroot $DESTMNTPT /etc/rc.d/rc.update option2hdinstall
   #(need to tell rc.update where src files are, as passed param)
   sync
    mv -f $DESTMNTPT/etc/fstab $DESTMNTPT/etc/fstab.bak
    echo "/dev/$DESTPART     /            $DESTFS     defaults               0 1" > $DESTMNTPT/etc/fstab
    echo "none          /proc        proc     defaults               0 0" >> $DESTMNTPT/etc/fstab
    echo "none          /sys         sysfs    defaults               0 0" >> $DESTMNTPT/etc/fstab
    echo "none          /dev/pts     devpts   gid=2,mode=620         0 0" >> $DESTMNTPT/etc/fstab
    echo "/dev/fd0      /mnt/floppy  auto     noauto,rw              0 0" >> $DESTMNTPT/etc/fstab
    #echo "/dev/cdrom    /mnt/cdrom   iso9660  noauto,ro              0 0" >> $DESTMNTPT/etc/fstab
    sync
   kill $XPID
   umount $DESTMNTPT/srcmntpt
   rmdir $DESTMNTPT/srcmntpt
  fi

  #make bootable...
  #usb/floppy boot disk, or grub.

  while [ "$INSTOPTION" = "2" ];do

   #091210 simpler stuff for grub4dos...
   if [ -f /usr/sbin/grub4dosconfig ];then
    mkdir -p /mnt/$DESTPART/boot/grub
    cp -af $SRCPATH/vmlinuz /mnt/$DESTPART/boot/
    sync
    umount /mnt/$DESTPART
    unmountcdfunc
    echo "`gettext \"
If you have GRUB installed, find the 'menu.lst' file (usually in /boot
in the partition in which GRUB is installed) and insert the text,
or, if you have GRUB4DOS installed, find the 'menu.lst' file (usually
in / in the partition in which GRUB4DOS is installed) and insert this:\"`
" > /tmp/NEWGRUBTEXT # transl-66
    echo "title Puppy Linux ${NEWVER} full install in ${DESTPART}
root (hd${GRUB_DRVN}${GRUB_PARTN})
kernel /boot/vmlinuz root=/dev/${DESTPART} pmedia=${FINALPMEDIA}
`eval_gettext \"
WARNING: If your PC has a mix of IDE and SATA hard drives, then (hd\\\${GRUB_DRVN}\\\${GRUB_PARTN})
may be wrong. GRUB numbers drives as hd<drive>,<partition> where
<drive> and <partition> numbering starts from zero. The problem is
that GRUB sees IDE drives first (hd0,), whereas if you look at Pmount
you may see it listed second (hd1,). The Uni. Installer uses the
ordering as reported by Pmount, which may be wrong for GRUB!
(EX: if an IDE drive is hd1,0 (sdb1), may need to be changed to hd0,0)\"`" >> /tmp/NEWGRUBTEXT # transl-67

    nohup defaulttextviewer /tmp/NEWGRUBTEXT &
    sleep 3

    Xdialog --wmclass "gtkdialog2" --left --buttons-style text --title "`gettext \"Puppy Universal Installer\"`" --ok-label "OK" --msgbox "`eval_gettext \"If all went well, Puppy has been installed to \\\$DESTPART.\n\
The text-editor window shows text that you can insert into the menu.lst
file if you have GRUB or GRUB4DOS inststalled.

If your PC does not have GRUB, GRUB4DOS, LILO or any other boot manager
installed, or you want to do a reinstallation, just click the 'OK'
button to finish the Universal Installer, then go to the 'System' menu
and run the GRUB or GRUB4DOS installer -- this will probe your PC, so
you probably won't need the contents of the text-editor...\"`" 0 0 # transl-68

    break
   fi

#TODO needs work, as could have usb hd, that cannot unplug and do not want it to be turned
#     into a boot disk!...
   Xdialog --wmclass "gtkdialog2" --left --buttons-style text --title "`gettext \"Puppy Universal Installer\"`" --ok-label "`gettext \"Boot from USB\"`" --cancel-label "`gettext \"Install/update GRUB\"`" --yesno "`eval_gettext \"If all went well, Puppy has been installed to \\\$DESTPART.\n\
But, now we have the sometimes-difficult part, how to make Puppy bootable.\n\
You can do one, or both, of these:\n\
\n\
Boot disk: Use a floppy disk or USB pen drive to boot Puppy.\n\
GRUB:      Install GRUB in the hard drive (or update existing GRUB).\n\
\n\
Click 'Boot from USB' if you want to sacrifice a usb Flash pen drive as a\n\
'boot disk'. This Universal Installer script will return to this dialog\n\
window after creating the USB 'boot disk'.\n\
Note, you would probably only choose this if your PC does not have a floppy\n\
drive and you do not want to install GRUB to the hard drive.\n\
\n\
Click 'Install/update GRUB' to install (or update) the GRUB boot manager.\n\
You will be given the opportunity to create a floppy 'boot disk' as well\n\
as install GRUB to the hard drive.\n\
\n\
FOR USB BOOT DISK CHOICE, PLEASE INSERT IT RIGHT NOW BEFORE PROCEEDING!\n\
 (must have FAT16 f.s., and any files in it will be deleted)\n\
 IT MUST ALSO BE UNMOUNTED -- BE SURE BEFORE PROCEEDING\"`" 0 0 # transl-69
   if [ $? -eq 0 ];then #BOOT DISK
    BOOTPART=""
    #v3.96...
    USBDRIVES="`echo "$PROBEDISK" | grep '|usbdrv|' | cut -f 3 -d '/' | cut -f 1 -d '|' | tr "\n" " "`"
    for ONEUSB in $USBDRIVES
    do
     [ "$ATADRIVES" != "" ] && [ "`echo "$ATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #eliminate ide/sata drives. v3.97
     [ "$SATADRIVES" != "" ] && [ "`echo "$SATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #eliminate sata drives, old kernel v3.97
     if [ "`disktype /dev/$ONEUSB | grep "file system" | grep "^FAT"`" != "" ];then
      BOOTPART="$ONEUSB"
      break
     fi
     if [ "`disktype /dev/${ONEUSB}1 | grep "file system" | grep "^FAT"`" != "" ];then
      BOOTPART="${ONEUSB}1"
      break
     fi
    done
    if [ ! "$BOOTPART" = "" ];then
     Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --yesno "`eval_gettext \"Please confirm that you want to make '\\\$BOOTPART' into a boot disk for Puppy.\nIf Puppy has mis-identified the device, then answer 'No' here...\n\nClick 'Yes' button if correct device...\"`" 0 0 # transl-70
     [ ! $? -eq 0 ] && continue
    fi
    if [ ! "$BOOTPART" = "" ];then
     cp -af $SRCPATH/vmlinuz /mnt/$DESTPART/
     sync
     Xdialog --wmclass "gtkdialog2" --title "`gettext \"Puppy Universal Installer\"`" --msgbox "`eval_gettext \"Creating \\\$BOOTPART boot disk...\"`" 0 0 & # transl-71
     XPID=$!
     #passed params $BOOTPART $DESTPART $SRCPATH $FINALPMEDIA
     echo '#!/bin/sh
     BOOTPART="$1"
     DESTPART="$2"
     SRCPATH="$3"
     FINALPMEDIA="$4"
      mkdir /tmp/bootdiskmntpt 2> /dev/null
      mount -t msdos /dev/$BOOTPART /tmp/bootdiskmntpt
      rm -rf /tmp/bootdiskmntpt/*
      echo "Creating syslinux.cfg on /dev/$BOOTPART..."
      echo "default vmlinuz root=/dev/$DESTPART pmedia=$FINALPMEDIA" > /tmp/bootdiskmntpt/syslinux.cfg
      echo "Writing the Linux kernel, vmlinuz, to /dev/$BOOTPART..."
      cp -f $SRCPATH/vmlinuz /tmp/bootdiskmntpt/
      sync
      umount /dev/$BOOTPART
      rmdir /tmp/bootdiskmntpt
      echo "Making the /dev/$BOOTPART bootable using Syslinux..."
      syslinux /dev/$BOOTPART
     sync
     echo -n "Done. Press ENTER key: "
     read allisdone
' > /tmp/installpup.sh
     chmod 755 /tmp/installpup.sh
     rxvt -bg "orange" -title "`gettext \"Puppy Universal Installer\"`" -geometry 80x10 -e /tmp/installpup.sh $BOOTPART $DESTPART $SRCPATH $FINALPMEDIA # transl-72

     kill $XPID
    fi
   else #Grub
    mkdir -p /mnt/$DESTPART/boot/grub
    cp -af $SRCPATH/vmlinuz /mnt/$DESTPART/boot/
    sync
    umount /mnt/$DESTPART
    unmountcdfunc
    if [ -e /proc/ide ];then #v3.97
     grubEXTRAMSG=""
    else
     grubEXTRAMSG="`gettext \"
WARNING: If your PC has a mix of IDE and SATA hard drives, then
GRUB may get the drive numbering wrong. In which case, you may
have to manually edit the entry or entries in /boot/grub/menu.lst
in the partition where GRUB is installed. This problem has come
with recent Linux kernels where IDE drives are now /dev/sd*, the
same letters as SATA drives, whereas before they were /dev/hd*.
GRUB uses \"hd\" notation for both IDE and SATA drives, and numbers
drives as hd<drive>,<partition> where <drive> and <partition> numbering
starts from zero (again different, as Linux numbers partitions from 1).
The problem is that GRUB sees IDE drives first (hd0,), whereas if you
look at Pmount you may see it listed second (hd1,). The Uni. Installer
uses the ordering as reported by Pmount, which may be wrong for GRUB!
(EX: if an IDE drive is hd1,0 (sdb1), may need to be changed to hd0,0)\"`" # transl-73
    fi
    Xdialog --buttons-style "text" --wmclass "gtkdialog2" --left --title "`gettext \"Universal Installer\"`" --ok-label "`gettext \"UPDATE\"`" --cancel-label "`gettext \"INSTALL\"`" --yesno "`eval_gettext \"Click UPDATE button if you want to update an existing installation
of GRUB, or click INSTALL to install or reinstall GRUB...
\\\${grubEXTRAMSG}\"`" 0 0 # transl-74
    if [ $? -eq 0 ];then #v3.96 update grub.
     echo "title Puppy Linux $NEWVER full install
root (hd${GRUB_DRVN}${GRUB_PARTN})
kernel /boot/vmlinuz root=/dev/$DESTPART pmedia=${FINALPMEDIA}" > /tmp/NEWGRUBTEXT
     if [ -e /proc/ide ];then #v3.97
      grubEXTRAMSG="`gettext \"...for your convenience, this text has been written to /tmp/NEWGRUBTEXT\"`" # transl-75
     else
      grubEXTRAMSG="`eval_gettext \"...for your convenience, this text has been written to /tmp/NEWGRUBTEXT

WARNING: If your PC has a mix of IDE and SATA hard drives, then (hd\\\${GRUB_DRVN}\\\${GRUB_PARTN})
may be wrong. GRUB numbers drives as hd<drive>,<partition> where
<drive> and <partition> numbering starts from zero. The problem is
that GRUB sees IDE drives first (hd0,), whereas if you look at Pmount
you may see it listed second (hd1,). The Uni. Installer uses the
ordering as reported by Pmount, which may be wrong for GRUB!
(EX: if an IDE drive is hd1,0 (sdb1), may need to be changed to hd0,0)\"`" # transl-76
     fi

     Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Universal Installer\"`" --msgbox "`gettext \"You have chosen to update an existing GRUB installation.
This requires a final manual step...
Find the \"menu.lst\" file (usually in /boot/grub in the 
partition in which GRUB is installed) and insert this:\"`

title Puppy Linux $NEWVER full install in $DESTPART
root (hd${GRUB_DRVN}${GRUB_PARTN})
kernel /boot/vmlinuz root=/dev/$DESTPART pmedia=${FINALPMEDIA}

$grubEXTRAMSG

`gettext \"After you click the OK button, the Uni. Installer will exit.\"`" 0 0 # transl-76,77
     exit
    else
     Xdialog --wmclass "gtkdialog2" --left --title "`gettext \"Puppy Universal Installer\"`" --msgbox "`gettext \"The \"grubconfig\" script is about to be executed.\nJust accept the defaults. The very first question will ask if you\nwant to do a simple installation, and you accept that option, which\nis the default. The only place where I suggest you deviate from the\ndefault, is when it asks where to install Grub, choose \"MBR\".\"`" 0 0 # transl-78
     while [ 1 ];do
      grubconfig /dev/$DESTPART
      #...if choose to create a boot floppy, writes 'no' to /tmp/loopbrk.txt.
      Xdialog --wmclass "gtkdialog2" --title "`gettext \"Universal Installer\"`" --yesno "`gettext \"If you have already run grubconfig to create a boot floppy or installed\n\
to h.d., click 'Yes' button to rerun grubconfig script to either create\n\
another boot floppy or install or reinstall GRUB to the hard drive.\n\
If choose 'Yes', just accept all the defaults as before.\n\
\n\
Click 'Yes' to rerun grubconfig...\n\
Click 'No' if installation finished...\"`" 0 0 # transl-79
      [ ! $? -eq 0 ] && break
     done
     rm -f /tmp/loopbrk.txt
     exit
    fi
   fi
   Xdialog --wmclass "gtkdialog2" --title "`gettext \"Puppy Universal Installer\"`" --yesno "`gettext \"Do you want to go back and create another boot disk or Grub boot?...\"`" 0 0 # transl-80
   [ ! $? -eq 0 ] && break
  done

  umount /mnt/$DESTPART 2> /dev/null
  ;;
 atacd|scsicd|usbcd)
  gxmessage "`gettext \"not yet implemented\"`" # transl-81
  #TO DO
  ;;
esac

unmountcdfunc

###END###
