-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathlxc-precise-lts
104 lines (91 loc) · 2.5 KB
/
lxc-precise-lts
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
#!/usr/bin/env ruby
# This is just to fix precise in LTS
require 'fileutils'
LXC_TEMPLATE = '/usr/lib/lxc/templates/lxc-ubuntu'
def report(action)
print "#{action}... "
yield
puts 'done'
end
# Set paths
repo_root = ENV['REPO_PATH'] || '/opt/debootstrap-repos'
precise_root = File.join(repo_root, 'precise')
pool = File.join(precise_root, 'pool')
component = File.join(precise_root, 'dists/precise/main/binary-amd64')
conf = File.join(repo_root, 'debrepos.conf')
# Build paths
report 'Creating required directories' do
FileUtils.mkdir_p(component)
FileUtils.mkdir_p(pool)
FileUtils.ln_s(pool, File.join(component, pool))
end
# define required packages
report 'Fetching required package list' do
packages = `debootstrap --print-debs --include="vim,ssh" precise /tmp/precise-bootstrap`.strip
end
# download packages
report 'Downloading packages' do
Dir.chdir(pool)
unless system("apt-get download #{packages}")
warn 'Package download failed!'
exit 1
end
end
# Create conf file
report 'Creating configuration file' do
File.open(conf, 'w') do |f|
f.puts %(
Dir {
ArchiveDir #{precise_root};
}
Default
{
Packages::Compress ". gzip";
Sources::Compress ". gzip";
Contents::Compress ". gzip";
}
bindirectory "pool"
{
Packages "dists/precise/main/binary-amd64/Packages";
Contents "dists/precise/main/binary-amd64/Contents";
}
)
end
end
# generate
report 'Generating archive' do
Dir.chdir(repo_root)
unless system("apt-ftparchive generate #{File.basename(conf)}")
warn 'Archive generation failed!'
exit 1
end
end
report 'Adding release files' do
[precise_root, component].each do |d|
Dir.chdir(d)
con = `apt-ftparchive release .`
File.open(File.join(d, 'Release'), 'w') do |file|
file.puts "Components main\n#{con}\n"
end
end
end
if File.exist?(LXC_TEMPLATE)
report 'Updating ubuntu lxc template' do
contents = File.readlines(LXC_TEMPLATE)
contents.map! do |line|
if line =~ /^\s*debootstrap.+\$MIRROR\s*$/
'debootstrap --no-check-gpg --verbose --components=main --arch=$arch --include=$packages $release $cache/partial-$arch $LOCAL_REPO'
else
line
end
end
File.open(LXC_TEMPLATE, 'w') do |file|
file.puts contents.join("\n")
end
end
end
puts "\nSUCCESS: Local updated precise repository created for debootstrap"
puts " USAGE: debootstrap precise store_dir file://#{precise_root}"
if File.exist?(LXC_TEMPLATE)
puts "LXC USAGE: LOCAL_REPO=\"file://#{precise_root}\" lxc-create -n ctn-name -t ubuntu"
end