usbinstall.sh: use DeviceIsMounted property to check if device is already mounted at startup

This commit is contained in:
Silvan Calarco 2012-01-07 18:11:05 +01:00
parent 6a9f8d584d
commit 672c52e0a2

View File

@ -53,6 +53,13 @@ org.freedesktop.DBus.Properties.Get string:$3 string:$4`
return 0
}
function dbus_properties_get_bool() {
REPLY=`dbus-send --system --print-reply --dest=$1 $2 org.freedesktop.DBus.Properties.Get string:$3 string:$4`
[ $? -eq 0 ] || return 1
echo $REPLY | sed "s|.*boolean \(.*\)|\1|"
return 0
}
# Set progressbar
# Arg 1: value%
set_pbar()
@ -80,10 +87,16 @@ export SELECT_ISO=$3
set_status "Smonto la chiavetta"
LANG=C udisks --unmount ${SELECT_USB}1 | grep failed && {
DEVICEISMOUNTED=`dbus_properties_get_bool org.freedesktop.UDisks /org/freedesktop/UDisks/devices/${SELECT_USB/*\/}1 \
org.freedesktop.UDisks.Device DeviceIsMounted`
if [ "$DEVICEISMOUNTED" = "true" ]; then
LANG=C udisks --unmount ${SELECT_USB}1 | grep failed && {
echo "Error: fail to umount the usb key (${SELECT_USB}1)"
exit 1
}
}
fi
set_pbar 2
@ -92,7 +105,7 @@ sudo fdisk $SELECT_USB < ./fdisk_template
set_pbar 5
sudo mkfs.ext3 ${SELECT_USB}1 -L openmamba_live
sleep 1
udisks --mount ${SELECT_USB}1
LANG=C udisks --mount ${SELECT_USB}1
set_pbar 30
@ -130,7 +143,7 @@ set_pbar 98
set_status "Smonto la chiavetta"
udisks --unmount ${SELECT_USB}1 | grep failed && {
LANG=C udisks --unmount ${SELECT_USB}1 | grep failed && {
echo "Error: fail to umount the usb key (${SELECT_USB}1)"
exit 2
}