Add initial checks && Move usbinstall into /usr/sbin
This commit is contained in:
parent
16679d4071
commit
9370ac1141
3
Makefile
3
Makefile
@ -11,6 +11,7 @@ dist_archive := $(distdir).tar.bz2
|
||||
|
||||
# Directory
|
||||
bindir := /usr/bin
|
||||
sbindir := /usr/sbin
|
||||
sysconfdir := /etc
|
||||
datadir := /usr/share
|
||||
mambadir := /usr/share/openmamba
|
||||
@ -52,7 +53,7 @@ install-dirs:
|
||||
|
||||
install: install-dirs install-locales
|
||||
$(INSTALL_PROGRAM) src/usbinstall.py $(DESTDIR)$(mambadir)/usbinstall/usbinstall.py
|
||||
$(INSTALL_SCRIPT) src/usbinstall.sh $(DESTDIR)$(bindir)/usbinstall.sh
|
||||
$(INSTALL_SCRIPT) src/usbinstall.sh $(DESTDIR)$(sbindir)/usbinstall
|
||||
$(INSTALL_DATA) src/fdisk_template $(DESTDIR)$(mambadir)/usbinstall/fdisk_template
|
||||
$(INSTALL_DATA) src/img/*.png $(DESTDIR)$(mambadir)/usbinstall/img/
|
||||
${INSTALL} -m 440 src/usbinstall-sudoers $(DESTDIR)$(sysconfdir)/sudoers.d/usbinstall
|
||||
|
@ -21,6 +21,8 @@
|
||||
# 06/01/12 (michiamophil)
|
||||
# * "sudo u/mount -> udisks"
|
||||
# * export $1, $2, $3 -> OPENMAMBA_*
|
||||
# 08/01/12 (michiamophil)
|
||||
# * INITIAL-CHECK
|
||||
|
||||
|
||||
|
||||
@ -54,7 +56,7 @@ org.freedesktop.DBus.Properties.Get string:$3 string:$4`
|
||||
}
|
||||
|
||||
function dbus_properties_get_bool() {
|
||||
REPLY=`dbus-send --system --print-reply --dest=$1 $2 org.freedesktop.DBus.Properties.Get string:$3 string:$4`
|
||||
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
|
||||
@ -81,15 +83,91 @@ set_status()
|
||||
####################################(DBUS)###########################################
|
||||
|
||||
|
||||
function errorAndExit()
|
||||
{
|
||||
echo "$1"
|
||||
# Se l'argomento 2 è settato stampa anche l'help
|
||||
if [ -n "$2" ]; then
|
||||
usage
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
function usage()
|
||||
{
|
||||
echo "Usbistall: write Openmamba into your usb key!"
|
||||
echo -e "\tUsage: sudo usbinstall Arg1 Arg2 Arg3"
|
||||
echo -e "\tArg 1: Usb device path (es. /dev/sdc)"
|
||||
echo -e "\tArg 2: Cpio.gz file (es. ~/openmamba-bootusb-it-milestone2-2.0pre8.i586.cpio.gz)"
|
||||
echo -e "\tArg 3: Iso file (es. ~/openmamba-livecd-it-milestone2-2.0pre8.i586.iso)"
|
||||
}
|
||||
|
||||
|
||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
#-------------------------------------(MAIN)-----------------------------------------
|
||||
#--------------------------------(INITIAL-CHECK)-------------------------------------
|
||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
export SELECT_USB=$1
|
||||
export SELECT_BOOT=$2
|
||||
export SELECT_ISO=$3
|
||||
# Help
|
||||
if [ "$1" = "-h" -o "$1" = "--help" ]; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if usbinstall have root permission
|
||||
if [ "`id -u`" != 0 ]; then
|
||||
errorAndExit "Error: usbinstall must be run as root" 1
|
||||
fi
|
||||
|
||||
# Check if Arg 1 is valid
|
||||
if [ -b "$1" ]; then # If is a block device
|
||||
ISKEY=`dbus_properties_get_bool org.freedesktop.UDisks /org/freedesktop/UDisks/devices/${1/*\/} \
|
||||
org.freedesktop.UDisks.Device DeviceIsRemovable`
|
||||
if [ "$ISKEY" = "true" ]; then # If is a usb
|
||||
export SELECT_USB=$1
|
||||
else # If not, user can choose
|
||||
echo "Warning: you haven't choose a usb key ($1). Are you sure to continue? [yes/no]"
|
||||
read KEY
|
||||
case "$KEY" in
|
||||
yes)
|
||||
export SELECT_USB=$1
|
||||
;;
|
||||
*)
|
||||
errorAndExit "Installation aborted"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
errorAndExit "Error(Arg 1): \"$1\" isn't a block device" 1
|
||||
fi
|
||||
|
||||
# Check if Arg 2 is valid
|
||||
if [ -f "$2" ]; then # Check if is a file
|
||||
if [ -r "$2" ]; then # Chek is is readable
|
||||
export SELECT_BOOT=$2
|
||||
else
|
||||
errorAndExit "Error(Arg 2): \"$2\" is not readable" 1
|
||||
fi
|
||||
else
|
||||
errorAndExit "Error(Arg 2): \"$2\" isn't a regular file" 1
|
||||
fi
|
||||
|
||||
# Check if Arg 3 is valid
|
||||
if [ -f "$3" ]; then # Check if is a file
|
||||
if [ -r "$3" ]; then # Chek is is readable
|
||||
export SELECT_ISO=$3
|
||||
else
|
||||
errorAndExit "Error(Arg 3): \"$3\" is not readable" 1
|
||||
fi
|
||||
else
|
||||
errorAndExit "Error(Arg 3): \"$3\" isn't a regular file" 1
|
||||
fi
|
||||
#################################(INITIAL-CHECK)#####################################
|
||||
|
||||
|
||||
|
||||
|
||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
#--------------------------------(INSTALLATION)--------------------------------------
|
||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
set_status "Smonto la chiavetta"
|
||||
|
||||
DEVICEISMOUNTED=`dbus_properties_get_bool org.freedesktop.UDisks /org/freedesktop/UDisks/devices/${SELECT_USB/*\/}1 \
|
||||
@ -114,7 +192,7 @@ set_pbar 30
|
||||
|
||||
|
||||
# Riceve la mountdir della chiavetta da dbus
|
||||
MOUNTDIR=`dbus_properties_get_stringlist org.freedesktop.UDisks /org/freedesktop/UDisks/devices/$(basename $SELECT_USB)1 \
|
||||
MOUNTDIR=`dbus_properties_get_stringlist org.freedesktop.UDisks /org/freedesktop/UDisks/devices/${SELECT_USB/*\/}1 \
|
||||
org.freedesktop.UDisks.Device DeviceMountPaths`
|
||||
|
||||
set_status "Estrazione del file di boot in corso..."
|
||||
@ -152,4 +230,4 @@ LANG=C udisks --unmount ${SELECT_USB}1 | grep failed && {
|
||||
exit 2
|
||||
}
|
||||
set_pbar 100
|
||||
####################################(MAIN)###########################################
|
||||
#################################(INSTALLATION)######################################
|
||||
|
Loading…
Reference in New Issue
Block a user