-
Notifications
You must be signed in to change notification settings - Fork 2
/
pxemultiboot.rb
executable file
·1502 lines (1301 loc) · 40.4 KB
/
pxemultiboot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
= PXE Multi Boot environment builder
This program builds PXE multi boot environment.
== Requirements
* Ruby 1.8.x or later
* wget
* GNU tar (and gzip, bzip2)
Optional:
* unzip for some options
* 7z (7-Zip) for --ubuntu-casper (ubuntu live iso)
== Usage
== build tftpboot
* ruby pxemultiboot.rb --help
* ruby pxemultiboot.rb --debian lenny,etch,etchnhalf,squeeze,sid --ubuntu karmic,hardy,jaunty,intrepid,dapper,lucid --fedora 12,11,10,9 --centos 5.4,5.3,4.8,4.7 --vine 5.0,4.2 --memtest 4.00 --mbm 0.39 --plop-boot-manager 5.0.4 --freedos-balder10 --gag 4.10 --ping 3.00.03 --grub4dos 0.4.4
== PXE boot
* put tftpboot into tftpd's directory
* setup dhcpd PXE bootable
* boot some machine using PXE
== License
The MIT License
Copyright (C) 2009, 2010 Kazuhiro NISHIYAMA
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=end
require "fileutils"
require "optparse"
class PxeMultiBootHelper
def initialize
setup_default_mirror
set_top_dir
set_verbose
end
def setup_default_mirror
@mirror = {
:syslinux => "http://www.kernel.org/pub/linux/utils/boot/syslinux",
:debian => "http://ftp.jp.debian.org/debian",
:ubuntu => "http://jp.archive.ubuntu.com/ubuntu",
# see http://mirrors.fedoraproject.org/publiclist/Fedora/
:fedora => "http://ftp.riken.jp/Linux/fedora/releases",
:centos => "http://ftp.riken.jp/Linux/centos",
:vine => "http://ftp.vinelinux.org/pub/Vine",
#:vine => "http://www.t.ring.gr.jp/pub/linux/Vine",
:momonga => "http://dist.momonga-linux.org/pub/momonga",
:tinycore => "http://distro.ibiblio.org/pub/linux/distributions/tinycorelinux/3.x/release/",
:memtest => "http://www.memtest.org/download/%s/memtest86+-%s.zip",
:ping_release => "http://ping.windowsdream.com/ping/Releases",
:plop_files => "http://download.plop.at/files/bootmngr",
:balder10_img => "http://www.finnix.org/files/balder10.img",
:mbm_zip => "http://my.vector.co.jp/servlet/System.FileDownload/download/http/0/35596/pack/dos/util/boot/mbm039.zip",
:gag_zip => "http://downloads.sourceforge.net/gag/gag%s.zip",
:grub4dos => "http://download.gna.org/grub4dos/grub4dos-%s.zip",
# http://openlab.ring.gr.jp/oscircular/inetboot/index.html
:inetboot => "http://ring.aist.go.jp/archives/linux/oscircular/iso",
}
end
def mirror(target)
@mirror[target] or raise "unknown target: #{target}"
end
def set_verbose(flag=true)
if flag
@verbose = true
@fu = ::FileUtils::Verbose
else
@verbose = false
@fu = ::FileUtils
end
def @fu.cp(src, dest, options={})
options[:preserve] = true # always preserve
super(src, dest, options)
end
end
def set_top_dir(top_dir='.')
@tftpboot_dir = File.expand_path('tftpboot', top_dir)
@download_dir = File.expand_path('download', top_dir)
@boot_screens = File.join(tftpboot_dir, "boot-screens")
end
attr_reader :fu
attr_reader :tftpboot_dir, :download_dir, :boot_screens
def setup_directories
fu.mkpath(download_dir) unless File.directory?(download_dir)
fu.mkpath(boot_screens) unless File.directory?(boot_screens)
fu.chdir(tftpboot_dir)
end
def xsystem(*args)
puts "system(#{args.inspect})"
system(*args)
end
def download(path, uri)
unless File.exist?(path)
unless xsystem("wget", uri, "-O", path)
fu.rm_f(path)
raise "download failed: #{uri} to #{path}"
end
end
end
class Menu
def initialize(menu_cfg)
@menu_cfg = menu_cfg
@sub_menus = []
end
def push_sub_menu(menu)
@sub_menus.push(menu)
end
def cfg_puts(cfg_text)
@menu_cfg_file.puts cfg_text if cfg_text
end
def menu_include(sub_cfg)
cfg_puts "include #{sub_cfg}"
end
def run(parent, top)
open(@menu_cfg, "w") do |f|
@menu_cfg_file = f
cfg_puts cfg_prologue
main(parent, top)
cfg_puts cfg_epilogue
end
ensure
@menu_cfg_file = nil
end
def main(parent, top)
@sub_menus.each do |sub_menu|
sub_menu.run(self, top)
end
parent.menu_include @menu_cfg
end
def cfg_prologue
<<-CFG
label mainmenu
menu label ^Return to Top Menu
kernel boot-screens/vesamenu.c32
append pxelinux.cfg/default
CFG
end
def cfg_epilogue
nil
end
end
def menu_include(top_menu_cfg)
# ignore
end
class TopMenu < Menu
def cfg_prologue
<<-CFG
menu hshift 5
menu width 65
menu title PXE Boot Menu
menu background boot-screens/syslinux_splash.jpg
CFG
end
end
class SubMenu < Menu
def initialize(name, title)
@name = name
@title = title
super("boot-screens/#{@name}.cfg")
end
def cfg_prologue
<<-CFG
menu begin #{@title}
menu title #{@title}
label mainmenu
menu label ^Back..
menu exit
CFG
end
def cfg_epilogue
"menu end"
end
end
class DebianInstaller < Menu
def initialize(suite, title, options={})
@title = title
@arch = options[:arch] || "i386"
if options[:installer_suite]
@target_suite = suite
@installer_suite = options[:installer_suite]
else
@target_suite = suite
@installer_suite = suite
end
if options[:gtk]
@m_gtk = "-gtk" # minus and gtk
@slash_gtk = "/gtk" # slash and gtk
@s_GTK = " GTK" # space and GTK
else
@m_gtk = @slash_gtk = @s_GTK = ""
end
super("boot-screens/#{@target_suite}-#{@arch}#{@m_gtk}.cfg")
end
def distro
"debian"
end
def mirror(top)
top.mirror(:debian)
end
def extract_dir
"#{distro}-installer"
end
def installer_dir
"#{distro}/#{@installer_suite}#{@m_gtk}-installer"
end
def netboot_uri(top)
"#{mirror(top)}/dists/#{@installer_suite}/main/installer-#{@arch}/current/images/netboot#{@slash_gtk}/netboot.tar.gz"
end
def netboot_tar_gz(top)
"#{top.download_dir}/#{@installer_suite}-#{@arch}#{@m_gtk}-netboot.tar.gz"
end
def main(parent, top)
fu = top.fu
top.download(netboot_tar_gz(top), netboot_uri(top))
fu.mkpath("tmp")
fu.chdir("tmp") do
top.xsystem("tar", "xf", netboot_tar_gz(top), "./#{extract_dir}/")
end
fu.mkpath(installer_dir)
fu.rm_rf("#{installer_dir}/#{@arch}")
fu.mv("tmp/#{extract_dir}/#{@arch}", "#{installer_dir}/")
fu.rmdir("tmp/#{extract_dir}")
fu.rmdir("tmp")
menu_cfg = "#{installer_dir}/#{@arch}/boot-screens/menu.cfg"
if File.exist?(menu_cfg)
# interpid, jaunty
# lenny
proc_cfg_file = proc do |cfg_filename|
File.foreach(cfg_filename) do |line|
line.gsub!(extract_dir) { installer_dir }
if /\s*include (\S+)/ =~ line
if File.exist?($1)
cfg_puts '#^^^ ' + line
proc_cfg_file.call($1)
cfg_puts '#$$$ ' + line
else
cfg_puts '#### ' + line
end
else
cfg_puts line
end
end
end
proc_cfg_file.call(menu_cfg)
else
# dapper, hardy
# etch
File.foreach("#{installer_dir}/#{@arch}/pxelinux.cfg/default") do |line|
case line
when /^LABEL /
cfg_puts "label #{@target_suite}-#{@arch}-#{$'}"
when /^\s+(?:kernel|append)/
cfg_puts line.gsub(extract_dir) { installer_dir }
else
# ignore
end
end
end
#kernel = "#{@installer_suite}#{@m_gtk}-installer/#{@arch}/boot-screens/vesamenu.c32"
#unless File.exist?(kernel)
kernel = "boot-screens/vesamenu.c32"
#end
parent.cfg_puts <<-CFG
label #{@target_suite}-#{@arch}#{@m_gtk}
menu label #{@title} #{@arch}#{@s_GTK} Installer
kernel #{kernel}
append boot-screens/#{@target_suite}-#{@arch}#{@m_gtk}.cfg
CFG
end
end # DebianInstaller
class DebianAndAHalfInstaller < DebianInstaller
def initialize(suite, title, options={})
options[:installer_suite] = "lenny"
super
end
def cfg_puts(cfg_text)
return unless cfg_text
cfg_text.gsub!(/^\s*append.+(?= --)/) { $& + " suite=etch" }
@menu_cfg_file.puts cfg_text
end
end # DebianAndAHalfInstaller
class Ubuntu < DebianInstaller
def distro
"ubuntu"
end
def mirror(top)
top.mirror(:ubuntu)
end
end
class DebianLive < Menu
def initialize(binary_net_tar, title)
@binary_net_tar = File.expand_path(binary_net_tar)
@title = title
super("boot-screens/debian-live-#{base}.cfg")
end
def binary_net_tar
@binary_net_tar
end
def base
@base ||= File.basename(binary_net_tar).sub(/\..*\z/, '')
end
def extract_dir
"debian-live"
end
def live_dir
"debian-live/#{base}"
end
def arch
"i386"
end
def main(parent, top)
fu = top.fu
fu.mkpath("tmp")
fu.chdir("tmp") do
top.xsystem("tar", "xf", binary_net_tar, "tftpboot/#{extract_dir}/#{arch}")
end
fu.rm_rf(live_dir)
fu.mkpath(live_dir)
fu.mv("tmp/tftpboot/#{extract_dir}/#{arch}", live_dir)
fu.rmdir("tmp/tftpboot/#{extract_dir}")
fu.rmdir("tmp/tftpboot")
fu.rmdir("tmp")
menu_cfg = "#{live_dir}/#{arch}/boot-screens/menu.cfg"
proc_cfg_file = proc do |cfg_filename|
File.foreach(cfg_filename) do |line|
line.gsub!(extract_dir) { live_dir }
if /\s*include (\S+)/ =~ line
if File.exist?($1)
cfg_puts '#^^^ ' + line
proc_cfg_file.call($1)
cfg_puts '#$$$ ' + line
else
cfg_puts '#### ' + line
end
else
cfg_puts line
end
end
end
proc_cfg_file.call(menu_cfg)
#kernel = "#{live_dir}/#{arch}/boot-screens/vesamenu.c32"
#unless File.exist?(kernel)
kernel = "boot-screens/vesamenu.c32"
#end
parent.cfg_puts <<-CFG
label debian-live-#{base}
menu label #{@title}
kernel #{kernel}
append boot-screens/debian-live-#{base}.cfg
CFG
end
end # DebianLive
class UbuntuCasper < Menu
def initialize(ubuntu_iso, title, casper_options)
@ubuntu_iso = File.expand_path(ubuntu_iso)
@title = title
@casper_options = casper_options
super("boot-screens/ubuntu-casper-#{base}.cfg")
end
def ubuntu_iso
@ubuntu_iso
end
def casper_options
@casper_options
end
def base
@base ||= File.basename(ubuntu_iso).sub(/\.iso\z/, '')
end
def live_dir
"ubuntu-casper/#{base}"
end
def main(parent, top)
fu = top.fu
fu.mkpath("tmp/casper")
fu.chdir("tmp") do
files = [
"casper/initrd.gz",
"casper/initrd.lz",
"casper/vmlinuz",
"isolinux",
"preseed",
]
top.xsystem("7z", "x", ubuntu_iso, *files)
fu.chmod(0755, ["casper", "isolinux", "preseed"])
fu.chmod(0644, Dir.glob("{casper,isolinux,preseed}/*"))
end
fu.rm_rf(live_dir)
fu.mkpath("#{live_dir}/casper")
[
"initrd.gz",
"initrd.lz",
"vmlinuz",
].each do |filename|
if File.exist?("tmp/casper/#{filename}")
fu.mv("tmp/casper/#{filename}", "#{live_dir}/casper/#{filename}")
end
end
fu.mv("tmp/isolinux", live_dir)
fu.mv("tmp/preseed", live_dir)
fu.rmdir("tmp/casper")
fu.rmdir("tmp")
isolinux_cfg = "#{live_dir}/isolinux/isolinux.cfg"
proc_cfg_file = proc do |cfg_filename|
File.foreach(cfg_filename) do |line|
if /\s*include (\S+)/ =~ line
if File.exist?("#{live_dir}/isolinux/#{$1}")
cfg_puts '#^^^ ' + line
proc_cfg_file.call("#{live_dir}/isolinux/#{$1}")
cfg_puts '#$$$ ' + line
else
cfg_puts '#### ' + line
end
else
line.gsub!(/(\S+\s+)(?=(\S+))/) do
match, filename = $~.captures
if File.exist?("#{live_dir}/isolinux/#{filename}")
"#{match}/#{live_dir}/isolinux/"
else
match
end
end
line.sub!(/kernel\s+|initrd=/) do
"#{$&}#{live_dir}"
end
line.sub!(/boot=casper/) do
"#{$&} #{casper_options}"
end
line.sub!(/^timeout/i) do
"\##{$&}"
end
cfg_puts line
end
end
end
proc_cfg_file.call(isolinux_cfg)
#kernel = "#{live_dir}/isolinux/vesamenu.c32"
#unless File.exist?(kernel)
kernel = "boot-screens/vesamenu.c32"
#end
parent.cfg_puts <<-CFG
label ubuntu-casper-#{base}
menu label #{@title}
kernel #{kernel}
append boot-screens/ubuntu-casper-#{base}.cfg
CFG
end
end # UbuntuCasper
# http://github.com/znz/mk-live-recovery
class LiveRecovery < Menu
def initialize(live_recovery_iso, title, casper_options)
@live_recovery_iso = File.expand_path(live_recovery_iso)
@title = title
@casper_options = casper_options
super("boot-screens/live-recovery-#{base}.cfg")
end
def live_recovery_iso
@live_recovery_iso
end
def casper_options
@casper_options
end
def base
@base ||= File.basename(live_recovery_iso).sub(/\.iso\z/, '')
end
def live_dir
"live-recovery/#{base}"
end
def main(parent, top)
fu = top.fu
fu.mkpath("tmp/boot/grub")
fu.chdir("tmp") do
files = [
"boot/grub/grub.cfg",
"boot/initrd.img",
"boot/vmlinuz",
]
top.xsystem("7z", "x", live_recovery_iso, *files)
fu.chmod(0644, files)
end
fu.rm_rf(live_dir)
fu.mkpath("#{live_dir}/boot/grub")
[
"grub/grub.cfg",
"initrd.img",
"vmlinuz",
].each do |filename|
if File.exist?("tmp/boot/#{filename}")
fu.mv("tmp/boot/#{filename}", "#{live_dir}/boot/#{filename}")
end
end
fu.rmdir("tmp/boot/grub")
fu.rmdir("tmp/boot")
fu.rmdir("tmp")
cfg_puts <<-CFG
label live-recovery-#{base}
menu label #{@title}
kernel #{live_dir}/boot/vmlinuz
append initrd=#{live_dir}/boot/initrd.img boot=casper #{casper_options}
CFG
parent.menu_include @menu_cfg
end
def cfg_prologue
""
end
end # LiveRecovery
class Anaconda < Menu
def initialize(options)
@distro = options[:distro]
@title = options[:title]
@ver = options[:ver]
@arch = options[:arch]
@kernel = options.fetch(:kernel, "images/pxeboot/vmlinuz")
@initrd = options.fetch(:initrd, "images/pxeboot/initrd.img")
@isolinux_cfg = options.fetch(:isolinux_cfg, "isolinux/isolinux.cfg")
@template = options[:template]
@append_template = options.fetch(:append_template, nil)
d_v_a = "#{@distro}-#{@ver}-#{@arch}"
super("boot-screens/#{d_v_a}.cfg")
end
def mirror(top)
top.mirror(@distro.intern)
end
def main(parent, top)
fu = top.fu
d_v_a_dir = "#{@distro}/#{@ver}/#{@arch}"
d_v_a = "#{@distro}-#{@ver}-#{@arch}"
fu.mkpath(d_v_a_dir)
download_dir = "#{top.download_dir}/#{d_v_a}"
fu.mkpath(download_dir)
[@kernel, @initrd, @isolinux_cfg].each do |file|
download_file = "#{download_dir}/#{File.basename(file)}"
uri = sprintf(@template, mirror(top), @ver, @arch, file)
top.download(download_file, uri)
fu.cp(download_file, "#{d_v_a_dir}/#{File.basename(file)}")
end
cfg = File.read("#{download_dir}/#{File.basename(@isolinux_cfg)}")
cfg.gsub!(/^(?:prompt|timeout)/) { '###'+$& }
more_files = []
menu_c32 = "boot-screens/vesamenu.c32"
cfg.gsub!(/^(default|display|F\d|menu background|\s*kernel|KBDMAP) (vesamenu\.c32|\w+\.msg|splash\.jpg|memtest|jp106\.kbd)$/i) {
more_files << $2
#if $1 == "default"
# menu_c32 = "#{d_v_a_dir}/#{$2}"
#end
"#{$1} #{d_v_a_dir}/#{$2}"
}
if @append_template
append = sprintf(@append_template, mirror(top), @ver, @arch)
cfg.gsub!(/^\s*append.*initrd.*/) {
"#{$&} #{append}"
}
end
cfg.gsub!(/vmlinuz|initrd\.img/) {
"#{d_v_a_dir}/#{$&}"
}
cfg.gsub!(/^\s*label /) { "#{$&}#{d_v_a}-" }
more_files.each do |file|
file = File.join(File.dirname(@isolinux_cfg), file)
download_file = "#{download_dir}/#{File.basename(file)}"
uri = sprintf(@template, mirror(top), @ver, @arch, file)
top.download(download_file, uri)
fu.cp(download_file, "#{d_v_a_dir}/#{File.basename(file)}")
end
cfg_puts cfg
parent.cfg_puts <<-CFG
label #{d_v_a}
menu label #{@title} #{@ver} #{@arch} Installer
kernel #{menu_c32}
append boot-screens/#{d_v_a}.cfg
CFG
end
end # Anaconda
# PING (Partimage Is Not Ghost) -- Backup and Restore Disk Partitions
# http://ping.windowsdream.com/ping.html
class PING < Menu
TITLE = "PING(Partimage Is Not Ghost)"
def initialize(ver)
@name = "ping"
@ver = ver
@dir = "#{@name}-#{@ver}"
super("boot-screens/#{@dir}.cfg")
end
def uri(file, top)
"#{top.mirror(:ping_release)}/#{@ver}/#{file}"
end
def main(parent, top)
fu = top.fu
download_dir = "#{top.download_dir}/#{@dir}"
fu.mkpath(download_dir)
fu.mkpath(@dir)
isolinux_cfg = "#{download_dir}/isolinux.cfg"
top.download(isolinux_cfg, uri("isolinux.cfg", top))
cfg = File.read(isolinux_cfg)
more_files = ["initrd.gz"]
cfg.gsub!(/^(DISPLAY|KERNEL) (\w+\.msg|kernel)$/) {
more_files << $2
"#{$1} #{@dir}/#{$2}"
}
cfg.gsub!(/initrd\.gz/) {
"#{@dir}/#{$&}"
}
more_files.each do |file|
download_file = "#{download_dir}/#{file}"
top.download(download_file, uri(file, top))
fu.cp(download_file, "#{@dir}/#{File.basename(file)}")
end
cfg_puts cfg
parent.cfg_puts <<-CFG
label #{@dir}
menu label #{TITLE} #{@ver}
kernel boot-screens/vesamenu.c32
append boot-screens/#{@dir}.cfg
CFG
end
def cfg_prologue
"menu title #{TITLE} #{@ver}"
end
def cfg_epilogue
<<-CFG
label mainmenu
menu label ^Return to Top Menu
kernel boot-screens/vesamenu.c32
append pxelinux.cfg/default
CFG
end
end
class SimpleMenu < Menu
def initialize(name, ver)
@name ||= name
@ver ||= ver
@dir ||= "#{@name}-#{@ver}"
super("boot-screens/#{@dir}.cfg")
end
def title
"#{self.class::TITLE} #{@ver}"
end
def main(parent, top)
fu = top.fu
download_uri = uri(top)
download_file = "#{top.download_dir}/#{@name}/#{File.basename(download_uri)}"
fu.mkpath(File.dirname(download_file))
top.download(download_file, download_uri)
fu.mkpath(@dir)
main_after_download(download_file, parent, top)
parent.menu_include @menu_cfg
end
def cfg_prologue
nil
end
end
class FloppyImage < SimpleMenu
def main_after_download(download_file, parent, top)
img = install_img(download_file, parent, top)
cfg_puts <<-CFG
label #{@dir}
menu label #{title}
kernel boot-screens/memdisk
append initrd=#{img}
CFG
end
def install_img(download_file, parent, top)
img = "#{@dir}/#{File.basename(download_file)}"
top.fu.cp(download_file, img)
return img
end
end
class KernelImage < FloppyImage
def main_after_download(download_file, parent, top)
img = install_img(download_file, parent, top)
cfg_puts <<-CFG
label #{@dir}
menu label #{title}
kernel #{img}
CFG
end
end
class ImageFile < FloppyImage
def initialize(title, uri)
@title = title
@uri = uri
@dir = "image"
super("image", "dummy_ver")
end
def title
@title
end
def uri(top)
@uri
end
end
class FreedosBalder10 < FloppyImage
TITLE = "Balder 10 (FreeDOS 1.0)"
# title without ver
def title
TITLE
end
def initialize
super("freedos", "balder10")
end
def uri(top)
top.mirror(:balder10_img)
end
end
class GAG < FloppyImage
TITLE = "GAG (Graphical Boot Manager)"
def initialize(ver)
super("gag", ver)
end
def uri(top)
sprintf(top.mirror(:gag_zip), @ver.tr(".", "_"))
end
def install_img(download_file, parent, top)
fu = top.fu
src_disk_dsk = "gag#{@ver}/disk.dsk"
dst_disk_dsk = "#{@dir}/disk.dsk"
fu.mkpath("tmp")
fu.chdir("tmp") do
top.xsystem("unzip", download_file, src_disk_dsk)
end
fu.mv("tmp/#{src_disk_dsk}", dst_disk_dsk)
fu.rm_rf("tmp/#{File.dirname(src_disk_dsk)}")
fu.rmdir("tmp")
return dst_disk_dsk
end
end
# http://elm-chan.org/fsw/mbm/mbm.html
class MBM < FloppyImage
TITLE = "MBM (Multiple Boot Manager)"
def initialize(ver)
super("mbm", ver)
end
def uri(top)
top.mirror(:mbm_zip)
end
def install_img(download_file, parent, top)
fu = top.fu
fu.mkpath("tmp")
fu.chdir("tmp") do
top.xsystem("unzip", download_file, "BIN/MBM.144")
end
fu.mv("tmp/BIN/MBM.144", @dir)
fu.rmdir("tmp/BIN")
fu.rmdir("tmp")
return "#{@dir}/MBM.144"
end
end
# http://www.plop.at/en/bootmanager.html
class PLoPBootManager < KernelImage
TITLE = "PLoP Boot Manager"
def initialize(ver)
super("plop", ver)
end
def uri(top)
"#{top.mirror(:plop_files)}/plpbt-#{@ver}.zip"
end
def install_img(download_file, parent, top)
fu = top.fu
fu.mkpath("tmp")
fu.chdir("tmp") do
top.xsystem("unzip", download_file)
end
plpbt = "#{@dir}/plpbt"
fu.mv("tmp/plpbt-#{@ver}/plpbt.bin", plpbt)
fu.rm_rf("tmp/plpbt-#{@ver}")
fu.rmdir("tmp")
return plpbt
end
end
class Memtest < KernelImage
TITLE = "Memtest86+"
def initialize(ver)
super("memtest", ver)
end
def uri(top)
sprintf(top.mirror(:memtest), @ver, @ver)
end
def install_img(download_file, parent, top)
fu = top.fu
fu.mkpath("tmp")
fu.chdir("tmp") do
top.xsystem("unzip", download_file, "memtest86+-#{@ver}.bin")
end
memtest_bin = "#{@dir}/memtest86+"
fu.mv("tmp/memtest86+-#{@ver}.bin", memtest_bin)
fu.rmdir("tmp")
return memtest_bin
end
end
# Tiny Core Linux
# http://tinycorelinux.com/
class TinyCore < SimpleMenu
TITLE = "Tiny Core Linux"
def initialize(ver)
super("tinycore", ver)
end
def uri(top)
"#{top.mirror(:tinycore)}/tinycore_#{@ver}.iso"
end
def main_after_download(download_file, parent, top)
fu = top.fu
files = ["boot/bzImage", "boot/tinycore.gz"]
fu.mkpath("tmp")
fu.chdir("tmp") do
top.xsystem("7z", "x", download_file, *files)
end
files.each do |file|
fu.mv("tmp/#{file}", @dir)
end
fu.rmdir("tmp/boot")
fu.rmdir("tmp")
cfg_puts <<-CFG
label #{@dir}
menu label #{title}
kernel #{@dir}/bzImage
append initrd=#{@dir}/tinycore.gz quiet
CFG
end
end # TinyCore
class Grub4Dos < SimpleMenu
TITLE = "GRUB for DOS"
def initialize(ver)
super("grub4dos", ver)
end
def uri(top)
sprintf(top.mirror(:grub4dos), @ver)
end
def main_after_download(download_file, parent, top)
fu = top.fu
grub_exe = "#{@dir}/grub.exe"
files = [grub_exe, "#{@dir}/menu.lst"]
fu.mkpath("tmp")
fu.chdir("tmp") do
top.xsystem("unzip", download_file, *files)
end
files.each do |file|