Rev 51 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed
#!/bin/bash################################################################### Simple GUI for livecd-install## Urs beyerle, PSI##################################################################VERSION=0.1#################################################################clean_exit(){rm -rf $TMPDIR}trap "clean_exit" EXIT### ------------------------------------------------------------### Definitions### ------------------------------------------------------------### set path and langPATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin"LANG=en_US.UTF-8### define name of LiveCD install scriptLIVECD_INSTALL=livecd-install### title and script nameTITLE="LiveCD Install GUI version $VERSION"MENU_TITLE="LiveCD Install GUI version $VERSION"SCRIPTNAME=$( basename $0 )### tmpdirTMPDIR=/tmp/livecd-install-gui.$$TMP=$TMPDIR/dialogmkdir -p $TMPDIR### dialog or xdialog?DIALOG="dialog"XDIALOG_HIGH_DIALOG_COMPAT=1export XDIALOG_HIGH_DIALOG_COMPAT[ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"; XDIALOG="yes"### ------------------------------------------------------------### Functions### ------------------------------------------------------------### -------------------------------------------------------------about_message() {ABOUT_MESSAGE=$( cat <<EOF---------------------------------------\n$SCRIPTNAME\n$TITLE\n---------------------------------------\n(c) 2007, Urs Beyerle, PSI\n\nPress OK to continue\nEOF)$DIALOG --title "$TITLE" --infobox "$ABOUT_MESSAGE" 15 60 8}### -------------------------------------------------------------help_message() {HELP_MESSAGE=$( cat <<EOF--------------------------------------------------------------------\n$SCRIPTNAME\n$TITLE\n--------------------------------------------------------------------\n\nThis is the frontend of the $LIVECD_INSTALL script.Use it to install the LiveCD/DVD on your hardisk.\n\nThe LiveCD/DVD can be installed on a Linuxpartition, which you may have to create first using toolslike qtparted, gparted, fdisk or parted. All data on the selectedLinux partition will be deleted.It is recommended tocreate in addition a Swap partition that will be laterused by the installed Linux system.\n\nIn order that you can boot into the installed Linuxsystem, it is recommended that you choose to installthe bootloader GRUB into the Master Boot Record (MBR)of your primary boot disk.\n\nMore options are available, if you run the script$LIVECD_INSTALL directly from the command line.\nEOF)$DIALOG --title "$TITLE" --infobox "$HELP_MESSAGE" 30 60 12}### ------------------------------------------------------------test_for_livecd_install_script() {LIVECD_INSTALL_SCRIPT=$( which $LIVECD_INSTALL 2>/dev/null )if [ ! "$LIVECD_INSTALL_SCRIPT" ]; thenMESSAGE0="Script $LIVECD_INSTALL not found"$DIALOG --title "$TITLE" --msgbox "$MESSAGE0" 0 0exit 1fi}### ------------------------------------------------------------test_for_root() {if [ "$UID" -ne "0" ]; thenMESSAGE0="To use this program, you need to be root"$DIALOG --title "$TITLE" --msgbox "$MESSAGE0" 0 0exit 1fi}### ------------------------------------------------------------select_install_part() {PART_LIST=""PARTS=$( LANG=C fdisk -l | grep Linux$ | cut -d" " -f1 )if [ ! "$PARTS" ]; thenNOPART_MESSAGE="No Linux partition found.\n\n\Please create one first"$DIALOG --title "$TITLE" --infobox "$NOPART_MESSAGE" 15 60 8exit 1fifor p in $PARTS; doPART_LIST="$PART_LIST $p Linux-Partiton off"doneMESSAGE1="Please select a partition to install the LiveCD"$DIALOG --title "$TITLE" --no-cancel --radiolist "$MESSAGE1" 20 60 8 $PART_LIST 2>$TMPcat $TMP}### ------------------------------------------------------------select_swap_part() {PART_LIST=""PARTS=$( LANG=C fdisk -l | grep "Linux swap" | cut -d" " -f1 )if [ ! "$PARTS" ]; thenNOSWAP_MESSAGE="No Swap partition found.\n\n\You can install the LiveCD without having\n\a Swap partition, but it is not recommended.\n\n\Continue ?"$DIALOG --title "$TITLE" --yesno "$NOSWAP_MESSAGE" 15 60 8return $?fifor p in $PARTS; doPART_LIST="$PART_LIST $p Swap-Partiton off"doneMESSAGE2="Please select a SWAP partition"$DIALOG --title "$TITLE" --no-cancel --radiolist "$MESSAGE2" 15 60 5 $PART_LIST \NONE "Do not use a swap partition (not recommended)" off 2>$TMPa=$( cat $TMP )[ "$a" != "NONE" ] && echo $areturn 0}### ------------------------------------------------------------ok_continue() {OK_MESSAGE="\nLiveCD will be installed on $INSTALL_PART.\n\All data on $INSTALL_PART will be deleted !!\n\n"if [ $SWAP_PART ]; thenOK_MESSAGE="${OK_MESSAGE}$SWAP_PART will be used as Swap partition.\n\n"fiif [ $MBR_DISK ]; thenOK_MESSAGE="${OK_MESSAGE}GRUB will be installed as bootloader into the\n\Master Boot Record (MBR) of disk $MBR_DISK.\n\n"fiOK_MESSAGE="${OK_MESSAGE}Is this ok ?\n"$DIALOG --title "$TITLE" --default-no --yesno "$OK_MESSAGE" 15 60 8return $?}### ------------------------------------------------------------select_mbr_disk() {DISK_LIST=""DISKS=$( LANG=C fdisk -l | grep ^Disk | cut -d":" -f1 | cut -d" " -f2 )for p in $DISKS; doDISK_LIST="$DISK_LIST $p Disk off"doneMESSAGE3="Please select a disk to install the bootloader GRUB"$DIALOG --title "$TITLE" --no-cancel --radiolist "$MESSAGE3" 15 60 5 $DISK_LIST \NONE "Do not install GRUB (not recommended)" off 2>$TMPa=$( cat $TMP )[ "$a" != "NONE" ] && echo $a}### ------------------------------------------------------------run_qtparted() {QTPARTED=$( which qtparted 2>/dev/null )if [ ! $QTPARTED ]; thenNO_QTPARTED_MESSAGE="Sorry, qtparted not found.\n\n\Please use an other tool like fdisk or parted."$DIALOG --title "$TITLE" --infobox "$NO_QTPARTED_MESSAGE" 10 60 8else$QTPARTED &fi}### ------------------------------------------------------------run_livecd_install() {xterm -sb -title "Run: $LIVECD_INSTALL -y $SWAP_PART_OPT $MBR_DISK_OPT $INSTALL_PART" \-geometry 130x45+100+20 \-e 'echo; \echo "Run: $LIVECD_INSTALL -y $SWAP_PART_OPT $MBR_DISK_OPT $INSTALL_PART"; \echo; \$LIVECD_INSTALL -y $SWAP_PART_OPT $MBR_DISK_OPT $INSTALL_PART; \echo; \echo "$LIVECD_INSTALL finished.";\echo;\echo "- Press a key to close this window -"; \read -n 1'}### ------------------------------------------------------------main_menu() {MENU_1="Install the LiveCD"MENU_2="Create Linux/Swap Partitions with qtparted"MENU_3="Help"MENU_4="About"MENU_5="Quit"while true; do$DIALOG --title "$TITLE" \--menu "$MENU_TITLE" 15 60 6\1 "$MENU_1" \2 "$MENU_2" \3 "$MENU_3" \4 "$MENU_4" \5 "$MENU_5" \2> $TMP[ $? -ne 0 ] && breakCHOICE=$(cat $TMP)case "$CHOICE" in1)INSTALL_PART=$( select_install_part )if [ "$?" = "0" ]; thenSWAP_PART=$( select_swap_part )if [ "$?" = "0" ]; thenMBR_DISK=$( select_mbr_disk )ok_continue && breakfifiINSTALL_PART="" ;;2)run_qtparted ;;3)help_message ;;4)about_message ;;5)exit ;;esacdone}### ------------------------------------------------------------### Main Program### ------------------------------------------------------------### requirementstest_for_livecd_install_scripttest_for_root### main menumain_menu[ "$SWAP_PART" ] && export SWAP_PART_OPT="-swap $SWAP_PART"[ "$MBR_DISK" ] && export MBR_DISK_OPT="-mbr $MBR_DISK"export INSTALL_PART=$INSTALL_PARTexport LIVECD_INSTALL=$LIVECD_INSTALL### run $LIVECD_INSTALLif [ $INSTALL_PART ]; thenrun_livecd_installfi