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