Rev 51 | 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
### define name of LiveCD install script
LIVECD_INSTALL=livecd-install
### title and script name
TITLE="LiveCD Install GUI version $VERSION"
MENU_TITLE="LiveCD Install GUI version $VERSION"
SCRIPTNAME=$( basename $0 )
### tmpdir
TMPDIR=/tmp/livecd-install-gui.$$
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
$SCRIPTNAME\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
}
### -------------------------------------------------------------
help_message() {
HELP_MESSAGE=$( cat <<EOF
--------------------------------------------------------------------\n
$SCRIPTNAME\n
$TITLE\n
--------------------------------------------------------------------\n
\n
This is the frontend of the $LIVECD_INSTALL script.
Use it to install the LiveCD/DVD on your hardisk.
\n\n
The LiveCD/DVD can be installed on a Linux
partition, which you may have to create first using tools
like qtparted, gparted, fdisk or parted. All data on the selected
Linux partition will be deleted.
It is recommended to
create in addition a Swap partition that will be later
used by the installed Linux system.
\n\n
In order that you can boot into the installed Linux
system, it is recommended that you choose to install
the bootloader GRUB into the Master Boot Record (MBR)
of your primary boot disk.
\n\n
More options are available, if you run the script
$LIVECD_INSTALL directly from the command line.
\n
EOF)
$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" ]; 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" --default-no --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; \
$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 ] && 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)
help_message ;;
4)
about_message ;;
5)
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
export LIVECD_INSTALL=$LIVECD_INSTALL
### run $LIVECD_INSTALL
if [ $INSTALL_PART ]; then
run_livecd_install
fi