#!/bin/sh
#(c) Copyright Barry Kauler 2006 www.puppylinux.com
#2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
# 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 jan 2008: jump to puppyinstaller_old for kernels supporting hd*. --REMOVED.
#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.

##v3.97
#if [ -e /proc/ide ];then
# xmessage "Note, Puppy is using an older kernel that supports /dev/hd*
#drive naming for IDE drives. The old Universal Installer
#script will be run, which lacks some features."
# exec puppyinstaller_old
#fi


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

#v2.10
. /etc/rc.d/PUPSTATE
#v3.97 [ "$ATADRIVES" = "" ] && ATADRIVES="$SATADRIVES"

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 "パピーユニバーサルインストーラ" "パーティションマネージャ「GParted」はパピーバージョン２から利用できますが、バージョン２の
「ベアボーン」のリリース版には含まれていないかも知れません。その場合、
「PupGet」パッケージマネージャでインストールします。インストールされていれば、GPartedは
パーティションの削除、作成、及びサイズの変更が簡単にできます。

USBフラッシュドライブにパピーをインストールしても起動しない場合は、USBフラッシュ
ドライブに存在するパーティションがパソコンのBIOSかSyslinuxに混乱をきたしている
かも知れません。個人的には「GParted」を利用してUSBドライブのパーティションを
全部削除して、再度新しいパーティションを作成する事で問題が解決しました。
この方法はとても簡単です。「GParted」を実行して、
 １：USBドライブの全てのパーティションを削除します。
 ２：プライマリパーティションのドライブ全体を新しくFAT16で作成します。 
 ３：「Apply」ボタンをクリックして、変更をUSBドライブに書き込みます。
 ４：「boot」設定フラッグをセットします（パーティション上でマウスの
　　　 右ボタンをクリックして「manage flags」を選択します）。

 「GParted」がインストールされ実行していれば上記の方法でできます。
 「GParted」を終了するとパピーユニバーサルインストーラに戻ります..." &
 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 "パピーユニバーサルインストーラ" -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
}

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}/pup_${NEWVER}*.sfs ] && INCYES=`expr $INCYES + 1` #v3.01
 [ -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 "パピーユニバーサルインストーラ" --ok-label "CD" --cancel-label "DIRECTORY" --yesno "パピーは２から４個のファイルからできています:\nvmlinuz      リナックスカーネル\ninitrd.gz    イニシャルRAMディスク。\npup_$NEWVER.sfs  これにはパピーの全ファイルが含まれています（initrd.gzの中にもあります）。\n             (initrd.gzの中にビルドされているなら、initrd.gzだけが必要です）\nzdrv_$NEWVER.sfs 完全なカーネルドライバとファームウェアセット（オプション）。\n             (ある種のビルドはpup_$NEWVER.sfsに利用できるドライバのサブセットがあります）\nもしパピーをライブCDから起動しているなら、これらのファイルはメモリの中に入っています。\nあるいは「 .iso」ファイルにあり、取り出すことができます -- その場合、\nファイルを取り出して保存したディレクトリを選択しなくてはなりません。\nパス名にスペースを入れないで下さい！！！\n\n\nパピーファイルはどこにありますか？..." 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 --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --msgbox "CD-ROMドライバにパピーのライブCDを入れて下さい。\n注意、パソコンに2つのCD/DVDドライブがある場合は、パピーは\nそのライブCDが 「$CDDRIVE 」に入れられている事を予想し「 $CDDRVINFO 」とします。 \n\nライブCDを入れたら、「OK」ボタンをクリックして下さい..." 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 --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ: エラー" --msgbox "残念、パピーはCDにありません。\nマウントプログラムでCDをマウントし、\n(ファイルマネージャのメニューから探して下さい）「OK」ボタンをクリックして下さい..." 0 0
   RETVAL=1
  fi 
 fi
 if [ ! $RETVAL -eq 0 ];then #DIRECTORY
  SRCFPATH="`Xdialog --wmclass "gtkdialog2" --left --backtitle "最新のパピーファイル\nvmlinuz, initrd.gz と pup_$NEWVER.sfsを探して、\nその中の１つを選択して\n「OK」ボタンをクリックして下さい" --title "パピーユニバーサルインストーラ" --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 #v3.01
 Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ: エラー" --msgbox "なんと、「整合性チェック」は失敗しました。\n次のファイル: $SRCPATH/pup_$NEWVER.sfs\nは存在しません。\nこれはパピーファイルpup_xxx.sfsが保存されているパスのようです。\n「xxx」は最新のバージョン番号です。\n「OK」ボタンをクリックして中止して下さい..." 0 0
 exit
fi
} #end locate_puppy_src_files function.

HELPPUI='Notes for using the Universal Installer

Classmate, eeePC or similar baby laptop:
You firstly need to boot Puppy on the target PC, and one way is to first install Puppy
to a USB Flash pen drive then bootup on the baby laptop, or bootup from an external
USB CD/DVD drive (the Classmate BIOS is easy to setup for either). Then run this
Universal Installer again and choose the appropriate installation media -- for
example, install to the Internal USB uDiskOnChip Flash drive of the Classmate.
Note, if you want to backup a pre-existing operating system you will have to do it
manually. In the case of the Classmate this requires about 1GB free space on the pen
drive, but the Classmate BIOS will not boot from a USB pen drive bigger than 512MB
-- I got around this by the very awkward method of booting from a 512MB drive, then
plugin a 2GB pen drive and mount it, then use a command like:
# dd if=/dev/sdb | gzip - > /mnt/sdc1/backup-classmate-sdb.img.gz
where sdb is the entire internal drive and sdc1 is the mounted 2GB pen drive partition.
'

PMEDIA="`Xdialog --wmclass "gtkdialog2" --left --title "Puppy Universal Installer" --no-tags --stdout --help "${HELPPUI}" --menubox "パピーユニバーサルインストーラへようこそ！\nパピーを取り外しのできるメディアにインストールしたければ（例えば\nUSBフラッシュやハードディスクやCD/DVDディスク、Zipディスク\nLS-120ディスクなど）続ける前に今すぐメディアを挿入して下さい。\n\n繰り返します。===今すぐメディアを挿入して下さい！===\nそしてパピーをインストールするメディアを選択して下さい:" 0 0 10 usbflash "USBフラッシュドライブ" usbhd "USB ハードディスク" usb2ataflash "USB CFフラッシュドライブ、後ほどCFをIDE/SATAアダプタへ移します" iusbflash "内蔵USBフラッシュドライブ(例：uDiskOnChip)" ataflash "内蔵IDE/SATAフラッシュドライブ(例: IDEアダプタ内のCFカード)" atazip "内蔵ZIPあるいはLS120ドライブ" atahd "内蔵(IDEかSATA)ハードディスク" scsihd "古い本当のSCSIハードディスク" cd "CDドライブ"`"
[ ! $? -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

##v3.97 support /dev/hd*...
#if [ -e /proc/ide ];then
# case $FINALPMEDIA in
# ata*)
#  if [ "$SATADRIVES" = "" ];then #see /etc/rc.d/PUPSTATE.
#   SUBST_ATA="ide"
#  else
#   SUBST_ATA="sata"
#   #if [ "`probedisk | grep '^/dev/hd'`" != "" ];then
#    Xdialog --wmclass "gtkdialog2" --left --title "Puppy universal installer: IDE or SATA" --ok-label "IDE" --cancel-label "SATA" --yesno "Do you want to install to a IDE or SATA drive?
#Note, any computer manufactured before 2006 is unlikely to have a SATA
#drive. SATA is a new internal fast drive interface. Physically, you
#can tell the difference by the cable between motherboard and drive:
#IDE: broad flat cable  SATA: very narrow flat cable.
#
#NOte2, if you are installing to a USB or other pluggable media that
#will later be moved to an internal IDE or SATA socket, then you have
#to answer here according to what the final interface will be." 0 0
#    [ $? -eq 0 ] && SUBST_ATA="ide"
#   #fi
#  fi
#  substPATTERN="s/^ata/${SUBST_ATA}/"
#  PMEDIA="`echo -n "$PMEDIA" | sed -e "$substPATTERN"`"
#  FINALPMEDIA="`echo -n "$FINALPMEDIA" | sed -e "$substPATTERN"`"
#  ;;
# esac
#fi

PROBEDISK="`probedisk 2> /tmp/probediskerr.txt`"
case $PMEDIA in
 usbflash)
  USBDRIVES="`echo "$PROBEDISK" | grep 'Direct\-Access' | cut -f 3 -d '/' | cut -f 1 -d '|' | tr "\n" " "`"
  SELECTIONS=""
  for ONEUSB in $USBDRIVES
  do
   [ "$ATADRIVES" != "" ] && [ "`echo "$ATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #v3.94 eliminate ide/sata drives. v3.97
   [ "$SATADRIVES" != "" ] && [ "`echo "$SATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #v3.97 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/ $//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)
  USBDRIVES="`echo "$PROBEDISK" | grep 'Direct\-Access' | cut -f 3 -d '/' | cut -f 1 -d '|' | tr "\n" " "`"
  SELECTIONS=""
  for ONEUSB in $USBDRIVES
  do
   [ "$ATADRIVES" != "" ] && [ "`echo "$ATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #v3.94 eliminate ide/sata drives. v3.97
   [ "$SATADRIVES" != "" ] && [ "`echo "$SATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #v3.97 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) #v3.94 was idecd
  #find cd drives... v3.97...
  CDDRIVES="`echo "$PROBEDISK" | grep '|cdrom|' | 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/ $//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 --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --ok-label "終了" --msgbox "次のIDE(ATAPI)CD/DVDドライブが見つかりました：\n$SELECTIONS \n\nしかしハードディスク、USBフラッシュドライブやZipドライブ\nの様にパピーをCD/DVDにインストールする事は\nできません。なぜならCD/DVDは直接書き込みができない\nからです。CD/DVDでは「リマスタリング」する必要が\nあります。パピーには「パピーライブCDのリマスタ」と言う\nプログラムが\n「セットアップ」のメニューの中にあります。このプログラムは\n自分だけのカスタムライブCD/DVDを作る事ができます。\n注意、空のCD-RかDVD-R（+Rではなく）が必要です。\n\n終了するにはボタンをクリックして下さい..." 0 0
  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/ $//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
  ;;
 atahd|ataflash) #v3.94
  #at bootup, init script creates ATADRIVES='' in /etc/rc.d/PUPSTATE...
  HDDRIVES="$ATADRIVES"
  if [ -e /proc/ide ];then #v3.97 old kernel.
    IDEDRIVES="`echo "$PROBEDISK" | grep '|disk|' | 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/ $//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 "まだ実行されていません"
  exit
  ;;
esac


echo "$SELECTIONS"
#v2.11
if [ "$SELECTIONS" = "" ];then
 Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --ok-label "終了" --msgbox "何も選択されていません。プラグインデバイスは接続してありますか？" 0 0
 exit
fi

echo '#!/bin/sh' > /tmp/dlg1
echo -n 'Xdialog --wmclass "gtkdialog2" --title "パピーユニバーサルインストーラ" --no-cancel --stdout --menubox "インストール先デバイスの選択:" 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"

#v3.97 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="`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.

##v3.95 offer to backup entire drive...
#if [ "$PMEDIA" = "usbflash" ];then
# uPATTERN="/dev/$DRVSEL"
# uDRVDESCR="`echo "$PROBEDISK" | grep "$uPATTERN" | cut -f 3 -d '|'`"
# dsDEST='/'
# [ "$PUP_HOME" != "" ] && dsDEST='/initrd'"${PUP_HOME}"
# dsPATTERN=' '"$dsDEST"'$'
# HOMEFREEM="`df -m | grep "$dsPATTERN" | tr -s ' ' | cut -f 4 -d ' '`"
# Xdialog --buttons-style "text" --wmclass "gtkdialog2" --left --title "Puppy Universal Installer" --ok-label "No backup" --cancel-label "Backup"  --yesno "You have chosen to install to ${DRVSEL}, which is a USB Flash drive, described as:
# ${uDRVDESCR}
#
#Before continuing with choosing the partition and doing the actual install, you may
#at this stage backup the entire drive. This may be useful if you are installing to
#the internal USB Flash drive of a Intel Classmate or Asus eeePC baby laptop and you
#want to save the existing operating system, and maybe reinstall it later.
#
#The total size of ${DRVSEL} is ${IDRVSIZM}MB and this will be backed up to a compressed
#file named 'installer-backup-${DRVSEL}.img.gz' which will be approximately half to
#2/3 of this size.
#The backup file will be created at '${dsDEST}' which has ${HOMEFREEM}MB free space
#on it. This free space must be at least 200KB bigger than the anticipated size of the
#compressed backup file, if not then do not attempt to backup.
#
#Note, if you choose to backup, there is no progress window. You should see the LED
#light on the Flash drive flickering to indicate action. It may take 3 or 4 minutes,
#and when completed this Installer program will continue with normal installation.
#
#Click 'No backup' to bypass backup (normal choice)...
#Click 'Backup' to backup a pre-existing installation...
#" 0 0
# if [ $? -eq 1 ];then
#  sync
#  dd if=/dev/$DRVSEL | gzip - > ${dsDEST}/installer-backup-${DRVSEL}.img.gz
#  sync
# fi
#fi

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" || PUPINST="" #v3.01
#   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>パピーを ${ONECHOICE} にインストール:</label></text>
    <button>
     <input file>/usr/local/lib/X11/mini-icons/mini-dog.xpm</input>
     <action>Exit:${ONECHOICE}</action>
    </button>
   </hbox>
"
done
if [ "$FINALPMEDIA" = "usbflash" ];then
 MSGex1="<text><label>重要：「Gparted」を使用する場合、パーティションの作成後「ブート」フラグ（右クリック：Manage flags）を必ずセットして下さい。また、USBフラッシュドライブの場合は「fat32」よりも「fat16」ファイルシステムを選んで下さい。より簡単に起動できます。-- ext2やext3パーティションも使えます。</label></text>
<text><label>追記：「Gparted」がドライブに「！」アイコンをマークし、無効なパーティションとして表示する時があります。その場合はパーティションを削除し、再作成して「ブータブル」にして下さい。</label></text>"
else
 MSGex1="<text><label>重要：「Gparted」を使用する場合、パーティションの作成後「ブート」フラグ（右クリック：Manage flags）を必ずセットして下さい。</label></text>
<text><label>追記：「Gparted」がドライブに「！」アイコンをマークし、無効なパーティションとして表示する時があります。その場合はパーティションを削除し、再作成して「ブータブル」にして下さい。</label></text>"
fi
if [ "$DLGTXT" = "" ];then
 DLGTXT="<hbox>
 <text><label>ドライブ ${DRVSEL} にはパーティションがありません！「GParted」を使ってパーティションを作成する事をお勧めします：</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>
"
fi

DLGEXT=""

#v3.97 offer "comboformat" installation...
if [ "$FINALPMEDIA" = "usbflash" ];then
 DLGEXT="
   <frame コンボフォーマット>
    <hbox>
     <text><label>注意：これは今は使わないで下さい。バグがあります。コンボフォーマットは特にUSBフラッシュドライブ向きの新しいインストール方法です。これはドライブ全部を再区画して、小さい128MBのFAT16パーティションと残りをext2パーティションに切り直します。コンボフォーマットは1BG以上の大きなドライブ用です。これは標準でないテクニックです。BIOSでUSBブートオプションを付けたPC(特にUSB-ZIP)で起動させます。コンボフォーマットが堅実に動くという見解ができるまでは、まだ実験的ですが、たぶん他のオプションで動かない時の良い選択です。クリック：</label></text>
     <vbox>
      <button>
       <input file>/usr/local/lib/X11/mini-icons/mini-dog.xpm</input>
       <action>Exit:COMBOFORMAT</action>
      </button>
     </vbox>
    </hbox>
   </frame>
 "
fi

if [ "`echo "$DRVMSG" | cut -f 1 -d ':' | grep "[a-zA-Z]$"`" = "" ];then
 #ask if want superfloppy install...
 DLGEXT="$DLGEXT
   <frame パーティションのファイルシステム>
    <hbox>
     <text><label>警告： 意図した場所のファイルシステムに気を付けて下さい。それは望むものですか？ 特にファイルシステムがVFATかNTFSで、もしパーティションを全てPuppyを使うために引き継がれる事ができるならば、Linux ext2あるいはext3ファイルシステムと入れ替えた方が良いかも知れません。PCの内蔵ドライブにインストールするのであれば、ファイルシステムがLinux ext2またはext3である事が高く推奨されます。パピーはVFATやNTFSにインストールできますが「pup_save」を使った「frugal(質素な)」インストールだけに限られます。NTFSは特に制限されて、遅くて、その上厳しいブートオプションがあるので、できればそれを何とかして下さい。パーティションを調べて変更できるGPartedを実行するにはボタンをクリックして下さい。</label></text>
     <vbox>
      <button>
       <input file>/usr/local/lib/X11/mini-icons/gparted.xpm</input>
       <action>Exit:RUNGPARTED</action>
      </button>
     </vbox>
    </hbox>
   </frame>
   <frame スーパーフロッピー>
   <hbox>
    <text><label>警告: 一般の状況では推薦しません。スーパーフロッピーモードでパピーをインストールしますか？ その場合、MBRもパーティションもありません...ドライブは /dev/$DRVSEL としてアクセスされ、パーティション番号もありません。変なBIOSのPCからUSBフラッシュドライブを起動するには良い選択かも知れません。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 #drive is a superfloppy.
 DLGEXT="$DLGEXT
   <frame スーパーフロッピー>
   <hbox>
    <text><label>このドライブは現在スーパーフロッピーモードです。MBRもパーティションもありません。 /dev/$DRVSEL としてアクセスされ、パーティション番号はありません(変なBIOSのPCからUSBフラッシュドライブを起動するには良い選択かも知れません)。パピーをインストールする /dev/${DRVSEL}1 パーティションを作成しますか？ 作成するにはボタンをクリックして下さい:</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>パピーユニバーサルインストーラ</wtitle>
 <vbox>
  <text><label>これはパピーが選択したドライブの情報です:</label></text>
  <text><label>\"${DRVMSG}\"</label></text>
$DLGTXT
$DLGEXT
   <button>
    <label>前に戻って違うドライブを選択する</label>
    <action>Exit:GOBACK</action>
   </button>
 </vbox>
"

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

if [ "`echo "$RETTXT" | grep 'RUNGPARTED'`" != "" ];then
 Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --msgbox "OKボタンを押すとユニバーサルインストーラは終了しGpartedが実行されます。これはパピーのインストール後にユニバーサルインストーラを再度実行しなければいけないと言う事です。このユニバーサルインストーラに自動的に戻る設定をまだしていません。最初に気をつけて欲しい事は、$｛DRVSEL｝のパーティションへのどんな変更もリナックスカーネルによって認識されるという事です。最近のカーネルではパーティションの変更がすぐには認識されないという独特な事があります。USBドライブの場合、カーネルに再スキャンさせるために、USBドライブを一度抜き、改めてもう一度差し込まなければなりません（アンマウントされている時）。これは本当に馬鹿げた事です。とにかく、どんな変更でも変更後にパピードライブマウンタ「Pmount」を実行してパーティションが正しく認識されているか見て下さい。変更が認識されていなければ、全く最悪の場合はカーネルにドライブを再スキャンさせるために自分でリブートしなければなりまん。変更が正しく認識されたらユニバーサルインストーラをもう一度実行して下さい。 

NTFSやVFATに関して、もしパーティションにWindowsかDOSがインストールされていれば、
もちろんext2やext3に変えないで下さい！ USBフラッシュドライブの場合、通常FAT16
パーティションでオーケーです。しかし「pup_save」ファイルに保存する事に制限されます。
これはすばらしく、ほとんどの人がドライブをWindowsと一緒にファイルを保存したり
移動するのに使えるので特にこれを選びます。
しかしフラッシュドライブはext2/3に変更でき、しかもちゃんと起動します。
むしろ「pup_save」ファイルよりも全パーティションを保存に使えると言う利点があります。
疑うならVFATのままにして下さい。しかしSyslinuxはFAT32をブータブルにする事に
問題があるのでパーティションがFAT32ではなくFAT16であると確認して下さい。

警告：ファイルシステムを変更するとパーティションの中は全て消去されます！

もうひとつ。GPartedの実行時、パーティション上で右クリックして下さい。
「Manage flags」するためのメニューオプションが表示されます。
ブートフラグが設定されている事を確認して下さい -- 忘れずに！" 0 0
 [ $? -ne 0 ] && exit
 exec gparted /dev/$DRVSEL
fi

#v3.97 ComboFormat method....
if [ "`echo "$RETTXT" | grep 'COMBOFORMAT'`" != "" ];then
 Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ: 整合性チェック" --ok-label "続ける" --cancel-label "戻る" --yesno "コンボフォーマットは $DRVSEL ドライブを消去して、少し非標準的な方法で
2つのパーティションを作成します。考え方は最初の128MBのFAT16パーティションが
ほとんど「USB-ZIP」のBIOS起動設定に合うZIPドライブのように見えるという事です。
しかもドライブは「USB-FLOPPY」のBIOS起動設定に合うスーパーフロッピーに
（パーティションを持っているのに）見えるように作られます。パーティション
を持っているので「USB-HDD」のBIOS設定はほとんどのPCでも機能するはずです。
このカメレオンのような性質はGpartedなど若干のアプリケーションを混同します。
しかしfdisk、disktypeとpmountのような基本的なツールは全く幸せです。

コンボフォーマットまだ試験的と分類されています。ドライブにそのような
過激な手術をしたくなければ「戻る」をクリックして下さい...

「続ける」をクリックするとドライブはこれ以上質問なしですぐに分割されます。
その /dev/$DRVSEL が消去したいドライブであると
絶対に確信して下さい！！！..." 0 0
 [ ! $? -eq 0 ] && continue
 while [ "`mount | grep "$DRVSEL"`" != "" ];do
  Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --ok-label "続ける" --cancel-label "終了" --yesno "残念ながら、 $DRVSEL は現在マウントされています。アンマウントしてから「続ける」ボタンをクリックして下さい。アンマウントできなければインストールできないので終了しなければなりません。" 0 0
  [ ! $? -eq 0 ] && exit
 done
 #copy special 128MB fat16 partition image to flash drive...
 yaf-splash -font "8x16" -outline 0 -margin 4 -bg orange -text "Please wait, copying /lib/boot128m.img 128MB boot image to /dev/$DRVSEL..." &
 XPID9=$!
 gunzip -c /lib/boot128m.img.gz | dd of=/dev/$DRVSEL
 sync
 kill $XPID9
 yaf-splash -font "8x16" -outline 0 -margin 4 -bg orange -text "Please wait, creating a second ext2 partition to fill the drive..." &
 XPID9=$!
 echo -e 'n\np\n2\n\n\nw\n' | fdisk /dev/$DRVSEL
 sync
 mke2fs -m 0 /dev/${DRVSEL}2
 sync
 kill $XPID9
 sfPATTERN="/dev/${DRVSEL}2|ext2"
 if [ "`probepart | grep "$sfPATTERN"`" = "" ];then
  Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ: エラー" --msgbox "えー、うまくいかなかったようです。ボタンをクリックして終了して下さい..." 0 0
  exit
 fi
 #this returns with SRCPATH, path of puppy files that are to be installed...
 locate_puppy_src_files
 #now copy puppy files to first fat16 partition...
 DESTPART="${DRVSEL}4"
 yaf-splash -font "8x16" -outline 0 -margin 4 -bg orange -text "Please wait, copying Puppy files to /dev/${DRVSEL}4, the FAT16 partition on /dev/$DRVSEL..." &
 XPID9=$!
 mkdir -p /mnt/$DESTPART
 mount -t vfat /dev/$DESTPART /mnt/$DESTPART
 cp -f $SRCPATH/vmlinuz /mnt/$DESTPART/
 if [ "$FINALPMEDIA" = "ataflash" -o "$FINALPMEDIA" = "ideflash" ];then
  echo "default vmlinuz initrd=initrd.gz ide=nodma pmedia=$FINALPMEDIA" > /mnt/$DESTPART/syslinux.cfg
 else
  echo "default vmlinuz initrd=initrd.gz pmedia=$FINALPMEDIA" > /mnt/$DESTPART/syslinux.cfg
 fi
 sync
 echo "Creating marker file for wakepup boot floppy..."
 [ "$FINALPMEDIA" = "usbflash" ] && touch /mnt/$DESTPART/USBFLASH
 [ "$FINALPMEDIA" = "ataflash" ] && touch /mnt/$DESTPART/IDEFLASH
 [ "$FINALPMEDIA" = "ideflash" ] && touch /mnt/$DESTPART/IDEFLASH
 [ "$FINALPMEDIA" = "usbhd" ] && touch /mnt/$DESTPART/USBHD
 sync
 echo "Copying initrd.gz..."
 cp -f $SRCPATH/initrd.gz /mnt/$DESTPART/
 sync
 echo "Copying .sfs files..."
 cp -f $SRCPATH/pup_${NEWVER}.sfs /mnt/$DESTPART/ 2>/dev/null
 sync
 cp -f $SRCPATH/zdrv_${NEWVER}.sfs /mnt/$DESTPART/ 2>/dev/null
 sync
 umount /mnt/$DESTPART
 kill $XPID9
 Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --msgbox "以上です。これでパピーは /dev/$DRVSEL にインストールされました。BIOSを
USB-ZIPに設定すれば動くはずです。失敗したらUSB-FLOPPYかUSB-HDDを試して下さい。
注意。新しいBIOSにはこれらのオプションがないのもあります。その代わりに
詳しく調べて接続されているUSBドライブのタイプを自動的に検出します。
終了するにはOKをクリックして下さい..." 0 0
 exit
fi

[ ! "`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 --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ: 整合性チェック" --ok-label "続ける" --cancel-label "終了" --yesno "パーティションの整合性チェックをしてから続けます：\n$SANITYMSG1 \n$SANITYMSG2 \n$SANITYMSG3 \n\n上記のレポートでパーティションがマウントされているなら今すぐアンマウント\n必要があります。しかしレポートでパーティションがアンマウントができないなら\nインストールは困難でしょう -- 確かに、ハードディスクにインストールする場合\n「option1」のインストールしかできません(後ほど説明します)。\nもしパーティションに「pup_save.3fs」があるとアンマウントできません\n -- このファイルはパピーが現在使用中だからです。もしパピーを\nライブCDから起動し「pup_save.3fs」がない場合はパピーは完全に\nRAMの中で実行するので問題は解決します。 -- しかしpup_save.3fsは\n今現在使用中なのでこれを削除したりリネームはすべきではありません。\n代わりに何か他のOSを起動してファイル名を変えて下さい。\nそれからパピーライブCDを起動して下さい。\n\n現実的には可能ならすぐにパーティションをアンマウントして下さい。\nさもなければ限定されたインストールを選択して「続ける」かあるいは\nこれでスクリプトを「終了」してマウントされているパーティションの\n問題の解決を試みて下さい..." 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>パピーユニバーサルインストールーラ</wtitle>
 <vbox>
   <text><label>「/dev/${DESTPART}」をスーパーフロッピーとしてフォーマットする選択をしました。ドライブを「vfat」或いは「ext3」ファイルシステムで作成する選択が必要です。「Ext3」は最もフレキシブルな
（そして推奨する）選択ですがWindowsから読めるようにするには「vfat」を選択して下さい。注意、Windowsにも「ext2/3」ドライブにアクセスするツールがあります。</label></text>
   <text><label>詳細説明: 「ext3」を選択するとドライブ全体がすぐに個人データ保存用として使えますが、「vfat」を選択するとこのインストーラはドライブの中に「ext3」ファイルシステムのファイル「pup_save.3fs」を作成しようとします -- このファイルは全ての個人データを含みます。フォーマットを開始するには「FORMAT_ext3」か「FORMAT_vfat」ボタンを押して下さい...</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>パピーユニバーサルインストーラ</wtitle>
 <vbox>
   <text><label>「/dev/${DRVSEL}」にMBR及びパーティションを付けてフォーマットする選択をしました。そのパーティションに「vfat」か「ext3」のファイルシステムを作成する選択が必要です。「ext3」は最もフレキシブルで（推奨する）選択ですがWindowsから読めるようにするには「vfat」を選択して下さい。注意、Windowsにも「ext2/3」ドライブにアクセスするツールがあります。</label></text>
   <text><label>詳細説明：「ext3」を選択するとドライブ全体を個人データ保存用にすぐに使えますが、「vfat」を選択するとドライブ内に「ext3」ファイルシステムのファイルを作成しなくてはなりません（すなわち「pup_save.2fs」と言うファイルです） -- このファイルは全ての個人データを含みます。</label></text>
   <text><label>USBフラッシュドライブ: これらのデバイスにはvfat（fat16）パーティションを作成するのが普通です。Windows互換や古いBIOSではfat16ファイルシステムでしか起動できません。</label></text>
   <text><label>\" \"</label></text>
   <text><label>この時点でユニバーサルインストーラを一度終了してGPartedを実行し、その後ユニバーサルインストーラを再度実行して下さい。GPartd」は一番大事な事を忘れないで下さい -- すなわちパーティション作成後マウスを右クリックして「Manage flags」を選択し「ブート」フラグをセットして下さい。</label></text>
   <text><label>追記。Gpartedがドライブに「！」アイコンを付け無効なパーティションとして表示する時があります。その場合はパーティションを削除し再作成して「ブータブル」にして下さい。</label></text>
   <text><label>Click button to run GParted...</label></text>
  <hbox>
   <button>
    <label>GPartedの実行</label>
    <action>Exit:gparted</action>
   </button>
   <button cancel>
   </button>
  </hbox>
 </vbox>
"
  RETTXT="`echo "$DLG3" | gtkdialog2 --stdin`"
  MYACTION="`echo "$RETTXT" | grep 'EXIT:' | cut -f 2 -d ':'`"
  [ "$MYACTION" = "gparted" ] && exec gparted /dev/$DRVSEL
  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="`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>パピーユニバーサルインストーラ</wtitle>
 <vbox>
  <text><label>パピーをドライブ全部にインストールする選択をしました。これをスーパーフロッピモードと呼びます。このモードではMBR(Master Boot Record)もパーティションもありません。特にUSBフラッシュはPCのBIOSからUSBフラッシュドライブを起動するのが難しいのでフラッシュメモリには良い選択です。</label></text>
  <text><label>ターゲットドライブは ${DESTPART} で ${DESTFS} を持ち ${DESTSIZM} Mあります。パピーをこのドライブにインストールするにはOKボタンを押して下さい...</label></text>
  <hbox><button ok></button><button cancel></button></hbox>
 </vbox>
"
 RETTXT="`echo "$DLG4" | gtkdialog2 --stdin`"
else
 DLG4="
 <wtitle>パピーユニバーサルインストーラ</wtitle>
 <vbox>
  <text><label>パピーを /dev/${DESTPART} パーティションにインストールする選択をしました。このパーティションは ${DESTFS}  ファイルシステムを持ち、サイズは ${DESTSIZM}M です。</label></text>
  <text><label>パピーをインストールするにはOKボタンを押して下さい（注意。実際のインストールの前に１、２の確認ダイアログウィンドウが現れます）...</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....
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 "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 --wmclass "gtkdialog2" --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
   
   #check that partition has 'boot' flag set...
   QPATTERN="^Partition ${DESTNUM}:"
   if [ "`disktype /dev/$DESTDRV | grep "$QPATTERN" | grep 'bootable'`" = "" ];then
    Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --no-cancel --stdout --ok-label "GParted" --cancel-label "bypass" --yesno "少々問題があります。このパーティション ${DESTPART} には起動可能にするために必要な「ブート」フラグがセットされていないので起動できません。
今すぐ「GParted」ボタンをクリックしてGPartedを実行し、マウスの右ボタンをクリックし
「Manage flags」を選択して「ブート」フラグをセットして下さい。
GPartedを終了すると「パピーユニバーサルインストーラ」が続けられます。

「GParted」をクリックしてGParedを実行（推奨）...
「bypass」をクリックしてGPartedをパスする..." 0 0
    [ $? -eq 0 ] && gparted /dev/$DESTDRV
   fi
  fi

  case $DESTFS in
   vfat)
     if [ ! "`echo "$DESTPART" | grep '[0-9]$'`" = "" ];then
      PARTCHOICE="`Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --no-cancel --stdout --menubox "ここではデフォルトのまま「続行」して下さい。\n==トップエントリが選択されている事を確認してからOKボタンをクリックして下さい==\n\nしかしこのパピーユニバーサルインストーラを試したけれど\nパピーが起動しなければ以下の選択を試す事ができます。\n\n個人的にはGPartedを使ってパーティションの削除及び\n作成に成功しています..." 0 0 4 default "続行" GParted "GPartedを使ってUSB/IDE-CFパーティションの削除と再作成をする" syslinux "USBやIDE-CFのmsdos/vfatパーティションを起動可能にする"`"
      [ "$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 "(and maybe zdrv_xxx.sfs if it exists. pup_xxx.fs 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 pup_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_*.sfs #v2.11
 rm -f /mnt/data/devx_*.sfs #v2.11
 rm -f /mnt/data/zdrv_*.sfs #v2.16
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..."
FNORAM="" #v3.95...
echo "Would you like syslinux.cfg to have pfix=noram boot parameter?"
echo "this will prevent pup_xxx.sfs file from being copyied into RAM, which speeds"
echo "bootup and frees up RAM space, but slows down application startup slightly."
echo "Probably good to answer yes here if PC has 256MB and no swap file/partition"
echo "in an internal hard drive. But, you can always edit syslinux.cfg later if"
echo "you want to try with or without loading to RAM."
echo "NOTE: you can answer no here if the PC has less than 256MB RAM, as Puppy"
echo "will automatically see insufficient RAM and not copy the .sfs file to RAM."
echo -n "ENTER key only for no, else any char then ENTER for yes: "
read FNORAM
[ "$FNORAM" != "" ] && FNORAM=" pfix=noram"
#v2.20 root=/dev/ram0 removed...
if [ "$FINALPMEDIA" = "ataflash" ];then
 echo "default vmlinuz initrd=initrd.gz ide=nodma pmedia=$FINALPMEDIA$FNORAM" > /mnt/data/syslinux.cfg
else
 echo "default vmlinuz initrd=initrd.gz pmedia=$FINALPMEDIA$FNORAM" > /mnt/data/syslinux.cfg
fi
sync
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/pup_*.sfs /mnt/data/ 2>/dev/null
sync
cp -f $SRCPATH/zdrv_*.sfs /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 "Puppy Universal Installer" -geometry 80x10 -e /tmp/installpup.sh $DESTPART $SRCPATH $FINALPMEDIA
    ;;
   ext2|ext3)
    #params passed in: $DESTPART "$SRCPATH" $FINALPMEDIA
    echo '#!/bin/sh
DESTPART="$1"
SRCPATH="$2"
FINALPMEDIA="$3"
DESTFS="$4"
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 "(and maybe zdrv_xxx.sfs if it exists. pup_xxx.fs 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 pup_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/pup_*.sfs #v2.11
 rm -f /mnt/data/devx_*.sfs #v2.11
 rm -f /mnt/data/zdrv_*.sfs #v2.16
fi
sync
echo
echo "Making $DESTPART bootable..."
if [ ! "`echo "$DESTPART" | grep '[0-9]$'`" = "" ];then
 extlinux /mnt/data #i think only use -z for superfloppy.
else
 extlinux -z /mnt/data
fi
sync
echo "Copying vmlinuz..."
cp -f $SRCPATH/vmlinuz /mnt/data/
sync
echo "Creating extlinux.conf..."
FNORAM="" #v3.95...
echo "Would you like extlinux.conf to have pfix=noram boot parameter?"
echo "this will prevent pup_xxx.sfs file from being copyied into RAM, which speeds"
echo "bootup and frees up RAM space, but slows down application startup slightly."
echo "Probably good to answer yes here if PC has 256MB and no swap file/partition"
echo "in an internal hard drive. But, you can always edit extlinux.conf later if"
echo "you want to try with or without loading to RAM."
echo "NOTE: You can answer no here if the PC has less than 256MB RAM, as Puppy"
echo "will automatically see insufficient RAM and not copy the .sfs file to RAM."
echo "NOTE: If are installing to one of the baby-laptops with only 256MB RAM, it"
echo "is strongly recommended to answer yes here (ex: Intel Classmate laptop)."
echo -n "ENTER key only for no, else any char then ENTER for yes: "
read FNORAM
[ "$FNORAM" != "" ] && FNORAM=" pfix=noram"
#v2.20 root=/dev/ram0 removed...
if [ "$FINALPMEDIA" = "ataflash" ];then
 echo "default vmlinuz initrd=initrd.gz ide=nodma pmedia=$FINALPMEDIA$FNORAM" > /mnt/data/extlinux.conf
else
 echo "default vmlinuz initrd=initrd.gz pmedia=$FINALPMEDIA$FNORAM" > /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/pup_*.sfs /mnt/data/
cp -f $SRCPATH/zdrv_*.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 "パピーユニバーサルインストーラ" -geometry 80x10 -e /tmp/installpup.sh $DESTPART $SRCPATH $FINALPMEDIA $DESTFS
    ;;
   *)
    gxmessage " $DESTPART には $DESTFS ファイルシステムがあります。現在
外部vfat(FAT16/32)か ext2/ext3ファイルシステムだけをサポートします。
終了するにはOKをクリックして下さい..."
    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, 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="これは新規インストールのようです。"
  else
   PREVPUPMSG="パピーがすでにインストールされています。バージョンは「$PUPVEROLD」で、
アップグレードするか全て置き替えるか選択できます。"
  fi
  INSTOPTION="1"
  if [ ! "$DESTFS" = "vfat" ];then
   Xdialog --wmclass "gtkdialog2" --left --buttons-style text --title "パピーユニバーサルインストーラ" --ok-label "FRUGAL" --cancel-label "FULL" --yesno "パピーを /dev/$DESTPART にインストールする選択をしました。これは内蔵ハードディスク
 ($FINALPMEDIA) のようです。
$PREVPUPMSG 

パピーをこのパーティションにインストールするには２通りの方法があります：

1. FRUGAL (推奨)
vmlinuz、initrd.gz、pup_$NEWVER.sfsとzdrv_$NEWVER.sfsファイルをパーティション
にコピーし個人の設定をpup_saveファイルに保存します（CDから実行すると同じように）。
そのパーティションの以前の内容にはさわらずそのままの状況に保ちます。
利点:
- 同じパーティションにインストールしている他のデストリビューションと共存できます。
- 非LinuxのFATやNTFSパーティションにインストールできます (FATを推奨)。
- アップグレードがより簡単: 新しい「.iso」ファイルをダウンロードし上記ファイルを
  新しいバージョンのものに代えるだけです。(ファイルにアクセスするには.isoをマウントします)
  (注意。パピーはISOをクリックするだけで簡単にマウントできます)
- .sfsアドオン(アプリケーションのコンボパック)の使用が可能です。
- Linuxファイルシステムで共存の必要がなければ全パーティションに保存できます。

2. FULL
「普通の」リナックスインストールです。パピーはそのパーティション全部を使います。

注意。FRUGALオプション。FATやNTFSパーティションにインストールすると
追加起動オプションがあります： フロッピーディスクを使う「WakePup2」。あるいは
フロッピー、USB、内蔵ハードディスクから起動するにはGRUBが一般的な方法です。

共存インストールするにはFRUGALをクリック(推奨) ...
標準的なインストールはFULLをクリック...
終了するにはウィンドウを閉じて下さい..." 0 0
   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.
   
   Xdialog --stdout --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --fixed-font --no-cancel --inputbox "パピーは「${DESTMNTPT}」にマウントされている「${DESTPART}」パーティションにインストール
されます。これはFRUGAL(質素な)インストールの為、パピーのファイルを任意のフォルダに 
置く選択ができ、パピーのマルチインストールには便利です。単独のインストールでも
パピーの全ファイルがそれ自身のフォルダにあれば、ディレクトリのトップレベル「/」の
他のファイルと衝突の可能性をなくします（例えば：他のリナックスがすでにインストールされて
いる場合は「initrd.gz」が「/」レベルにインストールされている可能性があります）。

フォルダに独自の名前を付けて下さい。名前にスペースや「/」があってはいけません。
起動時、パピーは「/」から一層下だけ探すので、パスが「puppyfiles/pup${NEWVER}」
ではいけません。「pup${NEWVER}」は問題ありません。アルファベットと数字で
単語を入力するか、パピーを「/」のトップディレクトリにインストールしたければ、
空白のままにして下さい..." 0 0 "puppy${NEWVER}" >/tmp/NEWPSUBDIR
   [ $? -ne 0 ] && exit
   NEWPSUBDIR="`cat /tmp/NEWPSUBDIR | sed -e 's%/%%g'`"
   
   yaf-splash -font "8x16" -outline 0 -margin 4 -bg orange -text "Please wait, copying files to $DESTPART, in folder $NEWPSUBDIR..." &
   XPID=$!
   mkdir -p $DESTMNTPT/$NEWPSUBDIR
   cp -f $SRCPATH/vmlinuz $DESTMNTPT/$NEWPSUBDIR/
   sync
   cp -f $SRCPATH/initrd.gz $DESTMNTPT/$NEWPSUBDIR/
   sync
   cp -f ${SRCPATH}/pup_${NEWVER}*.sfs $DESTMNTPT/$NEWPSUBDIR/
   sync
   [ -f $SRCPATH/zdrv_$NEWVER.sfs ] && cp -f $SRCPATH/zdrv_$NEWVER.sfs $DESTMNTPT/$NEWPSUBDIR/
   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 "パピーユニバーサルインストーラ" --ok-label "CREATE_BOOT_DISK" --cancel-label "NO_BOOT_DISK" --yesno "
パピーを起動するにはフロッピディスクも使えます。
現在「WakePup2」と言う一般的なブートフロッピを提供しています。
これはPCをスキャンしてパピーがどこにインストールされているか
見つけ出します。

注意。その後Grubブートローダの設定方法の情報が与えられます。" 0 0
    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="...for your convenience, this text has been written to /tmp/NEWGRUBTEXT"
   else
    grubEXTRAMSG="...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)"
   fi
   echo "title Puppy Linux $NEWVER frugal
rootnoverify (hd${GRUB_DRVN}${GRUB_PARTN})
kernel ${xNEWPSUBDIR}/vmlinuz pmedia=${FINALPMEDIA}${OPTIONPSUBDIR}
initrd ${xNEWPSUBDIR}/initrd.gz" > /tmp/NEWGRUBTEXT

   Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --msgbox "手動で「Grub」や「Lilo」やその他のブートシステムの設定ができます。

パーティション「$DESTPART」には「vmlinux」「initrd.gz」「pup_$NEWVER.sfs」ファイル
があり、「vmlinux」はカーネル、「initrd.gz」はイニシャルRAMディスク、そして
「pup_$NEWVER.sfs」には全てのパピーファイルが含まれています

Grubがインストールされているならmenu.lstと言うファイルを探し（一般的に
Grubがインストールされているパーティションの「/boot」ディレクトリにあります）
下の行を追加して下さい：

title Puppy Linux $NEWVER frugal
rootnoverify (hd${GRUB_DRVN}${GRUB_PARTN})
kernel ${xNEWPSUBDIR}/vmlinuz pmedia=${FINALPMEDIA}${OPTIONPSUBDIR}
initrd ${xNEWPSUBDIR}/initrd.gz

${grubEXTRAMSG}" 0 0
   
   #finished. could put up a final dlg here, then quit script.
   Xdialog --wmclass "gtkdialog2" --title "パピーユニバーサルインストーラ" --msgbox "オーケー、全て完了！" 0 0
   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 "パピーユニバーサルインストーラ" --ok-label "アップグレード" --cancel-label "消去" --yesno "すでに$DESTPARTにパピーがインストールされています。\nアップグレードしますか？ それともこのパーティションを全部削除しますか？\n\n最後の整合性チェック: $DESTPART は正しいパーティションであると確信しますか？\n(注意、$DESTPARTは現在 $DESTMNTPTにマウントされています---OK？)\n\n「アップグレード」ボタンを選ぶとアップグレードします...\n消去ボタンを選ぶとパーティションを消去します...\nウィンドウを閉じると終了します..." 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 --wmclass "gtkdialog2" --title "パピーユニバーサルインストーラ" --no-buttons --infobox "お待ち下さい。「$DESTPART」の中のファイルを削除しています..." 0 0 200000 &
     XPID=$!
     sleep 3
     rm -rf $DESTMNTPT/*
     sync
     kill $XPID
    fi
   fi
   Xdialog --wmclass "gtkdialog2" --title "パピーユニバーサルインストーラ" --no-buttons --infobox "お待ち下さい。「$DESTPART」にパピーのファイルをコピーしています..." 0 0 120000 &
   XPID=$!
   sleep 1
   #loop-device mount pup_xxx.sfs in DESTPART, copy contents of pup_xxx.sfs to DESTPART...
   SFSPATTERN="^pup_${NEWVER}.*\\.sfs" #v3.01
   xSFSNAME="`ls -1 $SRCPATH/ | grep "$SFSPATTERN" | head -n 1`" #v3.01
   #losetup-FULL /dev/loop2 $SRCPATH/pup_$NEWVER.sfs
   losetup-FULL /dev/loop2 $SRCPATH/$xSFSNAME #v3.01
   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
   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 /etc/puppyversion back to PUPVEROLD, run rc.update
   Xdialog --wmclass "gtkdialog2" --title "パピーユニバーサルインストーラ" --no-buttons --infobox "お待ち下さい。「rc.update」スクリプトを実行中です..." 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 --wmclass "gtkdialog2" --left --buttons-style text --title "パピーユニバーサルインストーラ" --ok-label "USBから起動" --cancel-label "GRUBをインストール/更新" --yesno "順調にいくとパピーは $DESTPART にインストールされました。\n\
しかしパピーをどうやって起動するかと言う難題にぶつかります。\n\
下記の１つか両方を実行する事ができます：\n\
\n\
起動ディスク: フロッピディスクかUSBペンドライブを使ってパピーを起動します。\n\
GRUB:      GRUBをハードディスクにインストール(あるいは今のGRUBを更新)します。\n\
\n\
USBフラッシュペンドライブを「起動ディスク」として使いたければ「USBから起動」\n\
をクリックして下さい。このユニバーサルインストーラスクリプトはUSB「起動ディスク」\n\
を作成した時点でこのダイヤログウィンドウに戻ります。\n\
注意。PCがフロッピドライブを持っていなくてハードディスクにGRUBを\n\
インストールしたくない時だけ選択して下さい。\n\
\n\
「GRUBをインストール/更新」をクリックするとGRUBブートマネージャをインストール/更新します。\n\
GRUBがハードディスクにインストールされるとフロッピ「起動ディスク」の\n\
作成オプションの選択ができます。\n\
\n\
== USB起動ディスクを選択したら続ける前に今すぐ挿入して下さい！ ==\n\
 (FAT16ファイルシステムでなければなりません。全てのファイルは削除されます)\n\
 == アンマウントでなければなりません -- 続ける前に確認して下さい ==" 0 0
   if [ $? -eq 0 ];then #BOOT DISK
    BOOTPART=""
    #v3.96...
    USBDRIVES="`echo "$PROBEDISK" | grep 'Direct\-Access' | 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 "パピーユニバーサルインストーラ" --yesno "パピー用起動ディスクに「$BOOTPART」を作成したいかどうか確認して下さい。\nパピーがこのデバイスを間違えて確認した場合は「No」と答えて下さい...\n\nn正しいデバイスであれば「Yes」ボタンをクリックして下さい..." 0 0
     [ ! $? -eq 0 ] && continue
    fi
    if [ ! "$BOOTPART" = "" ];then
     cp -af $SRCPATH/vmlinuz /mnt/$DESTPART/
     sync
     Xdialog --wmclass "gtkdialog2" --title "パピーユニバーサルインストーラ" --msgbox " $BOOTPART 起動ディスクを作成しています..." 0 0 &
     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 "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
    unmountcdfunc
    if [ -e /proc/ide ];then #v3.97
     grubEXTRAMSG=""
    else
     grubEXTRAMSG="
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)"
    fi
    Xdialog --buttons-style "text" --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --ok-label "更新" --cancel-label "インストール" --yesno "今のGRUBのインストールを更新するには「更新」ボタンをクリック
あるいはGRUBを(再)インストールするには「インストール」をクリック...
${grubEXTRAMSG}" 0 0
    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="...for your convenience, this text has been written to /tmp/NEWGRUBTEXT"
     else
      grubEXTRAMSG="...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)"
     fi

     Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --msgbox "今のGRUBインストールを更新する選択がされました。
これは最後の手作業が必要です...
menu.1stファイルを見つけます(普通はGRUBがインストールされている
パーティションの /boot/grubにあります)。そして以下を挿入します:

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

$grubEXTRAMSG

OKボタンを押すとパピーユニバーサルインストーラは終了します。" 0 0
     exit
    else
     Xdialog --wmclass "gtkdialog2" --left --title "パピーユニバーサルインストーラ" --msgbox "「grubconfig」スクリプトを実行しようとしています。\nデフォルトのままにして下さい。一番最初の質問は簡単なインストールをするかどうかです。\nデフォルトオプションのままにして下さい。\nフォルトオプションと違う選択をするのは\nGrubをどこにインストールするかと聞かれた時です。「MBR」を選択して下さい。" 0 0
     while [ 1 ];do
      grubconfig /dev/$DESTPART
      #...if choose to create a boot floppy, writes 'no' to /tmp/loopbrk.txt.
      Xdialog --wmclass "gtkdialog2" --title "パピーユニバーサルインストーラ" --yesno "すでに起動フロッピの作成やハードディスクへのインストールに「grubconfig」を\n\
実行していれば「Yes」ボタンをクリックしてgrubconfigスクリプトを再実行し、もう一枚\n\
起動フロッピを作成するか「GRUB]をハードディスクへ(再)インストールして下さい。\n\
「Yes」を選択したら前のように全てデフォルトのままにして下さい。\n\
\n\
「Yes」をクリックするとgrubconfigを再実行...\n\
インストールが完了したら「No」をクリック..." 0 0
      [ ! $? -eq 0 ] && break
     done
     rm -f /tmp/loopbrk.txt
     exit
    fi
   fi
   Xdialog --wmclass "gtkdialog2" --title "パピーユニバーサルインストーラ" --yesno "前に戻ってもう一枚起動ディスクを作成をしますか？ あるいはGrubを起動しますか？..." 0 0
   [ ! $? -eq 0 ] && break
  done
  umount /mnt/$DESTPART 2> /dev/null
  ;;
 atacd|scsicd|usbcd)
  gxmessage "まだ実行されていません"
  #TO DO
  ;;
esac

unmountcdfunc

###END###
