Subversion Repositories livecd

Rev

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

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