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 / pmount < prev    next >
Encoding:
Text File  |  2000-04-19  |  26.8 KB  |  828 lines

  1. #! /bin/bash
  2. # (c) Copyright 2003/2004/2005/2006 Barry Kauler www.puppylinux.com
  3. # This script has a GUI to mount and unmount partitions. 
  4. # Oct 2005 total rewrite.
  5. # v1.0.7 Nov 2005: bugfix by GuestToo.
  6. # Jan 2006 updated for Puppy2.
  7.  
  8. # Note:
  9. # The mount* program normally saves info on what is mounted
  10. # in /etc/mtab and /proc/mounts, however these files are
  11. # not used in Puppy ... (turned off in Busybox)
  12. # Anyway, just executing "mount" returns the info.
  13.  
  14. # i want to use eject* to eject removable media, but this
  15. # reads /etc/mtab ...so, I'll write to mtab in this script!
  16.  
  17. fsfunc() #f.s. type param passed in
  18. {
  19.  FSTYPE="$1"
  20.  [ "$FSTYPE" = "Ext2" ] && FSTYPE="ext2"
  21.  [ "$FSTYPE" = "ReiserFS" ] && FSTYPE="reiserfs"
  22.  [ "$FSTYPE" = "Ext3" ] && FSTYPE="ext3"
  23.  [ "$FSTYPE" = "FAT12" ] && FSTYPE="vfat"
  24.  [ "$FSTYPE" = "FAT16" ] && FSTYPE="vfat"
  25.  [ "$FSTYPE" = "FAT32" ] && FSTYPE="vfat"
  26.  [ "$FSTYPE" = "NTFS" ] && FSTYPE="ntfs"
  27.  [ "$FSTYPE" = "ISO9660" ] && FSTYPE="iso9660"
  28. }
  29.  
  30. #see if the hardware has usb...
  31. cat /proc/pci | grep -i "usb" > /dev/null
  32. if [ $? -eq 0 ];then
  33.  #k2.6 module is usb-storage.ko but lsmod shows it as usb_storage!!!...
  34.  if [ "`lsmod | grep --extended-regexp 'usb\-storage|usb_storage' | head -n 1 | tr -s " " | cut -f 1 -d " " | grep --extended-regexp 'usb\-storage|usb_storage'`" = "" ];then
  35.    xmessage -bg "#ff00ff" -title "Puppy drive mounter" -center -buttons "" "Please wait for the usb-storage driver to load...
  36.  
  37. Note: A USB1 interface takes longer to initialise than a USB2 interface,
  38. in the former case up to 25 seconds, in the latter about 4 seconds." &
  39.   XPID=$!
  40.   #v2.0.0
  41.   modprobe usb-storage &
  42.   sleep 6
  43.   [ "`cat /proc/pci | grep -i "usb" | grep "Controller" | grep '2\.[0-9]'`" = "" ] && sleep 20
  44.   kill $XPID
  45.  fi
  46. fi
  47.  
  48. #/usr/sbin/disk.tcl & #displays partition sizes graphically.
  49. #X0PID=$!
  50.  
  51.  
  52. while :; do #BIGLOOP
  53.  
  54. xmessage -bg "orange" -buttons "" -title "Puppy drive mounter" "Please wait, probing hardware..." &
  55. X1PID=$!
  56.  
  57. DISKINFO="`probedisk 2> /tmp/probediskerr.txt`"
  58. PARTINFO="`probepart -m 2> /tmp/probeparterr.txt | grep "/dev/" | grep -v '|swap|' | grep --extended-regexp "ext2|ext3|reiserfs|msdos|vfat|ntfs|NTFS|iso9660"`"
  59.  
  60. #v2.0.0
  61. #a drive could be a "superfloppy", with no mbr and no partitions...
  62. #remove partition entries from PARTINFO, replace with one entry...
  63. for ONEDRIVE in `echo "$DISKINFO" | cut -f 1 -d '|' | tr "\n" " "`
  64. do
  65.  DISKTYPE="`disktype /dev/$ONEDRIVE 2> /dev/null`"
  66.  SUPERFLOPPYFS="`echo "$DISKTYPE" | grep "file system" | grep "^[a-zA-Z]" | head -n 1 | cut -f 1 -d " "`"
  67.  if [ "$SUPERFLOPPYFS" ];then
  68.   fsfunc $SUPERFLOPPYFS #returns FSTYPE
  69.   SUPERSIZM="`echo "$DISKTYPE" | grep "Block device" | tr -s " " | cut -f 4 -d " "`"
  70.   PARTTMP="`echo "$PARTINFO" | grep -v "/dev/$ONEDRIVE"`"
  71.   PARTINFO="$PARTTMP
  72. /dev/${ONEDRIVE}|${FSTYPE}|${SUPERSIZM}|Superfloppy drive"
  73.  fi
  74. done
  75.  
  76.  
  77. #one tricky thing about probedisk is it returns both ide and scsi names for scsi-emulated drive...
  78. #if cd/dvd drive is scsi-emul, screen out the line with ide name...
  79. if [ -f /etc/cdburnerdevice ];then
  80.  BURNERDEVICE="/dev/`cat /etc/cdburnerdevice`"
  81.  if [ -f /etc/scsiemul ];then
  82.   if [ "`cat /etc/scsiemul`" = "on" ];then
  83.    TITLESTRING="`echo "$DISKINFO" | grep "$BURNERDEVICE" | cut -f 3 -d '|'`"
  84.    IDEDEVICE="`echo "$DISKINFO" | grep "$TITLESTRING" | grep -v "$BURNERDEVICE" | head -n 1 | cut -f 1 -d '|'`"
  85.    [ "$IDEDEVICE" ] && DISKINFO="`echo -n "$DISKINFO" | grep -v "$IDEDEVICE"`"
  86.   fi
  87.  fi
  88. fi
  89.  
  90. kill $X1PID
  91.  
  92. #if a removable drive is mounted, check that it hasn't been removed...
  93. if [ -z /tmp/probeparterr.txt ];then
  94.  ERRDEVS="`cat /tmp/probeparterr.txt | grep "libcfdisk" | cut -f 3 -d '/'`"
  95.  for AERRDEV in $ERRDEVS
  96.  do
  97.   if [ ! "`mount | grep "/dev/$AERRDEV"`" = "" ];then
  98.    DRVDEV="/dev/`echo -n "$AERRDEV" | cut -b 1-3`"
  99.    DRVDESCR="`echo "$DISKINFO" | grep "$DRVDEV" | cut -f 3 -d '|'`"
  100.    xmessage -bg "#ff8080" -title "Puppy drive mounter: ERROR" -center "
  101. You have unplugged drive /dev/$AERRDEV while it is still mounted.
  102. Drive description: $DRVDESCR
  103.  
  104. A removable drive must always be unmounted before being removed.
  105.  
  106. Plug the drive back in RIGHT NOW, then click OK button..."
  107.   fi
  108.  done
  109. fi
  110.  
  111. DIALOGMAIN="
  112.  <wtitle>Puppy drive mounter</wtitle>
  113.  <vbox>
  114. "
  115.  
  116. #######FLOPPY###########
  117. if [ ! "`cat /var/log/messages | grep "Floppy drive" | grep "fd0"`" = "" ];then
  118.  DEVFD0="/dev/fd0"
  119.  MNTFD0="`mount | grep "/dev/fd0" | cut -f 3 -d ' '`"
  120.  DIALOGMAIN="$DIALOGMAIN <frame Floppy drive>"
  121.  if [ "$MNTFD0" ];then
  122.   DIALOGMAIN="$DIALOGMAIN
  123.   <hbox>
  124.    <text><label>\"Mounted on /mnt/floppy
  125. DO NOT REMOVE FLOPPY\"</label></text>
  126.    <text><label>\"   \"</label></text>
  127.    <text><label>/dev/fd0</label></text>
  128.    <button>
  129.     <input file>/usr/local/lib/X11/pixmaps/floppy24green.xpm</input>
  130.     <action>Exit:/dev/fd0_/mnt/floppy_GREEN</action>
  131.    </button>
  132.   </hbox>"
  133.  else
  134.   DIALOGMAIN="$DIALOGMAIN
  135.   <hbox>
  136.    <text><label>/dev/fd0</label></text>
  137.    <button>
  138.     <input file>/usr/local/lib/X11/pixmaps/floppy24red.xpm</input>
  139.     <action>Exit:/dev/fd0_/mnt/floppy_RED</action>
  140.    </button>
  141.   </hbox>"
  142.  fi
  143.  DIALOGMAIN="$DIALOGMAIN </frame>"
  144. fi
  145. #######END FLOPPY###########
  146.  
  147. #v2.0.0
  148. #######ZIP/LS120 IDE FLOPPY###########
  149. if [ ! "`cat /var/log/messages | grep "ATAPI FLOPPY"`" = "" ];then
  150.  ZIPDISK="`echo "$DISKINFO" | grep '|floppy|' | grep "ATAPI" | cut -f 1 -d '|'`"
  151.  ZIPNUM="`disktype $ZIPDISK | grep '^Partition ' | cut -f 1 -d ':' | cut -f 2 -d " "`"
  152.  DEVZIP="$ZIPDISK$ZIPNUM" #ex: /dev/hdd4
  153.  MNTZIP="/mnt/`echo -n "$DEVZIP" | cut -f 3 -d '/'`"
  154.  FSZIP="`disktype $DEVZIP | grep 'file system' | cut -f 1 -d " "`" #ex: FAT16
  155.  fsfunc $FSZIP
  156.  FSZIP="$FSTYPE"
  157.  XMNTZIP="`mount | grep "$DEVZIP"`"
  158.  
  159.  DIALOGMAIN="$DIALOGMAIN <frame Zip/LS120 ATAPI drive>"
  160.  if [ "$XMNTZIP" ];then
  161.   DIALOGMAIN="$DIALOGMAIN
  162.   <hbox>
  163.    <text><label>\"Mounted on $MNTZIP
  164. DO NOT REMOVE ZIP DISK\"</label></text>
  165.    <text><label>\"   \"</label></text>
  166.    <text><label>$DEVZIP</label></text>
  167.    <button>
  168.     <input file>/usr/local/lib/X11/pixmaps/floppy24green.xpm</input>
  169.     <action>Exit:${DEVZIP}_${MNTZIP}_GREEN</action>
  170.    </button>
  171.   </hbox>"
  172.  else
  173.   DIALOGMAIN="$DIALOGMAIN
  174.   <hbox>
  175.    <text><label>$DEVZIP</label></text>
  176.    <button>
  177.     <input file>/usr/local/lib/X11/pixmaps/floppy24red.xpm</input>
  178.     <action>Exit:${DEVZIP}_${MNTZIP}_RED</action>
  179.    </button>
  180.   </hbox>"
  181.  fi
  182.  DIALOGMAIN="$DIALOGMAIN </frame>"
  183. fi
  184. #######END ZIP/LS120###########
  185.  
  186.  
  187. #####CD/DVD##############
  188. CDROMS="`echo -n "$DISKINFO" | grep '|cdrom|'`"
  189. if [ "$CDROMS" ];then
  190.  NUMLINES=`echo "$CDROMS" | wc -l | tr -s ' ' | cut -f 2 -d ' '`
  191.  while [ $NUMLINES -gt 0 ];do
  192.   [ $NUMLINES -eq 1 ] && CDROM1="`echo -n "$CDROMS" | tail -n 1 | head -n 1`"
  193.   [ $NUMLINES -eq 2 ] && CDROM2="`echo -n "$CDROMS" | tail -n 2 | head -n 1`"
  194.   [ $NUMLINES -eq 3 ] && CDROM3="`echo -n "$CDROMS" | tail -n 3 | head -n 1`"
  195.   NUMLINES=`expr $NUMLINES - 1`
  196.  done
  197. fi
  198. if [ "$CDROM1" ];then
  199.  DEVCDR1="`echo -n "$CDROM1" | cut -f 1 -d '|'`"
  200.  DESCRCDR1="`echo -n "$CDROM1" | cut -f 3 -d '|'`"
  201.  MNTCDR1="`mount | grep "$DEVCDR1" | cut -f 3 -d ' '`"
  202.  FSCDR1="`echo "$PARTINFO" | grep "$DEVCDR1" | cut -f 2 -d '|'`"
  203.  DVDRWMEDIAINFO="`dvd+rw-mediainfo $DEVCDR1 2>&1`"
  204.  MEDIACDR1="DVD"
  205.  [ ! "`echo -n "$DVDRWMEDIAINFO" | grep --extended-regexp "non\\-DVD|not a DVD unit"`" = "" ] && MEDIACDR1="CD"
  206.  DIALOGMAIN="$DIALOGMAIN <frame $MEDIACDR1 $DEVCDR1, $DESCRCDR1>"
  207.  if [ "$MNTCDR1" ];then
  208.   DIALOGMAIN="$DIALOGMAIN
  209.   <hbox>
  210.    <text><label>\"Mounted on $MNTCDR1
  211. DO NOT EJECT MEDIA\"</label></text>
  212.    <text><label>\"   \"</label></text>
  213.    <text><label>$DEVCDR1</label></text>
  214.    <button>
  215.     <input file>/usr/local/lib/X11/pixmaps/cd24green.xpm</input>
  216.     <action>Exit:${DEVCDR1}_${MNTCDR1}_GREEN</action>
  217.    </button>
  218.   </hbox>"
  219.  else
  220.   DIALOGMAIN="$DIALOGMAIN
  221.   <hbox>
  222.    <text><label>$DEVCDR1</label></text>
  223.    <button>
  224.     <input file>/usr/local/lib/X11/pixmaps/cd24red.xpm</input>
  225.     <action>Exit:${DEVCDR1}_XXX_RED</action>
  226.    </button>
  227.   </hbox>"
  228.  fi
  229.  DIALOGMAIN="$DIALOGMAIN </frame>"
  230. fi
  231. if [ "$CDROM2" ];then
  232.  DEVCDR2="`echo -n "$CDROM2" | cut -f 1 -d '|'`"
  233.  DESCRCDR2="`echo -n "$CDROM2" | cut -f 3 -d '|'`"
  234.  MNTCDR2="`mount | grep "$DEVCDR2" | cut -f 3 -d ' '`"
  235.  FSCDR2="`echo "$PARTINFO" | grep "$DEVCDR2" | cut -f 2 -d '|'`"
  236.  DVDRWMEDIAINFO="`dvd+rw-mediainfo $DEVCDR2 2>&1`"
  237.  MEDIACDR2="DVD"
  238.  [ ! "`echo -n "$DVDRWMEDIAINFO" | grep --extended-regexp "non\\-DVD|not a DVD unit"`" = "" ] && MEDIACDR2="CD"
  239.  DIALOGMAIN="$DIALOGMAIN <frame $MEDIACDR2 $DEVCDR2, $DESCRCDR2>"
  240.  if [ "$MNTCDR2" ];then
  241.   DIALOGMAIN="$DIALOGMAIN
  242.   <hbox>
  243.    <text><label>\"Mounted on $MNTCDR2
  244. DO NOT EJECT MEDIA\"</label></text>
  245.    <text><label>\"   \"</label></text>
  246.    <text><label>$DEVCDR2</label></text>
  247.    <button>
  248.     <input file>/usr/local/lib/X11/pixmaps/cd24green.xpm</input>
  249.     <action>Exit:${DEVCDR2}_${MNTCDR2}_GREEN</action>
  250.    </button>
  251.   </hbox>"
  252.  else
  253.   DIALOGMAIN="$DIALOGMAIN
  254.   <hbox>
  255.    <text><label>$DEVCDR2</label></text>
  256.    <button>
  257.     <input file>/usr/local/lib/X11/pixmaps/cd24red.xpm</input>
  258.     <action>Exit:${DEVCDR2}_XXX_RED</action>
  259.    </button>
  260.   </hbox>"
  261.  fi
  262.  DIALOGMAIN="$DIALOGMAIN </frame>"
  263. fi
  264. #########CD/DVD##########
  265.  
  266. #########HARD DRIVE###########
  267. DISKS="`echo -n "$DISKINFO" | grep '|disk|'`"
  268. if [ "$DISKS" ];then
  269.  NUMLINES=`echo "$DISKS" | wc -l | tr -s ' ' | cut -f 2 -d ' '`
  270.  while [ $NUMLINES -gt 0 ];do
  271.   [ $NUMLINES -eq 1 ] && DISK1="`echo -n "$DISKS" | tail -n 1 | head -n 1`"
  272.   [ $NUMLINES -eq 2 ] && DISK2="`echo -n "$DISKS" | tail -n 2 | head -n 1`"
  273.   [ $NUMLINES -eq 3 ] && DISK3="`echo -n "$DISKS" | tail -n 3 | head -n 1`"
  274.   NUMLINES=`expr $NUMLINES - 1`
  275.  done
  276. fi
  277.  
  278. if [ "$DISK1" ];then
  279.  DEVDISK1="`echo -n "$DISK1" | cut -f 1 -d '|'`"
  280.  DESCRDISK1="`echo -n "$DISK1" | cut -f 3 -d '|'`"
  281.  INFODISK1="`fdisk -l $DEVDISK1 | head -n 2 | tail -n 1 | cut -f 1 -d ','`"
  282.  DIALOGMAIN="$DIALOGMAIN <frame $INFODISK1, $DESCRDISK1>"
  283.  PARTSDISK1="`echo "$PARTINFO" | grep "$DEVDISK1"`"
  284.  if [ "$PARTSDISK1" ];then
  285.   NUMLINES=`echo "$PARTSDISK1" | wc -l | tr -s ' ' | cut -f 2 -d ' '`
  286.   while [ $NUMLINES -gt 0 ];do
  287.    [ $NUMLINES -eq 1 ] && PART1DISK1="`echo -n "$PARTSDISK1" | tail -n 1 | head -n 1`"
  288.    [ $NUMLINES -eq 2 ] && PART2DISK1="`echo -n "$PARTSDISK1" | tail -n 2 | head -n 1`"
  289.    [ $NUMLINES -eq 3 ] && PART3DISK1="`echo -n "$PARTSDISK1" | tail -n 3 | head -n 1`"
  290.    [ $NUMLINES -eq 4 ] && PART4DISK1="`echo -n "$PARTSDISK1" | tail -n 4 | head -n 1`"
  291.    NUMLINES=`expr $NUMLINES - 1`
  292.   done
  293.   if [ "$PART1DISK1" ];then
  294.    DEVP1D1="`echo -n "$PART1DISK1" | cut -f 1 -d '|'`"
  295.    MNTP1D1="`mount | grep "$DEVP1D1" | cut -f 3 -d ' '`"
  296.    FSP1D1="`echo "$PARTINFO" | grep "$DEVP1D1" | cut -f 2 -d '|'`"
  297.    SIZEP1D1="`echo "$PARTINFO" | grep "$DEVP1D1" | cut -f 3 -d '|'`"
  298.    if [ "$MNTP1D1" ];then
  299.     DIALOGMAIN="$DIALOGMAIN
  300.     <hbox>
  301.      <text><label>\"Mounted on
  302. $MNTP1D1\"</label></text>
  303.      <text><label>\"   \"</label></text>
  304.      <text><label>\"$DEVP1D1
  305. ${SIZEP1D1}M $FSP1D1\"</label></text>
  306.      <button>
  307.       <input file>/usr/local/lib/X11/pixmaps/hd24green.xpm</input>
  308.       <action>Exit:${DEVP1D1}_${MNTP1D1}_GREEN</action>
  309.      </button>
  310.     </hbox>"
  311.    else
  312.     DIALOGMAIN="$DIALOGMAIN
  313.     <hbox>
  314.      <text><label>\"$DEVP1D1
  315. ${SIZEP1D1}M $FSP1D1\"</label></text>
  316.      <button>
  317.       <input file>/usr/local/lib/X11/pixmaps/hd24red.xpm</input>
  318.       <action>Exit:${DEVP1D1}_XXX_RED</action>
  319.      </button>
  320.     </hbox>"
  321.    fi
  322.   fi
  323.   if [ "$PART2DISK1" ];then
  324.    DEVP2D1="`echo -n "$PART2DISK1" | cut -f 1 -d '|'`"
  325.    MNTP2D1="`mount | grep "$DEVP2D1" | cut -f 3 -d ' '`"
  326.    FSP2D1="`echo "$PARTINFO" | grep "$DEVP2D1" | cut -f 2 -d '|'`"
  327.    SIZEP2D1="`echo "$PARTINFO" | grep "$DEVP2D1" | cut -f 3 -d '|'`"
  328.    if [ "$MNTP2D1" ];then
  329.     DIALOGMAIN="$DIALOGMAIN
  330.     <hbox>
  331.      <text><label>\"Mounted on
  332. $MNTP2D1\"</label></text>
  333.      <text><label>\"   \"</label></text>
  334.      <text><label>\"$DEVP2D1
  335. ${SIZEP2D1}M $FSP2D1\"</label></text>
  336.      <button>
  337.       <input file>/usr/local/lib/X11/pixmaps/hd24green.xpm</input>
  338.       <action>Exit:${DEVP2D1}_${MNTP2D1}_GREEN</action>
  339.      </button>
  340.     </hbox>"
  341.    else
  342.     DIALOGMAIN="$DIALOGMAIN
  343.     <hbox>
  344.      <text><label>\"$DEVP2D1
  345. ${SIZEP2D1}M $FSP2D1\"</label></text>
  346.      <button>
  347.       <input file>/usr/local/lib/X11/pixmaps/hd24red.xpm</input>
  348.       <action>Exit:${DEVP2D1}_XXX_RED</action>
  349.      </button>
  350.     </hbox>"
  351.    fi
  352.   fi
  353.   if [ "$PART3DISK1" ];then
  354.    DEVP3D1="`echo -n "$PART3DISK1" | cut -f 1 -d '|'`"
  355.    MNTP3D1="`mount | grep "$DEVP3D1" | cut -f 3 -d ' '`"
  356.    FSP3D1="`echo "$PARTINFO" | grep "$DEVP3D1" | cut -f 2 -d '|'`"
  357.    SIZEP3D1="`echo "$PARTINFO" | grep "$DEVP3D1" | cut -f 3 -d '|'`"
  358.    if [ "$MNTP3D1" ];then
  359.     DIALOGMAIN="$DIALOGMAIN
  360.     <hbox>
  361.      <text><label>\"Mounted on
  362. $MNTP3D1\"</label></text>
  363.      <text><label>\"   \"</label></text>
  364.      <text><label>\"$DEVP3D1
  365. ${SIZEP3D1}M $FSP3D1\"</label></text>
  366.      <button>
  367.       <input file>/usr/local/lib/X11/pixmaps/hd24green.xpm</input>
  368.       <action>Exit:${DEVP3D1}_${MNTP3D1}_GREEN</action>
  369.      </button>
  370.     </hbox>"
  371.    else
  372.     DIALOGMAIN="$DIALOGMAIN
  373.     <hbox>
  374.      <text><label>\"$DEVP3D1
  375. ${SIZEP3D1}M $FSP3D1\"</label></text>
  376.      <button>
  377.       <input file>/usr/local/lib/X11/pixmaps/hd24red.xpm</input>
  378.       <action>Exit:${DEVP3D1}_XXX_RED</action>
  379.      </button>
  380.     </hbox>"
  381.    fi
  382.   fi
  383.   if [ "$PART4DISK1" ];then
  384.    DEVP4D1="`echo -n "$PART4DISK1" | cut -f 1 -d '|'`"
  385.    MNTP4D1="`mount | grep "$DEVP4D1" | cut -f 3 -d ' '`"
  386.    FSP4D1="`echo "$PARTINFO" | grep "$DEVP4D1" | cut -f 2 -d '|'`"
  387.    SIZEP4D1="`echo "$PARTINFO" | grep "$DEVP4D1" | cut -f 3 -d '|'`"
  388.    if [ "$MNTP4D1" ];then
  389.     DIALOGMAIN="$DIALOGMAIN
  390.     <hbox>
  391.      <text><label>\"Mounted on
  392. $MNTP4D1\"</label></text>
  393.      <text><label>\"   \"</label></text>
  394.      <text><label>\"$DEVP4D1
  395. ${SIZEP4D1}M $FSP4D1\"</label></text>
  396.      <button>
  397.       <input file>/usr/local/lib/X11/pixmaps/hd24green.xpm</input>
  398.       <action>Exit:${DEVP4D1}_${MNTP4D1}_GREEN</action>
  399.      </button>
  400.     </hbox>"
  401.    else
  402.     DIALOGMAIN="$DIALOGMAIN
  403.     <hbox>
  404.      <text><label>\"$DEVP4D1
  405. ${SIZEP4D1}M $FSP4D1\"</label></text>
  406.      <button>
  407.       <input file>/usr/local/lib/X11/pixmaps/hd24red.xpm</input>
  408.       <action>Exit:${DEVP4D1}_XXX_RED</action>
  409.      </button>
  410.     </hbox>"
  411.    fi
  412.   fi
  413.  fi
  414.  DIALOGMAIN="$DIALOGMAIN </frame>"
  415. fi
  416.  
  417. if [ "$DISK2" ];then
  418.  DEVDISK2="`echo -n "$DISK2" | cut -f 1 -d '|'`"
  419.  DESCRDISK2="`echo -n "$DISK2" | cut -f 3 -d '|'`"
  420.  INFODISK2="`fdisk -l $DEVDISK2 | head -n 2 | tail -n 1 | cut -f 1 -d ','`"
  421.  DIALOGMAIN="$DIALOGMAIN <frame $INFODISK2, $DESCRDISK2>"
  422.  PARTSDISK2="`echo "$PARTINFO" | grep "$DEVDISK2"`"
  423.  if [ "$PARTSDISK2" ];then
  424.   NUMLINES=`echo "$PARTSDISK2" | wc -l | tr -s ' ' | cut -f 2 -d ' '`
  425.   while [ $NUMLINES -gt 0 ];do
  426.    [ $NUMLINES -eq 1 ] && PART1DISK2="`echo -n "$PARTSDISK2" | tail -n 1 | head -n 1`"
  427.    [ $NUMLINES -eq 2 ] && PART2DISK2="`echo -n "$PARTSDISK2" | tail -n 2 | head -n 1`"
  428.    [ $NUMLINES -eq 3 ] && PART3DISK2="`echo -n "$PARTSDISK2" | tail -n 3 | head -n 1`"
  429.    [ $NUMLINES -eq 4 ] && PART4DISK2="`echo -n "$PARTSDISK2" | tail -n 4 | head -n 1`"
  430.    NUMLINES=`expr $NUMLINES - 1`
  431.   done
  432.   if [ "$PART1DISK2" ];then
  433.    DEVP1D2="`echo -n "$PART1DISK2" | cut -f 1 -d '|'`"
  434.    MNTP1D2="`mount | grep "$DEVP1D2" | cut -f 3 -d ' '`"
  435.    FSP1D2="`echo "$PARTINFO" | grep "$DEVP1D2" | cut -f 2 -d '|'`"
  436.    SIZEP1D2="`echo "$PARTINFO" | grep "$DEVP1D2" | cut -f 3 -d '|'`"
  437.    if [ "$MNTP1D2" ];then
  438.     DIALOGMAIN="$DIALOGMAIN
  439.     <hbox>
  440.      <text><label>\"Mounted on
  441. $MNTP1D2\"</label></text>
  442.      <text><label>\"   \"</label></text>
  443.      <text><label>\"$DEVP1D2
  444. ${SIZEP1D2}M $FSP1D2\"</label></text>
  445.      <button>
  446.       <input file>/usr/local/lib/X11/pixmaps/hd24green.xpm</input>
  447.       <action>Exit:${DEVP1D2}_${MNTP1D2}_GREEN</action>
  448.      </button>
  449.     </hbox>"
  450.    else
  451.     DIALOGMAIN="$DIALOGMAIN
  452.     <hbox>
  453.      <text><label>\"$DEVP1D2
  454. ${SIZEP1D2}M $FSP1D2\"</label></text>
  455.      <button>
  456.       <input file>/usr/local/lib/X11/pixmaps/hd24red.xpm</input>
  457.       <action>Exit:${DEVP1D2}_XXX_RED</action>
  458.      </button>
  459.     </hbox>"
  460.    fi
  461.   fi
  462.   if [ "$PART2DISK2" ];then
  463.    DEVP2D2="`echo -n "$PART2DISK2" | cut -f 1 -d '|'`"
  464.    MNTP2D2="`mount | grep "$DEVP2D2" | cut -f 3 -d ' '`"
  465.    FSP2D2="`echo "$PARTINFO" | grep "$DEVP2D2" | cut -f 2 -d '|'`"
  466.    SIZEP2D2="`echo "$PARTINFO" | grep "$DEVP2D2" | cut -f 3 -d '|'`"
  467.    if [ "$MNTP2D2" ];then
  468.     DIALOGMAIN="$DIALOGMAIN
  469.     <hbox>
  470.      <text><label>\"Mounted on
  471. $MNTP2D2\"</label></text>
  472.      <text><label>\"   \"</label></text>
  473.      <text><label>\"$DEVP2D2
  474. ${SIZEP2D2}M $FSP2D2\"</label></text>
  475.      <button>
  476.       <input file>/usr/local/lib/X11/pixmaps/hd24green.xpm</input>
  477.       <action>Exit:${DEVP2D2}_${MNTP2D2}_GREEN</action>
  478.      </button>
  479.     </hbox>"
  480.    else
  481.     DIALOGMAIN="$DIALOGMAIN
  482.     <hbox>
  483.      <text><label>\"$DEVP2D2
  484. ${SIZEP2D2}M $FSP2D2\"</label></text>
  485.      <button>
  486.       <input file>/usr/local/lib/X11/pixmaps/hd24red.xpm</input>
  487.       <action>Exit:${DEVP2D2}_XXX_RED</action>
  488.      </button>
  489.     </hbox>"
  490.    fi
  491.   fi
  492.   if [ "$PART3DISK2" ];then
  493.    DEVP3D2="`echo -n "$PART3DISK2" | cut -f 1 -d '|'`"
  494.    MNTP3D2="`mount | grep "$DEVP3D2" | cut -f 3 -d ' '`"
  495.    FSP3D2="`echo "$PARTINFO" | grep "$DEVP3D2" | cut -f 2 -d '|'`"
  496.    SIZEP3D2="`echo "$PARTINFO" | grep "$DEVP3D2" | cut -f 3 -d '|'`"
  497.    if [ "$MNTP3D2" ];then
  498.     DIALOGMAIN="$DIALOGMAIN
  499.     <hbox>
  500.      <text><label>\"Mounted on
  501. $MNTP3D2\"</label></text>
  502.      <text><label>\"   \"</label></text>
  503.      <text><label>\"$DEVP3D2
  504. ${SIZEP3D2}M $FSP3D2\"</label></text>
  505.      <button>
  506.       <input file>/usr/local/lib/X11/pixmaps/hd24green.xpm</input>
  507.       <action>Exit:${DEVP3D2}_${MNTP3D2}_GREEN</action>
  508.      </button>
  509.     </hbox>"
  510.    else
  511.     DIALOGMAIN="$DIALOGMAIN
  512.     <hbox>
  513.      <text><label>\"$DEVP3D2
  514. ${SIZEP3D2}M $FSP3D2\"</label></text>
  515.      <button>
  516.       <input file>/usr/local/lib/X11/pixmaps/hd24red.xpm</input>
  517.       <action>Exit:${DEVP3D2}_XXX_RED</action>
  518.      </button>
  519.     </hbox>"
  520.    fi
  521.   fi
  522.   if [ "$PART4DISK2" ];then
  523.    DEVP4D2="`echo -n "$PART4DISK2" | cut -f 1 -d '|'`"
  524.    MNTP4D2="`mount | grep "$DEVP4D2" | cut -f 3 -d ' '`"
  525.    FSP4D2="`echo "$PARTINFO" | grep "$DEVP4D2" | cut -f 2 -d '|'`"
  526.    SIZEP4D2="`echo "$PARTINFO" | grep "$DEVP4D2" | cut -f 3 -d '|'`"
  527.    if [ "$MNTP4D2" ];then
  528.     DIALOGMAIN="$DIALOGMAIN
  529.     <hbox>
  530.      <text><label>\"Mounted on
  531. $MNTP4D2\"</label></text>
  532.      <text><label>\"   \"</label></text>
  533.      <text><label>\"$DEVP4D2
  534. ${SIZEP4D2}M $FSP4D2\"</label></text>
  535.      <button>
  536.       <input file>/usr/local/lib/X11/pixmaps/hd24green.xpm</input>
  537.       <action>Exit:${DEVP4D2}_${MNTP4D2}_GREEN</action>
  538.      </button>
  539.     </hbox>"
  540.    else
  541.     DIALOGMAIN="$DIALOGMAIN
  542.     <hbox>
  543.      <text><label>\"$DEVP4D2
  544. ${SIZEP4D2}M $FSP4D2\"</label></text>
  545.      <button>
  546.       <input file>/usr/local/lib/X11/pixmaps/hd24red.xpm</input>
  547.       <action>Exit:${DEVP4D2}_XXX_RED</action>
  548.      </button>
  549.     </hbox>"
  550.    fi
  551.   fi
  552.  fi
  553.  DIALOGMAIN="$DIALOGMAIN </frame>"
  554. fi
  555. #########HARD DRIVE###########
  556.  
  557.  
  558. #########USB DRIVE############
  559. DACCS="`echo -n "$DISKINFO" | grep '|Direct\-Access|'`"
  560. if [ "$DACCS" ];then
  561.  NUMLINES=`echo "$DACCS" | wc -l | tr -s ' ' | cut -f 2 -d ' '`
  562.  while [ $NUMLINES -gt 0 ];do
  563.   [ $NUMLINES -eq 1 ] && DACC1="`echo -n "$DACCS" | tail -n 1 | head -n 1`"
  564.   [ $NUMLINES -eq 2 ] && DACC2="`echo -n "$DACCS" | tail -n 2 | head -n 1`"
  565.   NUMLINES=`expr $NUMLINES - 1`
  566.  done
  567. fi
  568. CHECKA1=""
  569. if [ "$DACC1" ];then #in case it is removed.
  570.  DEVDACC1="`echo -n "$DACC1" | cut -f 1 -d '|'`"
  571.  CHECKA1="`echo "$PARTINFO" | grep "$DEVDACC1"`"
  572. fi
  573. if [ "$CHECKA1" ];then
  574.  #DEVDACC1="`echo -n "$DACC1" | cut -f 1 -d '|'`"
  575.  DESCRDACC1="`echo -n "$DACC1" | cut -f 3 -d '|'`"
  576.  INFODACC1="`fdisk -l $DEVDACC1 | head -n 2 | tail -n 1 | cut -f 1 -d ','`,"
  577.  DIALOGMAIN="$DIALOGMAIN <frame $INFODACC1 $DESCRDACC1>"
  578.  PARTSDACC1="`echo "$PARTINFO" | grep "$DEVDACC1"`"
  579.  if [ "$PARTSDACC1" ];then
  580.   NUMLINES=`echo "$PARTSDACC1" | wc -l | tr -s ' ' | cut -f 2 -d ' '`
  581.   while [ $NUMLINES -gt 0 ];do
  582.    [ $NUMLINES -eq 1 ] && PART1DACC1="`echo -n "$PARTSDACC1" | tail -n 1 | head -n 1`"
  583.    NUMLINES=`expr $NUMLINES - 1`
  584.   done
  585.   if [ "$PART1DACC1" ];then
  586.    DEVP1A1="`echo -n "$PART1DACC1" | cut -f 1 -d '|'`"
  587.    MNTP1A1="`mount | grep "$DEVP1A1" | cut -f 3 -d ' '`"
  588.    FSP1A1="`echo "$PARTINFO" | grep "$DEVP1A1" | cut -f 2 -d '|'`"
  589.    SIZEP1A1="`echo "$PARTINFO" | grep "$DEVP1A1" | cut -f 3 -d '|'`"
  590.    if [ "$MNTP1A1" ];then
  591.     DIALOGMAIN="$DIALOGMAIN
  592.     <hbox>
  593.      <text><label>\"Mounted on $MNTP1A1
  594. DO NOT UNPLUG DRIVE\"</label></text>
  595.      <text><label>\"   \"</label></text>
  596.      <text><label>\"$DEVP1A1
  597. ${SIZEP1A1}M $FSP1A1\"</label></text>
  598.      <button>
  599.       <input file>/usr/local/lib/X11/pixmaps/da24green.xpm</input>
  600.       <action>Exit:${DEVP1A1}_${MNTP1A1}_GREEN</action>
  601.      </button>
  602.     </hbox>"
  603.    else
  604.     DIALOGMAIN="$DIALOGMAIN
  605.     <hbox>
  606.      <text><label>\"$DEVP1A1
  607. ${SIZEP1A1}M $FSP1A1\"</label></text>
  608.      <button>
  609.       <input file>/usr/local/lib/X11/pixmaps/da24red.xpm</input>
  610.       <action>Exit:${DEVP1A1}_XXX_RED</action>
  611.      </button>
  612.     </hbox>"
  613.    fi
  614.   fi
  615.  fi
  616.  DIALOGMAIN="$DIALOGMAIN </frame>"
  617. fi
  618. CHECKA2=""
  619. if [ "$DACC2" ];then #in case it is removed.
  620.  DEVDACC2="`echo -n "$DACC2" | cut -f 1 -d '|'`"
  621.  CHECKA2="`echo "$PARTINFO" | grep "$DEVDACC2"`"
  622. fi
  623. if [ "$CHECKA2" ];then
  624.  DEVDACC2="`echo -n "$DACC2" | cut -f 1 -d '|'`"
  625.  DESCRDACC2="`echo -n "$DACC2" | cut -f 3 -d '|'`"
  626.  INFODACC2="`fdisk -l $DEVDACC2 | head -n 2 | tail -n 1 | cut -f 1 -d ','`"
  627.  DIALOGMAIN="$DIALOGMAIN <frame $INFODACC2, $DESCRDACC2>"
  628.  PARTSDACC2="`echo "$PARTINFO" | grep "$DEVDACC2"`"
  629.  if [ "$PARTSDACC2" ];then
  630.   NUMLINES=`echo "$PARTSDACC2" | wc -l | tr -s ' ' | cut -f 2 -d ' '`
  631.   while [ $NUMLINES -gt 0 ];do
  632.    [ $NUMLINES -eq 1 ] && PART1DACC2="`echo -n "$PARTSDACC2" | tail -n 1 | head -n 1`"
  633.    NUMLINES=`expr $NUMLINES - 1`
  634.   done
  635.   if [ "$PART1DACC2" ];then
  636.    DEVP1A2="`echo -n "$PART1DACC2" | cut -f 1 -d '|'`"
  637.    MNTP1A2="`mount | grep "$DEVP1A2" | cut -f 3 -d ' '`"
  638.    FSP1A2="`echo "$PARTINFO" | grep "$DEVP1A2" | cut -f 2 -d '|'`"
  639.    SIZEP1A2="`echo "$PARTINFO" | grep "$DEVP1A2" | cut -f 3 -d '|'`"
  640.    if [ "$MNTP1A2" ];then
  641.     DIALOGMAIN="$DIALOGMAIN
  642.     <hbox>
  643.      <text><label>\"Mounted on $MNTP1A2
  644. DO NOT UNPLUG DRIVE\"</label></text>
  645.      <text><label>\"   \"</label></text>
  646.      <text><label>\"$DEVP1A2
  647. ${SIZEP1A2}M $FSP1A2\"</label></text>
  648.      <button>
  649.       <input file>/usr/local/lib/X11/pixmaps/da24green.xpm</input>
  650.       <action>Exit:${DEVP1A2}_${MNTP1A2}_GREEN</action>
  651.      </button>
  652.     </hbox>"
  653.    else
  654.     DIALOGMAIN="$DIALOGMAIN
  655.     <hbox>
  656.      <text><label>\"$DEVP1A2
  657. ${SIZEP1A2}M $FSP1A2\"</label></text>
  658.      <button>
  659.       <input file>/usr/local/lib/X11/pixmaps/da24red.xpm</input>
  660.       <action>Exit:${DEVP1A2}_XXX_RED</action>
  661.      </button>
  662.     </hbox>"
  663.    fi
  664.   fi
  665.  fi
  666.  DIALOGMAIN="$DIALOGMAIN </frame>"
  667. fi
  668. #########USB DRIVE############
  669.  
  670. #prevent some partitions from being unmounted...
  671. NUMLINES=`echo "$DIALOGMAIN" | wc -l | tr -s " " | cut -f 2 -d " "`
  672. REDUCELIST="$DIALOGMAIN"
  673. while [ ! $NUMLINES -eq 0 ];do
  674.  HEAD1ST="`echo "$REDUCELIST" | head -n 1`"
  675.  NUMLINES=`expr $NUMLINES - 1`
  676.  REDUCELIST="`echo -n "$REDUCELIST" | tail -n $NUMLINES`"
  677.  if [ "`echo -n "$HEAD1ST" | grep "_GREEN"`" = "" ];then
  678.   NEWDIALOGMAIN="$NEWDIALOGMAIN
  679. $HEAD1ST"
  680.  else
  681.   #HMNTPT="`echo -n "$HEAD1ST" | cut -f 2 -d ':' | cut -f 2 -d '_'`"
  682.   #v2.0.0...
  683.   HMNTPT="`echo -n "$HEAD1ST" | cut -f 2 -d ':' | cut -f 2 -d '_' | cut -f 2 -d '/'`"
  684.   case $HMNTPT in
  685.   #v2.0.0 replaced those below with just this...
  686.   "initrd")
  687.    NEWDIALOGMAIN="$NEWDIALOGMAIN
  688. <visible>disabled</visible>
  689. $HEAD1ST"
  690.    ;;
  691. #  "/root")
  692. #   NEWDIALOGMAIN="$NEWDIALOGMAIN
  693. #<visible>disabled</visible>
  694. #$HEAD1ST"
  695. #   ;;
  696. #  "/mnt/pupxxx")
  697. #   NEWDIALOGMAIN="$NEWDIALOGMAIN
  698. #<visible>disabled</visible>
  699. #$HEAD1ST"
  700. #   ;;
  701. #  "/mnt/home")
  702. #   if [ -f /etc/multisessionmediatype ];then
  703. #    NEWDIALOGMAIN="$NEWDIALOGMAIN
  704. #$HEAD1ST"
  705. #   else
  706. #    NEWDIALOGMAIN="$NEWDIALOGMAIN
  707. #<visible>disabled</visible>
  708. #$HEAD1ST"
  709. #   fi
  710. #   ;;
  711.   *)
  712.    NEWDIALOGMAIN="$NEWDIALOGMAIN
  713. $HEAD1ST"
  714.    ;;
  715.   esac
  716.  fi
  717. done
  718. DIALOGMAIN="$NEWDIALOGMAIN"
  719.  
  720. #bring up the gui...
  721. DIALOGMAIN="$DIALOGMAIN
  722.  <hbox>
  723.   <button><input file>/usr/local/lib/X11/mini-icons/mini-turn.xpm</input><label>REFRESH</label></button>
  724.   <button><input file>/usr/local/lib/X11/mini-icons/mini.checkmark.xpm</input><label>QUIT</label></button>
  725.  </hbox>
  726. </vbox>"
  727. echo "$DIALOGMAIN" > /tmp/pmountdlg.txt
  728. RETSTRING="`echo "$DIALOGMAIN" | gtkdialog2 --stdin`"
  729.  
  730. echo "$RETSTRING" #to console
  731. [ ! "`echo "$RETSTRING" | grep "EXIT" | grep "abort"`" = "" ] && break #exit BIGLOOP v2.0.0
  732. [ ! "`echo "$RETSTRING" | grep "QUIT"`" = "" ] && break #exit BIGLOOP
  733.  
  734. ABUTTON="`echo "$RETSTRING" | grep "EXIT:" | cut -f 2 -d ':'`"
  735. [ "$ABUTTON" = "" ] && continue #restart BIGLOOP
  736. ADEVICE="`echo -n "$ABUTTON" | cut -f 1 -d '_'`"
  737. AMNTPT="`echo -n "$ABUTTON" | cut -f 2 -d '_'`"
  738. ASTATUS="`echo -n "$ABUTTON" | cut -f 3 -d '_'`"
  739. AFSYS="`echo "$PARTINFO" | grep "$ADEVICE" | cut -f 2 -d '|'`"
  740. if [ "$AFSYS" = "none" ];then
  741.  if [ ! "`echo "$PARTINFO" | grep "$ADEVICE" | grep -i "ntfs"`" = "" ];then
  742.   AFSYS="ntfs"
  743.  fi
  744. fi
  745. if [ "$AFSYS" = "msdos" ];then
  746.  AFSYS="vfat"
  747. fi
  748.  
  749. #v2.0.0
  750. if [ "$AFSYS" = "" ];then
  751.  fsfunc "`disktype $ADEVICE | grep "file system" | grep "^[a-zA-Z]" | head -n 1 | cut -f 1 -d " "`"
  752.  AFSYS="$FSTYPE"
  753. fi
  754.  
  755. if [ "$ASTATUS" = "GREEN" ];then
  756.  #need to unmount a partition...
  757.  CURRENTMNT="$AMNTPT"
  758.  rox -D "$CURRENTMNT"
  759.  sync
  760.  umount $ADEVICE
  761.  FTRY=$?
  762.  MNTATTEMPT="unmount"
  763.  if [ $FTRY -eq 0 ];then
  764.   [ ! "`echo -n "$CDROMS" | grep "$ADEVICE"`" = "" ] && /usr/bin/eject $ADEVICE
  765.  fi
  766. else
  767.  if [ "$AMNTPT" = "XXX" ];then
  768.   xADEVICE="`echo -n "$ADEVICE" | cut -f 3 -d '/'`"
  769.   AMNTPT="/mnt/$xADEVICE"
  770.  fi
  771.  #special case...
  772.  if [ -f /etc/multisessionmediatype ];then
  773.   if [ "$BURNERDEVICE" = "$ADEVICE" ];then
  774.    [ "`mount | grep "/mnt/home"`" = "" ] && AMNTPT="/mnt/home"
  775.   fi
  776.  fi
  777.  [ ! -d $AMNTPT ] && mkdir $AMNTPT
  778.  if [ "$AFSYS" = "ntfs" ];then
  779.   mount -r -t $AFSYS $ADEVICE $AMNTPT
  780.  else
  781.   mount -t $AFSYS $ADEVICE $AMNTPT
  782.  fi
  783.  FTRY=$?
  784.  MNTATTEMPT="mount"
  785.  CURRENTMNT="$AMNTPT"
  786. fi
  787.  
  788.  
  789. if [ ! $FTRY -eq 0 ];then #=1 if failed
  790.  EXTRAMSG0="`fuser -v -m $CURRENTMNT`"
  791.  if [ "$EXTRAMSG0" = "" ];then
  792.   xmessage -bg "#ff8080" -title "Puppy drive mounter: ERROR" -center "FAILURE! In the case of removable media, the most
  793. common reason is the media is not currently inserted.
  794. If so, please remedy."
  795.  else
  796.   if [ "$MNTATTEMPT" = "unmount" ];then #have failed attempt to unmount...
  797.    xmessage -bg "#ff00ff" -title "KILL, KILL..." -center -buttons KILL:10,EXIT:20 "FAILURE! One or more processes (programs) are currently
  798. using the partition. Here they are:
  799. $EXTRAMSG0
  800.  
  801. If you press the \"KILL\" button, Puppy will attempt to
  802. kill the offending programs for you. Only do this as a
  803. last resort. Firstly you should try to close the programs
  804. manually, so do not press \"KILL\".
  805. PLEASE PRESS THE \"EXIT\" BUTTON!"
  806.    if [ $? -eq 10 ];then
  807.     fuser -k -m $CURRENTMNT
  808.    fi
  809.   else #have failed attempt to mount.
  810.   xmessage -bg "#ff8080" -title "Puppy drive mounter: ERROR" -center "FAILURE! In the case of removable media, the most
  811. common reason is the media is not currently inserted.
  812. Or, you forgot to unmount the previously inserted media.
  813. If so, please remedy."
  814.   fi
  815.  fi
  816. else
  817.  if [ "$MNTATTEMPT" = "mount" ];then
  818.   #comes here if have just successfully mounted a partition.
  819.   #launch rox
  820.   rox -d "$CURRENTMNT" &
  821.  fi
  822. fi
  823.  
  824. done #BIGLOOP
  825.  
  826. #killall disk.tcl
  827. ###END###
  828.