modified: src/usbinstall.sh

This commit is contained in:
Filippo Bedendo Bordon 2012-01-07 17:55:29 +01:00
parent 045652dcd8
commit 6a9f8d584d

View File

@ -1,131 +1,138 @@
#!/bin/bash
# openmamba-usbinstall è uno script per la generazione automatica di una chiavetta di boot per openmamba snapshot.
# Se i file necessari sono presenti sul disco fisso verranno utilizzati quelli altrimenti
# scaricherà direttamente la versione attuale dal sito di openmamba.
# se il file iso è presente nella home verrà usato direttamente altrimenti si aprirà un dialogo dove sarà possibile cercarlo.
# (c) 2009 ercole 'ercolinux' carpanetto - ercole69@gmail.com
# (c) 2009-2010 Silvan Calarco - silvan.calarco@mambasoft.it
# rilasciato secondo la licenza GPL v.3
# 17/10/11 Script modificato organizzando il codice in funzioni, chiamate dal modulo installazione.py
#usbinstall.sh
# Arg 1: usb device for installation
# Arg 2: boot file
# Arg 3: iso file
# formattazione della chiavetta e installazione dei file necessari al boot di openmamba
#~ # openmamba-usbinstall è uno script per la generazione automatica di una chiavetta di boot per openmamba snapshot.
#~ # Se i file necessari sono presenti sul disco fisso verranno utilizzati quelli altrimenti
#~ # scaricherà direttamente la versione attuale dal sito di openmamba.
#~ # se il file iso è presente nella home verrà usato direttamente altrimenti si aprirà un dialogo dove sarà possibile cercarlo.
#~ # (c) 2009 ercole 'ercolinux' carpanetto - ercole69@gmail.com
#~ # (c) 2009-2010 Silvan Calarco - silvan.calarco@mambasoft.it
# License: GPL v.3
#1 Smonta la partizione
inst_dev_umount()
{
sudo umount ${1}1
#%Changelog:
# 17/10/11 (michiamophil)
# * Script modificato organizzando il codice in funzioni, chiamate dal modulo installazione.py
# 06/01/12 (michiamophil)
# * "sudo u/mount -> udisks"
# * export $1, $2, $3 -> OPENMAMBA_*
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
#-------------------------------------(DBUS)-----------------------------------------
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
function dbus_properties_get_string() {
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|.*string.*\"\(.*\)\"|\1|"
return 0
}
#2 Crea la partizione
inst_new_part()
{
sudo fdisk $1 <./fdisk_template
function dbus_properties_get_stringlist() {
# FIXME: only returns first element
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|.*array.*\[ string \"\(.*\)\" ]|\1|"
return 0
}
#3 Formatta la partizione (e la monta)
inst_format()
{
#add_progress 5 29 1 &
sudo mkfs.ext3 ${1}1 -L openmamba_live
mkdir -p ~/tmpmamba
sudo mount ${1}1 ~/tmpmamba
sudo chmod 777 ~/tmpmamba
function dbus_properties_get_uint64() {
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|.*uint64 \(.*\)|\1|"
return 0
}
#4 Estrae il file boot
inst_extr_boot()
{
cd ~/tmpmamba
gunzip -c < $1 | cpio -i
}
#5 Installa il bootloader
inst_make_boot()
{
cd ~/tmpmamba
sudo extlinux --install boot
sudo install-mbr -e 1 $1
}
#6 Copia la iso sull'usb
inst_copy_iso()
{
cd ~/tmpmamba
orig_size=$(stat -c %s $1)
cp "$1" ./ &
dest_size=0
sleep 2
while [ $orig_size -gt $dest_size ] ; do
dest_size=$(stat -c %s ./"`basename $1`")
percentuale=$((45 + ( 50 * $dest_size ) / $orig_size ))
pbar $percentuale
done
ln -fs `basename $1` ./openmamba-live.iso
}
#7 Smonta la chiavetta
inst_dir_umount()
{
sleep 5
sudo umount ${1}1
echo "Done"
}
# $1 begin value; $2 max value; $3 sleep time;
#add_progress()
#{
# while [ $1 <= $2 ] ; do
# $1 += 1
# dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_progressBar int32:$1
# sleep $3
# done
#}
# Aggiorna la progressbar $1 == %
pbar()
# Set progressbar
# Arg 1: value%
set_pbar()
{
dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_progressBar int32:$1
}
descrizione()
# Set status label
# Arg 1: string
set_status()
{
dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_description "string:$1"
}
####################################(DBUS)###########################################
if [ $1 == "start" ]; then
descrizione "Smonto la chiavetta"
inst_dev_umount $2
pbar 2
descrizione "Formattazione della chiavetta in corso..."
inst_new_part $2
pbar 5
inst_format $2
pbar 30
descrizione "Estrazione del file di boot in corso..."
inst_extr_boot $3
pbar 38
descrizione "Scrittura del bootloader in corso..."
inst_make_boot $2
pbar 45
descrizione "Copia del file iso di openmamba in corso..."
inst_copy_iso $4
pbar 98
descrizione "Smonto la chiavetta"
inst_dir_umount $2
pbar 100
else
echo $1 "Parametri non validi"
fi
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
#-------------------------------------(MAIN)-----------------------------------------
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
export SELECT_USB=$1
export SELECT_BOOT=$2
export SELECT_ISO=$3
set_status "Smonto la chiavetta"
LANG=C udisks --unmount ${SELECT_USB}1 | grep failed && {
echo "Error: fail to umount the usb key (${SELECT_USB}1)"
exit 1
}
set_pbar 2
set_status "Formattazione della chiavetta in corso..."
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
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 \
org.freedesktop.UDisks.Device DeviceMountPaths`
set_status "Estrazione del file di boot in corso..."
pushd $MOUNTDIR
sudo chmod 777 ./
gunzip -c $SELECT_BOOT | cpio -i
set_pbar 38
set_status "Scrittura del bootloader in corso..."
sudo extlinux --install boot
sudo install-mbr -e 1 $SELECT_USB
set_pbar 45
set_status "Copia del file iso di openmamba in corso..."
# Copy code
ORIG_SIZE=`stat -c %s $SELECT_ISO`
cp $SELECT_ISO ./ &
DEST_SIZE=0
sleep 2
while [ $ORIG_SIZE -gt $DEST_SIZE ]; do
DEST_SIZE=$(stat -c %s ./"`basename $SELECT_ISO`")
percentuale=$((45 + ( 50 * $DEST_SIZE ) / $ORIG_SIZE ))
set_pbar $percentuale
done
ln -fs `basename $SELECT_ISO` ./openmamba-live.iso
popd
set_pbar 98
set_status "Smonto la chiavetta"
udisks --unmount ${SELECT_USB}1 | grep failed && {
echo "Error: fail to umount the usb key (${SELECT_USB}1)"
exit 2
}
set_pbar 100
####################################(MAIN)###########################################