====== mkliveimage, un script de re-masterisation pour mklivecd ====== c'est le script qui sert a fabriquer les [[http://ladybug.du-libre.org|LadyBug]] #!/bin/sh # make a iso image from the system end put it on a usbkey # Requires Zenity # Licence GPL 2.0 or later # base on a MCNLive flash drive install, without formatting # (c) 2005, 2006 Chris, mcnlive@googlemail.com # (c) www.mandrivaclub.nl # (c) 2005, 2007 bretzel@apo33.org # Requires Zenity case $LANG in fr*|FR*) er1="Ce script doit etre lance sous root" start1="Lancement de mkliveimage" TITLE1="Creation de image pour une cle USB" text1=" Cet utilitaire creer une image iso du syteme et en fait une cle USB amorcable. Avant de commencer lisez les indications suivantes: 0. Tous les peripheriques USB detectes, flash, disque externe ou SATA interne sont affiches. Avant de commencer assurez vous de choisir le bon! Utilisez le centre de control ou la ligne de commande : fdisk -l /dev/sd... pour vous renseigner 1. Votre BIOS doit supporter de booter sur USB-HDD. - Ne pas passer par l'option copy2ram du boot, - Connecter votre cle USB seulement apres avoir booter correctement la machine. 2. Le device, cleUSB, doit faire plus que l'image generee .. soit au moins 1GB 3. La cle sera totalement effacee et reformatee en deux partitions, une pour le systeme, l'autre pour vos donnees futures. 4. Les fichiers vont etre copies sur cette premiere partition et syslinux va y etre installe. 5. L image iso generee doit pouvoir tenir sur la cle USB! *** Nous declinons toute responsabilite sur l'usage de ce logiciel ou sur la perte de donnee. *** Tapez 'Annuler' si vous voulez arreter *** Verifiez que votre peripherique USB est correctement connecté ettapez 'Valider' pour continuer"; error1="Sortie. Vous avez choisi de sortir." err_name="Sortie. Vous devez donner un nom!" ERROR="Sortie apres une erreur" err_mklivecd="Erreur lors de /tmp/mklivecd.sh" err_taille="Sortie , votre image iso est dans /tmp" err_gogo="Sortie le script est sauvegarder dans /tmp/mklivecd.sh" error3="Erreur, Pas de device USB trouve :-(" msg_mklive="Fabrication de l'image iso en cours" TITLE2="Selection de device USB " MESSAGE2="Selectionnez un device USB a preparer. Assurez vous de ne pas selectionner un disque interne SATA ou un gros disque externe." TITLE3="Creation LiveUSB" text3="Creation LiveUSB, cela peut prendre quelques minutes ...Soyez patient! " TITLE4="TERMINE" MESSAGE4="La cle USBLive a ete cree avec succes sur $DEVICE. Vous pouvez la deconnecter maintenant. Quand vous rebooterez inserer a nouveau ce device et verifier votre BIOS Tapez 'Valider' pour finir ." text7="Entree un nom pour cette version du sauvegarde du live ..." text8="La taille de l'image iso est elle acceptable ? Annuler = Sortie et sauvegarde de l'image iso" text9="Clee USB pas vue ,Re-inserer la" text10="Donner la taille de la partition qui va contenir l'image attention ! la taille doit etre en Mega octet ex 730" text11="Clee USB pas vue ,Re-inserer la" text12="L'image iso existe deja sous ce nom ! Voulez vous juste l'utiliser pour générer une cleUSB?" msg1="effacement et preparation" msg2="creation de la partition primaire" msg3="creation de la partition secondaire" msg3="formatage de la partition primaire" msg4="formatage de la partition secondaire" msg6="MBR preparation" msg7="MBR installation" msg8="Copie des fichiers du systeme" msg9="demontage" ;; *) ERROR="Error Occurred" er1="You must be root" start1="Starting mkmcnlive" err_name="Exit. You must name the file!" TITLE1="Create LiveUSB" text1=" This wizard creates a bootable USB Flash Drive on your chosen usb device. Before proceeding please notice: 0. All detected usb devices, flash drives, external harddrives and *internal sata disks* are shown. Before proceeding, make sure which device is the correct one. Use the Mandriva Control Center or the command line: fdisk -l. 1. Your BIOS must support USB-HDD booting. When using this wizard: - don't boot with the copy2ram cheatcode, -plug in your usb flash drive after you booted sucessfully. 2. The Flash drive needs a capacity of at least 512 MB. 3. This wizard make 2 partition and format your device . 4. Files will be copied to the first partition, syslinux bootloader installed. *** No responsibility for data loss or hardware damage! *** *** Press 'Cancel' if you want to stop. *** Please verify that your usb flash drive is plugged in and press 'OK' to proceed." error1="Exiting. You chose not to continue." error3="Error: No suitable USB devices found :-(" err_gogo="Exit the script is in /tmp/mklivecd.sh" err_taille="Exit. Your iso image is in /tmp" TITLE2="Select USB Device" MESSAGE2="Please select a USB device to prepare. Make sure *not* to select an internal SATA harddisk, or an external large harddisk." text3="Creating LiveUSB, this can take some minutes ... Please be patient." text7="Name for this USB Live System ?" text8="is the size ok for your USBKey? Cancel = Exit and keep the iso file" text9="I can t see the USBKey, plug it again" text10="Give the size for the LiveUSB System in Mega Octet ex 730" text11="I can t see the USBKey, plug it again" text12="The iso image already existe with this name ! Do you want use it for a new USBkey ?" TITLE3="Creating LiveUSB" TITLE4="FINISHED" MESSAGE4="LiveUSB successfully created on $DEVICE. You can unplug it now. When rebooting, please check your BIOS settings while the flash drive is inserted! Press 'OK' to finish." msg1="erasing and preparation" msg2="primary partition creation" msg3="secondary partition creation" msg4="primary partition formating" msg5="secondary partition formating" msg6="MBR preparation" msg7="MBR installation" msg8="copy file system" msg9="unmount" ;; esac #### Check for root #### if [ "$UID" != "0" ]; then echo $er1 exit fi #### Constants, Functions #### # ## Constants DIALOG=zenity USB="$DEVICE"1 DATA="$DEVICE"2 MOUNT="$USB" MOUNT2="$DATA" TMP="/tmp/mkmcnlive.tmp" echo " " > $TMP goodbye() { [ -n "$MOUNT" ] && umount -dlf "$MOUNT" 2>/dev/null [ -n "$MOUNT2" ] && umount -dlf "$MOUNT2" 2>/dev/null umount -dl /mnt/usbstick 2>/dev/null exit 0 } #### Report error and exit error() { $DIALOG --error --text="$1" --title="$ERROR" } #### Command cmd() { echo "> $1 " >> "$TMP" $1 2>"$TMP" OK=$? RESULT="$(<$TMP)" echo "OK = $OK" >>"$TMP" if [ "$OK" != "0" ]; then # Haarlem, we have a problem if [ "$3" = "WARN" ]; then #$DIALOG --title "WARNING" --sorry "$2" $DIALOG --warning --text="$2" elif [ "$3" = "STOP" ]; then # Bad error - stop error "ERROR:$2: $RESULT" # Send to error func goodbye fi fi } trap goodbye 1 2 3 15 ###### MAIN SCRIPT ###### # ### Setup echo "$start1" echo "Dialog = $DIALOG" $DIALOG --question --title="$TITLE1" --width=600 --height=800 --text="$text1" RET=$? if [ "$RET" -eq "1" ]; then error "$error1" exit 0 fi #### make the iso image with mklivecd nom_iso=`$DIALOG --entry --title="$TITLE1" --text="$text7"` VERSION=`echo "$nom_iso"|tr " " "_"` ISO="$VERSION".iso if [ -z "$nom_iso" ] then error "$err_name" exit 1 fi REUSE="0" if [ -f "/tmp/$ISO" ] then $DIALOG --question --title="$TITLE1" --text="$text12" RET=$? if [ "$RET" -eq "0" ]; then REUSE="1" fi fi ICI=`pwd` cat /usr/local/etc/F1.top > /tmp/boot.msg echo -n $VERSION >> /tmp/boot.msg cat /usr/local/etc/F1.msg >> /tmp/boot.msg #echo $VERSION "Linux i586" > /etc/redhat-release #echo $VERSION "Linux i586" > /etc/version umount -a cd /tmp find /etc/X11/xkb -name "core.*" -exec rm '{}' \; find /home/toto -name "core.*" -exec rm '{}' \; find /root -name "core.*" -exec rm '{}' \; find /var/lib/gdm -name "core.*" -exec rm '{}' \; find /usr/lib/pd -name "core.*" -exec rm '{}' \; rm -rf /core.* find /var/log -name "*.gz" -exec rm '{}' \; #sup des param mesgrie instantanee et autre rm -rf /home/toto/.gaim #rm -rf /home/toto/.dvdcss rm -rf /home/toto/.thumbmails #cp -f /usr/share/mklivecd/finish-install /etc/sysconfig/ cd /tmp echo "#!/bin/bash" >/tmp/mklivecd.sh echo "trap 'rm -f "$ISO"' 1 2 3 15" >>/tmp/mklivecd.sh echo "/usr/sbin/mklivecd \\" >>/tmp/mklivecd.sh echo "--verbose \\" >>/tmp/mklivecd.sh echo "--ufs aufs \\" >>/tmp/mklivecd.sh echo "--bootloader=grub \\" >>/tmp/mklivecd.sh echo "--volumeid=$VERSION \\" >>/tmp/mklivecd.sh echo "--publisher=apo33.org \\" >>/tmp/mklivecd.sh echo "--tmp /tmp \\" >>/tmp/mklivecd.sh echo "--timeout=1000 \\" >>/tmp/mklivecd.sh echo "--verbose --debug \\" >>/tmp/mklivecd.sh echo "--blocksize 224 \\" >>/tmp/mklivecd.sh echo "--looptype sqfs \\" >>/tmp/mklivecd.sh echo "--keyboard=fr \\" >>/tmp/mklivecd.sh echo "--bootmsg /tmp/boot.msg \\" >>/tmp/mklivecd.sh echo "--bootkey F2=/tmp/boot.msg \\">>/tmp/mklivecd.sh echo "--bootopt hwdetect=yes \\" >>/tmp/mklivecd.sh echo "--nodir=\\" >>/tmp/mklivecd.sh cat /usr/local/etc/mklive_nodir.cfg >>/tmp/mklivecd.sh echo "$ISO" >>/tmp/mklivecd.sh echo "RET=\$?" >>/tmp/mklivecd.sh echo 'if [ "$RET" -eq 0 ];then exit 0;else rm -f '$ISO';fi'>>/tmp/mklivecd.sh script=`cat /tmp/mklivecd.sh` zenity --question --text "$script" --title="$TITLE1" RET="$?" if [ "$RET" -eq "1" ] ; then if [ -f /tmp/mklivecd.sh ];then mousepad /tmp/mklivecd.sh script=`cat /tmp/mklivecd.sh` zenity --question --text11 "$script" --title="$TITLE1" RET=$? if [ "$RET" -eq 1 ] ; then error "$err_gogo";exit 1 ; fi else error "$error1" exit 0 fi fi chmod 755 /tmp/mklivecd.sh if [ "$REUSE" -eq 0 ];then xterm -e '/bin/bash /tmp/mklivecd.sh' RET="$?" fi if [ "$RET" -eq "1" ] ; then error "$err_gogo";exit 1 ; fi if [ ! -f "$ISO" ] ; then error "$err_gogo";exit 1 ; fi echo "$ISO " > $ISO.md5sum md5sum $ISO >> $ISO.md5sum & text18=`ls -sh --si $ISO` text8="$text8 $text18" taille=`ls -sh --si $ISO |awk '{ print $1 }'|tr -d "M|G"` $DIALOG --question --title="$TITLE1" --text="$text8" if [ "$?" = "1" ]; then error "$err_taille" exit 0 fi # iso ok , mount it like the livecd mkdir -p /tmp/cdromlive mount $ISO /tmp/cdromlive -t iso9660 -o loop ####### #### Find the usb devices while [ ! -b /dev/sd[a+h] ] do $DIALOG --question --title="$TITLE1" --text="$text9" done DEVICES="" for stick in /dev/sd[a-h] do if [ -e "$stick" ]; then DEVICES="$DEVICES $stick" echo " USB devices: $stick" else ## Nothing found error "$error3" exit 0 fi done #### PAGE 2: User selects the usb device DEVICE="" while [ "$DEVICE" = "" ]; do $DIALOG --list --title="$TITLE2" --text="$MESSAGE2" \ --column="USB Device" $DEVICES 1>"$TMP" if [ "$?" = "1" ]; then error "$error1" exit 0 fi DEVICE="$(<$TMP)" done ## Unmount if mounted USB="$DEVICE"1 DATA="$DEVICE"2 cmd "umount -dlf $USB" 2>/dev/null $DIALOG --info --title="$TITLE3" --text="$text3" & # Changing geometry for USB-ZIP compatibility on /dev/$DEVICE echo "$msg1" dd if=/dev/zero of=$DEVICE bs=1k count=1 sleep 1 echo "$msg2" cmd "/usr/local/bin/mkdiskimage -1 $DEVICE $taille 64 32" "Problem changing geometry on $DEVICE" "STOP" # Creating 2. partition echo "$msg3" USB="$DEVICE"1 DATA="$DEVICE"2 fdisk $DEVICE << EOF >/dev/null 2>&1 n p 2 t 2 6 w EOF # sync sleep 2 umount -dl $USB >/dev/null 2>&1 sleep 1 umount -dl $DATA >/dev/null 2>&1 sleep 1 # formatting partitions echo "$msg4" cmd "mkfs.vfat -n "$VERSION" -F 16 $USB" sleep 1 echo "$msg5" cmd "mkfs.vfat -n "LiveUSB-2" -F 32 $DATA" sleep 2 # installing MBR echo "$msg6" cmd "dd if=/usr/local/bin/mbr.bin of=$DEVICE" "Problem writing MBR" "STOP" # echo " Setting up boot loader on $DEVICE" echo "$msg7 on $DEVICE" cmd "/usr/bin/syslinux $USB" "Problem installing bootloader" "STOP" sync # Copying the files echo "$msg8" IMAGE="/tmp/cdromlive" cmd "mkdir -p /mnt/usbstick" cmd "mount -t vfat $USB /mnt/usbstick" cmd "cp $IMAGE/isolinux/* /mnt/usbstick" cmd "rm /mnt/usbstick/isolinux.cfg" cmd "rm /mnt/usbstick/isolinux.bin" cmd "cp /tmp/$ISO.md5sum /mnt/usbstick" cmd "cp /usr/local/etc/splash.msg /mnt/usbstick" cmd "cp /usr/local/etc/F2_fr.msg /mnt/usbstick" cmd "cp /usr/local/etc/syslinux.cfg /mnt/usbstick" cmd "cp $IMAGE/livecd.sqfs /mnt/usbstick" "Problem copying files. Exiting." "STOP" sync echo "$msg9" umount /mnt/usbstick #### Finished #### $DIALOG --info --title="$TITLE4" --text="$MESSAGE4" [ -n "$MOUNT" ] && umount -dlf "$MOUNT" 2>/dev/null [ -n "$MOUNT2" ] && umount -dlf "$MOUNT2" 2>/dev/null umount -dl /tmp/cdromlive 2>/dev/null umount -dl /mnt/usbstick 2>/dev/null exit 0