home *** CD-ROM | disk | FTP | other *** search
/ Login Magazine 68 / LoginMagazineNo68.bin / slakware / makeflop < prev    next >
Text File  |  1999-11-07  |  18KB  |  579 lines

  1. #!/bin/sh
  2. # Copyright (C) 1993 David Niemi
  3. # The author places no restrictions on the use of this script.
  4.  
  5. #
  6. # Partial port to HP/UX by Michel Eyckmans (MCE) <eyckmans@imec.be>.
  7. # Only DOS formatting capability is missing.
  8. #
  9.  
  10. # this script requires mtools (except on HP/UX). If you don't have
  11. # it, get it from prep.ai.mit.edu: /pub/gnu or other GNU repositories.
  12.  
  13. # modified by Patrick Volkerding (volkerdi@mhd1.moorhead.msus.edu)
  14. # and IBM RS6000 compatibility by Torben N. Rasmussen (tnr@csd.cri.dk)
  15.  
  16. # Extensive cleanup/functionality additions by John Plocher (plocher@sun.com)
  17. # Provides interactive prompts to make disk mastering easier
  18. # Run this script in the directory containing the directories "a" "ap" ...
  19.  
  20. # Modified for Sun compatibility by Ted Kandell (ted@cashtrade.com)
  21. # Solaris 2.4 has a bug where the filesystem capacity for the floppy isn't reset
  22. # unless the new floppy is labelled with fdformat
  23. # Volume Management (vold) has a bug where the floppy device always is busy
  24. # even if there is nothing in the drive - the solution is to kill vold
  25. # Don't run Volume Management
  26.  
  27. # Modified by Patrick Volkerding, 3/98.  In light of the fact that Slackware
  28. # has grown from 10 floppy disks (including the bootdisk!) in its original
  29. # release back in 1993 to over 100 floppies, the ability to install other
  30. # than the base A series from floppy disk has been removed.  Basically, the
  31. # move allows much more streamlined development, since packages can be changed
  32. # in size without having to shuffle things around to make it all fit on 
  33. # floppies.  Also, recently some pieces of very nice software have become
  34. # available for Linux where the main binary is so large that even compressed
  35. # it won't fit on a floppy disk.  So, a decision had to be made.  For the
  36. # forseeable future, installing the A series from floppy disk *will* be
  37. # maintained and supported.  Once you've got that up and running it's not
  38. # too hard to fit a way to get the other packages into your system for
  39. # installation.
  40.  
  41. # Edit this as needed
  42.  
  43. MTOOLS=/usr
  44.  
  45. # Global defaults
  46.  
  47. export PATH LD_LIBRARY_PATH
  48. LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/ucblib:$MTOOLS/lib
  49. PATH=$PATH:$MTOOLS/bin
  50.  
  51. format=$MTOOLS/bin/fdformat
  52. copy=$MTOOLS/bin/cp
  53. erase=$MTOOLS/bin/rm
  54. eject="eject floppy"
  55.  
  56. dollar='$'
  57.  
  58. set -e  # Exit on error
  59.  
  60. # Number of disks in each set
  61.  
  62. a=14
  63. ap=1
  64. d=1
  65. e=1
  66. f=1
  67. k=1
  68. n=9
  69. t=1
  70. tcl=1
  71. x=1
  72. xap=1
  73. xd=1
  74. xv=1
  75. y=1
  76.  
  77. # Descriptions of the packages
  78.  
  79. at="Base Linux"
  80. apt="Text based applications"
  81. dt="Program Development/GCC c|c++|obj-C kernel source and more"
  82. et="Emacs"
  83. ft="FAQs"
  84. kt="Kernel source and includes"
  85. nt="Networking/UUCP/Mail/News"
  86. tt="TeX"
  87. tclt="Tcl Script Language/Tk Toolkit"
  88. xt="XFree86 X Window System"
  89. xapt="X Applications"
  90. xdt="X11 Server Development"
  91. xvt="XView (OpenLook Window Manager)"
  92. yt="Games"
  93.  
  94. # Only the A series fits on floppy disks any more.  Have to use Zip
  95. # disks for the rest of them. :^)
  96. #PACKAGES="a ap d e f k n t tcl x xap xd xv y"
  97. PACKAGES="a n"
  98.  
  99. ##########################################################################
  100. # These routines are only used on an hp/ux host
  101. #
  102. hpuxdosformat () {
  103.   echo "*** Warning *** No format on HP/UX, trying without !"
  104.   ## The mediainit utility can do a low level format, but there
  105.   ## seems to be no way to create an MS-DOS filesystem.
  106.   return 0
  107. }
  108.  
  109. hpuxdoserase() {
  110.   # HACK: We can ignore our $* here, since we just want to remove
  111.   #       everything anyway. HP/UX dos commands don't know about
  112.   #       filename completion, so we have to do it the hard way.
  113.   files=`dosls $FD`
  114.   if [ "$files" != '' ]
  115.   then
  116.       dosrm -r $files     
  117.   fi
  118. }
  119.  
  120. hpuxdoswrite() {
  121.   for file in $*
  122.   do
  123.       if [ "$file" != "$FD" ]
  124.       then
  125.       echo Copying $file ...
  126.           doscp -f $file $FD`basename $file`
  127.       fi
  128.   done
  129.   return 0
  130. }
  131.  
  132. hpuxeject(){
  133.   echo "Please eject floppy disk now"
  134. }
  135.  
  136. #       (End of HP/UX specific routines)
  137. ##########################################################################
  138.  
  139. ##########################################################################
  140. # These routines are only used on an aix host
  141. #
  142. aixdosformat () {
  143.   Echo "Formatting..."
  144.   dosformat > /dev/null << EOI
  145.  
  146. n
  147. EOI
  148.   echo "done"
  149.   return 0
  150. }
  151.  
  152. aixdoswrite() {
  153.   for file in $*; do
  154.     if [ "$file" != "$FD" ]; then
  155.       echo Copying $file ...
  156.       doswrite $file `basename $file` > /dev/null
  157.     fi
  158.   done
  159.   return 0
  160. }
  161.  
  162. aixeject(){
  163.   echo "Please eject floppy disk now"
  164. }
  165. #       (End of AIX specific routines)
  166. ##########################################################################
  167.  
  168. # Linux specific formatting routines:
  169.  
  170. Linuxaformat() {
  171.     fdformat /dev/fd0H1440
  172.         if [ $? = 0 ]; then
  173.          mformat a:
  174.         else
  175.          return 1;
  176.         fi
  177.         return $?
  178. }
  179.  
  180. Linuxbformat() {
  181.     fdformat /dev/fd1H1440
  182.         if [ $? = 0 ]; then
  183.          mformat b:
  184.         else
  185.          return 1;
  186.         fi
  187.         return $?
  188. }
  189.  
  190. ##########################################################################
  191. #                       Common routines
  192. ##########################################################################
  193.  
  194. Echo() {
  195.         if [ "`echo -n `" != "'-n'" ]
  196.     then
  197.             echo -n $*' '
  198.     else
  199.             echo $*' '"\c"
  200.     fi
  201. }
  202.  
  203. ##########################################################################
  204.  
  205. Prompt() { # => diskno alldone duplicate eraseit
  206.         my_IMAGE="$1"
  207.         my_default="$2"
  208.         my_disk="$3"
  209.         my_diskno="$4"
  210.         my_maxdisk="$5"
  211.         my_series="$6"
  212.         my_descrip="$7"
  213.  
  214.         valid_answer="no"
  215.         my_need_help="yes"
  216.         imagename=$my_diskno
  217.  
  218.         while [ "$valid_answer" = "no" ]; do
  219.                 if [ "$my_need_help" = "yes" ]; then
  220.                     my_need_help="no"
  221.                     echo "__"
  222.                   if [ -z "$my_IMAGE" ]; then
  223.                     echo "[$my_disk] disk $my_diskno of $my_maxdisk (${my_descrip})"
  224.                   else
  225.                     echo "[$my_disk] ${my_descrip}"
  226.                   fi
  227.                     echo "  Please insert a blank floppy and press"
  228.                     echo "    [q]  to Quit this program"
  229.                     echo "    [h]  to show this Help message"
  230.                     echo "    [f]  to Format floppy and duplicate disk image"
  231.                     echo "    [d]  to Duplicate disk image"
  232.                   if [ -z "$my_IMAGE" ]; then
  233.                     echo "    [l]  to List the contents of disk \"$my_series$my_diskno\""
  234.                     echo "    [sd] to Skip this Disk \"$my_series$my_diskno\""
  235.                     echo "    [ss] to Skip the entire \"$my_series\" Series"
  236.                   else
  237.                     echo "    [l]  to List the possible disk images"
  238.                     echo "    [c]  to Choose a disk image"
  239.                     echo "    [s]  to Skip this disk image"
  240.                     echo "    Current image: $my_diskno"
  241.                   fi
  242.                 fi
  243.  
  244.                 Echo "__Choice: [$my_default]: "
  245.                 answer="invalid"
  246.                 read answer junk
  247.                 if [ -z "$answer" ]; then
  248.                         answer="$my_default"
  249.                 fi
  250.     
  251.                 case $answer in
  252.                 q*) echo "Quitting"; exit 0 ;;
  253.                 h*) my_need_help=yes;;
  254.                 c*)
  255.                     if [ -n "$my_IMAGE" ]; then
  256.                         Echo "$disk image: [$my_diskno]: "
  257.                         read imagename junk
  258.                         if [ -z "$imagename" ]; then
  259.                             imagename="$default_image"
  260.                         fi
  261.                         if [ ! -r "$imagename" ]; then
  262.                            echo "ERROR: \"$imagename\" is not readable."
  263.                         else
  264.                            my_diskno=$imagename
  265.                         fi
  266.                     fi;
  267.                     ;;
  268.                 l*)
  269.                     if [ -z "$my_IMAGE" ]; then
  270.                         ls -Fl $my_series$my_diskno/.??* $my_series$my_diskno/* | cut -c30-41,54-
  271.                     else
  272.                         ls -Fl $my_IMAGE | cut -c30-41,54-
  273.                     fi
  274.                     duplicate=no
  275.                     alldone=no
  276.                     eraseit=no
  277.                     ;;
  278.                 sd)
  279.                     if [ -z "$my_IMAGE" ]; then
  280.                         alldone=yes
  281.                         valid_answer=yes
  282.                     else
  283.                         echo "ERROR: Invalid entry.  Try again"
  284.                     fi
  285.                     ;;
  286.                 ss)
  287.                     if [ -z "$my_IMAGE" ]; then
  288.                         diskno=$my_maxdisk;
  289.                         alldone=yes
  290.                         valid_answer=yes
  291.                     else
  292.                         echo "ERROR: Invalid entry.  Try again"
  293.                     fi
  294.                     ;;
  295.                 s*)
  296.                     if [ -z "$my_IMAGE" ]; then
  297.                         Echo "Skip what? [d]=disk [s]=series: [d]: "
  298.                         answer="invalid"
  299.                         read answer junk
  300.                         if [ -z "$answer" ]; then
  301.                                 answer="d"
  302.                         fi
  303.                         case $answer in
  304.                                 d) alldone=yes;
  305.                                    valid_answer=yes;;
  306.                                 s) diskno=$maxdisk;
  307.                                    alldone=yes;
  308.                                    valid_answer=yes;;
  309.                                 *) echo "invalid entry - try again";;
  310.                         esac
  311.                     else
  312.                         alldone=yes
  313.                         valid_answer=yes
  314.                     fi
  315.                     ;;
  316.                 d*) 
  317.                     if [ -z "$forceformat" ]; then
  318.                        duplicate=yes
  319.                        eraseit=yes
  320.                        default="d"
  321.                        valid_answer=yes
  322.                        break
  323.                     else
  324.                        echo labelling $device as \"$disk\"
  325.                        label="-x -b $disk"
  326.                        if $format $label; then
  327.                              duplicate=yes
  328.                              eraseit=no
  329.                              valid_answer=yes
  330.                              break
  331.                        else
  332.                              echo "Error: labelling failed!"
  333.                              $eject
  334.                        fi
  335.                        break
  336.                     fi
  337.                     ;;
  338.                 f*) default="f"
  339.                     if [ "X$forceformat" != "X" ]; then
  340.                        label="-b $disk"
  341.                     fi
  342.                     if $format $label; then
  343.                           duplicate=yes
  344.                           eraseit=no
  345.                           valid_answer=yes
  346.                           break
  347.                     else
  348.                           echo "Error: format failed!"
  349.                           $eject
  350.                     fi
  351.                    ;;
  352.                 *)
  353.                    echo "ERROR: Invalid entry.  Try again"
  354.                    ;;
  355.                 esac
  356.         done;
  357. }
  358.  
  359. ##########################################################################
  360.  
  361. CopyImage()
  362. {
  363.     alldone=no
  364.  
  365.     echo
  366.     echo "=== $descrip ==="
  367.  
  368.     while [ "$alldone" = "no" ]; do
  369.             Prompt "$images" "f" "$disk" "$default_image" "" "" "${descrip}"
  370.             if [ "$alldone" != "no" ]; then break; fi
  371.  
  372.             if [ "$duplicate" = "yes" ]; then
  373.                 if [ -r $imagename -o -r $imagename.gz ]; then
  374.                     if [ "`basename $imagename .gz`" != "$imagename" ]; then # compressed
  375.                         gzip -cd $imagename | dd of=$device obs=18k 
  376.                         $eject
  377.                         alldone=yes
  378.                     else # uncompressed
  379.                         dd of=$device obs=18k if=$imagename 
  380.                         $eject
  381.                         alldone=yes
  382.                     fi
  383.                     break;
  384.                 else
  385.                     echo
  386.                     echo "ERROR: \"$imagename\" does not exist."
  387.                 fi
  388.             fi
  389.  
  390.     done
  391. }
  392.  
  393. ##########################################################################
  394.  
  395. CopyDisk()
  396. {
  397.     while [ "$alldone" = "no" ]; do
  398.         Prompt "" "$default" "$disk" "$diskno" "$maxdisk" "$series" "${descrip}"
  399.         if [ "$alldone" != "no" ]; then break; fi
  400.         if [ "$duplicate" = "yes" ]; then
  401.             if [ ! -d "$disk" ]; then
  402.                     echo "ERROR: Disk Image Directory \"$disk\" does not exist!"
  403.             else
  404.                     set +e
  405.                     if [ "X$mount" != "X" ]; then
  406.                        sleep 2
  407.                        echo mounting $FD
  408.                        if $mount $FD; then
  409.                           sleep 1
  410.                        else
  411.                           if [ "X$umount" != "X" ]; then
  412.                              sleep 1
  413.                              $umount $FD
  414.                           fi
  415.                           continue
  416.                        fi
  417.                     fi  
  418.                     if [ "X$eraseit" = "Xyes" ]; then
  419.                        $erase $FD/\* 2>&1 > /dev/null
  420.                     fi
  421.                     echo copying contents of disk \"$disk\" to $FD ...
  422.                     if $copy $disk/* $FD; then
  423.                             alldone=yes
  424.                             if [ "X$umount" != "X" ]; then
  425.                                sleep 2
  426.                                echo unmounting $FD
  427.                                $umount  $FD
  428.                                sleep 1
  429.                             fi  
  430.                             $eject
  431.                     else
  432.                             echo "ERROR: $copy $disk/\* $FD failed!"
  433.                             if [ "X$umount" != "X" ]; then
  434.                                sleep 2
  435.                                echo unmounting $FD
  436.                                $umount  $FD
  437.                                sleep 1
  438.                             fi
  439.                             $eject
  440.                             set -e
  441.                             continue
  442.                     fi
  443.                     set -e
  444.             fi
  445.         fi
  446.     done
  447. }
  448.  
  449. ########################################################################
  450.  
  451.  
  452.  
  453.  
  454. echo "########################################################################"
  455. echo "            Linux Slackware 3.3.0 disk mastering utility"
  456. echo "########################################################################"
  457. echo
  458. echo "This program should be run in the directory containing the"
  459. echo "Linux Slackware directories: $PACKAGES"
  460. echo
  461. echo "Which of the following is your target device:"
  462. echo
  463. echo "    1 - Sun floppy drive"
  464. echo "    2 - A: 3.5\" linux drive (/dev/fd0H1440)"
  465. echo "    3 - B: 3.5\" linux drive (/dev/fd1H1440)"
  466. echo "    4 - AIX RS6000 floppy drive"
  467. echo "    5 - HP/UX floppy drive"
  468. echo "    6 - Quit"
  469. echo
  470. if [ "`echo -n `" != "'-n'" ]
  471. then
  472.     echo -n "Enter your choice: [Q]: "
  473. else
  474.     echo "Enter your choice: [Q]: \c"
  475. fi
  476.  
  477. #read device junk
  478. read device;
  479. if [ -z "$device" ]; then
  480.         device="Q"
  481. fi
  482.  
  483. case "$device" in
  484.         1*|[sS]* )
  485.           if ps -ef | grep vold | grep -v grep >> /dev/null; then
  486.              echo Volume Management \(vold\) is running. 
  487.              echo become superuser then kill the vold process and re-run $0
  488.              exit 0
  489.           fi
  490.           FD="/floppy"
  491.           format="fdformat -Uft dos"
  492.           forceformat=yes
  493.           device=/dev/rdiskette
  494.           eject="eject floppy"
  495.           erase="rm -rf"
  496.           mount="/usr/sbin/mount -F pcfs -o rw "
  497.           umount="/usr/sbin/umount"
  498.         ;;
  499.         2*|[aA]:* )
  500.           FD="a:"
  501.           format=Linuxaformat
  502.           device=/dev/fd0H1440
  503.           eject=:
  504.         ;;
  505.         3*|[bB]:* )
  506.           FD="b:"
  507.           format=Linuxbformat
  508.           device=/dev/fd1H1440
  509.           eject=:
  510.         ;;
  511.         4*|[Aa][Ii][Xx]* )
  512.           FD="a:"
  513.           device=/dev/rfd0
  514.           format=aixdosformat
  515.           copy=aixdoswrite
  516.           eject=aixeject
  517.         ;;
  518.         5*|[Hh][Pp]* )
  519.           device=/dev/rfloppy/c201d0s0
  520.           FD=$device:
  521.           format=hpuxdosformat
  522.           copy=hpuxdoswrite
  523.       erase=hpuxdoserase
  524.           eject=hpuxeject           
  525.         ;;
  526.         [6qQ]* )
  527.           echo "Quitting"
  528.           exit 0
  529.           ;;
  530.         * )
  531.           echo "ERROR: invalid entry"
  532.           echo "Quitting"
  533.           exit 0;
  534.         ;;
  535. esac
  536.  
  537. echo "Using $FD ($device) to create floppies."
  538. echo
  539.  
  540. descrip="Slackware bootkernel disk"
  541. images="../bootdsks.*/*.gz"
  542. default_image=../bootdsks.144/pick_the_right_one.gz
  543. disk="Boot"
  544.  
  545. CopyImage
  546.  
  547. descrip="Slackware root/install disk"
  548. images="../rootdsks.*/*.gz"
  549. disk="Filesystem"
  550. default_image=../rootdsks.144/color.gz
  551.  
  552. CopyImage
  553.  
  554. default="f"
  555.  
  556. for series in $PACKAGES; do
  557.         diskno=1
  558.         maxdisk=`eval echo "$dollar$series"`
  559.         descrip=`eval echo "$dollar${series}t"`
  560.  
  561.         echo
  562.         echo "=== ${descrip} ==="
  563.         echo "Making $maxdisk floppies for series \"$series\" (${descrip})"
  564.         while [ "$diskno" -le $maxdisk ]; do
  565.                 disk=$series$diskno
  566.                 alldone=no
  567.                 duplicate=no
  568.                 if [ ! -d "$disk" ]; then
  569.                         echo "ERROR: Disk Image Directory \"$disk\" does not exist!"
  570.                         alldone="yes"
  571.                 fi
  572.                 CopyDisk
  573.         diskno=`expr $diskno + 1`
  574.         done
  575. done
  576.  
  577.