#!/bin/zsh

PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin

source /lib/dyne/wmaker.sh
source /lib/dyne/volumes.sh

# TODO:
# check that in the past happened hotplug event: usb_device
# if dmesg is hanging on "usb-storage: waiting"
# then wait for "usb-storage: device scan complete"
# scan for the new "SCSI device sd*"
# scan for partitions in sd??
# if not partitions present, pick MBR sd?
# if partitions present, pick the first (i.e. sda1)



notice "new storage device plugged"

# by default we don't do fsck on hotplugged devices
export fsck=false

/bin/pidof X
if ! [ $? = 0 ]; then
    act "X is not running, user confirmation skipped"
    scan_storage
    act "device scanned and mounted"
    unset fsck
    exit 0
fi

export MAIN_DIALOG="
<vbox>

<frame New storage device detected>

<hbox>

<pixmap>
  <input file>/usr/share/icons/graphite/48x48/devices/gnome-dev-harddisk-usb.png</input>
</pixmap>

<text>
  <label>Do you want to scan and mount the storage device connected?</label>
</text>

</hbox>

</frame>

<hbox>

 <button ok></button>

 <button cancel></button>

</hbox>

</vbox>
"


eval `DISPLAY=:0.0 gtkdialog --program=MAIN_DIALOG`

if [ "$EXIT" = "OK" ]; then

    scan_storage hotplug
    
# popup rox filer on volumes
    DISPLAY=:0.0 launch rox /mnt

fi

unset fsck
    

