slitaz-tools view tinyutils/bootfloppybox @ rev 213

bootfloppybox: may work without X11
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jun 18 17:29:16 2008 +0000 (2008-06-18)
parents d4475be45426
children 33e84b0821de
line source
1 #! /bin/sh
2 #
3 # Gtkdialog box for the mount command. Part of SliTaz tools.
4 #
5 VERSION=20080409
7 # Check if user is root.
8 check_root()
9 {
10 if test $(id -u) != 0 ; then
11 echo -e "
12 You must be root to run `basename $0`. Please type 'su' and
13 root password to become super-user.\n"
14 exit 0
15 fi
16 }
18 # This function is used after each screen to contine or abort install.
19 check_retval()
20 {
21 case $retval in
22 1)
23 echo -e "\nVoluntary exit.\n" && exit 0 ;;
24 255)
25 echo -e "ESC pressed.\n" && exit 0 ;;
26 esac
27 }
29 select_floppy()
30 {
31 exec 3>&1
32 DEVICE=`$DIALOG --title " Floppy device " \
33 --backtitle "Boot Floppy Creation" --clear \
34 --extra-button --extra-label "Format" \
35 --colors --inputbox "
36 Enter floppy device (default /dev/fd0)
37 " 18 70 2>&1 1>&3`
38 retval=$?
39 exec 3>&-
40 check_retval
41 case "$DEVICE" in
42 /dev/fd*);;
43 *) DEVICE=/dev/fd0;;
44 esac
45 if [ "$retval" = "3" ]; then
46 fdformat -n $DEVICE
47 fi
48 }
50 if [ "$1" == "call" ]; then
51 case "$2" in
52 setup-grub)
53 DEVICE=$3
54 mke2fs $DEVICE
55 mkdir /media/floppy
56 mount $DEVICE /media/floppy
57 mkdir -p /media/floppy/boot/grub
58 cp /usr/lib/grub/i386-pc/stage? /media/floppy/boot/grub
59 cat > /media/floppy/boot/grub/menu.lst <<EOT
60 default saved
61 timeout 10
63 title Windows (example on /dev/hda1)
64 rootnoverify (hd0,0)
65 chainloader +1
66 save default
68 title Slitaz Live (example on /dev/hda1)
69 root (hd0,0)
70 kernel /boot/bzImage rw root=/dev/null vga=normal
71 initrd /boot/rootfs.gz
72 save default
74 title Slitaz Installed (example on /dev/hda2)
75 root (hd0,1)
76 kernel /boot/bzImage ro root=/dev/hda2 vga=normal
77 save default
79 EOT
80 [ -f /usr/share/boot/btmgr -a -f /usr/share/boot/memdisk.lzma ]\
81 && cp /usr/share/boot/btmgr /media/floppy/boot \
82 && unlzma -c /usr/share/boot/memdisk.lzma > \
83 /media/floppy/boot/memdisk \
84 && cat >> /media/floppy/boot/grub/menu.lst <<EOT
85 title Smart Boot Manager
86 kernel /boot/memtest
87 initrd /boot/btmgr
89 EOT
90 [ -f /usr/share/boot/etherboot ]\
91 && cp /usr/share/boot/etherboot /media/floppy/boot \
92 && cat >> /media/floppy/boot/grub/menu.lst <<EOT
93 title Etherboot
94 kernel /boot/etherboot
96 EOT
97 [ -f /usr/share/boot/memtest.lzma ]\
98 && unlzma -c /usr/share/boot/memtest.lzma > \
99 /media/floppy/boot/memtest \
100 && cat >> /media/floppy/boot/grub/menu.lst <<EOT
101 title Memtest86+
102 kernel /boot/memtest
104 EOT
105 [ -f /usr/share/boot/grub.exe.lzma ]\
106 && unlzma -c /usr/share/boot/grub.exe.lzma > \
107 /media/floppy/boot/grub.exe \
108 && cat >> /media/floppy/boot/grub/menu.lst <<EOT
109 title Grub4Dos
110 kernel /boot/grub/grub.exe --config-file="configfile (fd0)/boot/grub/menu4dos.lst"
112 EOT
113 grub-set-default --root-directory=/media/floppy 0
114 umount $DEVICE
115 grub --batch <<EOT
116 root (${DEVICE#/dev/})
117 setup (${DEVICE#/dev/})
118 quit
119 EOT
120 ;;
121 *) echo "Invalid command $0 $@" 1>&2
122 exit 1;;
123 esac
124 exit 0
125 fi
127 if [ -z "$XAUTHORITY" ]; then
129 : ${DIALOG=dialog}
131 DEVICE=/dev/fd0
132 while true; do
133 exec 3>&1
134 ID_SOURCE=`$DIALOG --title " Choose a boot floppy " \
135 --backtitle "Boot Floppy Creation on $DEVICE" --clear \
136 --extra-button --extra-label "Change floppy" \
137 --yes-label "Install" \
138 --no-label "Quit" \
139 --colors --radiolist "
140 Create a floppy to boot a LiveCD, in a PXE network...
141 Need a floppy disk in drive. Erase the whole floppy disk.
142 " 18 70 50\
143 SmartBtmgr " Boot any partition or ATAPI CD-ROM." on \
144 Etherboot " Replacement for proprietary PXE ROMs." off \
145 Memtest86+ " Memory failures detection tool." off \
146 Grub " Boot loader with command shell." off 2>&1 1>&3`
147 retval=$?
148 exec 3>&-
149 check_retval
150 if [ "$retval" = "3" ]; then
151 select_floppy
152 continue;
153 fi
154 while read key file pkg; do
155 [ "$key" = "$ID_SOURCE" ] || continue
156 if [ ! -f "$file" ]; then
157 $DIALOG --title " Install package " --colors \
158 --backtitle "Boot Floppy Creation" --clear \
159 --yes-label "Install" \
160 --no-label "Quit" \
161 --yesno "The package $pkg is not yet installed. Install it ?" 18 70
162 retval=$?
163 tazpkg get-install $pkg
164 fi
165 if [ "$pkg" = "grub" ]; then
166 bootfloppybox call setup-grub $DEVICE
167 else
168 case "$file" in
169 *.lzma) action="unlzma -c";;
170 *.gz) action="zcat";;
171 *) action="cat";;
172 esac
173 $action $file > $DEVICE
174 fi
175 exit 0
176 done <<EOT
177 SmartBtmgr /usr/share/boot/btmgr btmgr
178 Etherboot /usr/share/boot/etherboot etherboot
179 Memtest86+ /usr/share/boot/memtest.lzma memtest
180 Grub /usr/sbin/grub grub
181 EOT
182 done
183 fi
184 # Write bootfloppy image to floppy device.
185 #
186 BOOT_DIALOG='
187 <window title="bootfloppybox" icon-name="gtk-floppy">
188 <vbox>
190 <text use-markup="true">
191 <label>
192 "
193 <b>SliTaz - Bootfloppybox</b>"
194 </label>
195 </text>
196 <text wrap="false" width-chars="44" use-markup="true">
197 <label>
198 "
199 Create a floppy to boot a LiveCD, in a PXE network...
200 Need a floppy disk in drive. Erase the whole floppy disk.
201 "
202 </label>
203 </text>
205 <frame Floppy disk drive>
206 <hbox>
207 <text use-markup="true">
208 <label>"<b>Device : </b>"</label>
209 </text>
210 <entry>
211 <default>/dev/fd0</default>
212 <variable>DEVICE</variable>
213 </entry>
214 <button>
215 <label>Format floppy</label>
216 <input file icon="forward"></input>
217 <action>fdformat -n $DEVICE</action>
218 </button>
219 </hbox>
220 </frame>
221 <notebook labels="LiveCD|PXE Network|Memory Test|Expert">
222 '
223 while read name file pkg desc; do
224 tmp="<frame $name>
225 <hbox>
226 <text wrap=\"true\" width-chars=\"44\" use-markup=\"true\">
227 <label>
228 \"
229 $(echo -e $desc)
230 \"
231 </label>
232 </text>
233 </hbox>
234 "
235 if [ -f $file ]; then
236 case "$file" in
237 *.lzma) action="unlzma -c";;
238 *.gz) action="zcat";;
239 *) action="cat";;
240 esac
241 if [ "$pkg" = "grub" ]; then
242 tmp="$tmp
243 <hbox>
244 <button>
245 <label>Grub menu</label>
246 <input file icon=\"accessories-text-editor\"></input>
247 <action>bootfloppybox call setup-grub \$DEVICE</action>
248 <action>mount \$DEVICE /media/floppy</action>
249 <action type=\"lauch\">leafpad /media/floppy/boot/grub/menu.lst</action>
250 <action>umount \$DEVICE</action>
251 </button>
252 <button>
253 <label>Write floppy</label>
254 <input file icon=\"forward\"></input>
255 <action>bootfloppybox call setup-grub \$DEVICE</action>
256 </button>
257 </hbox>
258 </frame>
259 "
260 else
261 tmp="$tmp
262 <hbox>
263 <button>
264 <label>Write floppy</label>
265 <input file icon=\"forward\"></input>
266 <action>$action $file > \$DEVICE</action>
267 </button>
268 </hbox>
269 </frame>
270 "
271 fi
272 else
273 tmp="$tmp
274 <hbox>
275 <text wrap=\"true\" width-chars=\"34\" use-markup=\"true\">
276 <label>
277 \"<i>The package <b>$pkg</b> is not yet installed</i>\"
278 </label>
279 </text>
280 <button>
281 <input file icon=\"go-jump\"></input>
282 <label>Install</label>
283 <action>[ -f /var/lib/tazpkg/packages.list ] || tazpkg recharge</action>
284 <action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 80x17 -title \"$pkg install\" -e \"tazpkg get-install $pkg ; echo -e \\\"----\\n\\nENTER to continue...\\\" && read close\"</action>
285 <action type=\"exit\">Exit</action>
286 </button>
287 </hbox>
288 </frame>
289 "
290 fi
291 BOOT_DIALOG="$BOOT_DIALOG$tmp"
292 done <<EOT
293 SmartBtmgr /usr/share/boot/btmgr btmgr This OS independent Smart Boot Manager can boot any partition or ATAPI CD-ROM.
294 Etherboot /usr/share/boot/etherboot etherboot This network bootloader provides a replacement for proprietary PXE or NBI ROMs.
295 Memtest86+ /usr/share/boot/memtest.lzma memtest Memory failures detection tool.
296 Grub /usr/sbin/grub grub General purpose boot loader with command shell
297 EOT
298 tmp='
299 </notebook>
300 <hbox>
301 <button>
302 <input file icon="exit"></input>
303 <label>Exit</label>
304 <action type="exit">Exit</action>
305 </button>
306 </hbox>
308 </vbox>
309 </window>
310 '
311 BOOT_DIALOG="$BOOT_DIALOG$tmp"
312 export BOOT_DIALOG
314 # Only root can create floppy.
315 check_root
316 gtkdialog --program=BOOT_DIALOG
318 exit 0