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### titleTITLE="LiveCD Install GUI version $VERSION"MENU_TITLE="LiveCD Install GUI version $VERSION"### tmpdirTMPDIR=/tmp/livecd-install-.$$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$TITLE\n-------------------------------------------\n(C) 2007, Urs Beyerle, PSI\n\nPress OK to continue\nEOF)$DIALOG --title "$TITLE" --infobox "$ABOUT_MESSAGE" 15 60 8[ $? -ne 0 ] && exit}### ------------------------------------------------------------test_for_livecd_install_script() {LIVECD_INSTALL=$( which livecd-install 2>/dev/null )if [ ! "$LIVECD_INSTALL" ]; 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" --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; \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="About"MENU_4="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" \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)about_message ;;4)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_PART### run livecd-installif [ $INSTALL_PART ]; thenrun_livecd_installfi