Subversion Repositories livecd

Rev

Rev 52 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 52 Rev 53
1
#!/bin/bash
1
#!/bin/bash
2
#
2
#
3
################################################################
3
################################################################
4
#
4
#
5
# Simple GUI for livecd-install 
5
# Simple GUI for livecd-install 
6
#
6
#
7
# Urs beyerle, PSI
7
# Urs beyerle, PSI
8
#
8
#
9
################################################################
9
################################################################
10
#
10
#
11
  VERSION=0.1
11
  VERSION=0.1
12
#
12
#
13
################################################################
13
################################################################
14
 
14
 
15
clean_exit()
15
clean_exit()
16
{
16
{
17
  rm -rf $TMPDIR
17
  rm -rf $TMPDIR
18
}
18
}
19
 
19
 
20
trap "clean_exit" EXIT
20
trap "clean_exit" EXIT
21
 
21
 
22
 
22
 
23
### ------------------------------------------------------------
23
### ------------------------------------------------------------
24
### Definitions
24
### Definitions
25
### ------------------------------------------------------------
25
### ------------------------------------------------------------
26
 
26
 
27
### set path and lang
27
### set path and lang
28
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin"
28
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin"
29
LANG=en_US.UTF-8
29
LANG=en_US.UTF-8
30
 
30
 
31
### define name of LiveCD install script
31
### define name of LiveCD install script
32
LIVECD_INSTALL=livecd-install
32
LIVECD_INSTALL=livecd-install
33
 
33
 
34
### title and script name
34
### title and script name
35
TITLE="LiveCD Install GUI version $VERSION"
35
TITLE="LiveCD Install GUI version $VERSION"
36
MENU_TITLE="LiveCD Install GUI version $VERSION"
36
MENU_TITLE="LiveCD Install GUI version $VERSION"
37
SCRIPTNAME=$( basename $0 )
37
SCRIPTNAME=$( basename $0 )
38
 
38
 
39
### tmpdir
39
### tmpdir
40
TMPDIR=/tmp/livecd-install-gui.$$
40
TMPDIR=/tmp/livecd-install-gui.$$
41
TMP=$TMPDIR/dialog
41
TMP=$TMPDIR/dialog
42
mkdir -p $TMPDIR
42
mkdir -p $TMPDIR
43
 
43
 
44
### dialog or xdialog?
44
### dialog or xdialog?
45
DIALOG="dialog"
45
DIALOG="dialog"
46
XDIALOG_HIGH_DIALOG_COMPAT=1
46
XDIALOG_HIGH_DIALOG_COMPAT=1
47
export XDIALOG_HIGH_DIALOG_COMPAT
47
export XDIALOG_HIGH_DIALOG_COMPAT
48
[ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"; XDIALOG="yes"
48
[ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"; XDIALOG="yes"
49
 
49
 
50
 
50
 
51
 
51
 
52
### ------------------------------------------------------------
52
### ------------------------------------------------------------
53
### Functions
53
### Functions
54
### ------------------------------------------------------------
54
### ------------------------------------------------------------
55
 
55
 
56
 
56
 
57
### -------------------------------------------------------------
57
### -------------------------------------------------------------
58
about_message() {
58
about_message() {
59
 
59
 
60
    ABOUT_MESSAGE=$( cat <<EOF
60
    ABOUT_MESSAGE=$( cat <<EOF
61
---------------------------------------\n
61
---------------------------------------\n
62
  $SCRIPTNAME\n
62
  $SCRIPTNAME\n
63
  $TITLE\n
63
  $TITLE\n
64
---------------------------------------\n
64
---------------------------------------\n
65
  (c) 2007, Urs Beyerle, PSI\n
65
  (c) 2007, Urs Beyerle, PSI\n
66
\n
66
\n
67
  Press OK to continue\n
67
  Press OK to continue\n
68
EOF)
68
EOF)
69
    $DIALOG --title "$TITLE" --infobox "$ABOUT_MESSAGE" 15 60 8
69
    $DIALOG --title "$TITLE" --infobox "$ABOUT_MESSAGE" 15 60 8
70
}
70
}
71
 
71
 
72
 
72
 
73
### -------------------------------------------------------------
73
### -------------------------------------------------------------
74
help_message() {
74
help_message() {
75
 
75
 
76
    HELP_MESSAGE=$( cat <<EOF
76
    HELP_MESSAGE=$( cat <<EOF
77
   --------------------------------------------------------------------\n
77
   --------------------------------------------------------------------\n
78
     $SCRIPTNAME\n
78
     $SCRIPTNAME\n
79
     $TITLE\n
79
     $TITLE\n
80
   --------------------------------------------------------------------\n
80
   --------------------------------------------------------------------\n
81
\n
81
\n
82
This is the frontend of the $LIVECD_INSTALL script.
82
This is the frontend of the $LIVECD_INSTALL script.
83
Use it to install the LiveCD/DVD on your hardisk.
83
Use it to install the LiveCD/DVD on your hardisk.
84
\n\n
84
\n\n
85
The LiveCD/DVD can be installed on a Linux
85
The LiveCD/DVD can be installed on a Linux
86
partition, which you may have to create first using tools
86
partition, which you may have to create first using tools
87
like qtparted, gparted, fdisk or parted. All data on the selected
87
like qtparted, gparted, fdisk or parted. All data on the selected
88
Linux partition will be deleted. 
88
Linux partition will be deleted. 
89
It is recommended to
89
It is recommended to
90
create in addition a Swap partition that will be later
90
create in addition a Swap partition that will be later
91
used by the installed Linux system.
91
used by the installed Linux system.
92
\n\n
92
\n\n
93
In order that you can boot into the installed Linux
93
In order that you can boot into the installed Linux
94
system, it is recommended that you choose to install
94
system, it is recommended that you choose to install
95
the bootloader GRUB into the Master Boot Record (MBR)
95
the bootloader GRUB into the Master Boot Record (MBR)
96
of your primary boot disk.
96
of your primary boot disk.
97
\n\n
97
\n\n
98
More options are available, if you run the script 
98
More options are available, if you run the script 
99
$LIVECD_INSTALL directly from the command line.
99
$LIVECD_INSTALL directly from the command line.
100
\n
100
\n
101
EOF)
101
EOF)
102
 
102
 
103
    $DIALOG --title "$TITLE" --infobox "$HELP_MESSAGE" 30 60 12
103
    $DIALOG --title "$TITLE" --infobox "$HELP_MESSAGE" 30 60 12
104
}
104
}
105
 
105
 
106
 
106
 
107
 
107
 
108
### ------------------------------------------------------------
108
### ------------------------------------------------------------
109
test_for_livecd_install_script() {
109
test_for_livecd_install_script() {
110
 
110
 
111
    LIVECD_INSTALL_SCRIPT=$( which $LIVECD_INSTALL 2>/dev/null )
111
    LIVECD_INSTALL_SCRIPT=$( which $LIVECD_INSTALL 2>/dev/null )
112
    if [ ! "$LIVECD_INSTALL_SCRIPT" ]; then
112
    if [ ! "$LIVECD_INSTALL_SCRIPT" ]; then
113
	MESSAGE0="Script $LIVECD_INSTALL not found"
113
	MESSAGE0="Script $LIVECD_INSTALL not found"
114
	$DIALOG --title "$TITLE" --msgbox "$MESSAGE0" 0 0
114
	$DIALOG --title "$TITLE" --msgbox "$MESSAGE0" 0 0
115
	exit 1
115
	exit 1
116
    fi
116
    fi
117
}
117
}
118
 
118
 
119
### ------------------------------------------------------------
119
### ------------------------------------------------------------
120
test_for_root() {
120
test_for_root() {
121
 
121
 
122
    if [ "$UID" -ne "0" ]; then
122
    if [ "$UID" -ne "0" ]; then
123
	MESSAGE0="To use this program, you need to be root"
123
	MESSAGE0="To use this program, you need to be root"
124
	$DIALOG --title "$TITLE" --msgbox "$MESSAGE0" 0 0
124
	$DIALOG --title "$TITLE" --msgbox "$MESSAGE0" 0 0
125
	exit 1
125
	exit 1
126
    fi
126
    fi
127
}
127
}
128
 
128
 
129
 
129
 
130
### ------------------------------------------------------------
130
### ------------------------------------------------------------
131
select_install_part() {
131
select_install_part() {
132
 
132
 
133
    PART_LIST=""
133
    PART_LIST=""
134
    PARTS=$( LANG=C fdisk -l | grep Linux$ | cut -d" " -f1 )
134
    PARTS=$( LANG=C fdisk -l | grep Linux$ | cut -d" " -f1 )
135
    if [ ! "$PARTS" ]; then
135
    if [ ! "$PARTS" ]; then
136
	NOPART_MESSAGE="No Linux partition found.\n\n\
136
	NOPART_MESSAGE="No Linux partition found.\n\n\
137
Please create one first" 
137
Please create one first" 
138
	$DIALOG --title "$TITLE" --infobox "$NOPART_MESSAGE" 15 60 8
138
	$DIALOG --title "$TITLE" --infobox "$NOPART_MESSAGE" 15 60 8
139
	exit 1
139
	exit 1
140
    fi
140
    fi
141
    for p in $PARTS; do
141
    for p in $PARTS; do
142
	PART_LIST="$PART_LIST $p Linux-Partiton off"
142
	PART_LIST="$PART_LIST $p Linux-Partiton off"
143
    done
143
    done
144
    MESSAGE1="Please select a partition to install the LiveCD"
144
    MESSAGE1="Please select a partition to install the LiveCD"
145
    $DIALOG --title "$TITLE" --no-cancel --radiolist "$MESSAGE1" 20 60 8 $PART_LIST 2>$TMP
145
    $DIALOG --title "$TITLE" --no-cancel --radiolist "$MESSAGE1" 20 60 8 $PART_LIST 2>$TMP
146
    cat $TMP
146
    cat $TMP
147
}
147
}
148
 
148
 
149
 
149
 
150
### ------------------------------------------------------------
150
### ------------------------------------------------------------
151
select_swap_part() {
151
select_swap_part() {
152
 
152
 
153
    PART_LIST=""
153
    PART_LIST=""
154
    PARTS=$( LANG=C fdisk -l | grep "Linux swap" | cut -d" " -f1 )
154
    PARTS=$( LANG=C fdisk -l | grep "Linux swap" | cut -d" " -f1 )
155
    if [ ! "$PARTS" ]; then
155
    if [ ! "$PARTS" ]; then
156
	NOSWAP_MESSAGE="No Swap partition found.\n\n\
156
	NOSWAP_MESSAGE="No Swap partition found.\n\n\
157
You can install the LiveCD without having\n\
157
You can install the LiveCD without having\n\
158
a Swap partition, but it is not recommended.\n\n\
158
a Swap partition, but it is not recommended.\n\n\
159
Continue ?" 
159
Continue ?" 
160
	$DIALOG --title "$TITLE" --yesno "$NOSWAP_MESSAGE" 15 60 8
160
	$DIALOG --title "$TITLE" --yesno "$NOSWAP_MESSAGE" 15 60 8
161
	return $?
161
	return $?
162
    fi
162
    fi
163
 
163
 
164
    for p in $PARTS; do
164
    for p in $PARTS; do
165
	PART_LIST="$PART_LIST $p Swap-Partiton off"
165
	PART_LIST="$PART_LIST $p Swap-Partiton off"
166
    done
166
    done
167
    MESSAGE2="Please select a SWAP partition"
167
    MESSAGE2="Please select a SWAP partition"
168
    $DIALOG --title "$TITLE" --no-cancel --radiolist "$MESSAGE2" 15 60 5 $PART_LIST \
168
    $DIALOG --title "$TITLE" --no-cancel --radiolist "$MESSAGE2" 15 60 5 $PART_LIST \
169
    NONE "Do not use a swap partition (not recommended)" off 2>$TMP
169
    NONE "Do not use a swap partition (not recommended)" off 2>$TMP
170
    a=$( cat $TMP )
170
    a=$( cat $TMP )
171
    [ "$a" != "NONE" ] && echo $a
171
    [ "$a" != "NONE" ] && echo $a
172
    return 0
172
    return 0
173
}
173
}
174
 
174
 
175
 
175
 
176
### ------------------------------------------------------------
176
### ------------------------------------------------------------
177
ok_continue() {
177
ok_continue() {
178
 
178
 
179
    OK_MESSAGE="\nLiveCD will be installed on $INSTALL_PART.\n\
179
    OK_MESSAGE="\nLiveCD will be installed on $INSTALL_PART.\n\
180
All data on $INSTALL_PART will be deleted !!\n\n"
180
All data on $INSTALL_PART will be deleted !!\n\n"
181
    if [ $SWAP_PART ]; then
181
    if [ $SWAP_PART ]; then
182
	OK_MESSAGE="${OK_MESSAGE}$SWAP_PART will be used as Swap partition.\n\n"
182
	OK_MESSAGE="${OK_MESSAGE}$SWAP_PART will be used as Swap partition.\n\n"
183
    fi
183
    fi
184
    if [ $MBR_DISK ]; then
184
    if [ $MBR_DISK ]; then
185
	OK_MESSAGE="${OK_MESSAGE}GRUB will be installed as bootloader into the\n\
185
	OK_MESSAGE="${OK_MESSAGE}GRUB will be installed as bootloader into the\n\
186
Master Boot Record (MBR) of disk $MBR_DISK.\n\n"
186
Master Boot Record (MBR) of disk $MBR_DISK.\n\n"
187
    fi
187
    fi
188
    OK_MESSAGE="${OK_MESSAGE}Is this ok ?\n"
188
    OK_MESSAGE="${OK_MESSAGE}Is this ok ?\n"
189
 
189
 
190
    $DIALOG --title "$TITLE" --default-no --yesno "$OK_MESSAGE" 15 60 8
190
    $DIALOG --title "$TITLE" --default-no --yesno "$OK_MESSAGE" 15 60 8
191
    return $?
191
    return $?
192
}
192
}
193
 
193
 
194
 
194
 
195
### ------------------------------------------------------------
195
### ------------------------------------------------------------
196
select_mbr_disk() {
196
select_mbr_disk() {
197
 
197
 
198
    DISK_LIST=""
198
    DISK_LIST=""
199
    DISKS=$( LANG=C fdisk -l | grep ^Disk | cut -d":" -f1 | cut -d" " -f2 )
199
    DISKS=$( LANG=C fdisk -l | grep ^Disk | cut -d":" -f1 | cut -d" " -f2 )
200
    for p in $DISKS; do
200
    for p in $DISKS; do
201
	DISK_LIST="$DISK_LIST $p Disk off"
201
	DISK_LIST="$DISK_LIST $p Disk off"
202
    done
202
    done
203
    MESSAGE3="Please select a disk to install the bootloader GRUB"
203
    MESSAGE3="Please select a disk to install the bootloader GRUB"
204
    $DIALOG --title "$TITLE" --no-cancel --radiolist "$MESSAGE3" 15 60 5 $DISK_LIST \
204
    $DIALOG --title "$TITLE" --no-cancel --radiolist "$MESSAGE3" 15 60 5 $DISK_LIST \
205
    NONE "Do not install GRUB (not recommended)" off 2>$TMP
205
    NONE "Do not install GRUB (not recommended)" off 2>$TMP
206
    a=$( cat $TMP )
206
    a=$( cat $TMP )
207
    [ "$a" != "NONE" ] && echo $a
207
    [ "$a" != "NONE" ] && echo $a
208
}
208
}
209
 
209
 
210
 
210
 
211
### ------------------------------------------------------------
211
### ------------------------------------------------------------
212
run_qtparted() {
212
run_qtparted() {
213
 
213
 
214
    QTPARTED=$( which qtparted 2>/dev/null )
214
    QTPARTED=$( which qtparted 2>/dev/null )
215
    if [ ! $QTPARTED ]; then
215
    if [ ! $QTPARTED ]; then
216
	NO_QTPARTED_MESSAGE="Sorry, qtparted not found.\n\n\
216
	NO_QTPARTED_MESSAGE="Sorry, qtparted not found.\n\n\
217
Please use an other tool like fdisk or parted."
217
Please use an other tool like fdisk or parted."
218
	$DIALOG --title "$TITLE" --infobox "$NO_QTPARTED_MESSAGE" 10 60 8
218
	$DIALOG --title "$TITLE" --infobox "$NO_QTPARTED_MESSAGE" 10 60 8
219
    else
219
    else
220
	$QTPARTED &
220
	$QTPARTED &
221
    fi
221
    fi
222
 
222
 
223
}
223
}
224
 
224
 
225
 
225
 
226
### ------------------------------------------------------------
226
### ------------------------------------------------------------
227
run_livecd_install() {
227
run_livecd_install() {
228
 
228
 
229
    xterm -sb -title "Run: $LIVECD_INSTALL -y $SWAP_PART_OPT $MBR_DISK_OPT $INSTALL_PART" \
229
    xterm -sb -title "Run: $LIVECD_INSTALL -y $SWAP_PART_OPT $MBR_DISK_OPT $INSTALL_PART" \
230
          -geometry 130x45+100+20 \
230
          -geometry 130x45+100+20 \
231
          -e 'echo; \
231
          -e 'echo; \
232
	      echo "Run: $LIVECD_INSTALL -y $SWAP_PART_OPT $MBR_DISK_OPT $INSTALL_PART"; \
232
	      echo "Run: $LIVECD_INSTALL -y $SWAP_PART_OPT $MBR_DISK_OPT $INSTALL_PART"; \
233
	      echo; \
233
	      echo; \
234
	      $LIVECD_INSTALL -y $SWAP_PART_OPT $MBR_DISK_OPT $INSTALL_PART; \
234
	      $LIVECD_INSTALL -y $SWAP_PART_OPT $MBR_DISK_OPT $INSTALL_PART; \
235
	      echo; \
235
	      echo; \
236
	      echo "$LIVECD_INSTALL finished.";\
236
	      echo "$LIVECD_INSTALL finished.";\
237
	      echo;\
237
	      echo;\
238
	      echo "- Press a key to close this window -"; \
238
	      echo "- Press a key to close this window -"; \
239
	      read -n 1'
239
	      read -n 1'
240
}
240
}
241
 
241
 
242
 
242
 
243
### ------------------------------------------------------------
243
### ------------------------------------------------------------
244
main_menu() {
244
main_menu() {
245
 
245
 
246
    MENU_1="Install the LiveCD"
246
    MENU_1="Install the LiveCD"
247
    MENU_2="Create Linux/Swap Partitions with qtparted"
247
    MENU_2="Create Linux/Swap Partitions with qtparted"
248
    MENU_3="Help"
248
    MENU_3="Help"
249
    MENU_4="About"
249
    MENU_4="About"
250
    MENU_5="Quit"
250
    MENU_5="Quit"
251
    
251
    
252
    while true; do
252
    while true; do
253
	
253
	
254
	$DIALOG --title "$TITLE" \
254
	$DIALOG --title "$TITLE" \
255
	    --menu "$MENU_TITLE" 15 60 6\
255
	    --menu "$MENU_TITLE" 15 60 6\
256
	    1 "$MENU_1" \
256
	    1 "$MENU_1" \
257
	    2 "$MENU_2" \
257
	    2 "$MENU_2" \
258
	    3 "$MENU_3" \
258
	    3 "$MENU_3" \
259
	    4 "$MENU_4" \
259
	    4 "$MENU_4" \
260
	    5 "$MENU_5" \
260
	    5 "$MENU_5" \
261
	    2> $TMP
261
	    2> $TMP
262
 
262
 
263
	[ $? -ne 0 ] && break
263
	[ $? -ne 0 ] && break
264
 
264
 
265
	CHOICE=$(cat $TMP)
265
	CHOICE=$(cat $TMP)
266
 
266
 
267
	case "$CHOICE" in
267
	case "$CHOICE" in
268
         1)
268
         1)
269
           INSTALL_PART=$( select_install_part )
269
           INSTALL_PART=$( select_install_part )
270
	   if [ "$?" = "0" ]; then
270
	   if [ "$?" = "0" ]; then
271
	       SWAP_PART=$( select_swap_part )
271
	       SWAP_PART=$( select_swap_part )
272
	       if [ "$?" = "0" ]; then
272
	       if [ "$?" = "0" ]; then
273
		   MBR_DISK=$( select_mbr_disk )
273
		   MBR_DISK=$( select_mbr_disk )
274
		   ok_continue && break 
274
		   ok_continue && break 
275
	       fi
275
	       fi
276
	   fi 
276
	   fi 
277
	   INSTALL_PART="" ;;
277
	   INSTALL_PART="" ;;
278
 
278
 
279
	 2)
279
	 2)
280
           run_qtparted ;;
280
           run_qtparted ;;
281
         3)
281
         3)
282
           help_message ;;
282
           help_message ;;
283
         4)
283
         4)
284
           about_message ;;
284
           about_message ;;
285
         5)
285
         5)
286
           exit ;;
286
           exit ;;
287
        esac
287
        esac
288
done
288
done
289
 
289
 
290
}
290
}
291
 
291
 
292
 
292
 
293
### ------------------------------------------------------------
293
### ------------------------------------------------------------
294
### Main Program
294
### Main Program
295
### ------------------------------------------------------------
295
### ------------------------------------------------------------
296
 
296
 
297
### requirements
297
### requirements
298
test_for_livecd_install_script
298
test_for_livecd_install_script
299
test_for_root
299
test_for_root
300
 
300
 
301
### main menu
301
### main menu
302
main_menu
302
main_menu
303
[ "$SWAP_PART" ] && export SWAP_PART_OPT="-swap $SWAP_PART"
303
[ "$SWAP_PART" ] && export SWAP_PART_OPT="-swap $SWAP_PART"
304
[ "$MBR_DISK" ]  && export MBR_DISK_OPT="-mbr $MBR_DISK"
304
[ "$MBR_DISK" ]  && export MBR_DISK_OPT="-mbr $MBR_DISK"
305
export INSTALL_PART=$INSTALL_PART
305
export INSTALL_PART=$INSTALL_PART
306
export LIVECD_INSTALL=$LIVECD_INSTALL
306
export LIVECD_INSTALL=$LIVECD_INSTALL
307
 
307
 
308
### run $LIVECD_INSTALL
308
### run $LIVECD_INSTALL
309
if [ $INSTALL_PART ]; then
309
if [ $INSTALL_PART ]; then
310
    run_livecd_install
310
    run_livecd_install
311
fi
311
fi
312
 
312