floppy-format.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/bin/sh
  2. #Format floppy disks
  3. #Copyright (c) Barry Kauler 2004 www.goosee.com/puppy
  4. #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  5. #130517 BK: code improved and internationalized.
  6. export TEXTDOMAIN=floppy-format
  7. export OUTPUT_CHARSET=UTF-8
  8. zapfloppy()
  9. {
  10. # Puppy will only allow 1440, 1680K and 1760K capacities.
  11. ERR0=1
  12. while [ $ERR0 -ne 0 ];do
  13. pwMSG="$(gettext 'Low-level formatting disk with this capacity:') ${1} Kbyte
  14. $(gettext 'Please wait...')"
  15. /usr/lib/gtkdialog/box_splash -close never -fontsize large -text "${pwMSG}" &
  16. pwID=$!
  17. fdformat /dev/fd0u$1
  18. ERR0=$?
  19. sync
  20. #killall xmessage
  21. pupkill $pwID
  22. if [ $ERR0 -ne 0 ];then
  23. xmessage -bg "#ffe0e0" -name "loformat" -title "$(gettext 'Puppy Low-level Formatter')" -center -buttons "$(gettext 'Try again')":20,"$(gettext 'QUIT')":10 -file -<<XMSG
  24. $(gettext 'ERROR low-level formatting disk.')
  25. $(gettext 'Is the write-protect tab closed?')
  26. XMSG
  27. AN0=$?
  28. if [ $AN0 -eq 10 ];then
  29. ERR0=0
  30. fi
  31. if [ $AN0 -eq 0 ];then
  32. ERR0=0
  33. fi
  34. if [ $AN0 -eq 1 ];then
  35. ERR0=0
  36. fi
  37. else
  38. INTROMSG="
  39. $(gettext '\ZbSUCCESS!\ZB')
  40. $(gettext 'Now you should press the \ZbMsdos/vfat filesystem\ZB button.')"
  41. fi
  42. done
  43. }
  44. fsfloppy()
  45. {
  46. echo "$(gettext 'Creating msdos filesystem on the disk...')"
  47. ERR1=1
  48. while [ ! $ERR1 -eq 0 ];do
  49. pwMSG="$(gettext 'Creating msdos/vfat filesystem on floppy disk')
  50. $(gettext 'Please wait...')"
  51. /usr/lib/gtkdialog/box_splash -close never -fontsize large -text "${pwMSG}" &
  52. pwID=$!
  53. mkfs.msdos -c /dev/fd0u$1
  54. #mformat -f $1 a:
  55. #mbadblocks a:
  56. ERR1=$?
  57. #killall xmessage
  58. pupkill $pwID
  59. if [ $ERR1 -ne 0 ];then
  60. xmessage -bg "#ffe0e0" -name "msdosvfat" -title "$(gettext 'Floppy msdos/vfat filesystem')" -center \
  61. -buttons "$(gettext 'Try again')":20,"$(gettext 'QUIT')":10 -file -<<XMSG
  62. $(gettext 'ERROR creating msdos/vfat filesystem on the floppy disk.')
  63. $(gettext 'Is the write-protect tab closed?')
  64. XMSG
  65. AN0=$?
  66. if [ $AN0 -eq 10 ];then
  67. ERR1=0
  68. fi
  69. if [ $AN0 -eq 0 ];then
  70. ERR1=0
  71. fi
  72. if [ $AN0 -eq 1 ];then
  73. ERR1=0
  74. fi
  75. else
  76. INTROMSG="
  77. $(gettext '\ZbSUCCESS!\ZB')
  78. $(gettext 'The floppy disk is now ready to be used. Use the Puppy Drive Mounter to mount it. Or, click the floppy-disk icon on the desktop.')
  79. $(gettext 'First though, press \ZbEXIT\ZB to get out of here...')"
  80. fi
  81. done
  82. sync
  83. echo "$(gettext '...done.')"
  84. echo " "
  85. }
  86. INTROMSG="$(gettext '\ZbWELCOME!\ZB')
  87. $(gettext 'The Puppy Floppy Formatter only formats floppies with 1440 Kbyte capacity and with the msdos/vfat filesystem, for interchangeability with Windows.')
  88. $(gettext 'You only need to low-level format if the disk is formatted with some other capacity, or it is corrupted. You do not have to low-level format a new disk, but may do so to check its integrity.')
  89. $(gettext 'A disk is NOT usable if it is only low-level formatted: it also must have a filesystem, so this must always be the second step.')
  90. $(gettext 'Doing step-2 only, that is, creating a filesystem on a disk, is also a method for wiping any existing files.')"
  91. #big loop...
  92. while :; do
  93. MNTDMSG=" "
  94. mount | grep "/dev/fd0" > /dev/null 2>&1
  95. if [ $? -eq 0 ];then #=0 if string found
  96. CURRENTMNT="`mount | grep "/dev/fd0" | cut -f 3 -d ' '`"
  97. #this tells Rox to close any window with this directory and subdirectories open...
  98. rox -D "$CURRENTMNT"
  99. sync
  100. umount "$CURRENTMNT" #/mnt/floppy
  101. if [ $? -ne 0 ];then
  102. MNTDMSG="
  103. $(gettext 'Puppy found a floppy disk already mounted in the drive, but is not able to unmount it. The disk must be unmounted now. Please click the \Zbclose box\ZB on the floppy-disk icon on the desktop, or use the Puppy Drive Mounter (click \Zbmount\ZB icon at top of screen) to unmount the floppy disk. DO THIS FIRST!')"
  104. else
  105. MNTDMSG="
  106. $(gettext 'Puppy found that the floppy disk was mounted, but has now unmounted it. Now ok to format disk.')"
  107. fi
  108. fi
  109. pressMSG="$(gettext 'Press a button:')"
  110. pupdialog --colors --background '#e0ffe0' --title "$(gettext 'Puppy Floppy Formatter')" --extra-button --yes-label "$(gettext 'Low-level Format')" --no-label "$(gettext 'EXIT')" --extra-label "$(gettext 'Msdos/vfat filesystem')" --yesno "${INTROMSG}
  111. ${MNTDMSG}
  112. ${pressMSG}" 0 0
  113. ANS=$?
  114. case $ANS in
  115. 0) #low-level format
  116. zapfloppy 1440
  117. ;;
  118. 3) #vfat
  119. fsfloppy 1440
  120. ;;
  121. 1) #exit
  122. break
  123. ;;
  124. *)
  125. break
  126. ;;
  127. esac
  128. done
  129. ###END###