desktop-base-openmamba/usbinstall/usbinstall.sh
2011-04-26 13:25:32 +02:00

150 lines
5.8 KiB
Bash

#!/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/
# formattazione della chiavetta e installazione dei file necessari al boot di openmamba
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() {
#scansione di hal alla ricerca di tutte le periferiche di archiviazione usb
c=0
for udi in $(/usr/bin/hal-find-by-capability --capability storage)
do
if [[ $(hal-get-property --udi $udi --key storage.removable) = "true" &&
$(hal-get-property --udi $udi --key storage.drive_type) = "disk" ]]; then
c=$((c+1))
device[$c]=$(hal-get-property --udi $udi --key block.device)
vendor[$c]=$(hal-get-property --udi $udi --key storage.vendor)
model[$c]=$(hal-get-property --udi $udi --key storage.model)
parent_udi=$(hal-find-by-property --key block.storage_device --string $udi)
# mount[$c]=$(hal-get-property --udi $parent_udi --key volume.mount_point)
# label[$c]=$(hal-get-property --udi $parent_udi --key volume.label)
media_size[$c]=$(hal-get-property --udi $udi --key storage.removable.media_size)
size[$c]=$(( ${media_size[$c]}/(1000*1000*1000)))
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