From 345d50c20b44e6b086d529decea0d1ca4ca7090e Mon Sep 17 00:00:00 2001 From: Robby Workman Date: Fri, 23 Apr 2010 14:42:27 -0500 Subject: More major upheaval in the code... * no more gvfs usage - that was a disaster * better handling of the notifications --- blueman-open | 146 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 78 insertions(+), 68 deletions(-) diff --git a/blueman-open b/blueman-open index f46d97a..0cfa688 100755 --- a/blueman-open +++ b/blueman-open @@ -1,98 +1,108 @@ #!/bin/sh # Blueman Mount Script for Slackware # by Zarren Spry & Robby Workman +# Based on http://kde-apps.org/content/show.php/kde4+bluetooth+files+open?content=108869 +# Set to 0 if you want more debugging messages +DEBUG=1 -DEBUG=${DEBUG:-"1"} -if [ ! -z $DEBUG ];then - dbg_msg="Check /var/log/messages for errors." -else - dbg_msg="Enable *DEBUG* for error log." -fi - -device_addr=$1 -device_name=$(hcitool name $device_addr) -own_name=$(basename $0) -basedir=${basedir:-$HOME/.gvfs} -dir=${basedir} +device_addr="$1" +device_name="$(hcitool name $device_addr)" +own_name="$(basename $0)" +basedir="${basedir:-$HOME/obexfs}" +mountpoint="${basedir}/${device_addr}" browser=${browser:-"xdg-open"} -max_tries=5 -# Check for kdialog -if which kdialog 1>/dev/null 2>/dev/null; then +# If we're running in kde, use kdialog +if [ "$KDE_FULL_SESSION" = "true" ]; then + if which kdialog 1>/dev/null 2>/dev/null; then messagetype="kdialog" -else + fi +# If not, then see if libnotify is available +# Even if it is, there may not be a notification daemon running, but there's +# no good way to check for this, so oh well... +elif which notify-send 1>/dev/null 2>/dev/null; then messagetype="libnotify" +# If no libnotify, then use kdialog if it's installed +elif which kdialog 1>/dev/null 2>/dev/null; then + messagetype="kdialog" +# If all else fails, just don't do notifications +else + messagetype="" fi # Mount function mount_device () { - loop=0 - while [ $loop -lt $max_tries ] - do - [ ! -z $DEBUG ] && logger -i -t $own_name "Perform $loop try to mount device $device_name to $dir using gvfs." - [ ! -z $DEBUG ] && logger -i -t $own_name "Execute: gvfs-mount obex://["$device_addr"]" - out=$(gvfs-mount obex://["$device_addr"] 2>&1) - [ ! -z $DEBUG ] && logger -i -t $own_name "$out" - mounts=$(ls $dir | grep $device_name) - [ ! -z $DEBUG ] && logger -i -t $own_name "Found $mounts mounted inside $dir" - - if [ "$mounts" = "$device_name" ] ;then - MSG_TXT="Successfully mounted $device_name to $dir" - if [ $messagetype == "kdialog" ]; then - kdialog --passivepopup "$MSG_TXT" 2 - elif [ $messagetype == "libnotify" ]; then - notify-send --expire-time=20000 --icon=blueman "$MSG_TXT" - fi - [ ! -z $DEBUG ] && logger -i -t $own_name "Open $dir/$device_name with $browser" - out=$($browser $dir/$device_name 2>&1) - [ ! -z $DEBUG ] && logger -i -t $own_name "$out" - exit 0 - else - [ ! -z $DEBUG ] && logger -i -t $own_name "Failed to mount $device_name to $dir/$device_name from try $loop " - if [ $loop -ne 4 ]; then - MSG_TXT="Attempt $loop to mount $device_name to $dir failed. Retrying, please wait ..." - else - MSG_TXT="Failed to mount $device_name to $dir. $dbg_msg" - fi - if [ $messagetype == "kdialog" ]; then - kdialog --passivepopup "$MSG_TXT" 3 - elif [ $messagetype == "libnotify" ]; then - notify-send --expire-time=20000 --icon=blueman "$MSG_TXT" - fi + [ ! -z $DEBUG ] && logger -i -t $own_name "Attempting to mount device $device_name to $mountpoint..." + [ ! -z $DEBUG ] && logger -i -t $own_name "Execute: obexfs -b $device_addr $mountpoint" + + mkdir -p $mountpoint + obexfs -b $device_addr $mountpoint 2>&1 + + if [ $? != 0 ]; then + MSG_TXT="Failed to mount $device_name to $mountpoint. $dbg_msg" + FAILZOR=definitely + if [ ! -z $DEBUG ]; then + logger -i -t $own_name "Failed to mount $device_name to $mountpoint." + fi + else + MSG_TXT="Successfully mounted $device_name to $mountpoint" + if [ ! -z $DEBUG ]; then + logger -i -t $own_name "Successfully mounted $device_name to $mountpoint." fi - sleep 2 - ((loop += 1)) - done + fi + + if [ $messagetype == "kdialog" ]; then + kdialog --passivepopup "$MSG_TXT" 2 + elif [ $messagetype == "libnotify" ]; then + notify-send --expire-time=20000 --icon=blueman "$MSG_TXT" + fi + + [ "$FAILZOR" = "definitely" ] && exit 1 + + [ ! -z $DEBUG ] && logger -i -t $own_name "Opening $mountpoint with $browser..." + $browser $mountpoint 2>&1 + } # Unmount function umount_device () { - mounts=$(ls $dir | grep $device_name) - if [ "$mounts" = "$device_name" ] ;then - [ ! -z $DEBUG ] && logger -i -t $own_name "Performing umount of $dir/$device_name." - out=$(gvfs-mount -u obex://[$device_addr] 2>&1) - [ ! -z $DEBUG ] && logger -i -t $own_name "$out" - if [ -d $dir/$device_name ] ;then - [ ! -z $DEBUG ] && logger -i -t $own_name "$device_name failed to unmount. Please perform its umount manually." - MSG_TXT="Failed to umount $dir - $dbg_msg" - if [ $messagetype == "kdialog" ]; then - kdialog --passivepopup "$MSG_TXT" 3 - elif [ $messagetype == "libnotify" ]; then - notify-send --expire-time=20000 --icon=blueman "$MSG_TXT" - fi + if grep -qw $mountpoint /proc/mounts 2>/dev/null ; then + [ ! -z $DEBUG ] && logger -i -t $own_name \ + "$mountpoint has something mounted on it already - unmounting it..." + + fusermount -u $mountpoint 1>/dev/null 2>/dev/null + + if [ $? != 0 ]; then + [ ! -z $DEBUG ] && logger -i -t $own_name "Failed to unmount $mountpoint with fusermount..." + umount -f $mountpoint 1>/dev/null 2>/dev/null + if [ $? != 0 ]; then + [ ! -z $DEBUG ] && \ + logger -i -t $own_name \ + "Failed to unmount $mountpoint with umount - try it manually as root and then start over." + FAILZOR=definitely + MSG_TXT="Failed to unmount $mountpoint with fusermount and umount - try it as root first." + else + break + fi else [ ! -z $DEBUG ] && logger -i -t $own_name "Successfully unmounted $device_name." fi else - [ ! -z $DEBUG ] && logger -i -t $own_name "$dir is not mounted - no need to perform umount..." + [ ! -z $DEBUG ] && logger -i -t $own_name "$mountpoint has nothing mounted on it - continuing..." + fi + + if [ $messagetype == "kdialog" ]; then + kdialog --passivepopup "$MSG_TXT" 3 + elif [ $messagetype == "libnotify" ]; then + notify-send --expire-time=20000 --icon=blueman "$MSG_TXT" fi + [ "$FAILZOR" = "definitely" ] && exit 1 } -# Main -MSG_TXT="Mount device is in progress... Please wait..." +MSG_TXT="Attempting to mount $device_name - please wait..." if [ $messagetype == "kdialog" ]; then kdialog --passivepopup "$MSG_TXT" 4 elif [ $messagetype == "libnotify" ]; then -- cgit v1.2.3