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