system-builder 0.0.23 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/bin/box +132 -79
- data/lib/system_builder.rb +0 -1
- data/lib/system_builder/boot.rb +3 -3
- data/lib/system_builder/box.rb +31 -12
- data/lib/system_builder/box_tasks.rb +25 -10
- data/lib/system_builder/configurator.rb +15 -11
- data/lib/system_builder/core_ext.rb +2 -0
- data/lib/system_builder/disk_nfsroot_image.rb +1 -1
- data/lib/system_builder/disk_squashfs_image.rb +22 -3
- data/lib/system_builder/init_ram_fs_configurator.rb +8 -3
- data/lib/system_builder/iso_squashfs_image.rb +14 -4
- data/lib/system_builder/mount_boot.sh +33 -15
- data/lib/system_builder/version.rb +1 -1
- metadata +5 -7
- data/lib/system_builder/iso_image.rb +0 -55
- data/lib/system_builder/task.rb +0 -70
data/Gemfile.lock
CHANGED
data/bin/box
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
+
require 'tmpdir'
|
4
5
|
|
5
6
|
@options = {}
|
6
7
|
OptionParser.new do |opts|
|
@@ -22,6 +23,14 @@ OptionParser.new do |opts|
|
|
22
23
|
"The host to be upgraded") { |arg| @options[:host] = arg }
|
23
24
|
opts.on("-s", "--skip-format",
|
24
25
|
"Skip partitionning and formatting") { |arg| @options[:skip_format] = true }
|
26
|
+
opts.on("-e", "--external-extlinux",
|
27
|
+
"Don't use extlinux provided by image") { |arg| @options[:external_extlinux] = true }
|
28
|
+
opts.on("-b", "--name=<box name>", String,
|
29
|
+
"The box name") { |arg| @options[:name] = arg }
|
30
|
+
opts.on("-m", "--mac-index=<index>", Integer,
|
31
|
+
"An numeric index uses to choose mac") { |arg| @options[:mac_index] = arg }
|
32
|
+
opts.on("-n", "--dry-run",
|
33
|
+
"Dry run mode") { |arg| @options[:dry_run] = true }
|
25
34
|
opts.on("-h", "--help",
|
26
35
|
"Show this help message.") { puts opts; exit }
|
27
36
|
opts.parse!(ARGV)
|
@@ -33,128 +42,172 @@ OptionParser.new do |opts|
|
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
45
|
+
module SystemTools
|
46
|
+
|
47
|
+
def sh(command)
|
48
|
+
puts "* #{command}"
|
49
|
+
unless @dry_run
|
50
|
+
raise "command failed: '#{command}'" unless system command
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def sudo(command)
|
55
|
+
sh "sudo #{command}"
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
36
60
|
class BoxCommand
|
61
|
+
include SystemTools
|
37
62
|
|
38
63
|
def boot(options = {})
|
39
64
|
qemu_options = []
|
40
65
|
|
41
66
|
qemu_disks = []
|
42
67
|
|
68
|
+
dist_dir = ["dist", options[:name]].compact.join("/")
|
69
|
+
|
43
70
|
case options[:root]
|
44
71
|
when "iso"
|
45
|
-
qemu_options << "-cdrom
|
72
|
+
qemu_options << "-cdrom #{dist_dir}/iso"
|
46
73
|
qemu_options << "--boot order=d"
|
47
74
|
else
|
48
|
-
qemu_disks << "
|
75
|
+
qemu_disks << "#{dist_dir}/disk"
|
49
76
|
end
|
50
77
|
|
51
|
-
qemu_disks.push *Dir["
|
78
|
+
qemu_disks.push *Dir["#{dist_dir}/storage*"]
|
52
79
|
|
53
80
|
qemu_disks.each_with_index do |disk, index|
|
54
81
|
qemu_options << "-drive file=#{disk},if=ide,index=#{index+1},media=disk"
|
55
82
|
end
|
56
83
|
|
57
|
-
|
84
|
+
mac_address_index = (options[:mac_index] or 0)
|
85
|
+
mac_address = "52:54:00:12:34:#{56+mac_address_index}"
|
86
|
+
|
87
|
+
qemu_options << "-net nic,macaddr=#{mac_address} -net vde,sock=/var/run/vde2/tap0.ctl"
|
88
|
+
|
89
|
+
memory = (ENV['MEMORY'] or "512")
|
58
90
|
|
59
91
|
ENV['QEMU_AUDIO_DRV']='alsa'
|
60
92
|
|
61
|
-
qemu_command = "qemu -enable-kvm -m
|
93
|
+
qemu_command = "qemu -enable-kvm -m #{memory}m -soundhw ac97 #{qemu_options.join(' ')}"
|
62
94
|
|
63
95
|
puts "Run #{qemu_command}"
|
64
96
|
system qemu_command
|
65
97
|
end
|
66
98
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
# like pigebox-20101014-1155
|
76
|
-
name = $1
|
77
|
-
release = $2
|
78
|
-
disk_image = "#{tmpdir}/#{name}-#{release}.disk"
|
79
|
-
sh "ssh dev.tryphon.priv cat /var/lib/buildbot/dist/#{name}/#{name}-#{release}.disk.gz | gunzip -c > #{disk_image}" unless File.exist?(disk_image)
|
99
|
+
class Cloner
|
100
|
+
include SystemTools
|
101
|
+
|
102
|
+
attr_accessor :target, :image, :dry_run, :skip_format, :external_extlinux
|
103
|
+
|
104
|
+
def initialize(options = {})
|
105
|
+
options = { :target => "/dev/sdb", :image => "dist/disk" }.merge options
|
106
|
+
options.each { |k,v| send "#{k}=", v }
|
80
107
|
end
|
81
108
|
|
82
|
-
|
109
|
+
def partition
|
110
|
+
"#{target}1"
|
111
|
+
end
|
83
112
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
partition_mount_point = "#{tmpdir}/boot"
|
88
|
-
#sudo "mkdir #{partition_mount_point}" unless File.exist? partition_mount_point
|
89
|
-
#sudo "mount #{partition} #{partition_mount_point}"
|
90
|
-
#end
|
113
|
+
def mounts
|
114
|
+
IO.readlines("/proc/mounts").map { |m| m.scan(/\S+/) }
|
115
|
+
end
|
91
116
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
117
|
+
def mount(volume, options = {}, &block)
|
118
|
+
name = File.basename(volume)
|
119
|
+
|
120
|
+
unless target = options.delete(:target)
|
121
|
+
Dir.mktmpdir("#{name}-") do |target|
|
122
|
+
mount volume, {:target => target}.merge(options), &block
|
123
|
+
end
|
124
|
+
return
|
125
|
+
end
|
126
|
+
|
127
|
+
name = File.basename(volume)
|
128
|
+
mount_options = options.collect do |pair|
|
129
|
+
[ pair - [true] ].join('=')
|
130
|
+
end.join(',')
|
131
|
+
|
132
|
+
mount_options = "-o #{mount_options}" unless mount_options.empty?
|
133
|
+
|
134
|
+
begin
|
135
|
+
sudo "mount #{mount_options} #{volume} #{target}"
|
136
|
+
yield target
|
137
|
+
ensure
|
138
|
+
sudo "umount #{target}"
|
139
|
+
end
|
140
|
+
end
|
97
141
|
|
98
|
-
|
99
|
-
|
100
|
-
|
142
|
+
def mount_image
|
143
|
+
mount(image, :loop => true, :offset => 64*512) do |mount_dir|
|
144
|
+
yield mount_dir
|
145
|
+
end
|
101
146
|
end
|
102
147
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
148
|
+
def chroot(root, command)
|
149
|
+
sudo "mount proc #{root}/proc -t proc"
|
150
|
+
sudo "mount -o bind /dev #{root}/dev"
|
151
|
+
|
152
|
+
begin
|
153
|
+
sudo "chroot #{root} #{command}"
|
154
|
+
ensure
|
155
|
+
sudo "umount #{root}/proc"
|
156
|
+
sudo "umount #{root}/dev"
|
157
|
+
end
|
108
158
|
end
|
109
159
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
160
|
+
def clone
|
161
|
+
puts "Dry run mode" if dry_run
|
162
|
+
confirm
|
163
|
+
format unless skip_format
|
164
|
+
copy
|
165
|
+
extlinux
|
116
166
|
end
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
167
|
+
|
168
|
+
def extlinux
|
169
|
+
mount(partition) do |partition_mount|
|
170
|
+
if external_extlinux
|
171
|
+
sudo "extlinux --install #{partition_mount}"
|
172
|
+
else
|
173
|
+
mount("#{partition_mount}/filesystem.squashfs", :loop => true) do |root|
|
174
|
+
mount(partition_mount, :bind => true, :target => "#{root}/boot") do
|
175
|
+
chroot root, "extlinux --install /boot"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# Required ?
|
182
|
+
# sudo "dd if=/usr/lib/syslinux/mbr.bin of=#{target}"
|
131
183
|
end
|
132
184
|
|
133
|
-
|
134
|
-
|
185
|
+
def copy
|
186
|
+
puts "Copy files"
|
187
|
+
mount_image do |image_mount|
|
188
|
+
mount(partition) do |partition_mount|
|
189
|
+
sudo "rsync -av #{image_mount}/ #{partition_mount}/"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
135
193
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
194
|
+
def format
|
195
|
+
puts "Formatting filesystem"
|
196
|
+
sh "echo ',,L,*' | sudo /sbin/sfdisk -f -uS #{target}"
|
197
|
+
sh "grep -q #{partition} /proc/mounts && sudo umount #{partition} || true"
|
198
|
+
sudo "mke2fs -j -L boot #{partition}"
|
199
|
+
end
|
140
200
|
|
141
|
-
|
142
|
-
|
143
|
-
|
201
|
+
def confirm
|
202
|
+
$stdout.write "Confirm you want install box image (#{image}) in #{target} [y/N] :"
|
203
|
+
$stdout.flush
|
204
|
+
exit 1 unless $stdin.read(1).downcase == 'y'
|
205
|
+
end
|
144
206
|
|
145
|
-
def mounts
|
146
|
-
IO.readlines("/proc/mounts").map { |m| m.scan(/\S+/) }
|
147
207
|
end
|
148
208
|
|
149
|
-
def
|
150
|
-
|
151
|
-
sh "[ -d #{mount_dir} ]||mkdir -p #{mount_dir}"
|
152
|
-
begin
|
153
|
-
sudo "mount -o loop,offset=#{64*512} #{disk_image} #{mount_dir}"
|
154
|
-
yield mount_dir
|
155
|
-
ensure
|
156
|
-
sudo "umount #{mount_dir}"
|
157
|
-
end
|
209
|
+
def clone(options = {})
|
210
|
+
Cloner.new(options).clone
|
158
211
|
end
|
159
212
|
|
160
213
|
def upgrade(options = {})
|
data/lib/system_builder.rb
CHANGED
@@ -20,7 +20,6 @@ end
|
|
20
20
|
require 'system_builder/version'
|
21
21
|
require 'system_builder/core_ext'
|
22
22
|
require 'system_builder/disk_image'
|
23
|
-
require 'system_builder/iso_image'
|
24
23
|
require 'system_builder/live_image'
|
25
24
|
require 'system_builder/init_ram_fs_configurator'
|
26
25
|
require 'system_builder/disk_squashfs_image'
|
data/lib/system_builder/boot.rb
CHANGED
@@ -67,7 +67,7 @@ class SystemBuilder::DebianBoot
|
|
67
67
|
unless @configurators.empty?
|
68
68
|
chroot do |chroot|
|
69
69
|
@configurators.each do |configurator|
|
70
|
-
configurator.configure
|
70
|
+
configurator.configure chroot, :debian_release => version
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -188,7 +188,7 @@ class SystemBuilder::DebianBoot
|
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
-
def configure(chroot)
|
191
|
+
def configure(chroot, options = {})
|
192
192
|
rewrite_sources_url(chroot)
|
193
193
|
update(chroot)
|
194
194
|
configure_proxy(chroot)
|
@@ -287,7 +287,7 @@ class SystemBuilder::DebianBoot
|
|
287
287
|
def rsync(target, *sources)
|
288
288
|
sources = sources.flatten
|
289
289
|
options = (Hash === sources.last ? sources.pop : {})
|
290
|
-
rsync_options = options.collect { |k,v| v == true ? "--#{k}" : "--#{k}
|
290
|
+
rsync_options = options.collect { |k,v| v == true ? "--#{k}" : "--#{k}='#{v}'" }
|
291
291
|
FileUtils::sudo "rsync -a #{rsync_options.join(' ')} #{sources.join(' ')} #{expand_path(target)}"
|
292
292
|
end
|
293
293
|
|
data/lib/system_builder/box.rb
CHANGED
@@ -14,52 +14,67 @@ class SystemBuilder::Box
|
|
14
14
|
@release_name ||= "#{name}-#{release_number}"
|
15
15
|
end
|
16
16
|
|
17
|
+
attr_accessor :named_mode
|
18
|
+
alias_method :named_mode?, :named_mode
|
19
|
+
|
20
|
+
def build_dir
|
21
|
+
named_mode? ? "build/#{name}" : "build"
|
22
|
+
end
|
23
|
+
|
24
|
+
def dist_dir
|
25
|
+
named_mode? ? "dist/#{name}" : "dist"
|
26
|
+
end
|
27
|
+
|
17
28
|
def root_file
|
18
|
-
"
|
29
|
+
"#{build_dir}/root"
|
19
30
|
end
|
20
31
|
|
21
32
|
def boot
|
22
|
-
@boot ||= SystemBuilder::DebianBoot.new(root_file)
|
23
|
-
|
24
|
-
|
33
|
+
@boot ||= SystemBuilder::DebianBoot.new(root_file)
|
34
|
+
unless @boot_configurated
|
35
|
+
@boot_configurated = true
|
25
36
|
|
26
|
-
|
37
|
+
yield @boot if block_given?
|
38
|
+
@boot.configurators << puppet_configurator
|
39
|
+
end
|
27
40
|
@boot
|
28
41
|
end
|
29
42
|
|
30
43
|
def puppet_configurator
|
31
|
-
@puppet_configurator ||= SystemBuilder::PuppetConfigurator.new :release_name => release_name
|
44
|
+
@puppet_configurator ||= SystemBuilder::PuppetConfigurator.new :box_name => name, :release_name => release_name, :debian_release => boot.version
|
32
45
|
yield @puppet_configurator if block_given?
|
33
46
|
@puppet_configurator
|
34
47
|
end
|
35
48
|
|
36
49
|
def disk_file
|
37
|
-
"
|
50
|
+
"#{dist_dir}/disk"
|
38
51
|
end
|
39
52
|
|
40
53
|
def disk_image
|
41
54
|
@disk_image ||= SystemBuilder::DiskSquashfsImage.new(disk_file).tap do |image|
|
42
55
|
image.boot = boot
|
43
56
|
image.size = 200.megabytes
|
57
|
+
image.build_dir = build_dir
|
44
58
|
end
|
45
59
|
yield @disk_image if block_given?
|
46
60
|
@disk_image
|
47
61
|
end
|
48
62
|
|
49
63
|
def iso_file
|
50
|
-
"
|
64
|
+
"#{dist_dir}/iso"
|
51
65
|
end
|
52
66
|
|
53
67
|
def iso_image
|
54
68
|
@iso_image ||= SystemBuilder::IsoSquashfsImage.new(iso_file).tap do |image|
|
55
69
|
image.boot = boot
|
70
|
+
image.build_dir = build_dir
|
56
71
|
end
|
57
72
|
yield @iso_image if block_given?
|
58
73
|
@iso_image
|
59
74
|
end
|
60
75
|
|
61
76
|
def nfs_file
|
62
|
-
"
|
77
|
+
"#{dist_dir}/nfs"
|
63
78
|
end
|
64
79
|
|
65
80
|
def nfs_image
|
@@ -71,18 +86,18 @@ class SystemBuilder::Box
|
|
71
86
|
end
|
72
87
|
|
73
88
|
def upgrade_directory
|
74
|
-
"
|
89
|
+
"#{build_dir}/upgrade"
|
75
90
|
end
|
76
91
|
|
77
92
|
def upgrade_file
|
78
|
-
"
|
93
|
+
"#{dist_dir}/upgrade.tar"
|
79
94
|
end
|
80
95
|
|
81
96
|
def upgrade_checksum
|
82
97
|
`sha256sum #{upgrade_file}`.split.first
|
83
98
|
end
|
84
99
|
|
85
|
-
def create_latest_file(latest_file)
|
100
|
+
def create_latest_file(latest_file = latest_file)
|
86
101
|
File.open(latest_file, "w") do |f|
|
87
102
|
f.puts "name: #{release_name}"
|
88
103
|
f.puts "url: http://download.tryphon.eu/#{name}/#{name}-#{release_number}.tar"
|
@@ -92,4 +107,8 @@ class SystemBuilder::Box
|
|
92
107
|
end
|
93
108
|
end
|
94
109
|
|
110
|
+
def latest_file
|
111
|
+
"#{dist_dir}/latest.yml"
|
112
|
+
end
|
113
|
+
|
95
114
|
end
|
@@ -2,6 +2,15 @@ require 'rake/tasklib'
|
|
2
2
|
|
3
3
|
class SystemBuilder::BoxTasks < Rake::TaskLib
|
4
4
|
|
5
|
+
# FIXME we can't count box instances .. the first box doesn't "see" next ones
|
6
|
+
@@multiple_boxes = nil
|
7
|
+
def self.multiple_boxes=(multiple_boxes)
|
8
|
+
@@multiple_boxes = multiple_boxes
|
9
|
+
end
|
10
|
+
def self.multiple_boxes?
|
11
|
+
@@multiple_boxes
|
12
|
+
end
|
13
|
+
|
5
14
|
attr_reader :box
|
6
15
|
|
7
16
|
def initialize(box, &block)
|
@@ -14,6 +23,8 @@ class SystemBuilder::BoxTasks < Rake::TaskLib
|
|
14
23
|
box
|
15
24
|
end
|
16
25
|
|
26
|
+
@box.named_mode = self.class.multiple_boxes?
|
27
|
+
|
17
28
|
yield @box if block_given?
|
18
29
|
|
19
30
|
define
|
@@ -34,6 +45,10 @@ class SystemBuilder::BoxTasks < Rake::TaskLib
|
|
34
45
|
desc "Shortcut for dist:disk task"
|
35
46
|
task :dist => "dist:disk"
|
36
47
|
|
48
|
+
task :inspect do
|
49
|
+
puts box.inspect
|
50
|
+
end
|
51
|
+
|
37
52
|
namespace :dist do
|
38
53
|
desc "Create disk image in #{box.disk_file}"
|
39
54
|
task :disk do
|
@@ -54,12 +69,12 @@ class SystemBuilder::BoxTasks < Rake::TaskLib
|
|
54
69
|
task :upgrade do
|
55
70
|
rm_rf box.upgrade_directory
|
56
71
|
mkdir_p box.upgrade_directory
|
57
|
-
ln_s File.expand_path("
|
72
|
+
ln_s File.expand_path("#{box.build_dir}/filesystem.squashfs"), "#{box.upgrade_directory}/filesystem-#{box.release_name}.squashfs"
|
58
73
|
ln_s File.expand_path("#{box.root_file}/vmlinuz"), "#{box.upgrade_directory}/vmlinuz-#{box.release_name}"
|
59
74
|
ln_s File.expand_path("#{box.root_file}/initrd.img"), "#{box.upgrade_directory}/initrd-#{box.release_name}.img"
|
60
|
-
sh "tar -cf #{box.upgrade_file} --dereference -C #{box.upgrade_directory} ."
|
75
|
+
FileUtils::sh "tar -cf #{box.upgrade_file} --dereference -C #{box.upgrade_directory} ."
|
61
76
|
|
62
|
-
box.create_latest_file "
|
77
|
+
box.create_latest_file "#{box.dist_dir}/latest.yml"
|
63
78
|
end
|
64
79
|
|
65
80
|
desc "Create all images (disk, iso and upgrade)"
|
@@ -82,20 +97,20 @@ class SystemBuilder::BoxTasks < Rake::TaskLib
|
|
82
97
|
desc "Clean build and dist directories"
|
83
98
|
task :clean do
|
84
99
|
unless File.exists?(box.root_file) and system "sudo fuser $PWD/#{box.root_file}"
|
85
|
-
|
100
|
+
sudo "rm -rf #{box.root_file}"
|
86
101
|
end
|
87
|
-
sh "rm -rf
|
88
|
-
sh "rm -f
|
89
|
-
sh "rm -rf
|
102
|
+
FileUtils::sh "rm -rf #{box.upgrade_directory}"
|
103
|
+
FileUtils::sh "rm -f #{box.build_dir}/*"
|
104
|
+
FileUtils::sh "rm -rf #{box.dist_dir}/*"
|
90
105
|
end
|
91
106
|
|
92
107
|
task :buildbot => [:clean, "dist:all", "buildbot:dist"] do
|
93
108
|
# clean in dependencies is executed only once
|
94
|
-
sh "rake #{box.name}:clean"
|
109
|
+
FileUtils::sh "rake #{box.name}:clean"
|
95
110
|
end
|
96
111
|
|
97
112
|
def latest_release_number
|
98
|
-
YAML.load(IO.read(
|
113
|
+
YAML.load(IO.read(box.latest_file))["name"].gsub("#{box.name}-","") if File.exists?(box.latest_file)
|
99
114
|
end
|
100
115
|
|
101
116
|
namespace :buildbot do
|
@@ -108,7 +123,7 @@ class SystemBuilder::BoxTasks < Rake::TaskLib
|
|
108
123
|
cp box.iso_file, "#{target_directory}/#{box.name}-#{release_number}.iso"
|
109
124
|
cp box.upgrade_file, "#{target_directory}/#{box.name}-#{release_number}.tar"
|
110
125
|
|
111
|
-
cp
|
126
|
+
cp box.latest_file, "#{target_directory}/latest.yml"
|
112
127
|
end
|
113
128
|
end
|
114
129
|
|
@@ -6,7 +6,7 @@ module SystemBuilder
|
|
6
6
|
@proc = (proc or block)
|
7
7
|
end
|
8
8
|
|
9
|
-
def configure(chroot)
|
9
|
+
def configure(chroot, options = {})
|
10
10
|
@proc.call chroot
|
11
11
|
end
|
12
12
|
|
@@ -25,24 +25,26 @@ module SystemBuilder
|
|
25
25
|
%w{manifests files modules templates plugins}.collect { |d| "#{manifest}/#{d}" }.select { |d| File.directory?(d) }
|
26
26
|
end
|
27
27
|
|
28
|
-
def configure(chroot)
|
28
|
+
def configure(chroot, options = {})
|
29
|
+
debian_release = (options.delete(:debian_release) or :lenny)
|
30
|
+
|
29
31
|
puts "* run puppet configuration"
|
30
32
|
|
31
|
-
unless chroot.image.exists?("/etc/apt/sources.list.d
|
32
|
-
chroot.image.open("/etc/apt/sources.list.d
|
33
|
-
f.puts "deb http://backports.debian.org/debian-backports
|
33
|
+
unless chroot.image.exists?("/etc/apt/sources.list.d/#{debian_release}-backports.list")
|
34
|
+
chroot.image.open("/etc/apt/sources.list.d/#{debian_release}-backports.list") do |f|
|
35
|
+
f.puts "deb http://backports.debian.org/debian-backports #{debian_release}-backports main contrib non-free"
|
34
36
|
end
|
35
37
|
|
36
38
|
chroot.image.open("/etc/apt/preferences") do |f|
|
37
39
|
f.puts "Package: puppet"
|
38
|
-
f.puts "Pin: release a
|
40
|
+
f.puts "Pin: release a=#{debian_release}-backports"
|
39
41
|
f.puts "Pin-Priority: 999"
|
40
|
-
end
|
42
|
+
end if debian_release == :lenny
|
41
43
|
|
42
44
|
chroot.sudo "apt-get update"
|
43
45
|
end
|
44
46
|
|
45
|
-
chroot.apt_install :puppet
|
47
|
+
chroot.apt_install :puppet, :rubygems
|
46
48
|
chroot.image.open("/etc/default/puppet") do |f|
|
47
49
|
f.puts "START=no"
|
48
50
|
end
|
@@ -50,7 +52,7 @@ module SystemBuilder
|
|
50
52
|
unless File.directory?(manifest)
|
51
53
|
chroot.image.install "/tmp/puppet.pp", manifest
|
52
54
|
# chmod +r to make file readable for buildbot
|
53
|
-
chroot.sudo "puppet --color=false tmp/puppet.pp | tee /tmp/puppet.log && chmod +r /tmp/puppet.log"
|
55
|
+
chroot.sudo "puppet --color=false tmp/puppet.pp 2>&1 | tee /tmp/puppet.log && chmod +r /tmp/puppet.log"
|
54
56
|
process_log_file(chroot.image.expand_path("/tmp/puppet.log"))
|
55
57
|
else
|
56
58
|
context_dir = "/tmp/puppet"
|
@@ -74,7 +76,9 @@ module SystemBuilder
|
|
74
76
|
end
|
75
77
|
|
76
78
|
chroot.image.mkdir "#{context_dir}/tmp"
|
77
|
-
|
79
|
+
|
80
|
+
debian_options = "export DEBIAN_SCRIPT_DEBUG=1;" if ENV['DEBIAN_SCRIPT_DEBUG']
|
81
|
+
chroot.sudo "#{debian_options} puppet --color=false --modulepath '#{context_dir}/modules' --confdir='#{context_dir}/config' --templatedir='#{context_dir}/templates' --manifestdir='#{context_dir}/manifests' --vardir=#{context_dir}/tmp '#{context_dir}/manifests/site.pp' 2>&1 | tee #{context_dir}/puppet.log"
|
78
82
|
|
79
83
|
process_log_file(chroot.image.expand_path("#{context_dir}/puppet.log"))
|
80
84
|
end
|
@@ -82,7 +86,7 @@ module SystemBuilder
|
|
82
86
|
|
83
87
|
def process_log_file(log_file)
|
84
88
|
FileUtils.cp log_file, "puppet.log"
|
85
|
-
unless File.readlines("puppet.log").grep(/^err
|
89
|
+
unless File.readlines("puppet.log").grep(/^(err:|Could not parse for environment production)/).empty?
|
86
90
|
raise "Error(s) during puppet configuration, see puppet.log file"
|
87
91
|
end
|
88
92
|
end
|
@@ -72,7 +72,7 @@ class SystemBuilder::DiskNfsRootImage
|
|
72
72
|
root = (options[:root] or "LABEL=#{fs_label}")
|
73
73
|
version = (options[:version] or Time.now.strftime("%Y%m%d%H%M"))
|
74
74
|
nfssvr = %x{/sbin/ip link show|grep -e "eth.:"|cut -d' ' -f 2|cut -d':' -f 1|xargs ip addr show|grep "inet "|cut -d' ' -f 6|cut -d'/' -f 1}.strip
|
75
|
-
nfsroot = %x{readlink -f
|
75
|
+
nfsroot = %x{readlink -f #{boot.root}}.strip
|
76
76
|
nfsopt = (options[:nfsroot] or "#{nfssvr}:#{nfsroot}")
|
77
77
|
|
78
78
|
mount_boot_fs do |mount_dir|
|
@@ -27,6 +27,7 @@ class SystemBuilder::DiskSquashfsImage
|
|
27
27
|
|
28
28
|
compress_root_fs
|
29
29
|
install_extlinux
|
30
|
+
compute_checksums
|
30
31
|
|
31
32
|
self
|
32
33
|
end
|
@@ -62,12 +63,22 @@ class SystemBuilder::DiskSquashfsImage
|
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
66
|
+
attr_accessor :build_dir
|
67
|
+
|
68
|
+
def build_dir
|
69
|
+
@build_dir ||= "build"
|
70
|
+
end
|
71
|
+
|
72
|
+
def squashfs_file
|
73
|
+
"#{build_dir}/filesystem.squashfs"
|
74
|
+
end
|
75
|
+
|
65
76
|
def compress_root_fs
|
66
|
-
FileUtils::sudo "mksquashfs #{boot.root}/
|
67
|
-
FileUtils::sudo "chown #{ENV['USER']}
|
77
|
+
FileUtils::sudo "mksquashfs #{boot.root}/ #{squashfs_file} -noappend -e #{boot.root}/boot"
|
78
|
+
FileUtils::sudo "chown #{ENV['USER']} #{squashfs_file} && chmod +r #{squashfs_file}"
|
68
79
|
|
69
80
|
mount_boot_fs do |mount_dir|
|
70
|
-
FileUtils::sudo "cp
|
81
|
+
FileUtils::sudo "cp #{squashfs_file} #{mount_dir}/filesystem.squashfs"
|
71
82
|
end
|
72
83
|
FileUtils.touch file
|
73
84
|
end
|
@@ -107,6 +118,14 @@ class SystemBuilder::DiskSquashfsImage
|
|
107
118
|
FileUtils::sh "dd if=#{boot.root}/usr/lib/syslinux/mbr.bin of=#{file} conv=notrunc"
|
108
119
|
end
|
109
120
|
|
121
|
+
def compute_checksums
|
122
|
+
mount_boot_fs do |mount_dir|
|
123
|
+
FileUtils::cd("#{mount_dir}") do
|
124
|
+
FileUtils::sh"md5sum * |sudo tee MD5SUM"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
110
129
|
def fs_label
|
111
130
|
"boot"
|
112
131
|
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
class SystemBuilder::InitRamFsConfigurator
|
2
2
|
|
3
|
-
def configure(chroot)
|
3
|
+
def configure(chroot, options = {})
|
4
|
+
debian_release = (options.delete(:debian_release) or :lenny)
|
5
|
+
|
4
6
|
puts "* install initramfs-tools"
|
5
|
-
|
7
|
+
|
8
|
+
packages = %w{initramfs-tools syslinux}
|
9
|
+
packages << "extlinux" unless debian_release == :lenny
|
10
|
+
chroot.apt_install packages
|
6
11
|
|
7
12
|
install_script(chroot, "local-top/mount_boot") do |f|
|
8
13
|
f.puts "modprobe loop"
|
@@ -33,7 +38,7 @@ class SystemBuilder::InitRamFsConfigurator
|
|
33
38
|
|
34
39
|
@@script_header = <<EOF
|
35
40
|
#!/bin/sh -x
|
36
|
-
if [ "$1"
|
41
|
+
if [ "$1" = "prereqs" ]; then
|
37
42
|
echo ""; exit 0;
|
38
43
|
fi
|
39
44
|
EOF
|
@@ -20,10 +20,20 @@ class SystemBuilder::IsoSquashfsImage
|
|
20
20
|
self
|
21
21
|
end
|
22
22
|
|
23
|
+
attr_accessor :build_dir
|
24
|
+
|
25
|
+
def build_dir
|
26
|
+
@build_dir ||= "build"
|
27
|
+
end
|
28
|
+
|
29
|
+
def squashfs_file
|
30
|
+
"#{build_dir}/filesystem.squashfs"
|
31
|
+
end
|
32
|
+
|
23
33
|
def compress_root_fs
|
24
|
-
unless File.exists?("
|
25
|
-
FileUtils::sudo "mksquashfs #{boot.root}/
|
26
|
-
FileUtils::sudo "chown #{ENV['USER']}
|
34
|
+
unless File.exists?("#{squashfs_file}")
|
35
|
+
FileUtils::sudo "mksquashfs #{boot.root}/ #{squashfs_file} -noappend -e /boot"
|
36
|
+
FileUtils::sudo "chown #{ENV['USER']} #{squashfs_file} && chmod +r #{squashfs_file}"
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
@@ -49,7 +59,7 @@ class SystemBuilder::IsoSquashfsImage
|
|
49
59
|
end
|
50
60
|
|
51
61
|
def make_iso_fs
|
52
|
-
FileUtils::sudo "genisoimage -quiet -R -o #{file} -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -graft-points vmlinuz=#{boot.root}/boot/#{readlink_boot_file('vmlinuz')} initrd.img=#{boot.root}/boot/#{readlink_boot_file('initrd.img')} filesystem.squashfs
|
62
|
+
FileUtils::sudo "genisoimage -quiet -R -o #{file} -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -graft-points vmlinuz=#{boot.root}/boot/#{readlink_boot_file('vmlinuz')} initrd.img=#{boot.root}/boot/#{readlink_boot_file('initrd.img')} filesystem.squashfs=#{squashfs_file} #{boot.root}/boot"
|
53
63
|
FileUtils::sudo "chown $USER #{file}"
|
54
64
|
end
|
55
65
|
|
@@ -21,21 +21,39 @@ list_devices() {
|
|
21
21
|
|
22
22
|
mkdir /boot
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
24
|
+
if [ -n "${nfsroot}" ]; then
|
25
|
+
. /scripts/functions
|
26
|
+
configure_networking
|
27
|
+
|
28
|
+
if [ -z "${nfsopts}" ]; then
|
29
|
+
nfsopts="retrans=10"
|
30
|
+
fi
|
31
|
+
|
32
|
+
echo "check if ${nfsroot} provided boot image"
|
33
|
+
nfsmount -o nolock,ro,${nfsopts} ${nfsroot} /boot
|
34
|
+
if [ -f "/boot/filesystem.squashfs" ]; then
|
35
|
+
exit 0
|
36
|
+
else
|
37
|
+
echo "no image found on nfs"
|
38
|
+
exit 1
|
39
|
+
fi
|
40
|
+
else
|
41
|
+
for device in `list_devices`; do
|
42
|
+
fs_type=`get_fstype ${device}`
|
43
|
+
echo "check if $device ($fs_type) is the boot image"
|
44
|
+
|
45
|
+
case $fs_type in
|
46
|
+
ext2|ext3|iso9660)
|
47
|
+
mount -r -t $fs_type $device /boot
|
48
|
+
if [ -f "/boot/config.pp" ]; then
|
49
|
+
exit 0
|
50
|
+
else
|
51
|
+
umount /boot
|
52
|
+
fi
|
53
|
+
;;
|
54
|
+
esac
|
55
|
+
done
|
56
|
+
fi
|
39
57
|
|
40
58
|
echo "no image found"
|
41
59
|
exit 1
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: system-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 43
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 26
|
10
|
+
version: 0.0.26
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alban Peignier
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2012-02-27 00:00:00 Z
|
20
20
|
dependencies: []
|
21
21
|
|
22
22
|
description: ""
|
@@ -61,11 +61,9 @@ files:
|
|
61
61
|
- lib/system_builder/disk_nfsroot_image.rb
|
62
62
|
- lib/system_builder/disk_squashfs_image.rb
|
63
63
|
- lib/system_builder/init_ram_fs_configurator.rb
|
64
|
-
- lib/system_builder/iso_image.rb
|
65
64
|
- lib/system_builder/iso_squashfs_image.rb
|
66
65
|
- lib/system_builder/live_image.rb
|
67
66
|
- lib/system_builder/mount_boot.sh
|
68
|
-
- lib/system_builder/task.rb
|
69
67
|
- lib/system_builder/version.rb
|
70
68
|
- script/console
|
71
69
|
- script/destroy
|
@@ -105,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
103
|
requirements: []
|
106
104
|
|
107
105
|
rubyforge_project: system-builder
|
108
|
-
rubygems_version: 1.
|
106
|
+
rubygems_version: 1.8.15
|
109
107
|
signing_key:
|
110
108
|
specification_version: 3
|
111
109
|
summary: Build bootable images
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
|
3
|
-
class SystemBuilder::IsoImage
|
4
|
-
|
5
|
-
attr_accessor :boot
|
6
|
-
attr_reader :file
|
7
|
-
|
8
|
-
def initialize(file)
|
9
|
-
@file = file
|
10
|
-
end
|
11
|
-
|
12
|
-
def create
|
13
|
-
boot.create
|
14
|
-
create_iso
|
15
|
-
|
16
|
-
self
|
17
|
-
end
|
18
|
-
|
19
|
-
def create_iso
|
20
|
-
install_isolinux_files
|
21
|
-
make_iso_fs
|
22
|
-
end
|
23
|
-
|
24
|
-
def install_isolinux_files(options = {})
|
25
|
-
root = (options[:root] or "/dev/hdc")
|
26
|
-
version = (options[:version] or Time.now.strftime("%Y%m%d%H%M"))
|
27
|
-
|
28
|
-
boot.image do |image|
|
29
|
-
image.mkdir "/boot/isolinux"
|
30
|
-
|
31
|
-
image.open("/boot/isolinux/isolinux.cfg") do |f|
|
32
|
-
f.puts "default linux"
|
33
|
-
f.puts "label linux"
|
34
|
-
f.puts "kernel /vmlinuz"
|
35
|
-
f.puts "append ro root=#{root} initrd=/initrd.img"
|
36
|
-
end
|
37
|
-
|
38
|
-
image.install "/boot/isolinux", "/usr/lib/syslinux/isolinux.bin"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def readlink_boot_file(boot_file)
|
43
|
-
File.basename(%x{readlink #{boot.root}/#{boot_file}}.strip)
|
44
|
-
end
|
45
|
-
|
46
|
-
def make_iso_fs
|
47
|
-
FileUtils::sudo "genisoimage -quiet -R -o #{file} -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -A #{root_fs_label} -V #{root_fs_label} -graft-points -hide build/root/initrd.img -hide build/root/vmlinuz vmlinuz=#{boot.root}/boot/#{readlink_boot_file('vmlinuz')} initrd.img=#{boot.root}/boot/#{readlink_boot_file('initrd.img')} #{boot.root}"
|
48
|
-
FileUtils::sudo "chown $USER #{file}"
|
49
|
-
end
|
50
|
-
|
51
|
-
def root_fs_label
|
52
|
-
"root"
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
data/lib/system_builder/task.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'rake/tasklib'
|
2
|
-
|
3
|
-
class SystemBuilder::Task < Rake::TaskLib
|
4
|
-
|
5
|
-
attr_reader :name
|
6
|
-
|
7
|
-
def initialize(name, &block)
|
8
|
-
@name = name
|
9
|
-
|
10
|
-
@image =
|
11
|
-
if block_given?
|
12
|
-
block.call
|
13
|
-
else
|
14
|
-
SystemBuilder.config(name)
|
15
|
-
end
|
16
|
-
|
17
|
-
define
|
18
|
-
end
|
19
|
-
|
20
|
-
def define
|
21
|
-
namespace name do
|
22
|
-
desc "Create image #{name} in #{@image.file}"
|
23
|
-
task :dist do
|
24
|
-
@image.create
|
25
|
-
end
|
26
|
-
namespace :dist do
|
27
|
-
desc "Create vmware image in #{@image.file}.vdmk"
|
28
|
-
task :vmware do
|
29
|
-
@image.convert "#{@image.file}.vmdk", :format => "vmdk"
|
30
|
-
end
|
31
|
-
|
32
|
-
desc "Create iso image in #{@image.file}.iso"
|
33
|
-
task :iso do
|
34
|
-
SystemBuilder::IsoImage.new("#{@image.file}.iso").tap do |image|
|
35
|
-
image.boot = @image.boot
|
36
|
-
end.create_iso
|
37
|
-
end
|
38
|
-
end
|
39
|
-
task "dist:vmware" => "dist"
|
40
|
-
|
41
|
-
namespace :build do
|
42
|
-
desc "Configure the image system"
|
43
|
-
task :configure do
|
44
|
-
@image.boot.configure
|
45
|
-
@image.boot.clean
|
46
|
-
end
|
47
|
-
|
48
|
-
desc "Clean the image system"
|
49
|
-
task :clean do
|
50
|
-
@image.boot.clean
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
task :setup do
|
55
|
-
required_packages = []
|
56
|
-
required_packages << "qemu" # to convert image files
|
57
|
-
required_packages << "util-linux" # provides sfdisk
|
58
|
-
required_packages << "sudo"
|
59
|
-
required_packages << "debootstrap"
|
60
|
-
required_packages << "rsync"
|
61
|
-
required_packages << "dosfstools"
|
62
|
-
required_packages << "syslinux"
|
63
|
-
required_packages << "squashfs-tools"
|
64
|
-
|
65
|
-
FileUtils.sudo "apt-get install #{required_packages.join(' ')}"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|