usbinstall: support for loop device installation and udisks2

This commit is contained in:
Silvan Calarco 2014-12-08 01:01:35 +01:00
parent 7bd135a19c
commit 9c5c860761

View File

@ -112,9 +112,11 @@ function errorAndExit()
if [ -n "$2" ]; then if [ -n "$2" ]; then
usage usage
fi fi
if [ "${SELECT_USB}" ]; then if [ "${SELECT_USB1}" ]; then
udisks --unmount ${SELECT_USB}1 >/dev/null udisksctl unmount -b ${SELECT_USB1} >/dev/null
udisks --unmount ${SELECT_USB}2 >/dev/null fi
if [ "${SELECT_USB2}" ]; then
udisksctl unmount -b ${SELECT_USB2} >/dev/null
fi fi
exit_frontend "$1" # Termina il frontend con codice di errore 1 exit_frontend "$1" # Termina il frontend con codice di errore 1
exit 1 exit 1
@ -157,9 +159,8 @@ fi
# Check if Arg 1 is valid # Check if Arg 1 is valid
if [ -b "$1" ]; then # If is a block device if [ -b "$1" ]; then # If is a block device
ISKEY=`dbus_properties_get_bool org.freedesktop.UDisks /org/freedesktop/UDisks/devices/${1/*\/} \ ISKEY=`udisksctl info -b $1 | grep HintSystem | sed "s|.*[[:space:]]||"`
org.freedesktop.UDisks.Device DeviceIsRemovable` if [ "$ISKEY" = "true" -o "$CONFIRM" = "0" ]; then # If is a usb
if [ "$ISKEY" = "true" ]; then # If is a usb
export SELECT_USB=$1 export SELECT_USB=$1
else # If not, user can choose else # If not, user can choose
echo $"Warning: you haven't choosen a removable device ($1). Are you sure to continue? [yes/no]" echo $"Warning: you haven't choosen a removable device ($1). Are you sure to continue? [yes/no]"
@ -177,6 +178,14 @@ else
errorAndExit $"Error(Arg 1): \"$1\" isn't a block device" 1 errorAndExit $"Error(Arg 1): \"$1\" isn't a block device" 1
fi fi
if [ "${SELECT_USB:0:9}" = "/dev/loop" ]; then
SELECT_USB1=${SELECT_USB}p1
SELECT_USB2=${SELECT_USB}p2
else
SELECT_USB1=${SELECT_USB}1
SELECT_USB2=${SELECT_USB}2
fi
# Check if Arg 2 is valid # Check if Arg 2 is valid
if [ -r "$2" ]; then # Check it is readable if [ -r "$2" ]; then # Check it is readable
# Check if Arg 2 is an iso file # Check if Arg 2 is an iso file
@ -190,8 +199,8 @@ fi
# Check if Arg 3 is valid # Check if Arg 3 is valid
if [ "$3" ]; then if [ "$3" ]; then
if [ "$3" != "-d" -a "$3" != "-t" ]; then # Check it is readable if [ "$3" != "-d" -a "$3" != "-y" ]; then # Check it is readable
errorAndExit $"Error(Arg 3): \"$3\" is not -d nor -t" 1 errorAndExit $"Error(Arg 3): \"$3\" is not -d nor -y" 1
fi fi
fi fi
@ -208,12 +217,11 @@ trap "[ \"$CPPID\" ] && kill -9 $CPPID" HUP INT QUIT ABRT KILL TERM
set_status $"Unmount usb device" set_status $"Unmount usb device"
echo $"Unmount usb device" echo $"Unmount usb device"
DEVICEISMOUNTED=`dbus_properties_get_bool org.freedesktop.UDisks /org/freedesktop/UDisks/devices/${SELECT_USB/*\/}1 \ DEVICEMOUNTPOINTS=`udisksctl info -b ${SELECT_USB1} | grep MountPoints: | sed "s|.*[[:space:]]||"`
org.freedesktop.UDisks.Device DeviceIsMounted`
if [ "$DEVICEISMOUNTED" = "true" ]; then if [ "$DEVICEMOUNTPOINTS" ]; then
LANG=C udisks --unmount ${SELECT_USB}1 | grep failed && { LANG=C udiskctl unmount -b ${SELECT_USB1} || {
errorAndExit $"Error: fail to umount the usb key (${SELECT_USB}1)" errorAndExit $"Error: fail to umount the usb key (${SELECT_USB1})"
} }
fi fi
set_pbar 2 set_pbar 2
@ -258,29 +266,28 @@ set_pbar 5
set_status $"Formatting $SELECT_USB..." set_status $"Formatting $SELECT_USB..."
echo $"Formatting $SELECT_USB..." echo $"Formatting $SELECT_USB..."
sudo mkfs.vfat ${SELECT_USB}1 -n EFI &>>$LOGFILE sudo mkfs.vfat ${SELECT_USB1} -n EFI &>>$LOGFILE
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
errorAndExit $"Error:"" \"mkfs.vfat\" "$"exit with error (see $LOGFILE)" errorAndExit $"Error:"" \"mkfs.vfat\" "$"exit with error (see $LOGFILE)"
fi fi
sudo mkfs.ext4 ${SELECT_USB}2 -L openmamba_live &>>$LOGFILE sudo mkfs.ext4 ${SELECT_USB2} -L openmamba_live &>>$LOGFILE
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
errorAndExit $"Error:"" \"mkfs.ext4\" "$"exit with error (see $LOGFILE)" errorAndExit $"Error:"" \"mkfs.ext4\" "$"exit with error (see $LOGFILE)"
fi fi
sleep 1 sleep 1
LANG=C udisks --mount ${SELECT_USB}1 &>>$LOGFILE LANG=C udisksctl mount -b ${SELECT_USB1} &>>$LOGFILE
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
errorAndExit $"Error:"" \"udisks --mount\" "$"exit with error (see $LOGFILE)" errorAndExit $"Error:"" \"udisks --mount\" "$"exit with error (see $LOGFILE)"
fi fi
LANG=C udisks --mount ${SELECT_USB}2 &>>$LOGFILE LANG=C udisksctl mount -b ${SELECT_USB2} &>>$LOGFILE
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
errorAndExit $"Error:"" \"udisks --mount\" "$"exit with error (see $LOGFILE)" errorAndExit $"Error:"" \"udisks --mount\" "$"exit with error (see $LOGFILE)"
fi fi
set_pbar 30 set_pbar 30
# Riceve la mountdir della chiavetta da dbus # Riceve la mountdir della chiavetta da dbus
MOUNTDIR_EFI=`dbus_properties_get_stringlist org.freedesktop.UDisks /org/freedesktop/UDisks/devices/${SELECT_USB/*\/}1 \ MOUNTDIR_EFI=`udisksctl info -b ${SELECT_USB1} | grep -m1 MountPoints: | sed "s|.*[[:space:]]||"`
org.freedesktop.UDisks.Device DeviceMountPaths`
if [ ! -d "$MOUNTDIR_EFI" ]; then if [ ! -d "$MOUNTDIR_EFI" ]; then
errorAndExit $"Error: unable to found usb mount path" errorAndExit $"Error: unable to found usb mount path"
@ -304,8 +311,7 @@ if [ -d /usr/lib/grub/i386-efi ]; then
fi fi
# Riceve la mountdir della chiavetta da dbus # Riceve la mountdir della chiavetta da dbus
MOUNTDIR=`dbus_properties_get_stringlist org.freedesktop.UDisks /org/freedesktop/UDisks/devices/${SELECT_USB/*\/}2 \ MOUNTDIR=`udisksctl info -b ${SELECT_USB2} | grep -m1 MountPoints: | sed "s|.*[[:space:]]||"`
org.freedesktop.UDisks.Device DeviceMountPaths`
if [ ! -d "$MOUNTDIR" ]; then if [ ! -d "$MOUNTDIR" ]; then
errorAndExit $"Error: unable to found usb mount path" errorAndExit $"Error: unable to found usb mount path"
@ -399,11 +405,11 @@ set_pbar 95
set_status $"Unmount usb device" set_status $"Unmount usb device"
echo $"Unmount usb device" echo $"Unmount usb device"
LANG=C udisks --unmount ${SELECT_USB}1 | grep failed && { LANG=C udisksctl unmount -b ${SELECT_USB1} || {
errorAndExit $"Error: fail to umount the usb key (${SELECT_USB}1)" errorAndExit $"Error: fail to umount the usb key (${SELECT_USB1})"
} }
LANG=C udisks --unmount ${SELECT_USB}2 | grep failed && { LANG=C udisksctl unmount -b ${SELECT_USB2} || {
errorAndExit $"Error: fail to umount the usb key (${SELECT_USB}2)" errorAndExit $"Error: fail to umount the usb key (${SELECT_USB2})"
} }
# WARNING: calling install-mbr after unmounting to prevent problems of FAT since EFI partition introduction # WARNING: calling install-mbr after unmounting to prevent problems of FAT since EFI partition introduction