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 lang
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin"
LANG=en_US.UTF-8
### title
TITLE="LiveCD Install GUI version $VERSION"
MENU_TITLE="LiveCD Install GUI version $VERSION"
### tmpdir
TMPDIR=/tmp/livecd-install-.$$
TMP=$TMPDIR/dialog
mkdir -p $TMPDIR
### dialog or xdialog?
DIALOG="dialog"
XDIALOG_HIGH_DIALOG_COMPAT=1
export 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
\n
Press OK to continue\n
EOF)
$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" ]; then
MESSAGE0="Script livecd-install not found"
$DIALOG --title "$TITLE" --msgbox "$MESSAGE0" 0 0
exit 1
fi
}
### ------------------------------------------------------------
test_for_root() {
if [ "$UID" -ne "0" ]; then
MESSAGE0="To use this program, you need to be root"
$DIALOG --title "$TITLE" --msgbox "$MESSAGE0" 0 0
exit 1
fi
}
### ------------------------------------------------------------
select_install_part() {
PART_LIST=""
PARTS=$( LANG=C fdisk -l | grep Linux$ | cut -d" " -f1 )
if [ ! "$PARTS" ]; then
NOPART_MESSAGE="No Linux partition found.\n\n\
Please create one first"
$DIALOG --title "$TITLE" --infobox "$NOPART_MESSAGE" 15 60 8
exit 1
fi
for p in $PARTS; do
PART_LIST="$PART_LIST $p Linux-Partiton off"
done
MESSAGE1="Please select a partition to install the LiveCD"
$DIALOG --title "$TITLE" --no-cancel --radiolist "$MESSAGE1" 20 60 8 $PART_LIST 2>$TMP
cat $TMP
}
### ------------------------------------------------------------
select_swap_part() {
PART_LIST=""
PARTS=$( LANG=C fdisk -l | grep "Linux swap" | cut -d" " -f1 )
if [ ! "$PARTS" ]; then
NOSWAP_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 8
return $?
fi
for p in $PARTS; do
PART_LIST="$PART_LIST $p Swap-Partiton off"
done
MESSAGE2="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>$TMP
a=$( cat $TMP )
[ "$a" != "NONE" ] && echo $a
return 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 ]; then
OK_MESSAGE="${OK_MESSAGE}$SWAP_PART will be used as Swap partition.\n\n"
fi
if [ $MBR_DISK ]; then
OK_MESSAGE="${OK_MESSAGE}GRUB will be installed as bootloader into the\n\
Master Boot Record (MBR) of disk $MBR_DISK.\n\n"
fi
OK_MESSAGE="${OK_MESSAGE}Is this ok ?\n"
$DIALOG --title "$TITLE" --yesno "$OK_MESSAGE" 15 60 8
return $?
}
### ------------------------------------------------------------
select_mbr_disk() {
DISK_LIST=""
DISKS=$( LANG=C fdisk -l | grep ^Disk | cut -d":" -f1 | cut -d" " -f2 )
for p in $DISKS; do
DISK_LIST="$DISK_LIST $p Disk off"
done
MESSAGE3="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>$TMP
a=$( cat $TMP )
[ "$a" != "NONE" ] && echo $a
}
### ------------------------------------------------------------
run_qtparted() {
QTPARTED=$( which qtparted 2>/dev/null )
if [ ! $QTPARTED ]; then
NO_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 8
else
$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 ] && break
CHOICE=$(cat $TMP)
case "$CHOICE" in
1)
INSTALL_PART=$( select_install_part )
if [ "$?" = "0" ]; then
SWAP_PART=$( select_swap_part )
if [ "$?" = "0" ]; then
MBR_DISK=$( select_mbr_disk )
ok_continue && break
fi
fi
INSTALL_PART="" ;;
2)
run_qtparted ;;
3)
about_message ;;
4)
exit ;;
esac
done
}
### ------------------------------------------------------------
### Main Program
### ------------------------------------------------------------
### requirements
test_for_livecd_install_script
test_for_root
### main menu
main_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-install
if [ $INSTALL_PART ]; then
run_livecd_install
fi