home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / floppy-format.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2004-03-27  |  3.7 KB  |  160 lines

  1. #!/bin/sh
  2. #Format floppy disks
  3. #Copyright (c) Barry Kauler 2004 www.goosee.com/puppy
  4.  
  5. zapfloppy()
  6. {
  7. # Puppy will only allow 1440, 1680K and 1760K capacities.
  8. ERR0=1
  9. while [ ! $ERR0 -eq 0 ];do
  10. xmessage -bg "#c0ffff" -center -title "Please wait..." -buttons "" "Low-level formatting disk with $1 Kbyte capacity" &
  11.  fdformat /dev/fd0u$1
  12.  ERR0=$?
  13.  killall xmessage
  14.  if [ ! $ERR0 -eq 0 ];then
  15.   xmessage -bg "#ffe0e0" -name "loformat" -title "Puppy Lo-level Formatter" -center \
  16.   -buttons "Try again":20,"QUIT":10 -file -<<XMSG
  17. ERROR low-level formatting disk.
  18. Is the write-protect tab closed?
  19. XMSG
  20.  
  21.   AN0=$?
  22.   if [ $AN0 -eq 10 ];then
  23.    ERR0=0
  24.   fi
  25.   if [ $AN0 -eq 0 ];then
  26.    ERR0=0
  27.   fi
  28.   if [ $AN0 -eq 1 ];then
  29.    ERR0=0
  30.   fi
  31.  else
  32.   INTROMSG="`
  33. echo "SUCCESS!"
  34. echo -e "Now you should press the \"Msdos/vfat filesystem\" button."
  35. `"
  36.  fi
  37. done
  38. }
  39.  
  40. fsfloppy()
  41. {
  42. echo "Creating msdos filesystem on the disk..."
  43. ERR1=1
  44. while [ ! $ERR1 -eq 0 ];do
  45. xmessage -bg "#c0ffff" -center -title "Please wait..." -buttons "" "Creating msdos/vfat filesystem on floppy disk" &
  46.  mkfs.msdos -c /dev/fd0u$1
  47.  #mformat -f $1 a:
  48.  #mbadblocks a:
  49.  ERR1=$?
  50.  killall xmessage
  51.  if [ ! $ERR1 -eq 0 ];then
  52.   xmessage -bg "#ffe0e0" -name "msdosvfat" -title "Floppy msdos/vfat filesystem" -center \
  53.   -buttons "Try again":20,"QUIT":10 -file -<<XMSG
  54. ERROR creating msdos/vfat filesystem on the floppy disk.
  55. Is the write-protect tab closed?
  56. XMSG
  57.  
  58.   AN0=$?
  59.   if [ $AN0 -eq 10 ];then
  60.    ERR1=0
  61.   fi
  62.   if [ $AN0 -eq 0 ];then
  63.    ERR1=0
  64.   fi
  65.   if [ $AN0 -eq 1 ];then
  66.    ERR1=0
  67.   fi
  68.  else
  69.   INTROMSG="`
  70. echo "SUCCESS!"
  71. echo "The floppy disk is now ready to be used."
  72. echo "Use the Puppy Drive Mounter to mount it."
  73. echo "(NOTE: if you use the MToolsFM floppy file"
  74. echo " manager, the floppy drive is accessed directly,"
  75. echo " so do NOT use the Puppy Drive Mounter)"
  76. echo "First though, press EXIT to get out of here..."
  77. `"
  78.  fi
  79. done
  80. sync
  81. echo "...done."
  82. echo " "
  83. }
  84.  
  85. INTROMSG="`
  86. echo "WELCOME!"
  87. echo "My Puppy Floppy Formatter only formats floppies with"
  88. echo "1440 Kbyte capacity and with the msdos/vfat filesystem,"
  89. echo "for interchangeability with Windows."
  90. echo " "
  91. echo "You only need to lo-level format if the disk is formatted"
  92. echo "with some other capacity, or it is corrupted. You do not"
  93. echo "have to lo-level format a new disk, but may do so to"
  94. echo "check its integrity."
  95. echo "A disk is NOT usable if it is only lo-level formatted: it"
  96. echo "also must have a filesystem, so this must always be the"
  97. echo "second step."
  98. echo "Doing step-2 only, that is, creating a filesystem on a"
  99. echo "disk, is also a method for wiping any existing files."
  100. `"
  101.  
  102. #big loop...
  103. while :; do
  104.  
  105. MNTDMSG=" "
  106. mount | grep "/dev/fd0" > /dev/null 2>&1
  107. if [ $? -eq 0 ];then #=0 if string found
  108.  CURRENTMNT="`mount | grep "/dev/fd0" | cut -f 3 -d ' '`"
  109.  #this tells Rox to close any window with this directory and subdirectories open...
  110.  rox -D "$CURRENTMNT"
  111.  sync
  112.  umount "$CURRENTMNT" #/mnt/floppy
  113.  if [ ! $? -eq 0 ];then
  114.   MNTDMSG="`
  115. echo " "
  116. echo "Puppy found a floppy disk already mounted in the drive, but"
  117. echo "is not able to unmount it. The disk must be unmounted now."
  118. echo "Please use the Puppy Drive Mounter (in the File Manager menu)"
  119. echo "to unmount the floppy disk. DO THIS FIRST!"
  120. echo " "
  121. `"
  122.  else
  123.   MNTDMSG="`
  124. echo " "
  125. echo "Puppy found that the floppy disk was mounted, but has now"
  126. echo "unmounted it. Now ok to format disk."
  127. echo " "
  128. `"
  129.  fi
  130. fi
  131.  
  132. xmessage -bg "#e0ffe0" -name "pformat" -title "Puppy Floppy Formatter" -center \
  133. -buttons "Lo-level Format":20,"Msdos/vfat filesystem":30,"EXIT":10 -file -<<XMSG
  134. $INTROMSG
  135. $MNTDMSG
  136. Press a button:
  137. XMSG
  138.  
  139. ANS=$?
  140.  
  141. if [ $ANS -eq 0 ]; then
  142.  break
  143. fi
  144. if [ $ANS -eq 1 ]; then
  145.  break
  146. fi
  147. if [ $ANS -eq 10 ]; then
  148.  break
  149. fi
  150.  
  151. if [ $ANS -eq 20 ];then #format
  152.  zapfloppy 1440
  153. fi
  154.  
  155. if [ $ANS -eq 30 ];then #vfat
  156.  fsfloppy 1440
  157. fi
  158.  
  159. done
  160.