slitaz-tools view tinyutils/bootfloppybox @ rev 292
netbox: indent with tabs, add comments and separate frame
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Feb 15 00:06:44 2009 +0100 (2009-02-15) |
parents | 682760cabf36 |
children | af65458ca488 |
line source
1 #! /bin/sh
2 #
3 # Gtkdialog box for the mount command. Part of SliTaz tools.
4 #
5 VERSION=20081121
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 rm -f /tmp/floppybox.grub.menu
24 echo -e "\nVoluntary exit.\n" && exit 0 ;;
25 255)
26 rm -f /tmp/floppybox.grub.menu
27 echo -e "ESC pressed.\n" && exit 0 ;;
28 esac
29 }
31 select_floppy()
32 {
33 DEVICE="$DIALOG --title \" Floppy device \" --backtitle \"Boot Floppy Creation\" --clear --extra-button --extra-label \"Format\" --colors --radiolist \"
34 Select boot device
35 \" 18 70 50"
36 on=on
37 for i in /sys/devices/platform/floppy.*/block:*; do
38 [ -d $i ] || continue
39 DEVICE="$DEVICE /dev/${i#*block:} 'Floppy in ${i#*block:}' $on"
40 on=off
41 done
42 DEVICE="$DEVICE floppy \"cdrom image file boot.iso\" $on"
43 DEVICE="$DEVICE cdrom \"floppy image file boot.fd\" off 2>&1 1>&3"
44 exec 3>&1
45 DEVICE=`eval $DEVICE`
46 retval=$?
47 exec 3>&-
48 check_retval
49 if [ "$retval" = "3" ]; then
50 case "$DEVICE" in
51 /dev/*) fdformat -n $DEVICE;;
52 esac
53 fi
54 }
56 mkmenu()
57 {
58 if [ "$1" = "grub4dos" ]; then
59 SAVEDEFAULT="save default"
60 cat > /tmp/floppybox.grub.menu <<EOT
61 # grub4dos menu
62 default /default
63 EOT
64 else
65 SAVEDEFAULT="savedefault"
66 cat > /tmp/floppybox.grub.menu <<EOT
67 # grub menu
68 default saved
69 EOT
70 fi
71 cat >> /tmp/floppybox.grub.menu <<EOT
72 timeout 8
73 color yellow/brown light-green/black
75 EOT
76 entry=0
77 [ -f /boot/gpxe ] && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
78 title gPXE (Boot from the Web, PXE/iSCSI/AoE support)
79 kernel /boot/gpxe $(dd if=/boot/gpxe bs=1 skip=519 count=255 2>/dev/null | strings)
81 EOT
82 [ -f /usr/share/boot/btmgr -a -f /usr/share/boot/memdisk.lzma ] \
83 && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
84 title Smart Boot Manager (text - boot floppy, hard disk or CD/DVD)
85 kernel /boot/memdisk floppy c=80 h=2 s=18
86 initrd /boot/btmgr.gz
88 EOT
89 [ -f /usr/share/boot/plop.gz -a -f /usr/share/boot/memdisk.lzma ] \
90 && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
91 title Plop Boot Manager (graphic - boot floppy, hard disk, CD/DVD or USB)
92 kernel /boot/memdisk floppy c=80 h=2 s=18
93 initrd /boot/plop.gz
95 EOT
96 [ -f /usr/share/boot/etherboot ] && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
97 title Etherboot (LAN boot, PXE or NBI)
98 kernel /boot/etherboot
100 EOT
101 [ -f /usr/share/boot/memtest.lzma -a -f /usr/share/boot/memdisk.lzma ] \
102 && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
103 title Memtest86+ (Test system memory)
104 kernel /boot/memdisk floppy c=80 h=2 s=18
105 initrd /boot/memtest.gz
107 EOT
108 [ "$1" = "grub4dos" ] && entry=$(($entry + 3)) && cat >> /tmp/floppybox.grub.menu <<EOT
109 title Windows (scan ntldr)
110 fallback $(($entry -3 + 1))
111 find --set-root /ntldr
112 chainloader /ntldr
113 $SAVEDEFAULT --wait=2
115 title Windows (scan cmldr)
116 fallback $(($entry -3 + 2))
117 find --set-root /cmldr
118 chainloader /cmldr
119 $SAVEDEFAULT --wait=2
121 title Windows (scan io.sys)
122 fallback $(($entry -3 + 3))
123 find --set-root /io.sys
124 chainloader /io.sys
125 $SAVEDEFAULT --wait=2
127 EOT
128 entry=$(($entry + 3)) && cat >> /tmp/floppybox.grub.menu <<EOT
129 title Windows (example on /dev/hda1)
130 rootnoverify (hd0,0)
131 chainloader +1
132 $SAVEDEFAULT
134 title Slitaz Frugal (example on /dev/hda1)
135 root (hd0,0)
136 kernel /boot/bzImage rw root=/dev/null vga=normal
137 initrd /boot/rootfs.gz
138 $SAVEDEFAULT
140 title Slitaz Installed (example on /dev/hda2)
141 root (hd0,1)
142 kernel /boot/bzImage ro root=/dev/hda2 vga=normal
143 $SAVEDEFAULT
145 EOT
146 [ "$1" = "grub4dos" ] && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
147 title Slitaz cdrom image (example on /dev/hda1, DEFRAGMENTED)
148 map (hd0,0)/boot/slitaz-cooking.iso (hd1)
149 map --hook
150 kernel (hd1)/boot/bzImage rw root=/dev/null vga=normal
151 initrd (hd1)/boot/rootfs.gz
152 $SAVEDEFAULT
154 EOT
155 false && [ -f /usr/share/boot/grub.exe.lzma ] && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
156 title Grub4Dos
157 kernel /boot/grub/grub.exe --config-file="configfile (fd0)/boot/grub/menu4dos.lst"
159 EOT
160 }
162 install_grub()
163 {
164 LOOP=""
165 GRUB_DEV=${DEVICE#/dev/}
166 GRUB_DEV=${GRUB_DEV%% *}
167 case "$DEVICE" in
168 floppy*)
169 LOOP="-o loop"
170 GRUB_DEV=fd0
171 DEVICE=boot.fd
172 dd if=/dev/zero of=$DEVICE bs=18k count=80;;
173 esac
174 grep -qs "^# $2 menu" /tmp/floppybox.grub.menu || mkmenu $2
175 case "$DEVICE" in
176 /dev/*|boot.fd)
177 yes y | mke2fs $DEVICE
178 mkdir /media/floppy
179 mount $LOOP $DEVICE /media/floppy
180 if [ "$2" = "grub4dos" ]; then
181 mkdir -p /media/floppy/boot
182 unlzma -c /usr/share/boot/grldr.lzma > /media/floppy/grldr
183 cp $1/boot/* /media/floppy/boot 2> /dev/null
184 cp /tmp/floppybox.grub.menu /media/floppy/menu.lst
185 umount -d /media/floppy
186 bootlace --floppy --sectors-per-track=18 --heads=2 \
187 --chs --ext2 $DEVICE
188 else
189 mkdir -p /media/floppy/boot/grub
190 cp /usr/lib/grub/i386-pc/stage? /media/floppy/boot/grub
191 cp -a $1/boot /media/floppy
192 cp /tmp/floppybox.grub.menu /media/floppy/boot/grub/menu.lst
193 grub-set-default --root-directory=/media/floppy 0
194 echo "($GRUB_DEV) $(losetup | grep $DEVICE | cut -d: -f1)" > $1/device.map
195 [ -n "$LOOP" ] && LOOP="--device-map=$1/device.map"
196 grub $LOOP --batch <<EOT
197 root ($GRUB_DEV)
198 setup ($GRUB_DEV)
199 quit
200 EOT
201 umount -d /media/floppy
202 fi ;;
203 cdrom*)
204 mkdir -p $1/boot/grub 2> /dev/null
205 cp /tmp/floppybox.grub.menu $1/boot/grub/menu.lst
206 if [ "$2" = "grub4dos" ]; then
207 unlzma -c /usr/share/boot/grldr.lzma > $1/boot/grub/grldr
208 genisoimage -R -o boot.iso -b boot/grub/grldr \
209 -c boot/boot.cat -no-emul-boot -boot-load-seg 0x1000 \
210 -hide boot/boot.cat -input-charset iso8859-1 $1
211 else
212 cp /usr/lib/grub/i386-pc/stage2_eltorito $1/boot/grub
213 genisoimage -R -o boot.iso -b boot/grub/stage2_eltorito \
214 -c boot/boot.cat -no-emul-boot -boot-load-size 4 \
215 -hide boot/boot.cat -input-charset iso8859-1 \
216 -boot-info-table $1
217 fi ;;
218 esac
219 }
221 while true; do
223 if [ "$1" == "call" ]; then
224 case "$2" in
225 mkmenu) mkmenu $3;;
226 install)
227 DIR=/tmp/mkbootfloppy$$
228 mkdir -p $DIR
229 DEVICE=$4
230 file=$5
231 case "$3" in
232 grub*)
233 mkdir -p $DIR/boot/grub
234 [ -f /usr/share/boot/btmgr -a -f /usr/share/boot/memdisk.lzma ] \
235 && cat /usr/share/boot/btmgr /dev/zero | \
236 dd bs=18k count=80 | gzip -9 > \
237 $DIR/boot/btmgr.gz \
238 && unlzma -c /usr/share/boot/memdisk.lzma > \
239 $DIR/boot/memdisk
240 [ -f /usr/share/boot/plop.gz -a \
241 -f /usr/share/boot/memdisk.lzma ] \
242 && zcat /usr/share/boot/plop.gz | \
243 cat - /dev/zero | dd bs=18k count=80 | \
244 gzip -9 > $DIR/boot/plop.gz \
245 && unlzma -c /usr/share/boot/memdisk.lzma > \
246 $DIR/boot/memdisk
247 [ -f /usr/share/boot/etherboot ] \
248 && cp /usr/share/boot/etherboot $DIR/boot
249 [ -f /boot/gpxe ]\
250 && cp /boot/gpxe $DIR/boot
251 [ -f /usr/share/boot/memtest.lzma -a \
252 -f /usr/share/boot/memdisk.lzma ] \
253 && unlzma -c /usr/share/boot/memtest.lzma | \
254 cat - /dev/zero | dd bs=18k count=80 | \
255 gzip -9 > $DIR/boot/memtest.gz \
256 && unlzma -c /usr/share/boot/memdisk.lzma > \
257 $DIR/boot/memdisk
258 install_grub $DIR $3
259 ;;
260 *)
261 case "$file" in
262 *.lzma) action="unlzma -c";;
263 *.gz) action="zcat";;
264 *) action="cat";;
265 esac
266 case "$DEVICE" in
267 /dev/*) $action $file > $DEVICE;;
268 flopp*) $action $file | cat - /dev/zero | \
269 dd bs=18k count=80 > boot.fd;;
270 cdrom*)
271 mkdir -p $DIR/boot/grub
272 case "$3" in
273 btmgr|plop|memtest)
274 $action $file | cat - /dev/zero | \
275 dd bs=18k count=80 | \
276 gzip -9 > $DIR/boot/$3.gz
277 unlzma -c /usr/share/boot/memdisk.lzma \
278 > $DIR/boot/memdisk
279 cat > /tmp/floppybox.grub.menu << EOT
280 # grub menu
281 timeout 0
282 title $3
283 kernel /boot/memdisk floppy c=80 h=2 s=18
284 initrd /boot/$3.gz
285 EOT
286 ;;
287 *) $action $file > $DIR/boot/$3
288 cat > /tmp/floppybox.grub.menu << EOT
289 # grub menu
290 timeout 0
291 title $3
292 kernel /boot/$3
293 EOT
294 ;;
295 esac
296 install_grub $DIR grub
297 ;;
298 esac
299 ;;
300 esac
301 rm -rf $DIR
302 ;;
303 get-plop)
304 PLOP_URL="$(wget -O - http://www.plop.at/en/bootmanagerdl.html |\
305 grep plpbt | head -1 |\
306 sed 's|.*href=\(.*\) target.*|\1|')"
307 VERSION="$(basename $PLOP_URL| sed 's/[^0-9\.]*\(.*\).zip/\1/')"
308 mkdir -p /tmp/get-plop$$/plop-$VERSION/fs/$(dirname $3)
309 wget -O - $PLOP_URL | unzip -p /dev/stdin '*/plpbt.img' | \
310 gzip -9 > /tmp/get-plop$$/plop-$VERSION/fs/$3
311 if [ -s /tmp/get-plop$$/plop-$VERSION/fs/$3 ]; then
312 cat > /tmp/get-plop$$/plop-$VERSION/receipt <<EOT
313 PACKAGE="plop"
314 VERSION="$VERSION"
315 CATEGORY="non-free"
316 SHORT_DESC="Plop boot manager."
317 WEB_SITE="http://www.plop.at/en/bootmanager.html"
318 EOT
319 ( cd /tmp/get-plop$$ ; tazpkg pack plop-$VERSION )
320 tazpkg install /tmp/get-plop$$/plop-$VERSION.tazpkg
321 fi
322 rm -rf /tmp/get-plop$$
323 ;;
324 *) echo "Invalid command $0 $@" 1>&2
325 exit 1;;
326 esac
327 exit 0
328 fi
330 if [ -z "$XAUTHORITY" ]; then
332 : ${DIALOG=dialog}
334 DEVICE=/dev/fd0
335 while true; do
336 exec 3>&1
337 ID_SOURCE=`$DIALOG --title " Choose a boot floppy " \
338 --backtitle "Boot Floppy Creation on $DEVICE" --clear \
339 --extra-button --extra-label "Change floppy" \
340 --yes-label "Install" \
341 --no-label "Quit" \
342 --colors --radiolist "
343 Create a floppy or a cdrom to boot a LiveCD, in a PXE network...
344 May need a floppy disk in drive. Erase the whole floppy disk.
345 " 18 70 50\
346 SmartBtmgr "Boot any partition or ATAPI CD-ROM." on \
347 Plop "Boot harddisk floppy CD/DVD or USB." off \
348 Etherboot "Replacement for proprietary PXE ROMs." off \
349 gPXE "Boot from http://boot.slitaz.org/" off \
350 Memtest86+ "Memory failures detection tool." off \
351 Grub4DOS "Enhanced grub version supporting NTFS" off \
352 Grub "Boot loader with command shell." off 2>&1 1>&3`
353 retval=$?
354 exec 3>&-
355 check_retval
356 if [ "$retval" = "3" ]; then
357 select_floppy
358 continue;
359 fi
360 while read key file pkg; do
361 [ "$key" = "$ID_SOURCE" ] || continue
362 if [ ! -f "$file" ]; then
363 $DIALOG --title " Install package " --colors \
364 --backtitle "Boot Floppy Creation" --clear \
365 --yes-label "Install" \
366 --no-label "Quit" \
367 --yesno "The package $pkg is not yet installed. Install it ?" 18 70
368 retval=$?
369 if [ "$pkg" = "plop" ]; then
370 bootfloppybox call get-plop $file
371 else
372 tazpkg get-install $pkg
373 fi
374 fi
375 bootfloppybox call install "$pkg" "$DEVICE" "$file"
376 exit 0
377 done <<EOT
378 SmartBtmgr /usr/share/boot/btmgr btmgr
379 Plop /usr/share/boot/plop.gz plop
380 Etherboot /usr/share/boot/etherboot etherboot
381 gPXE /boot/gpxe gpxe
382 Memtest86+ /usr/share/boot/memtest.lzma memtest
383 Grub4DOS /usr/share/boot/grldr.lzma grub4dos
384 Grub /usr/sbin/grub grub
385 EOT
386 done
387 fi
388 #
389 # Describe gPXE arguments.
390 #
391 export HELP='
392 <window title="gPXE forced url" icon-name="gtk-floppy">
393 <vbox>
394 <text use-markup="true">
395 <label>"
396 <b>Web boot parameters</b>"
397 </label>
398 </text>
399 <frame>
400 <text wrap="true" width-chars="58" use-markup="true">
401 <label>
402 "Without parameters (i.e. with an empty Boot URL) gPXE will perform a normal PXE boot: IP configuration with DHCP and download DHCP bootfile with TFTP.
404 You can override the DHCP bootfile with an Boot URL such as <i>tftp://192.168.0.1/pxe/pxeloader</i>, <i>http://mirror.slitaz.org/pxe/pxelinux.0</i>, or <i>x-tftm://192.168.0.201//lts/vmlinuz.ltsp</i>.
406 You can override IP configuration too (usefull without DHCP server), example:
407 <i>ip=192.168.0.10/24 gw=192.168.0.1 dns=192.168.0.1 nodhcp url=http://mirror.slitaz.org/pxe/pxelinux.0</i>
409 The <i>nodhcp</i> keyword avoids dhcp timeouts and the <i>url=</i> keyword is optionnal when the url is the only one argument.
410 "
411 </label>
412 </text>
413 </frame>
414 </vbox>
415 </window>
416 '
417 #
418 # Write bootfloppy image to floppy device.
419 #
420 BOOT_DIALOG='
421 <window title="bootfloppybox" icon-name="gtk-floppy">
422 <vbox>
424 <text use-markup="true">
425 <label>
426 "
427 <b>SliTaz - Bootfloppybox</b>"
428 </label>
429 </text>
430 <text wrap="false" width-chars="44" use-markup="true">
431 <label>
432 "
433 Create a floppy or a cdrom to boot a LiveCD, in a PXE network or WEB...
434 May need a floppy disk in drive. Erase the whole floppy disk.
435 "
436 </label>
437 </text>
439 <frame Floppy disk drive>
440 <hbox>
441 <text use-markup="true">
442 <label>"<b>Device : </b>"</label>
443 </text>
444 <combobox>
445 <variable>DEVICE</variable>'
446 for i in /sys/devices/platform/floppy.*/block:*; do
447 [ -d $i ] || continue
448 BOOT_DIALOG="$BOOT_DIALOG
449 <item>/dev/${i#*block:}</item>"
450 done
451 tmp=' <item>cdrom image (boot.iso)</item>
452 <item>floppy image (boot.fd)</item>
453 </combobox>
454 <button>
455 <label>Format floppy</label>
456 <input file icon="forward"></input>
457 <action>case "$DEVICE" in /dev/*) fdformat -n $DEVICE;; esac</action>
458 </button>
459 </hbox>
460 </frame>
461 <notebook labels="LiveCD|USB|PXE Network|WEB Network|Memory Test|Windows|Expert">
462 '
463 BOOT_DIALOG="$BOOT_DIALOG$tmp"
464 while read name file pkg desc; do
465 tmp="<frame $name>
466 <hbox>
467 <text wrap=\"true\" width-chars=\"44\" use-markup=\"true\">
468 <label>
469 \"
470 $(echo -e $desc)
471 \"
472 </label>
473 </text>
474 </hbox>
475 <hbox>
476 "
477 if [ -f $file ]; then
478 if [ "$pkg" = "grub" -o "$pkg" = "grub4dos" ]; then
479 tmp="$tmp
480 <button>
481 <label>Grub menu</label>
482 <input file icon=\"accessories-text-editor\"></input>
483 <action>bootfloppybox call mkmenu $pkg</action>
484 <action type=\"lauch\">leafpad /tmp/floppybox.grub.menu</action>
485 </button>
486 "
487 elif [ "$pkg" = "etherboot" ]; then
488 tmp="$tmp
489 <button>
490 <input file icon=\"browser\"></input>
491 <label>Wiki</label>
492 <action>firefox http://wiki.slitaz.org/doku.php?id=quickstart:pxe &</action>
493 </button>
494 "
495 elif [ "$pkg" = "gpxe" ]; then
496 tmp="$tmp
497 <text wrap=\"true\" use-markup=\"true\">
498 <label> \"<b>Boot URL:</b>\" </label>
499 </text>
500 <entry>
501 <default>$(dd if=$file bs=1 skip=519 count=255 2>/dev/null | strings)</default>
502 <variable>URL</variable>
503 </entry>
504 </hbox>
505 <hbox>
506 <button>
507 <input file icon=\"browser\"></input>
508 <label>Wiki</label>
509 <action>firefox http://wiki.slitaz.org/doku.php?id=quickstart:pxe &</action>
510 </button>
511 <button help>
512 <action type=\"launch\">HELP</action>
513 </button>
514 <button>
515 <label>Update</label>
516 <input file icon=\"reload\"></input>
517 <action>echo -n \"\$URL\" | cat - /dev/zero | dd conv=notrunc bs=1 count=255 seek=519 of=$file 2>/dev/null</action>
518 </button>
519 "
520 fi
521 receipt=/var/lib/tazpkg/installed/$pkg/receipt
522 if [ -f $receipt ]; then
523 . $receipt
524 tmp="$tmp
525 <button>
526 <input file icon=\"browser\"></input>
527 <label>Web</label>
528 <action>firefox $WEB_SITE &</action>
529 </button>
530 "
531 fi
532 tmp="$tmp
533 <button>
534 <label>Write floppy</label>
535 <input file icon=\"forward\"></input>
536 <action>bootfloppybox call install \"$pkg\" \"\$DEVICE\" \"$file\"</action>
537 </button>
538 </hbox>
539 </frame>
540 "
541 else
542 tmp2="tazpkg get-install $pkg --forced"
543 [ "$pkg" = "plop" ] && tmp2="bootfloppybox call get-plop $file"
544 tmp="$tmp
545 <text wrap=\"true\" width-chars=\"34\" use-markup=\"true\">
546 <label>
547 \"<i>The package <b>$pkg</b> is not yet installed</i>\"
548 </label>
549 </text>
550 <button>
551 <input file icon=\"go-jump\"></input>
552 <label>Install</label>
553 <action>[ -f /var/lib/tazpkg/packages.list ] || tazpkg recharge</action>
554 <action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 80x17 -title \"$pkg install\" -e \"$tmp2 ; sleep 2\"</action>
555 <action type=\"exit\">restart</action>
556 </button>
557 </hbox>
558 </frame>
559 "
560 fi
561 BOOT_DIALOG="$BOOT_DIALOG$tmp"
562 done <<EOT
563 SmartBtmgr /usr/share/boot/btmgr btmgr This OS independent Smart Boot Manager can boot any partition or ATAPI CD-ROM.
564 Plop /usr/share/boot/plop.gz plop This non free Boot Manager can boot floppy, hardisk, USB or CD/DVD. Hit Ctrl-ESC for text mode.
565 Etherboot /usr/share/boot/etherboot etherboot This network bootloader provides a replacement for proprietary PXE or NBI ROMs.
566 gPXE /boot/gpxe gpxe PXE / iSCSI / AoE network bootloader.
567 Memtest86+ /usr/share/boot/memtest.lzma memtest Memory failures detection tool.
568 Grub4DOS /usr/share/boot/grldr.lzma grub4dos Enhanced grub version supporting NTFS
569 Grub /usr/sbin/grub grub General purpose boot loader with command shell
570 EOT
571 tmp='
572 </notebook>
573 <hbox>
574 <button>
575 <input file icon="exit"></input>
576 <label>Exit</label>
577 <action type="exit">Exit</action>
578 </button>
579 </hbox>
581 </vbox>
582 </window>
583 '
584 BOOT_DIALOG="$BOOT_DIALOG$tmp"
585 export BOOT_DIALOG
587 # Only root can create floppy.
588 check_root
589 gtkdialog --program=BOOT_DIALOG | grep -q 'EXIT="restart"' && continue
590 rm -f /tmp/floppybox.grub.menu
591 exit 0
592 done