#!/bin/sh
#(c) Copyright 2008 Barry Kauler, puppylinux.com
#2008 Lesser GPL licence v2 (see /usr/share/doc/legal)
#/sbin/pup_event_frontend_d creates a desktop icon and copy of this script for each drive, ex:
# for drive sda: cp -a /usr/local/bin/drive_all /root/.pup_event/drive_sda/AppRun
#this script is launched by pup_event_frontend_d when the icon is first created. also,
#this script is launched when user clicks on deskop icon (former is configurable,
# see /usr/sbin/eventmanager.
#passed param is category of drive: card, floppy, optical, usbdrv, drive.
#v4.0.2 jun08: first write of this script, expanding 'pup_eventd' management.
#v403 icon menu, can call with 'unmount', 'eventmanager' and 'pmount_<DRV_CATEGORY>' params.
#v411 added 'quiet' option for vfat, suppresses error msg when file attribs not preserved on copy.
#w002 left click to unmount a partition.
#w476 fix codepage for vfat f.s.
# 13jun09 by Masaki Shinomiya <shino@pos.to> vfat and so9660 - utf8 option as the default
# 15jun09 : look up /etc/codepage only for vfat utf8 option
# 27jun09 : vfat mount options by Masaki Shinomiya <shino@pos.to>
# 30jun09 I18N
# 08jul09 looking up ONDRVNAME, ask to remove CD
# 16jul09 not ask to remove CD, only open tray
#v424 have added right-click menu item to unmount all partitions (see pup_event_frontend_d)...
#v424 have removed this dlg box. maybe make it optional in the future...
#091223 extra check for invalid desktop drive icon.
#100118 optional defaultcdplayer, defaultdvdplayer.
#100127 codepage fixes. 100131 iso9660 fix.
#100706 BK: bug fixes, introduced with i81n support.
#100719 BK: correct detection of DVD vidoe and launching mediaplayer.
#110126 support /dev/hd* optical device nodes.
#110505 support sudo for non-root user.
#110720 should not open a layer inside aufs, ex: session saved entire partition, desktop drive icon is /initrd/pup_rw.
#110721 detect if have clicked on a close-box of mounted partition.
#120110 running as fido, popup password box changes mouse pointer position, need read before run sudo.
#120129 karl godt: fix ZOMBIES, see http://murga-linux.com/puppy/viewtopic.php?t=71767&start=420. see also rc.shutdown, pmount, pup_event_frontend_d.
#120323 partial replace 'xmessage' with 'pupmessage'.
#120516 pup_event_frontend_d may call here when a drive plugged in, fix handling of automounting.
#120517 syntax error in 120516, quotes needed.
#130128 convert i18n "technosaurus-method" to gettext.
#130128 optical media, if has a f.s., can be either iso9660 or udf (see updated probepart and pup_event_frontend_d).
#130203 change probedisk2 to probedisk.
#130216 add support f2fs.

export TEXTDOMAIN=drive_all
export OUTPUT_CHARSET=UTF-8
. gettext.sh

[ ! -f /tmp/desktop_drives_curpos ] && getcurpos > /tmp/desktop_drives_curpos #120110
[ "`whoami`" != "root" ] && exec sudo -A ${0} ${@} #110505
CURPOS="`cat /tmp/desktop_drives_curpos`" #120110
rm -f /tmp/desktop_drives_curpos #120110

export LANG	# need to restart pmount with correct locale

#w002 extracted as a func...
unmount_func() {
 rox -D $MNTPT
 sync
 while [ 1 ];do
  umount $MNTPT ; umVAL=$?
  #fix zombie process prevents partition unmount, invisible to fuser...
  if [ $umVAL -ne 0 ];then
   #120129 karl godt: fix ZOMBIES, see http://murga-linux.com/puppy/viewtopic.php?t=71767&start=420 ...
    ZOMBIES="`ps -H -A | grep '<defunct>' | sed 's/^[[:blank:]]*//;s/  /|/g' | grep -v '|||' | cut -f 1 -d ' ' | tr '\n' ' '`"
   for ONEZOMBIE in $ZOMBIES
   do
    echo "Killing parentless zombie process $ONEZOMBIE"
    kill $ONEZOMBIE
   done
   umount $MNTPT ; umVAL=$?
  fi
  #rare ocassion, partition got unmounted before umount runs above...
  umPATTERN="${MNTPT} "
  [ "`busybox mount | grep "$umPATTERN"`" = "" ] && umVAL=0
  if [ $umVAL -ne 0 ];then
   EXTRAMSG0="`fuser -v -m $MNTPT`"  
   if [ "$EXTRAMSG0" = "" ];then
    pupmessage -bg "#ff8080" -title "$(gettext 'Puppy drive manager: ERROR')" -center "$(gettext 'FAILURE! In the case of removable media, the most
common reason is the media is not currently inserted.
If so, please remedy.')"
   else
    xmessage -bg "#ff99ff" -title "$(gettext 'Puppy drive manager: FAIL')" -center -buttons "$(gettext 'KILL')":10,"$(gettext 'EXIT')":20 "$(gettext 'FAILURE!')
$(gettext 'One or more processes (programs) are currently
using the partition. Here they are:')
${EXTRAMSG0}

$(gettext "If you press the 'KILL' button, Puppy will attempt to
kill the offending programs for you. Only do this as a
last resort.")
$(gettext "Firstly you should try to close the programs
manually, so do not press 'KILL'.")
$(gettext "PLEASE PRESS THE 'EXIT' BUTTON!")"

    if [ $? -eq 10 ];then
     fuser -k -m $MNTPT
     continue
    fi
   fi
  else
   [ "$DRV_CATEGORY" = "optical" ]  && eject_cd /dev/$ONEDRVNAME
  fi
  break
 done
}

eject_cd ()
{
	eject $1
}

FSTYPE=""
[ $2 ] && FSTYPE="$2" #see pup_event_frontend_d.
PARAM1=""
[ $1 ] && PARAM1="$1"

#extract drive name from end of the script name...
#note, when click on desktop icon, /root/.pup_event/drive_<ONEDRVNAME> is executed,
#however a script may run /root/.pup_event/drive_<ONEDRVNAME>/AppRun ...
ONEDRVNAME=$(dirname $0|sed -e 's/^.*_//')
if [ "`echo "${PARAM1}" | grep 'pmount_'`" != "" ];then #v403 chose pmount from drive icon menu.
 DRV_CATEGORY="`echo -n "${PARAM1}" | cut -f 2 -d '_'`"
 if [ "`pidof gtkdialog_pmount`" != "" ];then #if pmount running, kill it.
  killall gtkdialog_pmount 2>/dev/null
  sleep 0.1
 fi
 exec pmount ${DRV_CATEGORY}
fi

#110721 detect if have clicked on a close-box of mounted partition...
#when left-click desktop icon, param1 passed this script: drive|card|floppy|optical|usbdrv
# and param2 has the fs type...
case $PARAM1 in
 drive|card|floppy|optical|usbdrv)
  mPATTERN='^/dev/'"$ONEDRVNAME"' '
  MNTPT="`df -a| grep -m1 "$mPATTERN" | tr -s ' ' | cut -f 6 -d ' '`" #140702 shinobar
  if [ "$MNTPT" ];then
   #get coords of desktop icon...
   drPTN=">/root/.pup_event/drive_${ONEDRVNAME}<"
   PPENTRY="`grep "$drPTN" /root/Choices/ROX-Filer/PuppyPin`"
   if [ "$PPENTRY" ];then
    xleft="`echo -n "$PPENTRY" | grep -o ' x="[0-9]*"' | cut -f 2 -d '"'`" #'geany
    ytop="`echo -n "$PPENTRY" | grep -o ' y="[0-9]*"' | cut -f 2 -d '"'`" #'geany
    CURPOSX=`echo -n "$CURPOS" | cut -f 1 -d ' '`
    CURPOSY=`echo -n "$CURPOS" | cut -f 2 -d ' '`
    #hmmm, have to apply correction to cursor position...
    CURPOSX=$(($CURPOSX + 24))
    CURPOSY=$(($CURPOSY + 32))
    xcloseleft=$(($xleft + 35)) #close-box is 13x13 pixels, want bigger pickup area.
    xcloseright=$(($xleft + 53))
    yclosetop=$(($ytop - 5))
    yclosebottom=$(($ytop + 13))
    if [ $CURPOSX -ge $xcloseleft ];then
     if [ $CURPOSX -le $xcloseright ];then
      if [ $CURPOSY -ge $yclosetop ];then
       if [ $CURPOSY -le $yclosebottom ];then
        PARAM1="unmount"
       fi
      fi
     fi
    fi
   fi
  fi
 ;;
esac

if [ "$PARAM1" = "eventmanager" ];then #v403 chosen from drive icon menu.
 #v405 'desktop' param, cutdown tabs for desktop drive icons only...
 exec eventmanager desktop
fi

if [ "$PARAM1" = "unmount" ];then #v403 chose unmount from drive icon menu.
 mPATTERN='^/dev/'"$ONEDRVNAME"' '
 MNTPT="`df -a| grep -m1 "$mPATTERN" | tr -s ' ' | cut -f 6 -d ' '`" #140702 shinobar
 DRV_CATEGORY=""
 PROBEDISK="probedisk"
 DRV_CATEGORY=$($PROBEDISK | grep "^/dev/$ONEDRVNAME|" | cut -d'|' -f 2)
 echo "$DRV_CATEGORY" | grep '^cd' && DRV_CATEGORY="optical"
 [ "$MNTPT" = "" ] && [ "$DRV_CATEGORY" = "optical" ] && eject_cd /dev/$ONEDRVNAME
 [ "$MNTPT" = "" ] && exit #precaution.
 if [ "$MNTPT" = "/" -o "`echo "$MNTPT" | grep '/initrd/'`" != "" ];then
  pupmessage -bg "#ff8080" -title "$(gettext 'Puppy drive manager')" -center "$(eval_gettext "/dev/\${ONEDRVNAME} mounted on \${MNTPT}
is in use by Puppy. You cannot unmount it.")"
  exit
 fi
 unmount_func
 exit
fi

#v424 have added right-click menu item to unmount all partitions (see pup_event_frontend_d)...
if [ "$PARAM1" = "unmountall" ];then
 for MNTPT in `mount | grep '^/dev/' | grep -vE '^/dev/loop|^/dev/ram' | cut -f 3 -d ' ' | grep -v '^/initrd/' | grep -v '^/$' | tr '\n' ' '`
 do
  unmount_func
 done
 exit
fi

DRV_CATEGORY="${PARAM1}"
[ "$DRV_CATEGORY" = "" ] && DRV_CATEGORY="drive" #precaution.
[ "$DRV_CATEGORY" = "all" ] && DRV_CATEGORY="drive" #precaution.

[ -f /etc/eventmanager ] && . /etc/eventmanager #written by /usr/sbin/eventmanager
[ "$ICONDESK" != "true" -a "$ICONDESK" != "false" ] && ICONDESK="true"
[ ! $RAMSAVEINTERVAL ] && RAMSAVEINTERVAL=30
[ "$HOTPLUGNOISY" != "true" -a "$HOTPLUGNOISY" != "false" ] && HOTPLUGNOISY="false"
[ "$AUTOTARGET" != "true" -a "$AUTOTARGET" != "false" ] && AUTOTARGET="true"
[ "$ICONPARTITIONS" != "true" -a "$ICONPARTITIONS" != "false" ] && ICONPARTITIONS="true"

#if ICONDESK=false (see /etc/eventmanager and /sbin/pup_eventd) then there will only
#be one icon on the desktop, labelled 'drives' and handler script is /usr/local/bin/drive_drives
if [ "$ONEDRVNAME" = "drives" ];then
 if [ "`pidof gtkdialog_pmount`" != "" ];then #if pmount running, kill it.
  killall gtkdialog_pmount 2>/dev/null
  sleep 0.1
 fi
 exec pmount $DRV_CATEGORY
fi

#decision... we can bring up a "handler" window, that explains things, good for beginners.
#or jump direct to most appropriate target application, or do nothing.
#for now only have AUTOTARGET=true go direct to most appropriate target app,
# =false always start Pmount.
if [ "$AUTOTARGET" = "false" ];then
 if [ "`pidof gtkdialog_pmount`" != "" ];then #if pmount running, kill it.
  killall gtkdialog_pmount 2>/dev/null
  sleep 0.1
 fi
 exec pmount $DRV_CATEGORY
fi

#oh, now have to analyse the media, decide what app to run...
dPATTERN='^/dev/'"$ONEDRVNAME"' '
FLAGOPTICAL='no'
case $ONEDRVNAME in #110126
 sr*)
  FLAGOPTICAL='yes'
 ;;
 hd*)
  [ -e /proc/ide/$ONEDRVNAME/media ] && [ "`cat /proc/ide/$ONEDRVNAME/media`" = "cdrom" ] && FLAGOPTICAL='yes'
 ;;
esac

if [ "$FLAGOPTICAL" = "yes" ];then
	
	if [ "`busybox mount | grep "$dPATTERN"`" = "" ]; then
	
		DRIVEINFO="$(dvd+rw-mediainfo /dev/${ONEDRVNAME})"
		EXITCODE=$?
		DRIVETYPE="$(echo "$DRIVEINFO" | grep 'INQUIRY:')"
		
		echo "/dev/${ONEDRVNAME} filesystem: $FSTYPE "
		echo "dvd+rw-mediainfo exit code: $EXITCODE"
		echo "${DRIVETYPE}"
		
		case $EXITCODE in
			150)
				# :-( not a DVD unit
				[[ ${DRIVETYPE} == *CD-R* ]] && CDR="true"
				;;		
			251)
				# :-( no media mounted
				# cd/dvd might be blank
				DISK=`cddetect_quick -d/dev/${ONEDRVNAME}`
				if [ "$DISK" = "disc inserted" ];then
					# might be and old dvd drive and the disc a DVD9/DL-DVD
					echo "===================================="
					echo "* The disc in /dev/${ONEDRVNAME} is blank (or may be unsupported by your dvd drive)..."
					echo "===================================="
					#WARNINGDVD="true"
					msg="The disc in /dev/${ONEDRVNAME} is blank \n\n (or may be the case that is not supported by your dvd drive, \ncould be a double-layer DVD, and your dvd drive too old...)"
					yad --title="Blank disk" --center --button="Run pBurn:0" --button="gtk-close:1" --text="$msg"
					[ $? -ne 0 ] && exit 1
					BURNER="xmessage 'no burner?'"
					type pburn &>/dev/null && BURNER=pburn
					exec "$BURNER"
				fi
				;;					
			252) 
				# :-( non-DVD media mounted
				CDR="true"
				;;
		esac
		
		####### CDS ########
		if [ "$CDR" ] ; then
			cddetect -d/dev/${ONEDRVNAME} #-q
			RETVAL=$?
			echo "cddetect exit code: $RETVAL"
			case $RETVAL in
				2|3) #iso file: normal data cd.
					true
					;;
				6|7|8) #VCD|SVCD|UVCD
					echo "/dev/${ONEDRVNAME}: VCD (most likely)"
					ln -snf /dev/${ONEDRVNAME} /dev/dvd
					exe2use='/usr/local/bin/defaultmediaplayer'
					[ -f /usr/local/bin/defaultdvdplayer ] && exe2use='/usr/local/bin/defaultmediaplayer'
					[ "$(grep 'exec vlc' ${exe2use})" ] && exec ${exe2use} vcd:///dev/dvd
					[ "$(grep 'exec mplayer' ${exe2use})" ] && exec ${exe2use} vcd://2 -cdrom-device /dev/dvd
					exec ${exe2use} vcd://
					;;
				1|50) 
					#1) audio 
					#50) mixed. we don't want to mount it but we'll see if it plays
					ln -snf /dev/${ONEDRVNAME} /dev/cdrom
					exe2use='/usr/local/bin/defaultmediaplayer'
					[ -f /usr/local/bin/defaultcdplayer ] && exe2use='/usr/local/bin/defaultcdplayer'
					[ "$(grep 'exec deadbeef' ${exe2use})" ] && exec ${exe2use} all.cda
					exec ${exe2use} cdda://
					;;
				255) #might be blank, double check it's there #140712
					msg="The disc in /dev/${ONEDRVNAME} is blank (most likely)\n\n(if you know it's not blank then the CD might be damaged...)\n"
					yad --title="Blank disk" --center --button="Run pBurn:0" --button="gtk-close:2" --text="$msg" 
					[ $? -ne 0 ] && echo "User cancelled operation" && exit 1
					DISK=`cddetect_quick -d/dev/${ONEDRVNAME}`
					if [ "$DISK" = "disc inserted" ];then
						BURNER="xmessage 'no burner?'"
						type pburn &>/dev/null && BURNER=pburn
						exec "$BURNER"
					fi
					;;
			esac
		fi
		
		####### DVDs and more ######
		#if [[ ${DRIVETYPE} == *DVD* ]] ; then
		if [ ! "$CDR" ] ; then
			# check if it's blank
			ITSBLANK=$(echo "$DRIVEINFO" | grep -i 'Disc status:' | grep -i 'blank')
			if [ "$ITSBLANK" ] ; then
				yad --title="Blank disk" --center --button="Run pBurn:0" --button="gtk-close:1" --text="  The disc in /dev/${ONEDRVNAME} is blank                    "
				[ $? -ne 0 ] && exit 1
				echo "/dev/${ONEDRVNAME}: DVD is blank"
				BURNER="xmessage 'no burner?'"
				type pburn &>/dev/null && BURNER=pburn
				exec "$BURNER"				
			else
				# only test if not mounted.
				if [ "$(df | grep "$dPATTERN")" = "" ];then 
					# mount and look for 'video_ts' directory (dir should contain file video_ts.ifo)...
					echo "Trying to mount /dev/${ONEDRVNAME}"
					mkdir -p /mnt/${ONEDRVNAME}
					mount -t udf -o iocharset=utf8 /dev/${ONEDRVNAME} /mnt/${ONEDRVNAME}
					RETVALX=$?
					if [ ${RETVALX} -ne 0 ] ; then
						mount -t iso9660 -o iocharset=utf8 /dev/${ONEDRVNAME} /mnt/${ONEDRVNAME}
						RETVALX=$?
					fi
					if [ ${RETVALX} -eq 0 ]; then
						if [ -d /mnt/${ONEDRVNAME}/video_ts -o -d /mnt/${ONEDRVNAME}/VIDEO_TS ] ; then
							FLAGDVDVIDEO="yes"
							umount /mnt/${ONEDRVNAME}
						else
							OPTICALMOUNTED="true"
						fi
					else
						OPTICALMOUNTED="true"
					fi
					if [ "$FLAGDVDVIDEO" != "" ];then
						echo "/dev/${ONEDRVNAME}: DVD Video detected"
						ln -snf /dev/${ONEDRVNAME} /dev/dvd
						exe2use='/usr/local/bin/defaultmediaplayer'
						[ -f /usr/local/bin/defaultdvdplayer ] && exe2use='/usr/local/bin/defaultmediaplayer'
						[ "$(grep 'exec mplayer' ${exe2use})" != "" ] && exec ${exe2use} dvdnav:// #140712 ^exec
						exec ${exe2use} dvd://
					fi
				fi
			fi
			[ ! "$WARNINGDVD" ] && echo "/dev/${ONEDRVNAME}: data DVD (most likely)"
		#else
		fi
	fi
	
	# 130128 probepart now detects udf, FSTYPE should already be set to that...
	[ "$FSTYPE" != "udf" ] && FSTYPE="iso9660" # would already have been iso9660 anyway.
fi

#if dropped down here, it is likely to be a data partition...

#120516 pup_event_frontend_d may call here when a drive plugged in, but only passes one parameter (PARAM1). want FSTYPE also...
# also, for AUTOTARGET=true in /etc/eventmanager will come here, and a plugged in drive may be more than one partition to automount...
if [ "$FSTYPE" != "" ];then
 DOPARTS="${ONEDRVNAME}|${FSTYPE}" #120517
else
 #ONEDRVNAME is probably a drive name, ex sda...
 pPTN="/dev/${ONEDRVNAME}" #no space on end!
 DOPARTS="`probepart -m | grep "$pPTN" | cut -f 1,2 -d '|' | cut -f 3 -d '/' | grep -E 'btrfs|ext2|ext3|ext4|f2fs|hfs|iso9660|jfs|minix|msdos|ntfs|reiser|udf|vfat|xfs' | tr '\n' ' '`" #ex: sda1|ext3 sda2|vfat sda3|ext3  130216 added f2fs	# SFR: enabled jfs & hfs
fi

#if it is a mountable partition then mount and open with rox. If already mntd then open in rox...
EXITFLAG=no
for ONEDO in $DOPARTS
do
 xONEDRVNAME="`echo -n "$ONEDO" | cut -f 1 -d '|'`"
 xFSTYPE="`echo -n "$ONEDO" | cut -f 2 -d '|'`"
 if [ "`df | grep "$dPATTERN"`" = "" ];then
  #not mounted...
  mkdir -p /mnt/$xONEDRVNAME
  case $xFSTYPE in
   ntfs)
    #'mount' is a script that takes care of mounting ntfs...
    mount -t ntfs /dev/$xONEDRVNAME /mnt/$xONEDRVNAME
    RETVAL1=$?
    ;;
   vfat)
    #w476 modify codepage and iocharset (note: this code also in /usr/sbin/pmount)...
    #note, could also set iocharset=iso8859-2 (default: codepage=437, iocharset=iso8859-1)
    # 27jul09 lookup /etc/codepage and LANG by Masaki Shinomiya <shino@pos.to>
    NLS_PARAM=""
    if [ -f /etc/codepage ]; then #100127...
     grep -q -i '850' /etc/codepage && [ "$(echo $LANG|cut -d'.' -f1)" != "en_US" ] && NLS_PARAM=",codepage=850"
     grep -q -i '852' /etc/codepage && NLS_PARAM=",codepage=852,iocharset=iso8859-2"
    fi
    echo $LANG | grep -q -i '\.utf' && NLS_PARAM="$NLS_PARAM,utf8"
    mount -t vfat -o shortname=mixed,quiet${NLS_PARAM} /dev/$xONEDRVNAME /mnt/$xONEDRVNAME #v411
    RETVAL1=$?
    ;;
   #100127 not certain about this (inserted by shinobar)... 100131 shinobar informs needed for cds created in windows...
   
   iso9660|udf) # 130128 add udf.
		#jlst:::::::::::::::::::
		if [ "$OPTICALMOUNTED" ] ; then 
			RETVAL1=${RETVALX}
		else
			# jlst: always try to mount as udf first, no matter what...
			echo "* Trying to mount /dev/$xONEDRVNAME as udf"
			mount -t udf -o iocharset=utf8 /dev/$xONEDRVNAME /mnt/$xONEDRVNAME 
			RETVAL1=$?
			if [ $RETVAL1 -ne 0 ] && [ "$xFSTYPE" != "udf" ] ; then
				echo "* Trying to mount /dev/$xONEDRVNAME as $xFSTYPE"
				mount -t $xFSTYPE -o iocharset=utf8 /dev/$xONEDRVNAME /mnt/$xONEDRVNAME
				RETVAL1=$?
			fi
		fi
		;;  
   *)
    mount -t $xFSTYPE /dev/$xONEDRVNAME /mnt/$xONEDRVNAME
    RETVAL1=$?
    ;;
  esac
  if [ $RETVAL1 -eq 0 ];then
   rox -x /mnt/$xONEDRVNAME -d /mnt/$xONEDRVNAME &
   EXITFLAG=yes
  else
   #091223 why did it fail?
   dd if=/dev/$xONEDRVNAME of=/dev/null bs=512 count=1 > /dev/null 2>&1
   if [ $? -ne 0 ];then
    #/tmp/pup_event_frontend_block_request is used in /sbin/pup_event_frontend_d to refresh drv...
    case $xONEDRVNAME in
     mmcblk*)
      yONEDRV="`echo -n "$xONEDRVNAME" | cut -c 1-7`"
     ;;
     *)
      yONEDRV="`echo -n "$xONEDRVNAME" | cut -c 1-3`"
     ;;
    esac
    echo "$yONEDRV" > /tmp/pup_event_frontend_block_request
   fi
  fi
 else
  #mounted...
  sddPATTERN='/dev/'"$ONEDRVNAME"' '
  MNTPT="`df -a| grep -m1 "$dPATTERN" | tr -s ' ' | cut -f6 -d ' '`" #140702 shinobar
  if [ -h /mnt/home ];then
   [ "`readlink /mnt/home`" = "$MNTPT" ] && MNTPT="/mnt/home"
  fi
  #110720 should not open a layer inside aufs, ex: session saved entire partition, desktop drive icon is /initrd/pup_rw...
  case $MNTPT in
   /initrd/pup_*)
    MNTPT="/" #open rox at top of aufs layers.
   ;;
  esac
  rox -x $MNTPT -d $MNTPT &
  EXITFLAG=yes
 fi
done
[ "$EXITFLAG" = "yes" ] && exit

#NOTE: if pmount already running, don't really want to kill then restart,
# just want to bring the window up if it's minimised ...how?

if [ "`pidof gtkdialog_pmount`" != "" ];then #if pmount running, kill it.
 killall gtkdialog_pmount 2>/dev/null
 sleep 0.1
fi

exec pmount ${DRV_CATEGORY}

###END###
