2011-04-26 13:25:32 +02:00
#!/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
# per cambiare la versione della snapshot di openmamba modificare il valore qui sotto di conseguenza
version = 20091201
version_cd = 20091201
fileiso = "~/openmamba-livecd-it-snapshot-" $version_cd ".i586.iso"
filecpio = "" ~/openmamba-bootusb-it-snapshot-" $version " .i586.cpio.gz""
#da qui in poi non c'è nulla da modificare
TEXTDOMAIN = usbinstall
TEXTDOMAINDIR = /usr/share/locale/
2011-09-05 01:41:11 +02:00
function get_udisks_key( ) {
LANG = C udisks --show-info $1 | grep " $2 : " | head -n1 | sed " s|[[:space:]]* $2 :[[:space:]]*\(.*\)|\1| "
}
# formattazione della chiavetta e installazione dei file necessari al boot di openmamba
2011-04-26 13:25:32 +02:00
installa( ) {
conferma = 0
chiave = $c
kdialog --title $"openmamba installation on USB device" --yesno $" Warning all the data on the usb key <b> ${ vendor [ $chiave ] } ${ model [ $chiave ] } </b> with <b> ${ size [ $chiave ] } GB</b> will be destroyed! " && conferma = 1
if [ $conferma -eq 1 ] ; then
dcopRef = $( kdialog --geometry 450x140 --title $"openmamba installation on USB device" --progressbar $"Starting installation..." 12)
qdbus $dcopRef org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog maximum 20
sudo umount ${ device [ $chiave ] } 1
qdbus $dcopRef org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog value 1
qdbus $dcopRef org.kde.kdialog.ProgressDialog.setLabelText $"Creating partitions..."
sudo fdisk ${ device [ $chiave ] } <<EOF
d
4
d
3
d
2
d
n
p
1
1
a
1
w
EOF
qdbus $dcopRef org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog value 3
qdbus $dcopRef org.kde.kdialog.ProgressDialog.setLabelText $"Formattazione..."
disk = ${ device [ $chiave ] } 1
sudo mkfs.ext3 $disk -L openmamba_live
qdbus $dcopRef org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog value 6
qdbus $dcopRef org.kde.kdialog.ProgressDialog.setLabelText $"Mounting and file creation..."
mkdir -p ~/tmpmamba
sudo mount $disk ~/tmpmamba
sudo chmod 777 ~/tmpmamba
qdbus $dcopRef org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog value 10
qdbus $dcopRef org.kde.kdialog.ProgressDialog.setLabelText $"Verifing files and eventually download from internet..."
file = $filecpio
if [ ! -f $file ] ; then
file = $( kdialog --title $"Please select the 'bootusb' archive or press Cancel to download it" --getopenfilename $HOME "openmamba*-bootusb-*.cpio.gz |openmamba files" )
echo $file
if [ ! $file ] ; then
file = "~/openmamba-bootusb-it-snapshot-" $version ".i586.cpio.gz"
wget http://www.openmamba.org/pub/openmamba/devel/media/bootusb/it/openmamba-bootusb-it-snapshot-$version .i586.cpio.gz
fi
fi
cd ~/tmpmamba
qdbus $dcopRef org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog value 13
qdbus $dcopRef org.kde.kdialog.ProgressDialog.setLabelText $"Installing files..."
gunzip -c < $file | cpio -i
sudo extlinux --install boot
qdbus $dcopRef org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog value 14
qdbus $dcopRef org.kde.kdialog.ProgressDialog.setLabelText $"Installing bootloader..."
sudo install-mbr -e 1 ${ device [ $chiave ] }
qdbus $dcopRef org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog value 15
qdbus $dcopRef org.kde.kdialog.ProgressDialog.setLabelText $"Copying ISO image..."
if [ ! -f $fileiso ] ; then
fileiso = $( kdialog --title $"Please select the ISO image or press Cancel to download it" --getopenfilename $HOME "openmamba-*.iso |iso files" )
fi
if [ ! $fileiso ] ; then
sudo umount ~/tmpmamba
cd
qdbus $dcopRef org.kde.kdialog.ProgressDialog.close
exit 0
fi
cp $fileiso ./
ln -fs ` basename $fileiso ` ./openmamba-live.iso
cd ..
sudo umount ~/tmpmamba
fi
qdbus $dcopRef org.kde.kdialog.ProgressDialog.close
exit 0
}
scansione( ) {
2011-09-05 01:41:11 +02:00
#ricerca di tutte le periferiche di archiviazione usb
devices = ` udisks --enumerate-device-files | grep -v /dev/disk | sort -n`
2011-04-26 13:25:32 +02:00
c = 0
2011-09-05 01:41:11 +02:00
for dev in $devices ; do
native_path = ` get_udisks_key $dev native-path`
vend = ` get_udisks_key $dev vendor`
prod = ` get_udisks_key $dev model`
[ -e $native_path /partition ] || continue
is_system_internal = ` get_udisks_key $dev "system internal" `
if [ " $is_system_internal " != "1" ] ; then
c = $(( c+1))
device[ $c ] = $dev
vendor[ $c ] = $vend
model[ $c ] = $prod
media_size[ $c ] = ` get_udisks_key $dev size`
size[ $c ] = $(( ${ media_size [ $c ] } / ( 1000 * 1000 * 1000 )) )
2011-04-26 13:25:32 +02:00
fi
done
if [ $c -eq 0 ] ; then
t = $( kdialog --title $"USB key missing" --yesno $"Please insert a USB key or press No" )
if [ ! $t ] ; then
exit 0
fi
scansione
fi
}
menu( ) {
chiave = ""
if [ $c -gt 1 ] ; then
case $c in
2)
chiave = $( kdialog --radiolist $"Select the USB key on which you want to install openmamba" 1 " ${ vendor [1] } ${ model [1] } ${ size [1] } GB " 1 2 " ${ vendor [2] } ${ model [2] } ${ size [2] } GB " 2)
; ;
3)
chiave = $( kdialog --radiolist $"Select the USB key on which you want to install openmamba" 1 " ${ vendor [1] } ${ model [1] } ${ size [1] } GB " 1 2 " ${ vendor [2] } ${ model [2] } ${ size [2] } GB " 2 3 " ${ vendor [3] } ${ model [3] } ${ size [3] } GB " 3)
; ;
4)
chiave = $( kdialog --radiolist $"Select the USB key on which you want to install openmamba" 1 " ${ vendor [1] } ${ model [1] } ${ size [1] } GB " 1 2 " ${ vendor [2] } ${ model [2] } ${ size [2] } GB " 2 3 " ${ vendor [3] } ${ model [3] } ${ size [3] } GB " 3 4 " ${ vendor [4] } ${ model [4] } ${ size [4] } GB " 4)
; ;
esac
if [ ! " $chiave " ] ; then
exit 0
fi
fi
installa
}
scansione
menu
exit 0