#!/bin/bash
# openbox pipe menu to [u]mount removable & view mounts
# (c) Denis Kaganovich, Anarchy or GPLv2
notify="/usr/bin/notify-send -t 6000"
xml(){
x="${x//&/&}"
x="${x//<}"
x="${x//>/>}"
x="${x//\'/'}"
x="${x//\"/"}"
}
_removable(){
[ "$DEVNAME" != "$d" -o -b "$d" ] || return 1
local x= i s=
for i in /sys/block/*/"$DEVNAME"; do
[ -e "$i" ] && s="${i/$DEVNAME}" && break
done
[ -z "$s" ] && s="/sys/block/$DEVNAME" && ! [ -e "$s" ] && return 1
read x <"$s/removable"
read model <"$s/device/model" || read model <"$s/device/name"
return 0
}
_umnt(){
autofs=false
while read d m t f x; do
model=
f=",$f,"
dd="$d"
case "$1:$2" in
/etc/fstab:mount)
[ "$UID" = 0 -o -z "${f##*,users,*}" -o -z "${f##*,user,*}" ] || continue
;;&
/etc/fstab:umount)
[ "$UID" = 0 -o -z "${f##*,users,*}" ] || continue
;;&
/etc/mtab:umount)
[ -z "${f##*,user=$USER,*}" ] || continue
;;&
/etc/fstab:*)
d1=
case "$d" in
UUID=*|LABEL=*)
d1="${d%%=*}"
d1="/dev/disk/by-${d1,,}/${d#*=}"
;;&
LABEL=*)
if ! [ -L "$d1" ]; then
d1=$(/bin/mount -nfv "$d" |& {
d1=
while read i; do
x="${i##*/dev/}"
[ "$x" = "$i" ] && continue
i="/dev/${x%% *}"
[ -b "$i" ] || continue
[ -n "$d1" -a "$d1" != "$i" ] && break
d1="$i"
done
echo -n "$d1"
})
echo "$d1"
fi
;;
esac
[ -n "$d1" ] && d="$d1"
[ -L "$d" ] && d=`readlink -f "$d"`
;;&
*:mount|*:umount)
DEVNAME="${d#/dev/}"
_removable || continue
;;&
*:fs)
case "$d $m $t" in
/var/run/auto.dev\ /mnt/auto/disk\ autofs)autofs=true;continue;;
*\ autofs)continue;;
*/*\ *\ *);;
*)continue;;
esac
DEVNAME="${d#/dev/}"
_removable
;;&
/etc/fstab:*)
d1=
while read d1 m1; do
[ "$d1" = "$d" ] && break
done "
;;
*:umount)x="'$d'";;&
*:mount)x="'$m'";;&
*)
xml
echo "