home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 August - Disc 1 / PCNET_CD_2006_08_1.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / grubconfig < prev    next >
Encoding:
Text File  |  2006-07-04  |  44.3 KB  |  1,455 lines

  1. #!/bin/sh
  2. #Badly hacked by Barry Kauler 2005,2006, for Puppy Linux, www.puppylinux.com
  3.  
  4. #BK...
  5. export XDIALOG_HIGH_DIALOG_COMPAT=true
  6. #all incidents of 'dialog' replaced by 'Xdialog' below...
  7. BKPASSED_DEVICE="$1"
  8.  
  9. #BK 1.0.6... needs C locale to work...
  10. export LANG=C
  11.  
  12. # Copyright 2004 Kent Robotti <robotti@godmail.com> 8-31-2004
  13. # All rights reserved.
  14. #
  15. # Redistribution and use of this script, with or without modification, is
  16. # permitted provided that the following conditions are met:
  17. #
  18. # 1. Redistributions of this script must retain the above copyright
  19. #    notice, this list of conditions and the following disclaimer.
  20. #
  21. #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  22. #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  24. #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27. #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  30. #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. #
  32. # grubconfig is based on liloconfig by Patrick Volkerding fron the
  33. # Slackware Linux distribution.
  34. #
  35. # Copyright 1994, 1998, 1999  Patrick Volkerding, Moorhead, Minnesota USA
  36. # Copyright 2002, 2003, 2004  Slackware Linux, Inc, Concord, CA
  37. # All rights reserved.
  38. #
  39. # Redistribution and use of this script, with or without modification, is
  40. # permitted provided that the following conditions are met:
  41. #
  42. # 1. Redistributions of this script must retain the above copyright
  43. #    notice, this list of conditions and the following disclaimer.
  44. #
  45. #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  46. #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  47. #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  48. #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  49. #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  50. #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  51. #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  52. #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  53. #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  54. #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  55. #
  56.  
  57. TMP=/tmp/grubconfig
  58. BOOT_TMP=/tmp/boot
  59. CONSOLETYPE=standard
  60. CONSOLENUM=normal
  61.  
  62. rm -rf $TMP $BOOT_TMP
  63. mkdir -p $TMP $BOOT_TMP
  64.  
  65. PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin
  66.  
  67. # Menu to check if we want to use VESA framebuffer support:
  68. use_framebuffer() {
  69. CONSOLETYPE=standard
  70. CONSOLENUM=normal
  71. if grep -q "29 fb" /proc/devices ; then
  72.   Xdialog --title "CONFIGURE GRUB TO USE FRAME BUFFER CONSOLE?" \
  73.   --menu "Looking at /proc/devices, it seems your kernel has support for \
  74. the Linux frame buffer console.  If we enable this, it \
  75. will allow more rows and columns of text on the screen and give you a cool \
  76. penguin logo at boot time.  However, the frame buffer text console is \
  77. slower than a standard text console.  In addition, not every video card \
  78. or monitor supports all of these video modes.  Would you like to use the \
  79. frame buffer console, or the standard Linux console?" 0 0 0 \
  80.   "standard" "Use the standard Linux console (the safe choice)" \
  81.   "640x480x256" "Frame buffer console, 640x480x256" \
  82.   "800x600x256" "Frame buffer console, 800x600x256" \
  83.   "1024x768x256" "Frame buffer console, 1024x768x256" \
  84.   "640x480x32k" "Frame buffer console, 640x480x32k" \
  85.   "800x600x32k" "Frame buffer console, 800x600x32k" \
  86.   "1024x768x32k" "Frame buffer console, 1024x768x32k" \
  87.   "640x480x64k" "Frame buffer console, 640x480x64k" \
  88.   "800x600x64k" "Frame buffer console, 800x600x64k" \
  89.   "1024x768x64k" "Frame buffer console, 1024x768x64k" \
  90.   2> $TMP/reply
  91.   if [ ! $? = 0 ]; then
  92.     chroot_umount
  93.     exit
  94.   fi
  95. # Frame buffer modes above 1024x768 look terrible except
  96. # on LCD panels, and 32 bit color is slow.  Since we don't
  97. # even need to run a framebuffer console to run framebuffer
  98. # X anymore, these modes aren't of much real use.
  99. #  "1280x1024x256" "Frame buffer console, 1280x1024x256" \
  100. #  "1600x1200x256" "Frame buffer console, 1600x1200x256" \
  101. #  "1280x1024x32k" "Frame buffer console, 1280x1024x32k" \
  102. #  "1600x1200x32k" "Frame buffer console, 1600x1200x32k" \
  103. #  "1280x1024x64k" "Frame buffer console, 1280x1024x64k" \
  104. #  "1600x1200x64k" "Frame buffer console, 1600x1200x64k" \
  105. #  "640x480x16m" "Frame buffer console, 640x480x16.8m" \
  106. #  "800x600x16m" "Frame buffer console, 800x600x16.8m" \
  107. #  "1024x768x16m" "Frame buffer console, 1024x768x16.8m" \
  108. #  "1280x1024x16m" "Frame buffer console, 1280x1024x16.8m" \
  109. #  "1600x1200x16m" "Frame buffer console, 1600x1200x16.8m"
  110.   CONSOLETYPE="`cat $TMP/reply`"
  111.   if [ "$CONSOLETYPE" = "standard" ]; then
  112.     CONSOLENUM=normal
  113.   elif [ "$CONSOLETYPE" = "1600x1200x16m" ]; then
  114.     CONSOLENUM=799
  115.   elif [ "$CONSOLETYPE" = "1600x1200x64k" ]; then
  116.     CONSOLENUM=798
  117.   elif [ "$CONSOLETYPE" = "1600x1200x32k" ]; then
  118.     CONSOLENUM=797
  119.   elif [ "$CONSOLETYPE" = "1600x1200x256" ]; then
  120.     CONSOLENUM=796
  121.   elif [ "$CONSOLETYPE" = "1280x1024x16m" ]; then
  122.     CONSOLENUM=795
  123.   elif [ "$CONSOLETYPE" = "1280x1024x64k" ]; then
  124.     CONSOLENUM=794
  125.   elif [ "$CONSOLETYPE" = "1280x1024x32k" ]; then
  126.     CONSOLENUM=793
  127.   elif [ "$CONSOLETYPE" = "1280x1024x256" ]; then
  128.     CONSOLENUM=775
  129.   elif [ "$CONSOLETYPE" = "1024x768x16m" ]; then
  130.     CONSOLENUM=792
  131.   elif [ "$CONSOLETYPE" = "1024x768x64k" ]; then
  132.     CONSOLENUM=791
  133.   elif [ "$CONSOLETYPE" = "1024x768x32k" ]; then
  134.     CONSOLENUM=790
  135.   elif [ "$CONSOLETYPE" = "1024x768x256" ]; then
  136.     CONSOLENUM=773
  137.   elif [ "$CONSOLETYPE" = "800x600x16m" ]; then
  138.     CONSOLENUM=789
  139.   elif [ "$CONSOLETYPE" = "800x600x64k" ]; then
  140.     CONSOLENUM=788
  141.   elif [ "$CONSOLETYPE" = "800x600x32k" ]; then
  142.     CONSOLENUM=787
  143.   elif [ "$CONSOLETYPE" = "800x600x256" ]; then
  144.     CONSOLENUM=771
  145.   elif [ "$CONSOLETYPE" = "640x480x16m" ]; then
  146.     CONSOLENUM=786
  147.   elif [ "$CONSOLETYPE" = "640x480x64k" ]; then
  148.     CONSOLENUM=785
  149.   elif [ "$CONSOLETYPE" = "640x480x32k" ]; then
  150.     CONSOLENUM=784
  151.   elif [ "$CONSOLETYPE" = "640x480x256" ]; then
  152.     CONSOLENUM=769
  153.   fi
  154. fi
  155. }
  156.  
  157. chroot_umount() {
  158. if [ "$CHROOT" = "YES" ]; then
  159.   umount /proc
  160. fi
  161. }
  162.  
  163. create_devices() {
  164.       fdisk -l >$TMP/DEV 2>$TMP/null
  165. }
  166.  
  167. hd_mbr() {
  168.  mbr_dev="`grep "^Disk /dev/" $TMP/DEV | head -n 1 | cut -d ' ' -f 2 | cut -b 1-8`"
  169.  mbr_dev2="`grep "^Disk /dev/" $TMP/DEV | tail -n 1 | cut -d ' ' -f 2 | cut -b 1-8`"
  170.  if [ -z $mbr_dev ]; then
  171.   kill $INFOPID 2>/dev/null
  172.   $DIALOG --title "Grubconfig: ERROR" --msgbox \
  173.   "I can't find a device to install GRUB to!" 0 0 #5 60
  174.   umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  175.   rm -rf $TMP
  176.   chroot_umount
  177.   exit
  178.  elif [ $mbr_dev2 = $mbr_dev ]; then
  179.   mbr_grub_dev=hd0
  180.   #BK if ! probe $mbr_dev; then
  181.   if [ "`probepart | grep "$mbr_dev"`" = "" ];then
  182.    kill $INFOPID 2>/dev/null
  183.    $DIALOG --title "Grubconfig: ERROR" --msgbox \
  184.    "I can't find the device '$mbr_dev', so I can't install GRUB!" 0 0 #5 68
  185.    umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  186.    rm -rf $TMP
  187.    chroot_umount
  188.    exit
  189.   fi
  190.  else
  191.   while :
  192.   do
  193.    cat << EOF >$TMP/tmpmsg
  194. Puppy users: If running grubconfig from Universal Installer,
  195.              leave the box empty, just click OK button.
  196.  
  197. Usually GRUB is installed to the MBR of the primary
  198. hard drive, in your case '$mbr_dev'.
  199.  
  200. If you have more than one hard drive, and want GRUB installed
  201. to the MBR of another hard drive, put the device below or
  202. leave the box blank for '$mbr_dev'.
  203. EOF
  204.  
  205.    #    $DIALOG --title "HARD DRIVE MBR" --inputbox "`cat $TMP/tmpmsg`" 0 68 2> $TMP/mbr_dev
  206.    kill $INFOPID 2>/dev/null
  207.    $DIALOG --title "Grubconfig: HARD DRIVE MBR" --inputbox "`cat $TMP/tmpmsg`" 0 0 2> $TMP/mbr_dev
  208.    if [ ! $? = 0 ]; then
  209.     umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  210.     rm -rf $TMP
  211.     chroot_umount
  212.     echo
  213.     echo "Cancelled!"
  214.     exit
  215.    fi 
  216.    MBR_DEV="`cat $TMP/mbr_dev`"
  217.    ombr_dev="$mbr_dev" #BK
  218.    if [ -n $MBR_DEV ]; then
  219.     mbr_dev="$MBR_DEV"
  220.    fi
  221.    
  222.    #BK bug above, dunno why...
  223.    [ "$mbr_dev" = "" ] && mbr_dev="$ombr_dev"
  224.       
  225.    #BK if probe $mbr_dev; then
  226.    if [ ! "`probepart | grep "$mbr_dev"`" = "" ];then
  227.     break
  228.    else
  229.     kill $INFOPID 2>/dev/null
  230.     $DIALOG --title "Grubconfgi: ERROR" --msgbox \
  231.     "I can't find the device '$mbr_dev'." 0 0 #5 45
  232.     continue
  233.    fi
  234.   done
  235.   NUM=0
  236.   grep "^Disk /dev/" $TMP/DEV | cut -d ' ' -f 2 | cut -b 1-8 | while read dev; do
  237.    echo "hd$NUM" >$TMP/mbr_grub_dev
  238.    if [ "$dev" = "$mbr_dev" ]; then
  239.     break
  240.    fi
  241.    NUM=$(( $NUM + 1 ))
  242.   done
  243.   mbr_grub_dev="`cat $TMP/mbr_grub_dev`"
  244.  fi
  245. }
  246.  
  247. initrd() {
  248. if [ "$ROOT_DEVICE" = "$1" ]; then
  249. if ls $BOOT/initrd* 1>$TMP/null 2>$TMP/null ; then
  250. initrd=`ls -1 -t $BOOT/initrd* | head -n 1`
  251. if [ ! "$3" = "no" ]; then
  252.   kill $INFOPID 2>/dev/null
  253.   $DIALOG --title "Grubconfig: INITRD FOUND" --yesno "Do you want to include \
  254. the initrd '$initrd' in the GRUB config file?" 0 0 #7 66
  255. return=$?
  256. else
  257. return=0
  258. fi
  259. if [ $return = 0 ]; then
  260.     XDIALOG_HIGH_DIALOG_COMPAT=false $DIALOG --title "Grubconfig" --no-buttons --infobox \
  261.     "Creating /boot/grub/$grub_config file on $ROOT_DEVICE.\nPlease wait..." 0 0 25000 & #3 60
  262.     INFOPID=$!
  263.      sleep 3
  264. size=`gzip -l $initrd 2>$TMP/null | grep -v uncompressed_name | awk '{print $2}'`
  265. if [ ! "$size" = "" ]; then
  266. size=$(( $size / 1024 ))
  267. else
  268. size=$(( `ls -l $initrd | awk '{print $5}'` / 1024 ))
  269. fi
  270.   KERNEL="`echo $KERNEL | awk '{print $1,$2,$3}'` ramdisk_size=$size root=/dev/ram0 rw"
  271.   cat << EOF > $2
  272. # Linux bootable initrd config begins
  273.   title Linux initrd $initrd (on $1)
  274.   root ($hd,$p2)
  275.   $KERNEL
  276.   initrd $initrd
  277. # Linux bootable initrd config ends
  278. EOF
  279. fi
  280. fi
  281. fi
  282. }
  283.  
  284. get_root_dev() {
  285. NUM=0
  286. grep "^Disk /dev/" $TMP/DEV | cut -d ' ' -f 2 | cut -b 1-8 | while read dev; do
  287. echo "hd$NUM" >$TMP/hd_grub
  288. dev2="`echo $1 | cut -b 1-8`"
  289. if [ "$dev" = "$dev2" ]; then
  290. break
  291. fi
  292. NUM=$(( $NUM + 1 ))
  293. done
  294. hd="`cat $TMP/hd_grub`"
  295. }
  296.  
  297. other() {
  298.  D=`echo "$@" | cut -d ' ' -f 1`
  299.  get_root_dev $D
  300.  
  301. if echo "$@" | grep -q HURD ; then
  302. grub --no-floppy --batch << EOF 1>$TMP/find_file 2>$TMP/null
  303. find ($hd,$p2)/boot/gnumach.gz
  304. quit
  305. EOF
  306. if grep -q "($hd,$p2)" $TMP/find_file ; then
  307. OTHER="root ($hd,$p2)
  308.   kernel /boot/gnumach.gz root=device:$hd"s"$p1
  309.   module /hurd/ext2fs.static --multiboot-command-line=\${kernel-command-line} --host-priv-port=\${host-port} --device-master-port=\${device-port} --exec-server-task=\${exec-task} -T typed \${root} \$(task-create) \$(task-resume)
  310.   module /lib/ld.so.1 /hurd/exec \$(exec-task=task-create)"
  311. echo "GNU/Hurd (on $DOSP)" > $TMP/label
  312. else
  313. OTHER="rootnoverify ($hd,$p2)
  314.   makeactive
  315.   chainloader --force +1"
  316. echo "SCO Unixware (on $DOSP)" > $TMP/label
  317. fi
  318. elif echo "$@" | grep -q BSD ; then
  319. if echo "$@" | grep -q FreeBSD ; then
  320. OTHER="root ($hd,$p2,a)
  321.   kernel /boot/loader"
  322. else  
  323. OTHER="rootnoverify ($hd,$p2)
  324.   chainloader +1"
  325. fi
  326. elif echo "$@" | grep -q QNX ; then
  327. OTHER="map (hd0) ($hd)
  328.   map ($hd) (hd0)
  329.   rootnoverify ($hd,$p2)
  330.   chainloader +4"
  331. elif echo "$@" | grep -q -E "Plan 9|BeOS|Minix" ; then
  332. OTHER="rootnoverify ($hd,$p2)
  333.   chainloader +1"
  334. elif [ ! "$hd" = "hd0" ]; then
  335. if [ "$p2" = "0" ]; then
  336. OTHER="map (hd0) ($hd)
  337.   map ($hd) (hd0)
  338.   rootnoverify ($hd,$p2)
  339.   makeactive
  340.   chainloader +1"
  341. else
  342. OTHER="map (hd0) ($hd)
  343.   map ($hd) (hd0)
  344.   map (hd0,0) ($hd,$p2)
  345.   map ($hd,$p2) (hd0,0)
  346.   rootnoverify ($hd,$p2)
  347.   makeactive
  348.   chainloader +1"
  349. fi
  350. else
  351. if [ "$p2" = "0" ]; then
  352. OTHER="rootnoverify (hd0,$p2)
  353.   makeactive
  354.   chainloader +1"
  355. else
  356. OTHER="map (hd0,0) (hd0,$p2)
  357.   map (hd0,$p2) (hd0,0)
  358.   rootnoverify (hd0,$p2)
  359.   makeactive
  360.   chainloader +1"
  361. fi
  362. fi
  363. }
  364.  
  365. # This function scans for bootable partitions (making some assumptions along
  366. # the way which may or may not be correct, but usually work), and sets up
  367. # GRUB in either the superblock, or the MBR.
  368. simplegrub()
  369. {
  370.  LOOPBRK="yes" #BK v2.02
  371.  if grep -q "OS/2 Boot Manager" $TMP/DEV 2> $TMP/null ; then
  372.   kill $INFOPID 2>/dev/null
  373.   $DIALOG --title "Grubconfig: OS/2 BOOT MANAGER FOUND" --yesno \
  374.   "Your system appears to have Boot Manager, a boot menu system provided \
  375. with OS/2 and Partition Magic.  If you like, we can install a very simple \
  376. GRUB boot block at the start of your Linux partition.  Then, you can \
  377. add the partition to the Boot Manager menu, and you'll be able to use \
  378. Boot Manager to boot Linux.  Would you like to install GRUB in a Boot \
  379. Manager compatible way?" 0 0 #11 65
  380.   if [ $? = 0 ]; then
  381.     TG=Root
  382.     skip=yes
  383.   fi
  384. fi
  385.  
  386. #while [ 1 ];do #BIGWHILELOOP BK v2.02
  387.  
  388. if [ ! "$skip" = "yes" ]; then
  389.  kill $INFOPID 2>/dev/null
  390.  $DIALOG --title "Grubconfig: SELECT GRUB DESTINATION" --menu \
  391. "Pupply Linux users: if choose floppy boot disk here, this script\n\
  392. optionally reruns and redisplays this dialog so you can then choose\n\
  393. to install GRUB to MBR (usually MBR is best hard drive choice).\n\
  394. CLARIFY: Can create boot floppy first, then install to h.d. MBR.\n\
  395. \n\
  396. GRUB can be installed to a variety of places:\n\
  397. \n\
  398.   1. The superblock of a Linux partition '$ROOT_DEVICE',\n\
  399.      (which could be made the bootable partition with DOS or\n\
  400.      Linux fdisk, or booted with a Boot Manager like OS/2 etc.)\n\
  401.   2. A formatted floppy disk.\n\
  402.   3. The Master Boot Record of a hard drive.\n\
  403. \n\
  404. Options 1 and 2 are the safest, but option 1 does require a little\n\
  405. extra work later (setting the partition bootable with fdisk).\n\
  406. Which option would you like? (Cancel button to exit script)" \
  407.  0 0 3 \
  408.  "Root" "Install to superblock of Linux partition" \
  409.  "Floppy" "Install to a floppy in /dev/fd0 (A:)" \
  410.  "MBR" "Install to Master Boot Record (possibly unsafe)" \
  411.  2> $TMP/reply
  412.  if [ ! $? = 0 ]; then
  413.    chroot_umount
  414.    exit
  415.  fi
  416.  TG="`cat $TMP/reply`"
  417. fi
  418.  
  419.  if [ "$TG" = "MBR" ]; then
  420.   hd_mbr
  421.   MBR=YES
  422.  elif [ "$TG" = "Root" ]; then
  423.   MBR=NO
  424.  elif [ "$TG" = "Floppy" ]; then
  425.   GRUB_TARGET="/dev/fd0"
  426.   MBR=NO
  427.   LOOPBRK="no"
  428.  fi
  429.  
  430.     XDIALOG_HIGH_DIALOG_COMPAT=false $DIALOG --title "Grubconfig" --no-buttons --infobox \
  431.     "Creating /boot/grub/$grub_config file on $ROOT_DEVICE.\nPlease wait..." 0 0 25000 & #3 60
  432.     INFOPID=$!
  433.      sleep 3
  434.  
  435.  # Search for Linux partitions:
  436.  grep "83  Linux" $TMP/DEV | while read PART ; do 
  437.  if [ ! "$PART" = "" ]; then
  438.   LNXP="`echo $PART | cut -f 1 -d ' '`"
  439.   p1=`echo $LNXP | cut -b9-`
  440.   p2=$(( $p1 - 1 ))
  441.  
  442.   get_root_dev $LNXP
  443.  
  444.   KERNEL="kernel /boot/vmlinuz root=$LNXP ro vga=$CONSOLENUM"
  445.  
  446.   title="Linux (on $LNXP)"
  447.  
  448.   num="`echo $LNXP | cut -b8-`" 
  449.  
  450.   cat << EOF > $TMP/part.$num.sort
  451. # Linux bootable partition config begins
  452.   title $title
  453.   root ($hd,$p2)
  454.   $KERNEL
  455. # Linux bootable partition config ends
  456. EOF
  457. initrd $LNXP $TMP/initrd.conf no
  458.  fi
  459. done
  460.  
  461.  # OK, now let's look for DOS/WIN/OS2/BSD/HURD partitions:
  462. grep "^/dev/" $TMP/DEV | grep -E "DOS|Win95|W95|FAT|BSD|NTFS|HURD|QNX|Minix|Plan|BeOS" | \
  463. grep -v "Ext'd" | grep -v "Extend" | grep -v -i "swap" | while read PART ; do
  464.   if [ ! "$PART" = "" ]; then
  465.   DOSP="`echo $PART | cut -f 1 -d ' '`"
  466.   p1=`echo $DOSP | cut -b9-`
  467.   p2=$(( $p1 - 1 ))
  468.   if echo $PART | grep -q -E "Win95|W95|NTFS" ; then
  469.   LABEL="Windows (on $DOSP)"
  470.   elif echo $PART | grep -q -E "DOS|FAT" ; then
  471.   LABEL="DOS (on $DOSP)"
  472.   elif echo $PART | grep -q "FreeBSD" ; then
  473.   LABEL="FreeBSD (on $DOSP)"
  474.   elif echo $PART | grep -q "OpenBSD" ; then
  475.   LABEL="OpenBSD (on $DOSP)"
  476.   elif echo $PART | grep -q "NetBSD" ; then
  477.   LABEL="NetBSD (on $DOSP)"
  478.   elif echo $PART | grep -q "BSD" ; then
  479.   LABEL="BSD (on $DOSP)"
  480.   elif echo $PART | grep -q "Minix" ; then
  481.   LABEL="Minix (on $DOSP)"
  482.   elif echo $PART | grep -q "QNX" ; then
  483.   LABEL="QNX (on $DOSP)"
  484.   elif echo $PART | grep -q "BeOS" ; then
  485.   LABEL="BeOS (on $DOSP)"
  486.   elif echo $PART | grep -q "Plan 9" ; then
  487.   LABEL="Plan 9 (on $DOSP)"
  488.   fi
  489.  
  490.   other $PART
  491.  
  492.   if echo $PART | grep -q "HURD" ; then
  493.   LABEL="`cat $TMP/label`"
  494.   fi
  495.  
  496.   num="`echo $DOSP | cut -b8-`" 
  497.  
  498.   cat << EOF > $TMP/part.$num.sort
  499. # Other bootable partition config begins
  500.   title $LABEL
  501.   $OTHER
  502. # Other bootable partition config ends
  503. EOF
  504. fi
  505. done
  506.  # Done, now we must install GRUB:
  507.  chmod 644 $BOOT/grub/$grub_config
  508.  message=yes
  509.  installcolor;
  510.  
  511. #  # BK v2.02...
  512. #  if [ "$LOOPBRK" = "yes" ];then
  513.    umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  514.    rm -rf $TMP
  515. #   break 
  516. #  fi
  517. # done #BIGWHILELOOP BK
  518.  #something wrong with trying to have a while loop here.
  519.  #instead, a flag to rerun grubconfig...
  520.  echo -n "$LOOPBRK" > /tmp/loopbrk.txt
  521.  
  522. } #end simplegrub func.
  523.  
  524. find_kernel() {
  525. cat << EOF > $TMP/tmpmsg
  526. `echo "   Device Boot      Start         End      Blocks   Id  System"`
  527. `grep "^$PART" $TMP/fdisk.list`
  528.  
  529. Where on the above Linux partition is the kernel you
  530. want GRUB to boot?
  531.  
  532. The default is '/boot/vmlinuz'. Just press enter for it.
  533. EOF
  534.  
  535.     kill $INFOPID 2>/dev/null
  536.     $DIALOG --title "Grubconfig: KERNEL LOCATION" --cr-wrap --inputbox "`cat $TMP/tmpmsg`" 0 0 2> $TMP/kernel
  537.     if [ $? = 1 -o $? = 255 ]; then
  538.       umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  539.       rm -rf $TMP
  540.       chroot_umount
  541.       echo
  542.       echo "Cancelled!"
  543.       exit
  544.     else
  545.       kernel="`cat $TMP/kernel`"
  546.     if [ "$kernel" = "" ]; then
  547.       KERNEL="kernel /boot/vmlinuz root=$PART ro vga=$CONSOLENUM"
  548.     else
  549.       KERNEL="kernel $kernel root=$PART ro vga=$CONSOLENUM"
  550.     fi
  551.    fi
  552.  
  553. cat << EOF > $TMP/tmpmsg
  554. `echo "   Device Boot      Start         End      Blocks   Id  System"`
  555. `grep "^$PART" $TMP/fdisk.list`
  556.  
  557. `echo $KERNEL | cut -d ' ' -f 2-`
  558.  
  559. Do you want to pass any other options to the above kernel?
  560. For example: hdd=scsi foo=boo
  561.  
  562. Put then on one line one after the other or leave box blank.
  563. EOF
  564.  
  565.     kill $INFOPID 2>/dev/null
  566.     $DIALOG --title "KERNEL OPTIONS" --cr-wrap --inputbox "`cat $TMP/tmpmsg`" 0 0 2> $TMP/reply
  567.     APPEND="`cat $TMP/reply`"
  568. }
  569.  
  570. install_grub()
  571. {
  572. NUM=0
  573. grep "^Disk /dev/" $TMP/DEV | cut -d ' ' -f 2 | cut -b 1-8 | while read dev; do
  574. echo "hd$NUM" >$TMP/root_dev
  575. dev2="`echo $ROOT_DEVICE | cut -b 1-8`"
  576. if [ "$dev" = "$dev2" ]; then
  577. break
  578. fi
  579. NUM=$(( $NUM + 1 ))
  580. done
  581. root_dev="`cat $TMP/root_dev`"
  582.  
  583.      p1=`echo $ROOT_DEVICE | cut -b 9-`
  584.      p2=$(( $p1 - 1 ))
  585.  
  586. rm -f $TMP/grub.conf
  587. for f in `ls $TMP/part.*.sort`
  588. do
  589. cat $f >> $TMP/grub.conf
  590. done
  591.  
  592. if [ -f $TMP/initrd.conf ]; then
  593.   cat $TMP/initrd.conf >> $TMP/grub.conf
  594. fi
  595.  
  596. cat << EOF >> $TMP/grub.conf
  597. title Install GRUB to floppy disk (on /dev/fd0)
  598. pause Insert a formatted floppy disk and press enter.
  599. root ($root_dev,$p2)
  600. setup (fd0)
  601. pause Press enter to continue.
  602. title Install GRUB to Linux partition (on $ROOT_DEVICE)
  603. root ($root_dev,$p2)
  604. setup ($root_dev,$p2)
  605. pause Press enter to continue.
  606. EOF
  607.  
  608. cat << EOF >> $TMP/grub.conf
  609. title -     For help press 'c', then type: 'help'
  610. root (hd0)
  611. title -     For usage examples, type: 'cat /boot/grub/usage.txt'
  612. root (hd0)
  613. EOF
  614.  
  615. cat << EOF > $BOOT/grub/usage.txt
  616. =======================================================================
  617. This is an example of how to use the GRUB edit function.
  618.  
  619. Highlight the menu entry you want to edit, then press 'e', then
  620. highlight the line you want to edit and press 'e'. Add what
  621. you want to the line 'hdd=scsi' etc. and press enter, then
  622. 'b' to boot.
  623.  
  624. Examples of the difference between Linux and GRUB device names.
  625.  
  626. Linux IDE:    GRUB IDE:    Linux SCSI:    GRUB SCSI:
  627. /dev/hda1       (hd0,0)        /dev/sda1       (hd0,0)
  628. /dev/hda2       (hd0,1)        /dev/sda2       (hd0,1)
  629. /dev/hda3       (hd0,2)        /dev/sda1       (hd0,2)
  630. /dev/hda4       (hd0,3)        /dev/sda2       (hd0,3)
  631. /dev/hdb1       (hd1,0)        /dev/sdb1       (hd1,0)
  632. /dev/hdb2       (hd1,1)        /dev/sdb2       (hd1,1)
  633. /dev/hdb3       (hd1,2)        /dev/sdb1       (hd1,2)
  634. /dev/hdb4       (hd1,3)        /dev/sdb2       (hd1,3)
  635.  
  636. These are some examples of how to use GRUB from the command prompt.
  637.  
  638. Press the 'c' key for the command prompt.
  639.  
  640. If you want to boot a Linux system on a partition, using it's kernel
  641. /boot/vmlinuz etc., do this.
  642.  
  643. grub> root (hd0,1)
  644. grub> kernel /boot/vmlinuz root=/dev/hda2 ro
  645. grub> boot
  646.  
  647. You could do this to find what partition the kernel is on.
  648. For example, show me what partitions have a /boot/vmlinuz.
  649.  
  650. grub> find /boot/vmlinuz
  651. (hd0,1)
  652. (hd0,2)
  653.  
  654. If you want to boot a Dos/Win partition, do this.
  655.  
  656. For example, boot partition on /dev/hda1.
  657.  
  658. grub> rootnoverify (hd0,0)
  659. grub> makeactive
  660. grub> chainloader +1
  661. grub> boot
  662.  
  663. If you want to boot a FreeBSD partition using /boot/loader.
  664.  
  665. For example, boot freebsd partition on /dev/hda4.
  666.  
  667. grub> root (hd0,3,a)
  668. grub> kernel /boot/loader
  669. grub> boot
  670.  
  671. If that doesn't work, try this instead.
  672.  
  673. grub> rootnoverify (hd0,3,a)
  674. grub> chainloader +1
  675. grub> boot
  676. ==============================================================
  677.  
  678. Press the [Esc] key to return to the GRUB menu.
  679. EOF
  680.  
  681. if [ "$MBR" = "NO" ]; then
  682. if [ "$GRUB_TARGET" = "/dev/fd0" ]; then
  683. rm -f $BOOT/grub/device.map
  684. grub --device-map=$BOOT/grub/device.map --batch << EOF 1>$TMP/null 2>$TMP/null
  685. root ($root_dev,$p2)
  686. setup (fd0)
  687. quit
  688. EOF
  689. SUCCESS=$?
  690. installed="installed on the floppy disk"
  691. else
  692. rm -f $BOOT/grub/device.map
  693. grub --device-map=$BOOT/grub/device.map --no-floppy --batch << EOF 1>$TMP/null 2>$TMP/null
  694. root ($root_dev,$p2)
  695. setup ($root_dev,$p2)
  696. quit
  697. EOF
  698. SUCCESS=$?
  699. installed="installed on the Linux partition $ROOT_DEVICE"
  700. fi
  701. else
  702. dd if=$mbr_dev of=$BOOT/grub/mbr.`echo $mbr_dev | cut -b 6-8`.$$ bs=512 count=1 >$TMP/null 2>&1 && \
  703. backup_mbr=$BOOT/grub/mbr.`echo $mbr_dev | cut -b 6-8`.$$
  704. rm -f $BOOT/grub/device.map
  705. grub --device-map=$BOOT/grub/device.map --no-floppy --batch << EOF 1>$TMP/null 2>$TMP/null
  706. root ($root_dev,$p2)
  707. setup ($mbr_grub_dev)
  708. quit
  709. EOF
  710. SUCCESS=$?
  711. installed="installed on the MBR of $mbr_dev"
  712. fi  
  713.  
  714.       if [ -r $BOOT/grub/$grub_config ]; then
  715.        mv $BOOT/grub/$grub_config $BOOT/grub/$grub_config.old.$$
  716.       fi
  717.  
  718. if [ ! "$backup_mbr" = "" ]; then
  719. mbr_backup=`basename $backup_mbr` 
  720.  cat << EOF > $BOOT/grub/$grub_config
  721. # GRUB configuration file '/boot/grub/$grub_config'.
  722. # generated by 'grubconfig'.  `date +%c 2>$TMP/null`
  723. #
  724. # The backup copy of the MBR for drive '$mbr_dev' is
  725. # here '/boot/grub/$mbr_backup'.  You can restore it like this.
  726. # dd if=/boot/grub/$mbr_backup of=$mbr_dev bs=512 count=1
  727. #
  728. # Start GRUB global section
  729. #timeout 30
  730. color light-gray/blue black/light-gray
  731. # End GRUB global section
  732. EOF
  733. else
  734.  cat << EOF > $BOOT/grub/$grub_config
  735. # GRUB configuration file '/boot/grub/$grub_config'.
  736. # generated by 'grubconfig'.  `date +%c 2>$TMP/null`
  737. #
  738. # Start GRUB global section
  739. #timeout 30
  740. color light-gray/blue black/light-gray
  741. # End GRUB global section
  742. EOF
  743. fi
  744. cat $TMP/grub.conf >> $BOOT/grub/$grub_config
  745. chmod 644 $BOOT/grub/$grub_config
  746. }
  747.  
  748. installcolor()
  749. {
  750. if [ "$GRUB_TARGET" = "/dev/fd0" ]; then
  751. while :
  752. do
  753.      kill $INFOPID 2>/dev/null
  754.      $DIALOG --title "Grubconfig: FLOPPY DISK" --menu \
  755. "The floppy should be formatted. \n\
  756. Put the floppy in the drive and press enter." 10 55 2 \
  757.  "Ready" "The floppy is already formatted" \
  758.  "Format" "Format the floppy first" 2> $TMP/reply
  759.       if [ ! $? = 0 ]; then
  760.         chroot_umount
  761.         exit
  762.       elif ! (dd if=/dev/fd0 of=$TMP/null bs=1 count=1 1>$TMP/null 2>$TMP/null) ; then
  763.         continue
  764.       fi
  765.       REPLY="`cat $TMP/reply`"
  766.       if [ "$REPLY" = "Format" ]; then
  767.       [ -b /dev/fd0h1440 ] && fd=/dev/fd0h1440
  768.       [ -b /dev/fd0H1440 ] && fd=/dev/fd0H1440
  769.       [ -b /dev/fd0u1440 ] && fd=/dev/fd0u1440
  770.       #BK...
  771.       #if [ -x "`type -path fdformat`" ]; then
  772.         XDIALOG_HIGH_DIALOG_COMPAT=false $DIALOG --title "Grubconfig" --no-buttons --infobox \
  773.         "Formatting floppy:\nfdformat -n $fd \nPlease wait..." 0 0 25000 & #3 35
  774.         INFOPID=$!
  775.         fdformat -n $fd || continue
  776.       #elif [ -x "`type -path superformat`" ]; then
  777.       #  $DIALOG --title "Formatting floppy..." --infobox \
  778.       #  "superformat -f $fd" 3 35
  779.       #  superformat -f $fd || continue
  780.       #else
  781.       #   $DIALOG --title "ERROR" --msgbox \
  782.       #  "Can't find 'fdformat' or 'superformat' to format floppy." 5 65
  783.       #   continue
  784.       #fi
  785.       fi
  786.         break
  787. done
  788. fi
  789.  
  790.    kill $INFOPID 2>/dev/null
  791.    XDIALOG_HIGH_DIALOG_COMPAT=false $DIALOG --title "Grubconfig" --no-buttons --infobox "Installing the GRUB Bootloader..." 0 0 25000 & #5 40
  792.    INFOPID=$!
  793.    sleep 2 
  794.  
  795.    if [ ! "$KILL" = "NO" ]; then
  796.    killall klogd 2>$TMP/null
  797.    sleep 1
  798.    klogd -c 3 2>$TMP/null
  799.    fi
  800.    
  801.    install_grub
  802.  
  803.  if [ ! "$SUCCESS" = "0" ]; then # some GRUB error occured
  804.   if [ ! "$backup_mbr" = "" -a ! "$mbr_dev" = "" ]; then
  805.   if [ -s "$backup_mbr" ]; then
  806.   if dd if=$mbr_dev bs=512 count=1 | grep -q GRUB ; then
  807.     dd if=$backup_mbr of=$mbr_dev bs=512 count=1 >$TMP/null 2>&1
  808.   fi
  809.   fi
  810.   fi
  811.   kill $INFOPID 2>/dev/null
  812.   $DIALOG --title "GRUB INSTALL ERROR # $SUCCESS" --msgbox \
  813.   "Sorry, but the attempt to install GRUB has returned an error, so GRUB \
  814.   has not been correctly installed.  You'll have to use a bootdisk \
  815.   to start your \
  816.   machine instead.  It may be possible to get GRUB working by \
  817.   editing the /boot/grub/$grub_config file and reinstalling GRUB manually. \
  818.   See the GRUB man page and info documentation in /usr/info for more help." 11 60
  819.  else
  820.   if [ "$message" = "yes" ]; then
  821. cat << EOF >$TMP/tmpmsg
  822.  
  823. GRUB was successfully $installed.
  824.  
  825. You should check and edit the '/boot/grub/$grub_config'
  826. file on '$ROOT_DEVICE', if needed. You may want to change
  827. the location '/boot/vmlinuz', and/or options passed to any
  828. Linux kernel listed there.
  829.  
  830. EOF
  831.    kill $INFOPID 2>/dev/null
  832.    $DIALOG --title "GRUB INSTALL SUCCESS" --msgbox "`cat $TMP/tmpmsg`" 0 0 #12 70
  833.   else
  834.    kill $INFOPID 2>/dev/null
  835.    $DIALOG --title "GRUB INSTALL SUCCESS" --msgbox \
  836.    "GRUB was successfully $installed." 0 0 #5 70
  837.   fi
  838.  fi
  839. }
  840.  
  841. #BK not using this, had trouble with it...
  842. ## 'probe()' borrowed from GRUB QuickInst.
  843. #probe()
  844. #{
  845. # [ ! -z "`dd if=$1 bs=1 count=1 2>$TMP/null | tr '\0' x`" ]
  846. # return
  847. #}
  848.  
  849.    #BK...
  850.    DIALOG="`which Xdialog`"
  851.    #DIALOG=`type -path dialog`
  852.    #if [ ! -x "$DIALOG" ]; then
  853.    #  echo "This script requires the 'dialog' program to run."
  854.    #  chroot_umount
  855.    #  exit 1
  856.    #fi
  857.  
  858.  if [ ! `whoami` = "root" ]; then
  859.      $DIALOG --title "NOT ROOT" --msgbox \
  860.      "You need to be 'root' to run this script." 0 0 #5 50
  861.      chroot_umount
  862.      exit
  863.  fi
  864.  
  865.  #BK...
  866.  if [ ! -x "`which grub`" ]; then
  867.  #if [ ! -x "`type -path grub`" ]; then
  868.      $DIALOG --title "CAN'T FIND GRUB" --msgbox \
  869.      "I can't find 'grub' on the system." 0 0 #5 40
  870.      chroot_umount
  871.      exit
  872.  fi
  873.  
  874.  BOOT=/boot
  875.  #BK...
  876.  if grep -q $BOOT/grub/grub.conf 2>$TMP/null `which grub` ; then
  877.  #if grep -q $BOOT/grub/grub.conf 2>$TMP/null `type -path grub` ; then
  878.    grub_config=grub.conf
  879.  else
  880.    grub_config=menu.lst
  881.  fi
  882.  
  883. root_device() {
  884. # Determine the root partition (such as /dev/hda2)
  885.     ROOT_DEVICE="`mount 2>$TMP/null | grep " on / " | awk '{print $1}'`"
  886.  
  887.   if [ -z "$ROOT_DEVICE" -a -s /etc/fstab ]; then
  888.     ROOT_DEVICE="`grep -v "^#" /etc/fstab 2>$TMP/null | grep " / " | awk '{print $1}'`"
  889.   fi
  890.   
  891.   if [ -n "$ROOT_DEVICE" ]; then
  892.   if echo $ROOT_DEVICE | grep -q -E "/dev/ram|/dev/root|tmpfs|rootfs|/dev/loop"; then
  893.     unset ROOT_DEVICE
  894.   fi
  895.   fi
  896.  
  897.   #BK quick hack for puppy2...
  898.   [ "$ROOT_DEVICE" = "none" ] && ROOT_DEVICE=""
  899.   
  900.     if [ -n "$ROOT_DEVICE" ]; then
  901. cat << EOF > $TMP/tmpmsg
  902. Where do you want the GRUB files to go?
  903.  
  904. The default is to put them in /boot/grub on the current
  905. partition '$ROOT_DEVICE'.  To accept this default, leave
  906. the line below unchanged and hit ENTER (this should be
  907. fine for most users).  If (for some reason) you want to
  908. use a different partition, change it on the line below
  909. and hit ENTER.
  910. EOF
  911. else
  912. cat << EOF > $TMP/tmpmsg
  913. Puppy Linux users: If running from the Universal Installer,\n
  914.                    just accept default entry, click OK button.\n
  915. \n
  916. Where do you want the GRUB files to go?\n
  917. \n
  918. Usually they are put with the kernel in the /boot directory.\n
  919. What partition has the /boot directory you want to use?\n
  920. Put the partition (/dev/hda2 etc.) in the box below:
  921. EOF
  922.     fi
  923.  
  924. while :
  925. do
  926.  if [ "$ROOT_DEVICE" ];then #BK initialise text box...
  927.   BKINITIAL_DEVICE="$ROOT_DEVICE"
  928.  else
  929.   BKINITIAL_DEVICE="$BKPASSED_DEVICE"
  930.  fi
  931.  
  932. #BK    $DIALOG --title "SELECT GRUB PARTITION" --inputbox "`cat $TMP/tmpmsg`" 0 0 "$ROOT_DEVICE" 2> $TMP/root_device
  933.     kill $INFOPID 2>/dev/null
  934.     $DIALOG --title "Grubconfig: SELECT GRUB PARTITION" --no-collapse --inputbox "`cat $TMP/tmpmsg`" 0 0 "$BKINITIAL_DEVICE" 2> $TMP/root_device
  935.     if [ ! $? = 0 ]; then
  936.       umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  937.       rm -rf $TMP
  938.       chroot_umount
  939.       exit
  940.     fi    
  941.       ROOT_DEV=`cat $TMP/root_device`
  942.  
  943.      if [ "$ROOT_DEVICE" = "" -a "$ROOT_DEV" = "" ]; then
  944.        continue
  945.      fi
  946.  
  947.      if [ "$ROOT_DEVICE" = "$ROOT_DEV" ]; then
  948.        break
  949.      fi
  950.     
  951.        if [ ! "$ROOT_DEV" = "" ]; then
  952.          ROOT_DEVICE=`cat $TMP/root_device`
  953.        fi
  954.     
  955.         if ! grep "^$ROOT_DEVICE" $TMP/DEV | grep -q "83  Linux" ; then
  956.          kill $INFOPID 2>/dev/null
  957.          $DIALOG --title "Grubconfig: ERROR" --msgbox \
  958.           "The partition '$ROOT_DEVICE' is not Linux." 0 0 #5 55
  959.       continue
  960.         fi
  961.        
  962.        if mount 2>$TMP/null | grep -q "^$ROOT_DEVICE" 2>$TMP/null ; then
  963.            BOOT="`mount 2>$TMP/null | grep $ROOT_DEVICE | cut -d ' ' -f 3`/boot"
  964.          if echo "fooboo" > $BOOT/fooboo 2>$TMP/null ; then
  965.            rm -f $BOOT/fooboo
  966.          else
  967.           kill $INFOPID 2>/dev/null
  968.            $DIALOG --title "Grubconfig: ERROR" --msgbox \
  969.            "The partition '$ROOT_DEVICE' is mounted read-only, \
  970.            either unmount it or mount it read-write." 0 0 #6 55
  971.            rm -rf $TMP
  972.            chroot_umount
  973.        exit
  974.      fi
  975.            break
  976.        else
  977.        umount $BOOT_TMP 2>$TMP/null
  978.        mkdir -p $BOOT_TMP
  979.        mount -o rw $ROOT_DEVICE $BOOT_TMP 1>$TMP/null 2>$TMP/error
  980.        if [ ! $? = 0 ]; then
  981.        echo "" >> $TMP/error
  982.        echo "I couldn't mount '$ROOT_DEVICE' read-write!" >> $TMP/error
  983.        kill $INFOPID 2>/dev/null
  984.        $DIALOG --title "Grubconfig: MOUNT ERROR" --textbox "$TMP/error" 0 0
  985.        umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  986.        rm -rf $TMP
  987.        chroot_umount
  988.        exit
  989.        fi
  990.        BOOT=$BOOT_TMP/boot
  991.        break
  992.        fi
  993.  done
  994.  
  995.     XDIALOG_HIGH_DIALOG_COMPAT=false $DIALOG --title "Grubconfig" --no-buttons --infobox "Working, please wait..." 0 0 25000 & #3 20
  996.     INFOPID=$!
  997.     sleep 1
  998.     
  999.  fs=`mount | grep "^$ROOT_DEVICE" | awk '{print $5}'`
  1000.  [ "$fs" = "ext2" -o "$fs" = "ext3" ] && fs=e2fs
  1001.  [ "$fs" = "msdos" ] && fs=fat
  1002.  [ "$fs" = "vfat" ] && fs=fat
  1003.  
  1004.  if [ -d /usr/share/grub -o -d /usr/lib/grub -o -d /usr/local/share/grub ]; then
  1005.  mkdir -p $BOOT/grub
  1006.  if [ -d /usr/share/grub ]; then
  1007.  cp-FULL -p /usr/share/grub/*/*stage* $BOOT/grub 2>$TMP/null
  1008.  elif [ -d /usr/local/share/grub ]; then
  1009.  cp-FULL -p /usr/local/share/grub/*/*stage* $BOOT/grub 2>$TMP/null
  1010.  elif [ -d /usr/lib/grub ]; then
  1011.  cp-FULL -p /usr/lib/grub/*/*stage* $BOOT/grub 2>$TMP/null
  1012.  fi
  1013.  
  1014.  for f in stage1 stage2 $fs"_stage1_5"
  1015.  do
  1016.  if [ ! -f $BOOT/grub/$f ]; then
  1017.  echo "ERROR: Can't find '$f' from the grub package."
  1018.  echo "If you have the grub package installed, you should have a"
  1019.  echo "/usr/lib/grub, /usr/share/grub, or /usr/local/share/grub"
  1020.  echo "directory, containing the stage files."
  1021.  chroot_umount
  1022.  exit 1
  1023.  fi 
  1024.  done
  1025.  else
  1026.  echo "ERROR: Can't find stage files from the grub package."
  1027.  echo "If you have the grub package installed, you should have a"
  1028.  echo "/usr/lib/grub, /usr/share/grub, or /usr/local/share/grub"
  1029.  echo "directory, containing the stage files."
  1030.  chroot_umount
  1031.  exit 1
  1032.  fi
  1033. }
  1034.  
  1035. HDR="no" # this means the header section of /boot/grub/menu.lst has not yet
  1036.          # been configured
  1037. LNX="no" # this means no Linux partition has been defined as bootable
  1038.          # through GRUB. Both of these must change to "yes" before GRUB will
  1039.          # install from this script.
  1040.  
  1041.  # OK, now let's see if we should automate things:
  1042.  $DIALOG --title "GRUBCONFIG Kent Robotti (modified for Puppy Linux)" --no-collapse --menu \
  1043.  "Puppy Linux users: if running this from the Universal Installer,\n\
  1044.                     please choose 'simple' option!\n\
  1045.  \n\
  1046.  GRUB is a generic bootloader.  There's a simple installation which tries\n\
  1047.  to automatically set up GRUB to boot Linux (also DOS, Windows, BSD, HURD,\n\
  1048.  QNX, PLAN9, BEOS, Minix, and OS/2 if found).  For more advanced users,\n\
  1049.  the expert option offers more control over the installation process." 0 0 3 \
  1050.  "simple" "Try to install GRUB automatically" \
  1051.  "expert" "Use expert GRUB setup menu" 2> $TMP/reply
  1052.  if [ ! $? = 0 ]; then
  1053.   rm -rf $TMP
  1054.   chroot_umount
  1055.   echo
  1056.   exit
  1057.  fi
  1058.  
  1059.   REPLY="`cat $TMP/reply`"
  1060.  
  1061.   if [ ! -f /proc/partitions ]; then
  1062.     CHROOT=YES
  1063.     mkdir -p /proc
  1064.     mount -t proc proc /proc
  1065.   fi
  1066.  
  1067.  if [ "$REPLY" = "simple" ]; then
  1068.   # Do simple GRUB setup
  1069.    use_framebuffer
  1070.    XDIALOG_HIGH_DIALOG_COMPAT=false $DIALOG --title "Grubconfig" --no-buttons --infobox "Working, please wait..." 0 0 25000 & #BK 3 20
  1071.    INFOPID=$!
  1072.    sleep 1
  1073.    create_devices
  1074.    root_device
  1075.    killall klogd 2>$TMP/null
  1076.    sleep 1
  1077.    klogd -c 3 2>$TMP/null
  1078.    KILL=NO
  1079.    simplegrub
  1080.    umount $BOOT_TMP 2>$TMP/null
  1081.    rm -rf $TMP $BOOT_TMP
  1082.    chroot_umount
  1083.    exit
  1084.  fi
  1085.  # drop through to last option: (use the expert menus)
  1086.  while [ 0 ]; do
  1087.   $DIALOG --title "EXPERT GRUB INSTALLATION" --menu \
  1088. "This menu directs the creation of the GRUB config file. \
  1089. To install, you make a new GRUB configuration file by creating a new header \
  1090. and then adding one or more bootable partitions to the file. Once you've done \
  1091. this, you can select the install option. If you make \
  1092. a mistake, you can always start over by choosing 'Begin'. \
  1093. Which option would you like?" 18 76 7 \
  1094. "Begin" "Start GRUB configuration with a new GRUB header" \
  1095. "Linux" "Add Linux partition to GRUB config file" \
  1096. "Other" "Add DOS/WIN/BSD/OS2/HURD partition to GRUB config file" \
  1097. "Install" "Install GRUB" \
  1098. "Skip" "Skip GRUB installation or exit this menu" \
  1099. "View" "View your current /boot/grub/$grub_config" \
  1100. "Help" "Read the GRUB Bootloader HELP file" 2> $TMP/reply
  1101.   if [ ! $? = 0 ]; then
  1102.    REPLY="Skip"
  1103.   else
  1104.    REPLY="`cat $TMP/reply`"
  1105.   fi
  1106.   if [ "$REPLY" = "Begin" ]; then
  1107.     use_framebuffer
  1108.  
  1109.     XDIALOG_HIGH_DIALOG_COMPAT=false $DIALOG --title "Grubconfig" --no-buttons --infobox "Working, please wait..." 0 0 25000 & #3 20
  1110.     INFOPID=$!
  1111.     sleep 1
  1112.  
  1113.     create_devices
  1114.  
  1115.    kill $INFOPID 2>/dev/null
  1116.    $DIALOG --title "SELECT GRUB TARGET LOCATION" --menu "GRUB can be installed \
  1117. to a variety of places: the master boot record of a hard drive, \
  1118. the superblock of a Linux partition (which could be made \
  1119. active with fdisk, or booted with a boot manager), or a formatted floppy disk, \
  1120. If you're using a boot system such as OS/2's Boot Manager, you should use \
  1121. the "Root" selection. Please pick a target location:" 15 68 3 \
  1122. "Root" "Use superblock of Linux partition" \
  1123. "Floppy" "Use a formatted floppy disk in the boot drive" \
  1124. "MBR" "Use the Master Boot Record (possibly unsafe)" \
  1125. 2> $TMP/reply
  1126.    if [ $? = 1 -o $? = 255 ]; then
  1127.     HDR="no"
  1128.     continue;
  1129.    else
  1130.     LNX="no"
  1131.     TG="`cat $TMP/reply`"
  1132.    fi
  1133.    if [ "$TG" = "MBR" ]; then
  1134.     hd_mbr
  1135.     MBR=YES
  1136.    elif [ "$TG" = "Root" ]; then
  1137.     MBR=NO
  1138.    elif [ "$TG" = "Floppy" ]; then
  1139.     GRUB_TARGET="/dev/fd0"    
  1140.     MBR=NO
  1141.    else
  1142.     HDR="no"
  1143.     continue;
  1144.    fi
  1145.     HDR="yes"
  1146.     root_device
  1147.   elif [ "$REPLY" = "Linux" ]; then
  1148.    if [ "$HDR" = "yes" ]; then
  1149. echo "Press the [Space] key to untag any you don't want to include." > $TMP/tmpmsg1
  1150. echo "Device Boot Start End Blocks Id System" >> $TMP/tmpmsg1
  1151. grep "^/dev/" $TMP/DEV | grep "83  Linux" | grep -v "Ext'd" | grep -v "Extend" > $TMP/tmpmsg2
  1152.  
  1153. if [ -s $TMP/tmpmsg2 ]; then
  1154. echo '$DIALOG --title "POSSIBLE LINUX PARTITIONS" --cr-wrap --checklist "`cat $TMP/tmpmsg1`" 0 0 0 \' > $TMP/tmpmsg3
  1155. cat $TMP/tmpmsg2 | sed "/^$/d" | while read device ; do
  1156. device_name="`echo "$device" | awk '{print $1}'`"
  1157. device_info="`echo "$device" | awk '{print $2,$3,$4,$5,$6,$7}'`"
  1158. echo "$device_name" | sed "/^$/d" | sed -e 's/.*/"&" '"'$device_info'"' on \\/' >> $TMP/tmpmsg3
  1159. done
  1160. echo "2> $TMP/parts" >> $TMP/tmpmsg3
  1161.  
  1162.     . $TMP/tmpmsg3
  1163.     if [ $? = 1 -o $? = 255 ]; then
  1164.      rm -f $TMP/tmpmsg*
  1165.      continue
  1166.     else
  1167.      cat $TMP/tmpmsg2 > $TMP/fdisk.list
  1168.      rm -f $TMP/tmpmsg*
  1169.     fi
  1170. else
  1171.       $DIALOG --title "Grubconfig" --msgbox \
  1172.      "No Linux partitions found!" 0 0 #5 35
  1173.       continue
  1174. fi
  1175.     
  1176.     if [ -s $TMP/parts ]; then
  1177.       cat $TMP/parts | sed "s/\"//g" | sed "/^$/d" > $TMP/parts.a
  1178.     else
  1179.       $DIALOG --title "Grubconfig" --msgbox \
  1180.      "No Linux partitions chosen!" 0 0 #5 35
  1181.       continue
  1182.     fi
  1183.         
  1184.     for PART in `cat $TMP/parts.a` ; do
  1185.  
  1186. cat << EOF > $TMP/tmpmsg
  1187. `echo "   Device Boot      Start         End      Blocks   Id  System"`
  1188. `grep "^$PART" $TMP/fdisk.list`
  1189.  
  1190. Now you must select a name for the above partition.
  1191. You'll use this name to specify a partition to boot from
  1192. the GRUB menu.  Something like 'Slackware Linux' might
  1193. not be a bad choice.
  1194.  
  1195. The default is 'Linux (on $PART)'.  Just press ENTER for it.
  1196. (the menu will add '(on $PART)' for you automatically)
  1197. EOF
  1198.     kill $INFOPID 2>/dev/null
  1199.     $DIALOG --title "Grubconfig: SELECT PARTITION NAME" --cr-wrap --inputbox "`cat $TMP/tmpmsg`" 0 0 2> $TMP/reply
  1200.     if [ ! $? = 0 ]; then
  1201.      break;
  1202.     fi
  1203.      LABEL="`cat $TMP/reply`"
  1204.     if [ "$LABEL" = "" ]; then
  1205.      LABEL="Linux"
  1206.     fi    
  1207.     
  1208.   p1=`echo $PART | cut -b 9-`
  1209.   p2=$(( $p1 - 1 ))
  1210.  
  1211.   find_kernel
  1212.   get_root_dev $PART
  1213.  
  1214.   num="`echo $PART | cut -b8-`" 
  1215.  
  1216.   cat << EOF > $TMP/part.$num.sort
  1217. # Linux bootable partition config begins
  1218.   title $LABEL (on $PART)
  1219.   root ($hd,$p2)
  1220.   $KERNEL $APPEND
  1221. # Linux bootable partition config ends
  1222. EOF
  1223. initrd $PART $TMP/initrd.conf
  1224. done
  1225.    else
  1226.     kill $INFOPID 2>/dev/null
  1227.     $DIALOG --title "Grubconfig: CAN'T ADD LINUX PARTITION" --msgbox "You can't add \
  1228. partitions unless you start over with a new GRUB header." 0 0 #6 60
  1229.     continue
  1230.    fi
  1231.    LNX="yes"
  1232.   elif [ "$REPLY" = "Other" ]; then
  1233.    if [ "$HDR" = "yes" ]; then
  1234.    rm -f $TMP/parts
  1235. echo "Press the [Space] key to untag any you don't want to include." > $TMP/tmpmsg1
  1236. echo "Device Boot Start End Blocks Id System" >> $TMP/tmpmsg1
  1237. grep "^/dev/" $TMP/DEV | grep -E "DOS|Win95|W95|FAT|NTFS|BSD|HURD|QNX|BeOS|Minix|Plan" | \
  1238. grep -v "Ext'd" | grep -v "Extend" | grep -v -i "swap" > $TMP/tmpmsg2
  1239.  
  1240. if [ -s $TMP/tmpmsg2 ]; then
  1241. echo '$DIALOG --title "POSSIBLE DOS/WIN/OS2/BSD etc. PARTITIONS" --cr-wrap --checklist "`cat $TMP/tmpmsg1`" 0 0 0 \' > $TMP/tmpmsg3
  1242. cat $TMP/tmpmsg2 | sed "/^$/d" | while read device ; do
  1243. device_name="`echo "$device" | awk '{print $1}'`"
  1244. device_info="`echo "$device" | awk '{print $2,$3,$4,$5,$6,$7}'`"
  1245. echo "$device_name" | sed "/^$/d" | sed -e 's/.*/"&" '"'$device_info'"' on \\/' >> $TMP/tmpmsg3
  1246. done
  1247. echo "2> $TMP/parts" >> $TMP/tmpmsg3
  1248.  
  1249.     . $TMP/tmpmsg3
  1250.     if [ ! $? = 0 ]; then
  1251.      rm -f $TMP/tmpmsg*
  1252.      continue
  1253.     else
  1254.      cat $TMP/tmpmsg2 > $TMP/fdisk.list
  1255.     fi
  1256. fi
  1257.  
  1258.     if [ ! -s $TMP/tmpmsg2 ]; then
  1259.       $DIALOG --title "Grubconfig" --msgbox \
  1260.      "No Other partitions found!" 0 0 #5 35
  1261.       rm -f $TMP/tmpmsg*
  1262.       continue
  1263.     elif [ -s $TMP/parts ]; then
  1264.       cat $TMP/parts | sed "s/\"//g" | sed "/^$/d" > $TMP/parts.a
  1265.     else
  1266.       $DIALOG --title "Grubconfig" --msgbox \
  1267.      "No Other partitions chosen!" 0 0 #5 35
  1268.       rm -f $TMP/tmpmsg*
  1269.       continue
  1270.     fi
  1271.       rm -f $TMP/tmpmsg*
  1272.     
  1273.     for PART in `cat $TMP/parts.a` ; do
  1274. cat << EOF > $TMP/tmpmsg
  1275. `echo "   Device Boot      Start         End      Blocks   Id  System"`
  1276. `grep "^$PART" $TMP/fdisk.list`
  1277.  
  1278. Now you must select a name for the above partition.
  1279. You'll use this name to specify a partition to boot from
  1280. the GRUB menu. 'DOS, Win2k, WinXP, FreeBSD, GNU/Hurd,
  1281. etc.' might not be a bad choice.
  1282. EOF
  1283.  
  1284.     kill $INFOPID 2>/dev/null
  1285.     $DIALOG --title "Grubconfig: SELECT PARTITION NAME" --cr-wrap --inputbox "`cat $TMP/tmpmsg`" 0 0 2> $TMP/reply
  1286.     if [ ! $? = 0 ]; then
  1287.      break;
  1288.     fi
  1289.      LABEL="`cat $TMP/reply`"
  1290.     if [ "$LABEL" = "" ]; then
  1291.      LABEL=Unknown
  1292.     fi    
  1293.     p1=`echo $PART | cut -b 9-`
  1294.     p2=$(( $p1 - 1 ))
  1295.  
  1296.     part=`grep "^$PART" $TMP/fdisk.list`
  1297.  
  1298.     other $part
  1299.  
  1300.     num="`echo $PART | cut -b8-`" 
  1301.  
  1302.   cat << EOF > $TMP/part.$num.sort
  1303. # Other bootable partition config begins
  1304.   title $LABEL (on $PART)
  1305.   $OTHER
  1306. # Other bootable partition config ends
  1307. EOF
  1308. done
  1309.    else
  1310.     kill $INFOPID 2>/dev/null
  1311.     $DIALOG --title "Grubconfig: CAN'T ADD OTHER PARTITION" --msgbox "You can't add \
  1312. partitions unless you start over with a new GRUB header." 0 0 #6 60
  1313.     continue
  1314.    fi
  1315.   elif [ "$REPLY" = "Install" ]; then
  1316.    if [ "$LNX" = "no" ]; then
  1317.     kill $INFOPID 2>/dev/null
  1318.     $DIALOG --title "Grubconfig: CAN'T INSTALL GRUB" --msgbox "GRUB could not be \
  1319. installed. If you have not created a GRUB configuration file by defining \
  1320. a new header and adding at least one Linux bootable partition to it, you \
  1321. must do so before installing GRUB." 8 70
  1322.     continue
  1323.    else
  1324.        installcolor;
  1325.        umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  1326.        rm -rf $TMP
  1327.    fi
  1328.    rm -f $TMP/tmpmsg
  1329.    break
  1330.   elif [ "$REPLY" = "Skip" ]; then
  1331.    umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  1332.    rm -rf $TMP
  1333.    chroot_umount
  1334.    break
  1335.   elif [ "$REPLY" = "View" ]; then
  1336.   
  1337.   rm -f $TMP/view.conf
  1338.   if ls $TMP/part.*.sort 2>$TMP/null ; then
  1339.   for f in `ls $TMP/part.*.sort`
  1340.   do
  1341.     cat $f >> $TMP/view.conf
  1342.   done
  1343.   fi
  1344.   
  1345.   if [ -f $TMP/initrd.conf ]; then
  1346.     cat $TMP/initrd.conf >> $TMP/view.conf
  1347.     rm -f $TMP/initrd.conf
  1348.   fi
  1349.    
  1350.    if [ -r $TMP/view.conf ]; then
  1351.     kill $INFOPID 2>/dev/null
  1352.     $DIALOG --title "YOUR NEW /boot/grub/$grub_config" --textbox "$TMP/view.conf" 22 70
  1353.    else
  1354.     if [ -r $BOOT/grub/$grub_config ]; then
  1355.      kill $INFOPID 2>/dev/null
  1356.      $DIALOG --title "YOUR CURRENT /boot/grub/$grub_config" --textbox "$BOOT/grub/$grub_config" 22 70
  1357.     else
  1358.      kill $INFOPID 2>/dev/null
  1359.      $DIALOG --title "NO CONFIG FILE FOUND" --msgbox "Sorry, but you don't \
  1360. have a GRUB configuration file that can be viewed." 0 0 #6 60
  1361.     fi
  1362.    fi
  1363.   elif [ "$REPLY" = "Help" ]; then
  1364. cat << EOF > $TMP/tmpmsg
  1365.  
  1366. This script 'grubconfig' helps you install the GRUB bootloader
  1367. on your Linux system.
  1368.  
  1369. It supports IDE and SCSI devices, it has no support for RAID devices.
  1370.  
  1371. These are the options you can use at the GRUB expert install menu:
  1372.  
  1373. 1. Start GRUB configuration with a new GRUB header.
  1374.  
  1375.    This is the first step to start a new configuration file,
  1376.    /boot/grub/$grub_config, with no OS's entered into it (yet).
  1377.  
  1378.    You'll be asked where you want to install GRUB. This
  1379.    can be to your Master Boot Record, a Linux partition's
  1380.    superblock (for OS/2's Boot Manager etc. to boot), or
  1381.    to a 1.44MB formatted floppy disk. 
  1382.    
  1383.    Try installing to a floppy disk first, if it works
  1384.    on the floppy it will probably work on the MBR or
  1385.    superblock.
  1386.    
  1387.    Once you've started a new /boot/grub/$grub_config file, you must
  1388.    add at least one OS to it before you can install GRUB.
  1389.  
  1390.    Next you'll want to add at least one Linux partition, the
  1391.    one that will hold the GRUB files in /boot/grub.
  1392.  
  1393.    You then may want to add other partitions if you have any.
  1394.    
  1395. 2. Menu choices to add Linux and other DOS/WIN/BSD/OS2/HURD/QNX/
  1396.    PLAN9/BEOS/Minix partitions to the /boot/grub/$grub_config
  1397.    file.
  1398.  
  1399.    These all pretty much work the same way. You'll be asked 
  1400.    which partitions you want to include in the grub menu, and 
  1401.    you'll also be asked to assign a label to each partition.
  1402.    The label can be any name such as "Slackware Linux" or
  1403.    "WinXP" etc.
  1404.  
  1405. 3. Install GRUB
  1406.    
  1407.    Once you've looked at your new config file and are 
  1408.    satisfied with the way it looks, pick this option to 
  1409.    install GRUB and exit the GRUB installation menu.
  1410.  
  1411. Other options:
  1412.  
  1413.   -- View your current /boot/grub/$grub_config file
  1414.  
  1415.    If you haven't begun building a new $grub_config file, this choice
  1416.    will let you take a look at the existing one in /boot/grub
  1417.    on your GRUB Linux partition. 
  1418.  
  1419.    If you have begun constructing a new $grub_config file, this
  1420.    option will let you view the progress on that.
  1421.  
  1422.  -- Skip GRUB installation or exit this menu
  1423.  
  1424.   This option skips GRUB installation. Use this if you don't 
  1425.   want to install GRUB, or if you've already installed it and 
  1426.   want to exit.
  1427.  
  1428.  -- Help - Read this GRUB Bootloader HELP file 
  1429.  
  1430. -----------
  1431.  
  1432. Other GRUB information:
  1433.  
  1434.   GRUB on the Master Boot Record can be removed easily. 
  1435.   DOS/Win9x fdisk has a 'C:\ fdisk /mbr' option that restores the
  1436.   original master boot record. You can also restore your original boot
  1437.   sector from the copy 'grubconfig' makes in /boot/grub/mbr.device.number.
  1438.   
  1439.   This is probably the best way to go about it.
  1440.   # dd if=/boot/grub/mbr.device.number of=/dev/device bs=512 count=1
  1441.   
  1442.   If you want to make any changes you don't need to run grubconfig
  1443.   again, you can just edit /boot/grub/$grub_config by hand.
  1444.   
  1445. --- end of GRUB help
  1446.  
  1447. grubconfig is based on liloconfig by Patrick Volkerding fron the
  1448. Slackware Linux distribution.
  1449. EOF
  1450.    $DIALOG --title "GRUB INSTALLATION HELP" --textbox "$TMP/tmpmsg" 22 74
  1451.   fi
  1452.  done
  1453.  
  1454. ###the end###
  1455.