All pastes #800090 Raw Edit

Mine

public text v1 · immutable
#800090 ·published 2007-11-28 02:35 UTC
rendered paste body
#!/bin/sh
#(c) Copyright Barry Kauler 2006 www.puppylinux.com

NEWVER="`cat /etc/puppyversion`"
#mount > /etc/mtab   #v2.10 remove.
KERNVER="`uname -r`"

#USBINFO="`lspci -i /usr/share/pci-usb-pcmcia.ids`"

#v2.10
. /etc/rc.d/PUPSTATE

fsfunc() #f.s. type param passed in
{
 FSTYPE="$1"
 [ "$FSTYPE" = "Ext2" ] && FSTYPE="ext2"
 [ "$FSTYPE" = "ReiserFS" ] && FSTYPE="reiserfs"
 [ "$FSTYPE" = "Ext3" ] && FSTYPE="ext3"
 [ "$FSTYPE" = "FAT16" ] && FSTYPE="vfat"
 [ "$FSTYPE" = "FAT32" ] && FSTYPE="vfat"
 [ "$FSTYPE" = "NTFS" ] && FSTYPE="ntfs"
 [ "$FSTYPE" = "ISO9660" ] && FSTYPE="iso9660"
}


ispupfunc() #fstype partition
{
 PUPSFS=""
 PUPVEROLD=0
 [ ! $2 ] && return 0
 mkdir /mnt/$2 2> /dev/null
 #cannot test for /dev/$2 as mount reports ntfs device is /dev/fuse...
 #v2.12 latest ntfs-3g driver works with mount properly, so special handling
 #no longer necessary, but still here...
 ISPUPMNTPT="`mount | grep "/dev/$2" | tr -s " " | cut -f 3 -d " "`"
 #v2.02...
 #[ "$ISPUPMNTPT" = "" ] && ISPUPMNTPT="`ps -e | grep -o ntfs\-3g.* | grep "/dev/$2" | sed -e 's/[^a-zA-Z0-9/._\-]/ /g' | tr -s ' ' | tr ' ' "\n" | grep '^/mnt/'`"
 [ "$ISPUPMNTPT" = "" ] && ISPUPMNTPT="`ps -e | grep -o 'ntfs\-3g.*' | grep "/dev/$2" | tr '\t' ' ' | tr -s ' ' | tr ' ' '\n' | grep '^/mnt/'`"
 
 if [ "$ISPUPMNTPT" = "" ];then
  ISPUPMNTPT="/mnt/$2"
  mount -t $1 /dev/$2 /mnt/$2
 fi
  if [ $? -eq 0 ];then
   ISFILE="`ls -1 $ISPUPMNTPT/pup_[0-9][0-9][0-9].sfs | head -n 1`"
   [ ! "$ISFILE" = "" ] && PUPVEROLD=`basename $ISFILE | cut -f 2 -d '_' | cut -f 1 -d '.'`
   if [ -f $ISPUPMNTPT/etc/puppyversion ];then
    PUPVEROLD=`cat $ISPUPMNTPT/etc/puppyversion`
    #there is a bug in prev installer, put 0 into puppyversion...
    PREVVER=`expr $NEWVER \- 1`
    [ $PUPVEROLD -eq 0 ] && PUPVEROLD=$PREVVER
   fi
   [ -f $ISPUPMNTPT/usr_cram.fs ] && PUPVEROLD=108
   umount /dev/$2
  fi
 return $PUPVEROLD
}

gpartedfixusbfunc() { #params: $DESTPART $DESTFS
 GPDRV="`echo -n "$1" | sed -e 's/[0-9]//g'`"
 gparted /dev/$GPDRV &
 sleep 2
 gxmessage -bg '#ba55d3' -center -title "Puppy Universal Installer" "GParted is a partition manager, available in Puppy2, though a 'barebones'
release of Puppy2 may not have it, in which case you have to use the 
PupGet package manager to install it. If it is installed, GParted is a
very simple tool for deleting, creating and resizing partitions.

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 or Syslinux. 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..." &
 MSGID=$!
 while [ 1 ];do
  [ "`pidof gparted | tr "\n" '|'`" = "|" ] && break
  sleep 1
 done
 [ ! "`which gparted`" = "" ] && kill $MSGID 2>/dev/null
}

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 "Puppy Universal Installer" -geometry 80x25 -e /tmp/fixusb.sh
}

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
}

PMEDIA="`Xdialog --left --title "Puppy Universal Installer" --no-tags --stdout --menubox "Welcome to the Puppy Universal Installer!\nIf you wish to install Puppy to a removable media, such\nas a USB Flash or hard drive, CD/DVD disc, floppy disk,\nZip disk, LS-120 disk, please insert it right now,\nbefore proceeding.\n\nINSERT MEDIA NOW\nThen, choose the media that you want to install Puppy to:" 0 0 8 usbflash "USB Flash drive" usbhd "USB hard drive" usb2ideflash "USB CF Flash drive, later move CF to IDE adaptor" ideflash "IDE Flash drive (CF card in IDE adaptor)" idehd "IDE (ATA) internal hard drive" idezip "Internal (IDE) ZIP or LS120 drive" satahd "SATA internal hard drive" scsihd "SCSI internal hard drive"`"
[ ! $? -eq 0 ] && exit
[ "$PMEDIA" = "" ] && exit

FINALPMEDIA="$PMEDIA"
if [ "$PMEDIA" = "usb2ideflash" ];then
 PMEDIA="usbflash"
 FINALPMEDIA="ideflash"
fi

case $PMEDIA in
 usbflash)
  if [ "`lsmod | grep --extended-regexp '^usb\-storage|^usb_storage'`" = "" ];then
   echo "Loading usb-storage module (needs several seconds)..."
   USBDELAY=6
   [ "`lsmod | grep '^ehci\-hcd'`" = "" ] && USBDELAY=26
   modprobe usb-storage &
   sleep $USBDELAY
  fi
  #find usb drives...
  #USBDRIVES="`cat /proc/partitions | grep "sd[a-z]$" | tr -s " " | cut -f 5 -d " "`"
  PROBEDISK="`probedisk 2> /tmp/probediskerr.txt`"
  USBDRIVES="`echo "$PROBEDISK" | grep 'Direct\-Access' | cut -f 3 -d '/' | cut -f 1 -d '|' | tr "\n" " "`"
  SELECTIONS=""
  for ONEUSB in $USBDRIVES
  do
   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
  ;;
 usbhd) #TODO
  gxmessage "Not yet implemented"
  exit
  ;;
 ideflash)
  #find ide hard drives...
  PROBEDISK="`probedisk 2> /tmp/probediskerr.txt`"
  HDDRIVES="`echo "$PROBEDISK" | grep '|disk|' | grep '/dev/hd' | 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/ $//g'`"
   HDSIZE="`disktype /dev/$ONEHD | grep "Block device" | cut -f 2 -d ',' | tr -s " " | cut -f 1-4 -d " "`"
   SELECTIONS="${SELECTIONS} $ONEHD \"${HDINFO}, ${HDSIZE}\""
  done
  ;;
 idehd)
  #find ide hard drives...
  PROBEDISK="`probedisk 2> /tmp/probediskerr.txt`"
  HDDRIVES="`echo "$PROBEDISK" | grep '|disk|' | grep '/dev/hd' | 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/ $//g'`"
   HDSIZE="`disktype /dev/$ONEHD | grep "Block device" | cut -f 2 -d ',' | tr -s " " | cut -f 1-4 -d " "`"
   SELECTIONS="${SELECTIONS} $ONEHD \"${HDINFO}, ${HDSIZE}\""
  done
  ;;
 idecd)
  #find ide cd drives...
  PROBEDISK="`probedisk 2> /tmp/probediskerr.txt`"
  HDDRIVES="`echo "$PROBEDISK" | grep '|cdrom|' | grep '/dev/hd' | 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/ $//g'`"
   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 --left --title "Puppy Universal Installer" --ok-label "QUIT" --msgbox "Your computer has these IDE (ATAPI) 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
  exit
  ;;
 idezip)
  PROBEDISK="`probedisk 2> /tmp/probediskerr.txt`"
  HDDRIVES="`echo "$PROBEDISK" | grep '|floppy|' | grep '/dev/hd' | 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/ $//g'`"
   HDSIZE="`disktype /dev/$ONEHD | grep "Block device" | cut -f 2 -d ',' | tr -s " " | cut -f 1-4 -d " "`"
   SELECTIONS="${SELECTIONS} $ONEHD \"${HDINFO}, ${HDSIZE}\""
  done
  ;;
 satahd) #v2.10
  #at bootup, init script creates SATADRIVES='' in /etc/rc.d/PUPSTATE...
  PROBEDISK="`probedisk 2> /tmp/probediskerr.txt`"
  for ONEHD in $SATADRIVES
  do
   HDINFO="`echo "$PROBEDISK" | grep "/dev/$ONEHD" | head -n 1 | cut -f 3 -d '|' | tr '$' " " | tr -s " " | sed -e 's/ $//g'`"
   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 "Not yet implemented"
  exit
  ;;
esac


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

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

chmod 755 /tmp/dlg1

while [ 1 ];do #BIG LOOP

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

DRVINFO="`disktype /dev/$DRVSEL`"
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 " "`"
if [ ! "`echo "$DRVSIZE" | grep "GiB"`" = "" ];then
 DRVSIZM="`dc $DRVSIZM 1000 \* p`"
fi
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
 [ ! $? -eq 0 ] && PUPINST=", Puppy version $PUPVEROLD installed"
 DRVMSG="${DRVSEL}:  ${FSTYPE}, ${DRVSIZE}${PUPINST}
"
else
 #has mbr and partitions...
 echo -n "" > /tmp/pidrvmsg.txt
 echo "$DRVINFO" |
 while read ONELINE
 do
  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 pup_xxx.sfs file...
   ispupfunc $FSTYPE ${DRVSEL}${PARTNUM} #returns PUPVEROLD
   [ ! $? -eq 0 ] && PUPINST=", Puppy version $PUPVEROLD installed"
#   DRVMSG="${DRVMSG}${DRVSEL}${PARTNUM}: ${FSTYPE}, size ${PARTSIZE}${PUPINST}
#"
   echo "${DRVSEL}${PARTNUM}: ${FSTYPE}, size ${PARTSIZE}${PUPINST}" >> /tmp/pidrvmsg.txt
  fi
 done

 DRVMSG="`cat /tmp/pidrvmsg.txt`"

# NUMPARTS=`echo "$DRVINFO" | grep "file system" | grep "^ " | wc -l | tr -s " " | cut -f 2 -d " "`
# TRYPARTS="`echo "$DRVINFO" | grep 'Partition ' | cut -f 1 -d ':' | sed -e 's/Partition//g' | tr -s " " | cut -f 2 -d " " | tr "\n" " "`"
# for PARTNUM in $TRYPARTS
# do
#  PARTITIONFS="`echo "$DRVINFO" | grep "file system" | grep "^ " | head -n $PARTNUM | tail -n 1 | tr -s " " | cut -f 2 -d " "`"
#  if [ "$PARTITIONFS" ];then
#   PARTSIZE="`echo "$DRVINFO" | grep "Partition ${PARTNUM}:" | tr -s " " | cut -f 3-4 -d " "`"
#   fsfunc $PARTITIONFS #sets FSTYPE.
#   #find out if partition has puppy, or has pup_xxx.sfs file...
#   ispupfunc $FSTYPE ${DRVSEL}${PARTNUM} #returns PUPVEROLD
#   [ ! $? -eq 0 ] && PUPINST=", Puppy version $PUPVEROLD installed"
#   DRVMSG="${DRVMSG}${DRVSEL}${PARTNUM}: ${FSTYPE}, size ${PARTSIZE}${PUPINST}
#"
#  fi
# done

fi

echo "$DRVMSG"

DLGTXT=""
CHOICES="`echo "$DRVMSG" | grep ':' | cut -f 1 -d ':' | tr "\n" " "`"
for ONECHOICE in $CHOICES
do
 DLGTXT="$DLGTXT
   <hbox>
    <text><label>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>
"
done

DLGEXT=""
if [ "`echo "$DRVMSG" | cut -f 1 -d ':' | grep "[a-zA-Z]$"`" = "" ];then
 #ask if want superfloppy install...
 DLGEXT="
   <frame Superfloppy>
   <hbox>
    <text><label>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>
"
else
 DLGEXT="
   <frame Superfloppy>
   <hbox>
    <text><label>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>
"
fi

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

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

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

done #BIG LOOP

#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 "$DRVMSG" | cut -f 1 -d ':'`"
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 " "`"
#v2.02 cannot use mount for ntfs-3g driver...
#[ "$SANITYMNTPT" = "" ] && SANITYMNTPT="`ps -e | grep -o ntfs\-3g.* | grep "/dev/$SANITYPART" | sed -e 's/[^a-zA-Z0-9/._\-]/ /g' | tr -s ' ' | tr ' ' "\n" | grep '^/mnt/'`"

[ "$SANITYMNTPT" = "" ] && SANITYMNTPT="`ps -e | grep -o 'ntfs\-3g.*' | grep "/dev/$SANITYPART" | tr '\t' ' ' | tr -s ' ' | tr ' ' "\n" | grep '^/mnt/'`"

if [ ! "$SANITYMNTPT" = "" ];then
 SANITYMSG1="$SANITYPART currently mounted, need to unmount it!!!"
 SANITYMSG2="$SANITYPART currently mounted read-write."
 SANITYMSG3="$SANITYPART does not have pup_save.3fs file in it."
 #SANITYMNTPT="`mount | grep "/dev/$SANITYPART" | tr -s " " | cut -f 3 -d " "`"
 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/pup_save.3fs ] && SANITYMSG3="$SANITYPART has personal file pup_save.3fs in it!"
 Xdialog --left --title "Puppy universal installer: SANITY CHECK" --ok-label "CONTINUE" --cancel-label "QUIT" --yesno "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 pup_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 pup_save.3fs does not exist then Puppy will run totally in RAM, which will\nsolve the problem -- but you should not delete or rename pup_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
 [ ! $? -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>Puppy Universal Installer</wtitle>
 <vbox>
   <text><label>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>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 (pup_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>FORMAT_ext3</label>
    <action>Exit:ext3</action>
   </button>
   <button>
    <label>FORMAT_vfat</label>
    <action>Exit:vfat</action>
   </button>
  </hbox>
 </vbox>
"
  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 "Puppy Universal Installer" -geometry 80x10 -e /tmp/formatsuper.sh
  DESTSIZM="$DRVSIZM"
  IDESTSIZM="$IDRVSIZM"
  DESTVER="" #previous version, n.a.
 else
  #want to partition with partition 1...
  DLG3="
 <wtitle>Puppy Universal Installer</wtitle>
 <vbox>
   <text><label>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>A further clarification: if you choose ext3, then the entire partition 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 (pup_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>FORMAT_ext3</label>
    <action>Exit:ext3</action>
   </button>
   <button>
    <label>FORMAT_vfat</label>
    <action>Exit:vfat</action>
   </button>
  </hbox>
 </vbox>
"
  RETTXT="`echo "$DLG3" | gtkdialog2 --stdin`"
  DESTFS="`echo "$RETTXT" | grep 'EXIT:' | cut -f 2 -d ':'`"


  echo '#!/bin/sh' > /tmp/formatmbr.sh
  echo -e "echo -n \"SANITY CHECK: formatting /dev/${DRVSEL}, ENTER to continue or CTRL-C to quit: \""  >> /tmp/formatmbr.sh
  echo 'read mooo'  >> /tmp/formatmbr.sh
  #echo 'echo "Zeroising the entire drive..."'  >> /tmp/formatmbr.sh
  #echo 'echo "(please be very patient, this could take awhile)"'  >> /tmp/formatmbr.sh
  ##echo "dd if=/dev/zero bs=1024 | $BAR -of /dev/$DRVSEL -s ${IDRVSIZM}m" >> /tmp/formatmbr.sh
  #echo "dd if=/dev/zero of=/dev/$DRVSEL" >> /tmp/formatmbr.sh
  #no, just do the mbr...
  echo 'echo "Creating the MBR (Master Boot Record)..."'  >> /tmp/formatmbr.sh
  echo "dd if=/usr/lib/syslinux/mbr.bin of=/dev/$DRVSEL bs=512 count=1" >> /tmp/formatmbr.sh
  echo 'sync'  >> /tmp/formatmbr.sh
  #create a bootable partition...
  echo 'echo "Creating a partition..."'  >> /tmp/formatmbr.sh
  echo 'echo "n'  >> /tmp/formatmbr.sh
  echo 'p'  >> /tmp/formatmbr.sh
  echo '1'  >> /tmp/formatmbr.sh
  echo  >> /tmp/formatmbr.sh
  echo  >> /tmp/formatmbr.sh
  #make partition bootable...
  echo 'a'  >> /tmp/formatmbr.sh
  echo '1'  >> /tmp/formatmbr.sh
  #write and exit...
  echo -n 'w"'  >> /tmp/formatmbr.sh
  echo " | fdisk /dev/$DRVSEL"  >> /tmp/formatmbr.sh
  echo 'echo "Copying MBR..."'  >> /tmp/formatmbr.sh
  echo "dd if=/usr/lib/syslinux/mbr.bin of=/dev/$DRVSEL bs=512 count=1"  >> /tmp/formatmbr.sh
  echo 'sync'  >> /tmp/formatmbr.sh
  echo -e "echo \"Creating a FAT filesystem in /dev/${DRVSEL}1...\""  >> /tmp/formatmbr.sh
  echo "mkdosfs /dev/${DRVSEL}1" >> /tmp/formatmbr.sh
  #...this auto creates most appropriate fat f.s., so really should run fdisk set f.s. id now.
  echo 'sync'  >> /tmp/formatmbr.sh
  echo 'echo -n "Press ENTER key to continue: "'   >> /tmp/formatmbr.sh
  echo 'read moo'   >> /tmp/formatmbr.sh

  chmod 755 /tmp/formatmbr.sh
  rxvt -bg "orange" -title "Puppy Universal Installer" -geometry 80x10 -e /tmp/formatmbr.sh

  REALFS="`disktype /dev/${DRVSEL}1 | grep "file system" | cut -f 1 -d " "`"
  FSID="c" #FAT32(LBA)
  [ "$REALFS" = "FAT16" ] && FSID="6"
  [ "$REALFS" = "FAT32" ] && FSID="b"
  #f.s. id for partition... 6=FAT16 e=FAT16(LBA) c=FAT32(LBA) 83=Linux 4=FAT16<32M
  echo "t
$FSID
w" | fdisk /dev/$DRVSEL

 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="`dc $DESTSIZM 1000 \* p`"
 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


if [ "`echo "$DESTPART" | grep "[0-9]$"`" = "" ];then
 #superfloppy
 DLG4="
 <wtitle>Puppy Universal Installer</wtitle>
 <vbox>
  <text><label>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>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>
"
 RETTXT="`echo "$DLG4" | gtkdialog2 --stdin`"
else
 DLG4="
 <wtitle>Puppy Universal Installer</wtitle>
 <vbox>
  <text><label>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>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>
"
 RETTXT="`echo "$DLG4" | gtkdialog2 --stdin`"
fi

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



#get latest Puppy files....
SRCPATH=""
CDDRIVE=""
rm -f /tmp/srcpath.txt
mount | tr -s " " | cut -f 3 -d " " |
while read ONEDIR
do
 INCYES=0
 [ -f $ONEDIR/pup_$NEWVER.sfs ] && INCYES=`expr $INCYES + 1`
 [ -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 --left --buttons-style text --title "Puppy universal installer" --ok-label "CD" --cancel-label "DIRECTORY" --yesno "Puppy consists of three files:\nvmlinuz      The Linux kernel\ninitrd.gz    The initial ramdisk.\npup_$NEWVER.sfs  This has all the Puppy files.\nIf you booted Puppy from a live-CD, those three files will be on it.\nOtherwise, they are in the .iso file and can be extracted -- in that\ncase, you will need to select the directory where you have extracted\nthem to.\nPlease do NOT use a path with any spaces!!!\n\n\nWhere are the Puppy files?..." 0 0
 RETVAL=$?
 if [ $RETVAL -eq 0 ];then #CD
  CDDRIVE="`readlink /dev/cdrom`"
  CDDRIVE="`basename $CDDRIVE`"
  CDDRVINFO="`probedisk | grep "/dev/$CDDRIVE" | cut -f 3 -d '|'`"
  Xdialog --left --title "Puppy universal installer" --msgbox "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
  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 --left --title "Puppy universal installer: ERROR" --msgbox "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
   RETVAL=1
  fi 
 fi
 if [ ! $RETVAL -eq 0 ];then #DIRECTORY
  SRCFPATH="`Xdialog --left --backtitle "Please find the latest Puppy files\nvmlinuz, initrd.gz and pup_$NEWVER.sfs,\nTHEN HIGHLIGHT ANY ONE OF THEM\nand click the OK button" --title "Puppy universal installer" --stdout --no-buttons --no-cancel --fselect "*" 0 0`"
  [ ! $? -eq 0 ] && exit
  SRCPATH="`dirname $SRCFPATH`"
 fi
fi
#sanity check...
if [ ! -f $SRCPATH/pup_$NEWVER.sfs ];then
 Xdialog --left --title "Puppy universal installer: ERROR" --msgbox "Oh dear, a \"sanity check\" has failed.\nThis file: $SRCPATH/pup_$NEWVER.sfs\ndoes not exist.\nThe above is supposed to be path-to-where-puppy-files-are/pup_xxx.sfs\nwhere \"xxx\" is the latest version number.\nClick OK button to quit..." 0 0
 exit
fi

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

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

  #26mar06 JustGreg fix mbr...
  if [ ! "`echo "$DESTPART" | grep '[0-9]$'`" = "" ];then #superfloppy mode has no mbr.
   DESTDRV="`echo -n "$DESTPART" | cut -b 1-3`"
   dd if=/dev/$DESTDRV of=/tmp/mbr446.bin bs=446 count=1
   sync
   if [ "`hexdump -x /tmp/mbr446.bin | tr -s " " | cut -f 2-9 -d " " | grep '[1-9a-zA-Z]'`" = "" ];then
    MBRCHOICE="`Xdialog --left --title "Puppy Universal Installer" --no-cancel --stdout --menubox "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 "Bootstrap loader code, created by JustGreg" mbr.bin "From the Syslinux package" mbrfat.bin "From the makebootfat package" spb2_mbr.bin "From spblinux, created by Christian Ostheimer" `"
   else
    MBRCHOICE="`Xdialog --left --title "Puppy Universal Installer" --no-cancel --stdout --menubox "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 "DO NOTHING, leave current MBR alone" sys-nopart.mbr "Bootstrap loader code, created by JustGreg" mbr.bin "From the Syslinux package" mbrfat.bin "From the makebootfat package" spb2_mbr.bin "From spblinux, created by Christian Ostheimer" `"
   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
  fi

  case $DESTFS in
   vfat)
     if [ ! "`echo "$DESTPART" | grep '[0-9]$'`" = "" ];then
      PARTCHOICE="`Xdialog --left --title "Puppy Universal Installer" --no-cancel --stdout --menubox "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 "JUST KEEP GOING" GParted "Wipe and recreate USB/IDE-CF partition using GParted" syslinux "Make USB or IDE-CF msdos/vfat partition bootable"`"
      [ "$PARTCHOICE" = "syslinux" ] && fixusbfunc $DESTPART $DESTFS
      [ "$PARTCHOICE" = "GParted" ] && gpartedfixusbfunc $DESTPART $DESTFS
     fi
    #params passed in: $DESTPART "$SRCPATH" $FINALPMEDIA
    echo '#!/bin/sh
DESTPART="$1"
SRCPATH="$2"
FINALPMEDIA="$3"
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, pup_xxx.sfs, syslinux.cfg"
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
echo "Making $DESTPART bootable..."
syslinux  /dev/$DESTPART
sync
#remove old puppy1 files...
mount -t vfat /dev/$DESTPART /mnt/data
if [ -f /mnt/data/pup100 ];then
 echo "Whoa, $DESTPART has pup100 file on it. This has to be erased."
 echo "Press ENTER key only to continue, else any other letter then"
 echo -n "press ENTER to abort installation of Puppy: "
 read isnogo
 if [ ! "$isnogo" = "" ];then
  sync
  umount /dev/$DESTPART
  exit
 fi
 rm -f /mnt/data/pup100
fi
rm -f /mnt/data/image.gz 2> /dev/null
rm -f /mnt/data/usr_cram.fs 2> /dev/null
rm -f /mnt/data/pup_*.sfs #v2.11
rm -f /mnt/data/devx_*.sfs #v2.11
sync
echo "Copying vmlinuz..."
cp -f $SRCPATH/vmlinuz /mnt/data/
sync
echo "Creating syslinux.cfg..."
if [ "$FINALPMEDIA" = "ideflash" ];then
 echo "default vmlinuz root=/dev/ram0 initrd=initrd.gz ide=nodma PMEDIA=$FINALPMEDIA" > /mnt/data/syslinux.cfg
else
 echo "default vmlinuz root=/dev/ram0 initrd=initrd.gz PMEDIA=$FINALPMEDIA" > /mnt/data/syslinux.cfg
fi
sync
echo "Creating marker file for wakepup boot floppy..."
[ "$FINALPMEDIA" = "usbflash" ] && touch /mnt/data/USBFLASH
[ "$FINALPMEDIA" = "ideflash" ] && touch /mnt/data/IDEFLASH
[ "$FINALPMEDIA" = "usbhd" ] && touch /mnt/data/USBHD
[ "$FINALPMEDIA" = "idezip" ] && touch /mnt/data/IDEZIP
sync
echo "Copying initrd.gz..."
cp -f $SRCPATH/initrd.gz /mnt/data/
sync
echo "Copying .sfs files..."
cp -f $SRCPATH/*.sfs /mnt/data/
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 "Puppy Universal Installer" -geometry 80x10 -e /tmp/installpup.sh $DESTPART $SRCPATH $FINALPMEDIA
    ;;
   ext3)
    #params passed in: $DESTPART "$SRCPATH" $FINALPMEDIA
    echo '#!/bin/sh
DESTPART="$1"
SRCPATH="$2"
FINALPMEDIA="$3"
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, pup_xxx.sfs, extlinux.conf"
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 ext3 /dev/$DESTPART /mnt/data
echo "Making $DESTPART bootable..."
#extlinux -z /mnt/data
#v2.11
if [ ! "`echo "$DESTPART" | grep '[0-9]$'`" = "" ];then
 extlinux /mnt/data #i think only use -z for superfloppy.
else
 extlinux -z /mnt/data
fi
sync
rm -f /mnt/data/pup_*.sfs #v2.11
rm -f /mnt/data/devx_*.sfs #v2.11
sync
echo "Copying vmlinuz..."
cp -f $SRCPATH/vmlinuz /mnt/data/
sync
echo "Creating extlinux.conf..."
if [ "$FINALPMEDIA" = "ideflash" ];then
 echo "default vmlinuz root=/dev/ram0 initrd=initrd.gz ide=nodma PMEDIA=$FINALPMEDIA" > /mnt/data/extlinux.conf
else
 echo "default vmlinuz root=/dev/ram0 initrd=initrd.gz PMEDIA=$FINALPMEDIA" > /mnt/data/extlinux.conf
fi
sync
#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/*.sfs /mnt/data/
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 "Puppy Universal Installer" -geometry 80x10 -e /tmp/installpup.sh $DESTPART $SRCPATH $FINALPMEDIA
    ;;
   *)
    gxmessage "Your $DESTPART has a $DESTFS filesystem. Currently only install
to external vfat (FAT16/32) or ext3 filesystems is supported.
Click OK to quit..."
    exit
    ;;
  esac
  ;;
 scsihd|idehd|satahd) #internal media, boot with boot-disk or grub.
  #arrive here with DESTPART & DESTFS where installing to, PMEDIA boot param FINALPMEDIA,
  #SRCPATH where to get vmlinuz, initrd, pup_xxx.sfs, 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, pup_xxx.sfs, to dest partition.
  #option2: file vmlinuz to partition, contents of pup_xxx.sfs to partition.
  if [ $PUPVEROLD -eq 0 ];then
   PREVPUPMSG="It appears that this is a new installation."
  else
   PREVPUPMSG="There appears to be an existing installation of Puppy, version $PUPVEROLD,
and you may choose to upgrade or totally replace."
  fi
  INSTOPTION="1"
  if [ ! "$DESTFS" = "vfat" ];then
   Xdialog --left --buttons-style text --title "Puppy Universal Installer" --ok-label "NORMAL" --cancel-label "COEXIST" --yesno "You have chosen to install to /dev/$DESTPART, which appears to be an internal\nhard drive ($FINALPMEDIA).\n$PREVPUPMSG \n\nYou have two ways to install Puppy to the partition, either by what we call\n\"option1\", which means copy the files vmlinuz, initrd.gz, and pup_$NEWVER.sfs to the\npartition, leaving the previous contents of the partition untouched (good\nchoice if there is already another distro installed in the partition -- Puppy\ncan coexist with it, not interfere with it at all.\n\nOr, choose \"option2\" which is a \"normal\" Linux installation, requiring usage\nof the entire partition by Puppy. This choice is recommended by developers\n(anyone who wants to compile or develop/test applications for Puppy).\nIn fact, option2 is the recommended option for everyone, if the $DESTPART\npartition is available for Puppy to take over.\n\nNote, for option2 you can create either or both floppy/usb boot disk and/or\nh.d. Grub bootloader, but option1 only offers a floppy boot disk boot method.\nTHE OPTION1 BOOT DISK WILL ONLY BOOT PUPPY IN A FAT PARTITION!!!\n(see www.murga.org/~puppy/viewtopic.php?t=9699 for HOWTO boot from NTFS)\n\nDo you want to install Puppy like a normal Linux distro (option2)?\n\nClick NORMAL button for normal Linux install (option2)...\nClick COEXIST button for coexist type of install (option1)...\nClick window close box to quit..." 0 0
   RET_VAL=$?
   [ $RET_VAL -eq 255 ] && exit
   [ $RET_VAL -eq 0 ] && INSTOPTION="2"
  fi

  #INSTOPTION, install puppy to DESTPART...
  if [ "$INSTOPTION" = "1" ];then
   Xdialog --title "Puppy Universal Installer" --msgbox "Please wait, copying files to $DESTPART..." 0 0 &
   XPID=$!
   cp -f $SRCPATH/vmlinuz $DESTMNTPT/
   sync
   cp -f $SRCPATH/initrd.gz $DESTMNTPT/
   sync
   cp -f $SRCPATH/*_$NEWVER.sfs $DESTMNTPT/
   sync
   touch $DESTMNTPT/$FINALPMEDIA #needed by WakePup
   sync
   kill $XPID
   umount /dev/$DESTPART
   if [ ! "`echo -n "$DESTFS" | grep --extended-regexp 'msdos|vfat'`" = "" ];then
   
#    Xdialog --left --title "Puppy Universal Installer" --ok-label "CREATE_BOOT_DISK" --cancel-label "NO_BOOT_DISK" --yesno "
#A floppy disk can be used to boot Puppy.\nPLEASE INSERT THE FLOPPY DISK RIGHT NOW.\n(anything on the floppy disk will be wiped)\nBE SURE THAT THE FLOPPY DISK IS NOT CURRENTLY MOUNTED." 0 0
#    if [ $? -eq 0 ];then
#     echo '#!/bin/sh
#     SRCPATH="$1"
#     FINALPMEDIA="$2"
#     DESTPART="$3"
#     while [ 1 ];do
#      BOOTPART=""
#      [ ! "`disktype /dev/fd0 | grep "file system"`" = "" ] && BOOTPART="fd0"
#      if [ ! "$BOOTPART" = "" ];then
#       echo "Creating $BOOTPART boot disk..."
#       echo "Writing /lib/fdos2pup.img disk image..."
#       gunzip -c /lib/fdos2pup.img.gz | dd of=/dev/fd0
#       sync
#       echo "Creating config.sys on floppy drive..."
#       echo "SHELL=a:tiny.exe c:\vmlinuz c:\initrd.gz root=/dev/ram0 PMEDIA=$FINALPMEDIA" > /tmp/config.sys
#       echo
#       echo "PLEASE NOTE, Puppy now uses 2.6 kernel, which does not fit on a floppy."
#       echo "PLEASE NOTE, this is the content of config.sys:"
#       cat /tmp/config.sys
#       echo
#       echo "It should be okay as it is, however Puppy cannot guess the drive-letters"
#       echo "that Windows/DOS assigns to partitions. You can see above that initrd.gz and"
#       echo "vmlinuz are expected to be in the C: partition, which is normally equivalent"
#       echo "to hda1 in Linux notation. You have chosen to install to $DESTPART, and if this"
#       echo "is something other than hda1 then you have to figure out a suitable drive"
#       echo "letter -- a wild guess is it may be the D: partition -- in such a case,"
#       echo "you will have to edit config.sys."
#       echo "(Note, if choose to edit config.sys here, an editor will pop up, and you"
#       echo " will have to exit from it before this installer program can continue)"
#       echo "Press ENTER key only to accept config.sys as-is,"
#       echo -n "or any letter key then ENTER to edit config.sys: "
#       read nonono
#       if [ ! "$nonono" = "" ];then
#        gtk-shell -t "Editing file config.sys" -ef "/tmp/config.sys"
#       fi
#       sync
#       echo "Copying config.sys to floppy..."
#       mcopy -o /tmp/config.sys a:
##       echo "Copying vmlinuz to floppy drive..."
##       mcopy $SRCPATH/vmlinuz a:
#       #cp -f $SRCPATH/vmlinuz $DESTMNTPT/
#       sync
#       rm -f /tmp/config.sys
#       echo "...done"
#       echo
#       echo "If any errors writing to boot disk, or you want to make another boot"
#       echo "disk, insert it RIGHT NOW, then press any letter key then ENTER key,"
#       echo -n "or press ENTER key only when done: "
#       read moodoo
#       [ "$moodoo" = "" ] && break
#      else
#       echo -n "Please insert floppy disk now, then press ENTER key: "
#       read moodoo
#      fi
#     done
#' > /tmp/installpup.sh
#     chmod 755 /tmp/installpup.sh
#     rxvt -bg "orange" -title "Puppy Universal Installer" -geometry 80x17 -e /tmp/installpup.sh $SRCPATH $FINALPMEDIA $DESTPART

    Xdialog --left --title "Puppy Universal Installer" --ok-label "CREATE_BOOT_DISK" --cancel-label "NO_BOOT_DISK" --yesno "A floppy disk can be used to boot Puppy.\nCurrently we are offering WakePup2, a generic boot floppy\nthat scans the PC and finds where Puppy is installed." 0 0
    if [ $? -eq 0 ];then
     /usr/sbin/wakepup2
    fi
   else
    Xdialog --left --title "Puppy Universal Installer" --msgbox "NOTICE: As you have installed to a partition with a $DESTFS filesystem,\nwhich is non-FAT, you cannot create a boot floppy disk. The only option\nleft is to manually setup your Grub or Lilo or other boot system. Note,\nthere are other boot floppy systems that can boot a non-FAT partition.\nNote, partition $DESTPART has the files vmlinuz, initrd.gz and\npup_$NEWVER.sfs on it, where vmlinuz is the kernel and initrd.gz is the\ninitial ramdisk. You should provide the boot parameter 'PMEDIA=idehd' if\n$DESTPART is an ide drive." 0 0
   fi
   #finished. could put up a final dlg here, then quit script.
   Xdialog --title "Puppy Universal Installer" --msgbox "Okay, all done!" 0 0
  else #h.d. install option2
   #upgrade, ask if want delete partition...
   if [ ! $PUPVEROLD -eq 0 ];then
    Xdialog --left --buttons-style text --title "Puppy Universal Installer" --ok-label "UPGRADE" --cancel-label "WIPE" --yesno "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
    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 --title "Puppy Universal Installer" --no-buttons --infobox "Please wait, wiping all files in $DESTPART..." 0 0 50000 &
     XPID=$!
     sleep 3
     rm -rf $DESTMNTPT/*
     sync
     kill $XPID
    fi
   fi
   Xdialog --title "Puppy Universal Installer" --no-buttons --infobox "Please wait, copying Puppy files to $DESTPART..." 0 0 120000 &
   XPID=$!
   sleep 1
   #loop-device mount pup_xxx.sfs in DESTPART, copy contents of pup_xxx.sfs to DESTPART...
   losetup-FULL /dev/loop2 $SRCPATH/pup_$NEWVER.sfs
   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...
   [ -f $SRCPATH/zdrv_$NEWVER.sfs ] && cp -af $SRCPATH/zdrv_$NEWVER.sfs $DESTMNTPT/
   [ -f /zdrv_$NEWVER.sfs ] && cp -af /zdrv_$NEWVER.sfs $DESTMNTPT/
   #v2.12 also copy the 'fetched' kernel modules...
   #no, as a fetched module may also have firmware and that would have to
   #be copied also...
   #cp -a -f /lib/modules/$KERNVER/* $DESTMNTPT/lib/modules/$KERNVER/
   #v2.12 not really necessary, but copy this too...
   #no, as fetched modules are commented-out by modprobe script...
   #[ -f /lib/modules/firmware.dep.$KERNVER ] && cp -a -f /lib/modules/firmware.dep.$NEWVER $DESTMNTPT/lib/modules/firmware.dep.$KERNVER
   #but, do copy this...
   if [ -d /lib/modules/$KERNVER/initrd ];then
    mkdir -p $DESTMNTPT/lib/modules/$KERNVER/initrd
    cp -af /lib/modules/$KERNVER/initrd/* $DESTMNTPT/lib/modules/$KERNVER/initrd/
    depmod -b $DESTMNTPT
   fi
   mkdir $DESTMNTPT/sys 2>/dev/null
   sync
   kill $XPID
   #fix space optimisation links into initrd...
    #TODO
   #chroot to DESTPART, set /etc/puppyversion back to PUPVEROLD, run rc.update
   Xdialog --title "Puppy Universal Installer" --no-buttons --infobox "Please wait, executing rc.update script..." 0 0 60000 &
   XPID=$!
   sleep 2
   echo -n "$PUPVEROLD" > $DESTMNTPT/etc/puppyversion #set it back to what it was.
   
   #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
#TODO needs work, as could have usb hd, that cannot unplug and do not want it to be turned
#     into a boot disk!...
   Xdialog --left --buttons-style text --title "Puppy Universal Installer" --ok-label "Boot from USB" --cancel-label "Install GRUB" --yesno "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.\n\
\n\
If you already have GRUB installed in the hard drive, you can choose the\n\
GRUB option here and reinstall it with Puppy added to the boot menu.\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 GRUB' to install the GRUB boot manager. You will be given the\n\
opportunity to create a floppy 'boot disk' as well as install GRUB to the\n\
hard drive.\n\
\n\
FOR USB BOOT DISK CHOICE, PLEASE INSERT IT RIGHT NOW BEFORE PROCEEDING!\n\
 (any files in it will be deleted)\n\
 IT MUST ALSO BE UNMOUNTED -- BE SURE BEFORE PROCEEDING" 0 0
   if [ $? -eq 0 ];then #BOOT DISK
    BOOTPART=""
    [ ! "`disktype /dev/sda | grep "file system" | grep "^FAT"`" = "" ] && BOOTPART="sda"
    [ ! "`disktype /dev/sda1 | grep "file system" | grep "^FAT"`" = "" ] && BOOTPART="sda1"
    [ ! "`disktype /dev/sdb | grep "file system" | grep "^FAT"`" = "" ] && BOOTPART="sdb"
    [ ! "`disktype /dev/sdb1 | grep "file system" | grep "^FAT"`" = "" ] && BOOTPART="sdb1"
    [ ! "`disktype /dev/sdc | grep "file system" | grep "^FAT"`" = "" ] && BOOTPART="sdc"
    [ ! "`disktype /dev/sdc1 | grep "file system" | grep "^FAT"`" = "" ] && BOOTPART="sdc1"
#    [ ! "`disktype /dev/fd0 | grep "file system" | grep "^FAT"`" = "" ] && BOOTPART="fd0"
    if [ ! "$BOOTPART" = "" ];then
     Xdialog --left --title "Puppy Universal Installer" --yesno "Please confirm that you want to make '$BOOTPART' into a boot disk for Puppy.\nNote, be extremely careful here if you have a USB hard drive or SATA hard\ndrive, as these have the same 'sd' device notation as a removable Flash pen\ndrive. If Puppy has mis-identified the device, then answer 'No' here...\n\nClick 'Yes' button if correct device..." 0 0
     [ ! $? -eq 0 ] && continue
    fi
    if [ ! "$BOOTPART" = "" ];then
     cp -af $SRCPATH/vmlinuz /mnt/$DESTPART/
     sync
     Xdialog --title "Puppy Universal Installer" --msgbox "Creating $BOOTPART boot disk..." 0 0 &
     XPID=$!
     #passed params $BOOTPART $DESTPART $SRCPATH $FINALPMEDIA
     echo '#!/bin/sh
     BOOTPART="$1"
     DESTPART="$2"
     SRCPATH="$3"
     FINALPMEDIA="$4"
      echo "Making the /dev/$BOOTPART bootable using Syslinux..."
      syslinux /dev/$BOOTPART
      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
     sync
     echo -n "Done. Press ENTER key: "
     read allisdone
' > /tmp/installpup.sh
     chmod 755 /tmp/installpup.sh
     rxvt -bg "orange" -title "Puppy Universal Installer" -geometry 80x10 -e /tmp/installpup.sh $BOOTPART $DESTPART $SRCPATH $FINALPMEDIA

     kill $XPID
    fi
   else #Grub
    mkdir -p /mnt/$DESTPART/boot/grub
    cp -af $SRCPATH/vmlinuz /mnt/$DESTPART/boot/
    sync
    umount /mnt/$DESTPART
    Xdialog --left --title "Puppy Universal Installer" --msgbox "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
    unmountcdfunc
    while [ 1 ];do
     grubconfig /dev/$DESTPART
     #...if choose to create a boot floppy, writes 'no' to /tmp/loopbrk.txt.
     Xdialog --title "Universal Installer" --yesno "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
     [ ! $? -eq 0 ] && break
    done
    rm -f /tmp/loopbrk.txt
    exit
   fi
   Xdialog --title "Puppy Universal Installer" --yesno "Do you want to go back and create another boot disk or Grub boot?..." 0 0
   [ ! $? -eq 0 ] && break
  done
  umount /mnt/$DESTPART 2> /dev/null
  ;;
 idecd|scsicd|usbcd)
  gxmessage "not yet implemented"
  #TO DO
  ;;
esac

unmountcdfunc

###END###