Class: SystemBuilder::DebianBoot
Defined Under Namespace
Classes: AptConfigurator, Chroot, Image
Constant Summary
collapse
- @@default_mirror =
'http://ftp.debian.org/debian'
- @@apt_proxy =
nil
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of DebianBoot.
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/system_builder/boot.rb', line 26
def initialize(root)
@root = root
@version = :lenny
@mirror = @@default_mirror
@architecture = :i386
@components = ["main"]
@exclude = []
@include = [ "debian-archive-keyring" ]
@configurators =
[ localhost_configurator,
apt_configurator,
kernel_configurator,
fstab_configurator,
timezone_configurator,
resolvconf_configurator,
policyrc_configurator
]
@cleaners = [ apt_cleaner, policyrc_cleaner ]
end
|
Instance Attribute Details
#architecture ⇒ Object
Returns the value of attribute architecture.
3
4
5
|
# File 'lib/system_builder/boot.rb', line 3
def architecture
@architecture
end
|
#components ⇒ Object
Returns the value of attribute components.
4
5
6
|
# File 'lib/system_builder/boot.rb', line 4
def components
@components
end
|
#configurators ⇒ Object
Returns the value of attribute configurators.
7
8
9
|
# File 'lib/system_builder/boot.rb', line 7
def configurators
@configurators
end
|
Returns the value of attribute exclude.
4
5
6
|
# File 'lib/system_builder/boot.rb', line 4
def exclude
@exclude
end
|
Returns the value of attribute include.
4
5
6
|
# File 'lib/system_builder/boot.rb', line 4
def include
@include
end
|
Returns the value of attribute mirror.
3
4
5
|
# File 'lib/system_builder/boot.rb', line 3
def mirror
@mirror
end
|
Returns the value of attribute root.
6
7
8
|
# File 'lib/system_builder/boot.rb', line 6
def root
@root
end
|
Returns the value of attribute version.
3
4
5
|
# File 'lib/system_builder/boot.rb', line 3
def version
@version
end
|
Class Method Details
.apt_options ⇒ Object
22
23
24
|
# File 'lib/system_builder/boot.rb', line 22
def self.apt_options
"-o Acquire::http::Proxy='#{apt_proxy}'" if apt_proxy
end
|
.apt_proxy ⇒ Object
18
19
20
|
# File 'lib/system_builder/boot.rb', line 18
def self.apt_proxy
@@apt_proxy
end
|
.apt_proxy=(proxy) ⇒ Object
15
16
17
|
# File 'lib/system_builder/boot.rb', line 15
def self.apt_proxy=(proxy)
@@apt_proxy = proxy
end
|
.default_mirror=(mirror) ⇒ Object
10
11
12
|
# File 'lib/system_builder/boot.rb', line 10
def self.default_mirror=(mirror)
@@default_mirror = mirror
end
|
Instance Method Details
#apt_cleaner ⇒ Object
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'lib/system_builder/boot.rb', line 209
def apt_cleaner
Proc.new do |chroot|
if chroot.image.exists?(apt_confd_proxy_file)
puts "* remove apt proxy configuration"
chroot.sudo "rm #{apt_confd_proxy_file}"
end
puts "* clean apt caches"
chroot.sudo "apt-get clean"
puts "* autoremove packages"
chroot.sudo "apt-get autoremove --yes"
end
end
|
#apt_confd_proxy_file ⇒ Object
130
131
132
|
# File 'lib/system_builder/boot.rb', line 130
def apt_confd_proxy_file
"/etc/apt/apt.conf.d/02proxy-systembuilder"
end
|
#apt_configurator ⇒ Object
126
127
128
|
# File 'lib/system_builder/boot.rb', line 126
def apt_configurator
AptConfigurator.new(self)
end
|
#bootstrap ⇒ Object
58
59
60
61
62
63
|
# File 'lib/system_builder/boot.rb', line 58
def bootstrap
unless File.exists?(root)
FileUtils::mkdir_p root
FileUtils::sudo "debootstrap", debbootstrap_options, version, root, debbootstrap_url
end
end
|
#chroot(&block) ⇒ Object
268
269
270
271
|
# File 'lib/system_builder/boot.rb', line 268
def chroot(&block)
@chroot ||= Chroot.new(image)
@chroot.execute &block
end
|
76
77
78
79
80
81
82
83
84
|
# File 'lib/system_builder/boot.rb', line 76
def clean
unless @cleaners.empty?
chroot do |chroot|
@cleaners.each do |cleaner|
cleaner.call(chroot)
end
end
end
end
|
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/system_builder/boot.rb', line 65
def configure
puts "* #{configurators.size} configurators to run :"
unless @configurators.empty?
chroot do |chroot|
@configurators.each do |configurator|
configurator.configure chroot, :debian_release => version
end
end
end
end
|
#create(force = false) ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/system_builder/boot.rb', line 49
def create(force = false)
return if @creating and not force
bootstrap
configure
clean
@creating = true
end
|
#debbootstrap_options ⇒ Object
238
239
240
241
242
243
244
245
246
247
248
|
# File 'lib/system_builder/boot.rb', line 238
def debbootstrap_options
{
:arch => architecture,
:exclude => exclude.join(','),
:include => include.join(','),
:variant => :minbase,
:components => components.join(',')
}.collect do |k,v|
["--#{k}", Array(v).join(',')] unless v.blank?
end.compact
end
|
#debbootstrap_url ⇒ Object
250
251
252
253
254
255
256
|
# File 'lib/system_builder/boot.rb', line 250
def debbootstrap_url
if self.class.apt_proxy
"#{self.class.apt_proxy}#{mirror.gsub('http:/','')}"
else
mirror
end
end
|
#fstab_configurator ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/system_builder/boot.rb', line 96
def fstab_configurator
SystemBuilder::ProcConfigurator.new do |chroot|
puts "* create fstab"
chroot.image.open("/etc/fstab") do |f|
f.puts "LABEL=boot /boot auto defaults,noatime,ro 0 0"
%w{/tmp /var/run /var/log /var/lock /var/tmp}.each do |directory|
f.puts "tmpfs #{directory} tmpfs defaults,noatime 0 0"
end
end
end
end
|
#image(&block) ⇒ Object
258
259
260
261
262
263
264
265
266
|
# File 'lib/system_builder/boot.rb', line 258
def image(&block)
@image ||= Image.new(root)
if block_given?
yield @image
else
@image
end
end
|
#kernel_configurator ⇒ Object
86
87
88
89
90
91
92
93
94
|
# File 'lib/system_builder/boot.rb', line 86
def kernel_configurator
SystemBuilder::ProcConfigurator.new do |chroot|
puts "* install kernel"
chroot.image.open("/etc/kernel-img.conf") do |f|
f.puts "do_initrd = yes"
end
chroot.apt_install %w{linux-image-2.6-686}
end
end
|
#localhost_configurator ⇒ Object
229
230
231
232
233
234
235
236
|
# File 'lib/system_builder/boot.rb', line 229
def localhost_configurator
SystemBuilder::ProcConfigurator.new do |chroot|
chroot.image.open("/etc/hosts") do |f|
f.puts "127.0.0.1 localhost"
f.puts "::1 localhost ip6-localhost ip6-loopback"
end
end
end
|
#policyrc_cleaner ⇒ Object
222
223
224
225
226
227
|
# File 'lib/system_builder/boot.rb', line 222
def policyrc_cleaner
Proc.new do |chroot|
puts "* enable rc services"
chroot.sh "rm /usr/sbin/policy-rc.d"
end
end
|
#policyrc_configurator ⇒ Object
199
200
201
202
203
204
205
206
207
|
# File 'lib/system_builder/boot.rb', line 199
def policyrc_configurator
SystemBuilder::ProcConfigurator.new do |chroot|
puts "* disable rc services"
chroot.image.open("/usr/sbin/policy-rc.d") do |f|
f.puts "exit 101"
end
chroot.sh "chmod +x /usr/sbin/policy-rc.d"
end
end
|
#resolvconf_configurator ⇒ Object
116
117
118
119
120
121
122
123
124
|
# File 'lib/system_builder/boot.rb', line 116
def resolvconf_configurator
SystemBuilder::ProcConfigurator.new do |chroot|
unless chroot.image.exists?("/etc/resolv.conf")
puts "* define resolv.conf"
chroot.image.install "/etc/", "/etc/resolv.conf"
end
end
end
|
#timezone_configurator ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/system_builder/boot.rb', line 108
def timezone_configurator
SystemBuilder::ProcConfigurator.new do |chroot|
puts "* define timezone"
chroot.image.install "/etc/", "/etc/timezone", "/etc/localtime"
end
end
|