system-builder 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Manifest.txt CHANGED
@@ -15,10 +15,13 @@ features/support/env.rb
15
15
  features/support/matchers.rb
16
16
  lib/system_builder.rb
17
17
  lib/system_builder/boot.rb
18
+ lib/system_builder/box.rb
19
+ lib/system_builder/box_tasks.rb
18
20
  lib/system_builder/cli.rb
19
21
  lib/system_builder/configurator.rb
20
22
  lib/system_builder/core_ext.rb
21
23
  lib/system_builder/disk_image.rb
24
+ lib/system_builder/disk_nfsroot_image.rb
22
25
  lib/system_builder/disk_squashfs_image.rb
23
26
  lib/system_builder/init_ram_fs_configurator.rb
24
27
  lib/system_builder/iso_image.rb
@@ -46,10 +46,13 @@ class SystemBuilder::DebianBoot
46
46
  @cleaners = [ apt_cleaner, policyrc_cleaner ]
47
47
  end
48
48
 
49
- def create
49
+ def create(force = false)
50
+ return if @creating and not force
51
+
50
52
  bootstrap
51
53
  configure
52
54
  clean
55
+ @creating = true
53
56
  end
54
57
 
55
58
  def bootstrap
@@ -0,0 +1,95 @@
1
+ class SystemBuilder::Box
2
+
3
+ attr_reader :name
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ end
8
+
9
+ def release_number
10
+ @release_number ||= Time.now.strftime('%Y%m%d-%H%M')
11
+ end
12
+
13
+ def release_name
14
+ @release_name ||= "streambox-#{release_number}"
15
+ end
16
+
17
+ def root_file
18
+ "build/root"
19
+ end
20
+
21
+ def boot
22
+ @boot ||= SystemBuilder::DebianBoot.new(root_file).tap do |boot|
23
+ boot.configurators << puppet_configurator
24
+ end
25
+
26
+ yield @boot if block_given?
27
+ @boot
28
+ end
29
+
30
+ def puppet_configurator
31
+ @puppet_configurator ||= SystemBuilder::PuppetConfigurator.new :release_name => release_name
32
+ yield @puppet_configurator if block_given?
33
+ @puppet_configurator
34
+ end
35
+
36
+ def disk_file
37
+ "dist/disk"
38
+ end
39
+
40
+ def disk_image
41
+ @disk_image ||= SystemBuilder::DiskSquashfsImage.new(disk_file).tap do |image|
42
+ image.boot = boot
43
+ image.size = 200.megabytes
44
+ end
45
+ yield @disk_image if block_given?
46
+ @disk_image
47
+ end
48
+
49
+ def iso_file
50
+ "dist/iso"
51
+ end
52
+
53
+ def iso_image
54
+ @iso_image ||= SystemBuilder::IsoSquashfsImage.new(iso_file).tap do |image|
55
+ image.boot = boot
56
+ end
57
+ yield @iso_image if block_given?
58
+ @iso_image
59
+ end
60
+
61
+ def nfs_file
62
+ "dist/nfs"
63
+ end
64
+
65
+ def nfs_image
66
+ @nfs_image ||= SystemBuilder::DiskNfsRootImage.new(nfs_file).tap do |image|
67
+ image.boot = boot
68
+ end
69
+ yield @nfs_image if block_given?
70
+ @nfs_image
71
+ end
72
+
73
+ def upgrade_directory
74
+ "build/upgrade"
75
+ end
76
+
77
+ def upgrade_file
78
+ "dist/upgrade.tar"
79
+ end
80
+
81
+ def upgrade_checksum
82
+ `sha256sum #{upgrade_file}`.split.first
83
+ end
84
+
85
+ def create_latest_file(latest_file)
86
+ File.open(latest_file, "w") do |f|
87
+ f.puts "name: #{release_name}"
88
+ f.puts "url: http://download.tryphon.eu/streambox/streambox-#{release_number}.tar"
89
+ f.puts "checksum: #{upgrade_checksum}"
90
+ f.puts "status_updated_at: #{Time.now}"
91
+ f.puts "description_url: http://www.tryphon.eu/release/#{release_name}"
92
+ end
93
+ end
94
+
95
+ end
@@ -0,0 +1,132 @@
1
+ require 'rake/tasklib'
2
+
3
+ class SystemBuilder::BoxTasks < Rake::TaskLib
4
+
5
+ attr_reader :box
6
+
7
+ def initialize(box, &block)
8
+ init
9
+
10
+ @box =
11
+ if Symbol === box
12
+ SystemBuilder::Box.new(box)
13
+ else
14
+ box
15
+ end
16
+
17
+ yield @box if block_given?
18
+
19
+ define
20
+ end
21
+
22
+ def init
23
+ ["#{ENV['HOME']}/.system_builder.rc", "./local.rb"].each do |conf|
24
+ load conf if File.exists?(conf)
25
+ end
26
+
27
+ Dir['tasks/**/*.rake'].each { |t| load t }
28
+ end
29
+
30
+ def define
31
+ namespace box.name do
32
+ desc "Create disk/iso images"
33
+
34
+ desc "Shortcut for dist:disk task"
35
+ task :dist => "dist:disk"
36
+
37
+ namespace :dist do
38
+ desc "Create disk image in #{box.disk_file}"
39
+ task :disk do
40
+ box.disk_image.create
41
+ end
42
+
43
+ desc "Create iso image in #{@iso_file}"
44
+ task :iso do
45
+ box.iso_image.create
46
+ end
47
+
48
+ desc "Create NFS image in #{@nfs_file}"
49
+ task :nfs do
50
+ box.nfs_image.create
51
+ end
52
+
53
+ desc "Create upgrade files"
54
+ task :upgrade do
55
+ rm_rf box.upgrade_directory
56
+ mkdir_p box.upgrade_directory
57
+ ln_s File.expand_path("build/filesystem.squashfs"), "#{box.upgrade_directory}/filesystem-#{box.release_name}.squashfs"
58
+ ln_s File.expand_path("#{box.root_file}/vmlinuz"), "#{box.upgrade_directory}/vmlinuz-#{box.release_name}"
59
+ 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} ."
61
+
62
+ box.create_latest_file "dist/latest.yml"
63
+ end
64
+
65
+ desc "Create all images (disk, iso and upgrade)"
66
+ task :all => [:disk, :iso, :upgrade]
67
+ end
68
+
69
+ namespace :build do
70
+ desc "Configure the image system"
71
+ task :configure do
72
+ box.boot.configure
73
+ box.boot.clean
74
+ end
75
+
76
+ desc "Clean the image system"
77
+ task :clean do
78
+ box.boot.clean
79
+ end
80
+ end
81
+
82
+ desc "Clean build and dist directories"
83
+ task :clean do
84
+ unless File.exists?(box.root_file) and system "sudo fuser $PWD/#{box.root_file}"
85
+ sh "sudo rm -rf #{box.root_file}"
86
+ end
87
+ sh "rm -rf build/upgrade"
88
+ sh "rm -f build/*"
89
+ sh "rm -rf dist/*"
90
+ end
91
+
92
+ task :buildbot => [:clean, "dist:all", "buildbot:dist"] do
93
+ # clean in dependencies is executed only once
94
+ Rake::Task["#{box.name}:clean"].invoke
95
+ end
96
+
97
+ def latest_release_number
98
+ YAML.load(IO.read("dist/latest.yml"))["name"].gsub("#{box.name}-","") if File.exists?("dist/latest.yml")
99
+ end
100
+
101
+ namespace :buildbot do
102
+ task :dist do
103
+ target_directory = ENV['DIST'] or "#{ENV['HOME']}/dist/#{box.name}"
104
+ release_number = (latest_release_number or box.release_number)
105
+
106
+ mkdir_p target_directory
107
+ sh "gzip --fast --stdout #{box.disk_file} > #{target_directory}/#{box.name}-#{release_number}.disk.gz"
108
+ cp box.iso_file, "#{target_directory}/#{box.name}-#{release_number}.iso"
109
+ cp box.upgrade_file, "#{target_directory}/#{box.name}-#{release_number}.tar"
110
+
111
+ cp "dist/latest.yml", "#{target_directory}/latest.yml"
112
+ end
113
+ end
114
+
115
+ desc "Setup your environment to build an image"
116
+ task :setup do
117
+ if ENV['WORKING_DIR']
118
+ %w{build dist}.each do |subdir|
119
+ working_subdir = File.join ENV['WORKING_DIR'], subdir
120
+ unless File.exists?(working_subdir)
121
+ puts "* create and link #{working_subdir}"
122
+ mkdir_p working_subdir
123
+ end
124
+ ln_sf working_subdir, subdir unless File.exists?(subdir)
125
+ end
126
+ end
127
+ end
128
+
129
+ end
130
+ end
131
+
132
+ end
@@ -0,0 +1,121 @@
1
+ require 'tempfile'
2
+
3
+ class SystemBuilder::DiskNfsRootImage
4
+
5
+ attr_accessor :boot, :size
6
+ attr_reader :file
7
+
8
+ def initialize(file)
9
+ @file = file
10
+ @size = 40.megabytes
11
+ end
12
+
13
+ def create
14
+ boot.configurators << SystemBuilder::InitRamFsConfigurator.new
15
+ boot.create
16
+
17
+ file_creation = (not File.exists?(file))
18
+ if file_creation
19
+ create_file
20
+ create_partition_table
21
+
22
+ format_boot_fs
23
+ end
24
+
25
+ sync_boot_fs
26
+ install_extlinux_files
27
+ install_extlinux
28
+
29
+ self
30
+ end
31
+
32
+ def create_file
33
+ FileUtils::sh "dd if=/dev/zero of=#{file} count=#{size.in_megabytes.to_i} bs=1M"
34
+ end
35
+
36
+ def create_partition_table
37
+ # Partition must be bootable for syslinux
38
+ FileUtils::sh "echo '#{free_sectors},,L,*' | /sbin/sfdisk --force --no-reread -uS -H16 -S63 #{file}"
39
+ end
40
+
41
+ def format_boot_fs
42
+ loop_device = "/dev/loop0"
43
+ begin
44
+ FileUtils::sudo "losetup -o #{boot_fs_offset} #{loop_device} #{file}"
45
+ FileUtils::sudo "mke2fs -L #{fs_label} -jqF #{loop_device} #{boot_fs_block_size}"
46
+ ensure
47
+ FileUtils::sudo "losetup -d #{loop_device}"
48
+ end
49
+ end
50
+
51
+ def mount_boot_fs(mount_dir = "/tmp/mount_boot_fs", &block)
52
+ FileUtils::mkdir_p mount_dir
53
+
54
+ begin
55
+ FileUtils::sudo "mount -o loop,offset=#{boot_fs_offset} #{file} #{mount_dir}"
56
+ yield mount_dir
57
+ ensure
58
+ FileUtils::sudo "umount #{mount_dir}"
59
+ end
60
+ end
61
+
62
+ def sync_boot_fs
63
+ mount_boot_fs do |mount_dir|
64
+ FileUtils::sudo "rsync -a --delete #{boot.root}/boot/ #{mount_dir}/"
65
+ FileUtils::sudo "ln -s #{readlink_boot_file('initrd.img')} #{mount_dir}/initrd.img"
66
+ FileUtils::sudo "ln -s #{readlink_boot_file('vmlinuz')} #{mount_dir}/vmlinuz.img"
67
+ end
68
+ FileUtils.touch file
69
+ end
70
+
71
+ def install_extlinux_files(options = {})
72
+ root = (options[:root] or "LABEL=#{fs_label}")
73
+ version = (options[:version] or Time.now.strftime("%Y%m%d%H%M"))
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 build/root}.strip
76
+ nfsopt = (options[:nfsroot] or "#{nfssvr}:#{nfsroot}")
77
+
78
+ mount_boot_fs do |mount_dir|
79
+ SystemBuilder::DebianBoot::Image.new(mount_dir).tap do |image|
80
+ image.open("extlinux.conf") do |f|
81
+ f.puts "DEFAULT linux"
82
+ f.puts "LABEL linux"
83
+ f.puts "SAY Now booting #{version} from syslinux ..."
84
+ f.puts "KERNEL /vmlinuz"
85
+ f.puts "APPEND ro initrd=/initrd.img boot=nfs nfsroot=#{nfsopt}"
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ def install_extlinux
92
+ mount_boot_fs("#{boot.root}/boot") do
93
+ boot.chroot do |chroot|
94
+ chroot.sudo "extlinux --install -H16 -S63 /boot"
95
+ end
96
+ end
97
+ FileUtils::sh "dd if=#{boot.root}/usr/lib/syslinux/mbr.bin of=#{file} conv=notrunc"
98
+ end
99
+
100
+ def fs_label
101
+ "boot"
102
+ end
103
+
104
+ def readlink_boot_file(boot_file)
105
+ File.basename(%x{readlink #{boot.root}/#{boot_file}}.strip)
106
+ end
107
+
108
+ def free_sectors
109
+ 64
110
+ end
111
+
112
+ def boot_fs_offset
113
+ free_sectors * 512
114
+ end
115
+
116
+ def boot_fs_block_size
117
+ linux_partition_info = `/sbin/sfdisk -l #{file}`.scan(%r{#{file}.*Linux}).first
118
+ linux_partition_info.split[5].to_i
119
+ end
120
+
121
+ end
@@ -21,7 +21,10 @@ class SystemBuilder::IsoSquashfsImage
21
21
  end
22
22
 
23
23
  def compress_root_fs
24
- FileUtils::sudo "mksquashfs #{boot.root}/ build/filesystem.squashfs -noappend -e /boot"
24
+ unless File.exists?("build/filesystem.squashfs")
25
+ FileUtils::sudo "mksquashfs #{boot.root}/ build/filesystem.squashfs -noappend -e /boot"
26
+ FileUtils::sudo "chown #{ENV['USER']} build/filesystem.squashfs && chmod +r build/filesystem.squashfs"
27
+ end
25
28
  end
26
29
 
27
30
  def install_isolinux_files(options = {})
@@ -60,7 +60,7 @@ class SystemBuilder::Task < Rake::TaskLib
60
60
  required_packages << "rsync"
61
61
  required_packages << "dosfstools"
62
62
  required_packages << "syslinux"
63
- required_packages << "squashfs-tools"
63
+ required_packages << "squashfs-tools"
64
64
 
65
65
  FileUtils.sudo "apt-get install #{required_packages.join(' ')}"
66
66
  end
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module SystemBuilder
5
- VERSION = '0.0.12'
5
+ VERSION = '0.0.13'
6
6
 
7
7
  @@configurations = {}
8
8
 
@@ -24,6 +24,8 @@ require 'system_builder/iso_image'
24
24
  require 'system_builder/live_image'
25
25
  require 'system_builder/init_ram_fs_configurator'
26
26
  require 'system_builder/disk_squashfs_image'
27
+ require 'system_builder/disk_nfsroot_image'
27
28
  require 'system_builder/iso_squashfs_image'
28
29
  require 'system_builder/boot'
29
30
  require 'system_builder/configurator'
31
+ require 'system_builder/box'
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: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 12
10
- version: 0.0.12
9
+ - 13
10
+ version: 0.0.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alban Peignier
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-30 00:00:00 +02:00
18
+ date: 2010-09-11 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,12 +42,12 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 21
45
+ hash: 19
46
46
  segments:
47
47
  - 2
48
48
  - 6
49
- - 1
50
- version: 2.6.1
49
+ - 2
50
+ version: 2.6.2
51
51
  type: :development
52
52
  version_requirements: *id002
53
53
  description: FIX (describe your package)
@@ -79,10 +79,13 @@ files:
79
79
  - features/support/matchers.rb
80
80
  - lib/system_builder.rb
81
81
  - lib/system_builder/boot.rb
82
+ - lib/system_builder/box.rb
83
+ - lib/system_builder/box_tasks.rb
82
84
  - lib/system_builder/cli.rb
83
85
  - lib/system_builder/configurator.rb
84
86
  - lib/system_builder/core_ext.rb
85
87
  - lib/system_builder/disk_image.rb
88
+ - lib/system_builder/disk_nfsroot_image.rb
86
89
  - lib/system_builder/disk_squashfs_image.rb
87
90
  - lib/system_builder/init_ram_fs_configurator.rb
88
91
  - lib/system_builder/iso_image.rb