pi-bake 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,191 @@
1
+ mirror_style release
2
+ download_style apt
3
+ finddebs_style from-indices
4
+ variants - buildd fakechroot minbase scratchbox
5
+ keyring /usr/share/keyrings/debian-archive-keyring.gpg
6
+
7
+ if doing_variant fakechroot; then
8
+ test "$FAKECHROOT" = "true" || error 1 FAKECHROOTREQ "This variant requires fakechroot environment to be started"
9
+ fi
10
+
11
+ case $ARCH in
12
+ alpha|ia64) LIBC="libc6.1" ;;
13
+ kfreebsd-*) LIBC="libc0.1" ;;
14
+ hurd-*) LIBC="libc0.3" ;;
15
+ *) LIBC="libc6" ;;
16
+ esac
17
+
18
+ work_out_debs () {
19
+ required="$(get_debs Priority: required)"
20
+
21
+ if doing_variant - || doing_variant fakechroot; then
22
+ #required="$required $(get_debs Priority: important)"
23
+ # ^^ should be getting debconf here somehow maybe
24
+ base="$(get_debs Priority: important)"
25
+ elif doing_variant buildd || doing_variant scratchbox; then
26
+ base="apt build-essential"
27
+ elif doing_variant minbase; then
28
+ base="apt"
29
+ fi
30
+
31
+ if doing_variant fakechroot; then
32
+ # ldd.fake needs binutils
33
+ required="$required binutils"
34
+ fi
35
+ }
36
+
37
+ first_stage_install () {
38
+ extract $required
39
+
40
+ mkdir -p "$TARGET/var/lib/dpkg"
41
+ : >"$TARGET/var/lib/dpkg/status"
42
+ : >"$TARGET/var/lib/dpkg/available"
43
+
44
+ setup_etc
45
+ if [ ! -e "$TARGET/etc/fstab" ]; then
46
+ echo '# UNCONFIGURED FSTAB FOR BASE SYSTEM' > "$TARGET/etc/fstab"
47
+ chown 0:0 "$TARGET/etc/fstab"; chmod 644 "$TARGET/etc/fstab"
48
+ fi
49
+
50
+ x_feign_install () {
51
+ local pkg="$1"
52
+ local deb="$(debfor $pkg)"
53
+ local ver="$(extract_deb_field "$TARGET/$deb" Version)"
54
+
55
+ mkdir -p "$TARGET/var/lib/dpkg/info"
56
+
57
+ echo \
58
+ "Package: $pkg
59
+ Version: $ver
60
+ Maintainer: unknown
61
+ Status: install ok installed" >> "$TARGET/var/lib/dpkg/status"
62
+
63
+ touch "$TARGET/var/lib/dpkg/info/${pkg}.list"
64
+ }
65
+
66
+ x_feign_install dpkg
67
+ }
68
+
69
+ second_stage_install () {
70
+ setup_devices
71
+
72
+ x_core_install () {
73
+ smallyes '' | in_target dpkg --force-depends --install $(debfor "$@")
74
+ }
75
+
76
+ p () {
77
+ baseprog="$(($baseprog + ${1:-1}))"
78
+ }
79
+
80
+ if doing_variant fakechroot; then
81
+ setup_proc_fakechroot
82
+ elif doing_variant scratchbox; then
83
+ true
84
+ else
85
+ setup_proc
86
+ in_target /sbin/ldconfig
87
+ fi
88
+
89
+ DEBIAN_FRONTEND=noninteractive
90
+ DEBCONF_NONINTERACTIVE_SEEN=true
91
+ export DEBIAN_FRONTEND DEBCONF_NONINTERACTIVE_SEEN
92
+
93
+ baseprog=0
94
+ bases=7
95
+
96
+ p; progress $baseprog $bases INSTCORE "Installing core packages" #1
97
+ info INSTCORE "Installing core packages..."
98
+
99
+ p; progress $baseprog $bases INSTCORE "Installing core packages" #2
100
+ ln -sf mawk "$TARGET/usr/bin/awk"
101
+ x_core_install base-files base-passwd
102
+ p; progress $baseprog $bases INSTCORE "Installing core packages" #3
103
+ x_core_install dpkg
104
+
105
+ if [ ! -e "$TARGET/etc/localtime" ]; then
106
+ ln -sf /usr/share/zoneinfo/UTC "$TARGET/etc/localtime"
107
+ fi
108
+
109
+ if doing_variant fakechroot; then
110
+ install_fakechroot_tools
111
+ fi
112
+
113
+ p; progress $baseprog $bases INSTCORE "Installing core packages" #4
114
+ x_core_install $LIBC
115
+
116
+ p; progress $baseprog $bases INSTCORE "Installing core packages" #5
117
+ x_core_install perl-base
118
+
119
+ p; progress $baseprog $bases INSTCORE "Installing core packages" #6
120
+ rm "$TARGET/usr/bin/awk"
121
+ x_core_install mawk
122
+
123
+ p; progress $baseprog $bases INSTCORE "Installing core packages" #7
124
+ if doing_variant -; then
125
+ x_core_install debconf
126
+ fi
127
+
128
+ baseprog=0
129
+ bases=$(set -- $required; echo $#)
130
+
131
+ info UNPACKREQ "Unpacking required packages..."
132
+
133
+ exec 7>&1
134
+
135
+ smallyes '' |
136
+ (repeatn 5 in_target_failmsg UNPACK_REQ_FAIL_FIVE "Failure while unpacking required packages. This will be attempted up to five times." "" \
137
+ dpkg --status-fd 8 --force-depends --unpack $(debfor $required) 8>&1 1>&7 || echo EXITCODE $?) |
138
+ dpkg_progress $baseprog $bases UNPACKREQ "Unpacking required packages" UNPACKING
139
+
140
+ info CONFREQ "Configuring required packages..."
141
+
142
+ mv "$TARGET/sbin/start-stop-daemon" "$TARGET/sbin/start-stop-daemon.REAL"
143
+ echo \
144
+ "#!/bin/sh
145
+ echo
146
+ echo \"Warning: Fake start-stop-daemon called, doing nothing\"" > "$TARGET/sbin/start-stop-daemon"
147
+ chmod 755 "$TARGET/sbin/start-stop-daemon"
148
+
149
+ setup_dselect_method apt
150
+
151
+ smallyes '' |
152
+ (in_target_failmsg CONF_REQ_FAIL "Failure while configuring required packages." "" \
153
+ dpkg --status-fd 8 --configure --pending --force-configure-any --force-depends 8>&1 1>&7 || echo EXITCODE $?) |
154
+ dpkg_progress $baseprog $bases CONFREQ "Configuring required packages" CONFIGURING
155
+
156
+ baseprog=0
157
+ bases="$(set -- $base; echo $#)"
158
+
159
+ info UNPACKBASE "Unpacking the base system..."
160
+
161
+ setup_available $required $base
162
+ done_predeps=
163
+ while predep=$(get_next_predep); do
164
+ # We have to resolve dependencies of pre-dependencies manually because
165
+ # dpkg --predep-package doesn't handle this.
166
+ predep=$(without "$(without "$(resolve_deps $predep)" "$required")" "$done_predeps")
167
+ # XXX: progress is tricky due to how dpkg_progress works
168
+ # -- cjwatson 2009-07-29
169
+ p; smallyes '' |
170
+ in_target dpkg --force-overwrite --force-confold --skip-same-version --install $(debfor $predep)
171
+ base=$(without "$base" "$predep")
172
+ done_predeps="$done_predeps $predep"
173
+ done
174
+
175
+ smallyes '' |
176
+ (repeatn 5 in_target_failmsg INST_BASE_FAIL_FIVE "Failure while installing base packages. This will be re-attempted up to five times." "" \
177
+ dpkg --status-fd 8 --force-overwrite --force-confold --skip-same-version --unpack $(debfor $base) 8>&1 1>&7 || echo EXITCODE $?) |
178
+ dpkg_progress $baseprog $bases UNPACKBASE "Unpacking base system" UNPACKING
179
+
180
+ info CONFBASE "Configuring the base system..."
181
+
182
+ smallyes '' |
183
+ (repeatn 5 in_target_failmsg CONF_BASE_FAIL_FIVE "Failure while configuring base packages. This will be re-attempted up to five times." "" \
184
+ dpkg --status-fd 8 --force-confold --skip-same-version --configure -a 8>&1 1>&7 || echo EXITCODE $?) |
185
+ dpkg_progress $baseprog $bases CONFBASE "Configuring base system" CONFIGURING
186
+
187
+ mv "$TARGET/sbin/start-stop-daemon.REAL" "$TARGET/sbin/start-stop-daemon"
188
+
189
+ progress $bases $bases CONFBASE "Configuring base system"
190
+ info BASESUCCESS "Base system installed successfully."
191
+ }
data/lib/fs/geom.rb ADDED
@@ -0,0 +1,232 @@
1
+ ### Copyright (c) 2012 David Love <david@homeunix.org.uk>
2
+ ###
3
+ ### Permission to use, copy, modify, and/or distribute this software for
4
+ ### any purpose with or without fee is hereby granted, provided that the
5
+ ### above copyright notice and this permission notice appear in all copies.
6
+ ###
7
+ ### THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ ### WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ ### MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ### ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ ### WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ### ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ ### OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+ ###
15
+
16
+ ### @author David Love
17
+ ###
18
+ ### FreeBSD GEOM Interface. Packages the FreeBSD GEOM interfaces and utilities into
19
+ ### a single class.
20
+ ###
21
+
22
+ # Sub-process handling library
23
+ require "open4"
24
+
25
+ class Geom
26
+
27
+ # Attach a disk image
28
+ def self.attach_image(image_name)
29
+
30
+ # Sanity check the FreeBSD environment, making sure the
31
+ # geom_gate kernel module is loaded (or can be loaded) before
32
+ # we do anything else
33
+
34
+ unless system("kldstat -q -m ggate") then
35
+
36
+ # The kernel module isn't loaded, so lets try to
37
+ # load it
38
+ unless system("sudo kldload geom_gate") then
39
+ # OK now we are really stuck. The correct module
40
+ # isn't available, and we can't load it either.
41
+ # Not much else we can do now.
42
+ return nil
43
+ end
44
+
45
+ # Did that work?
46
+ unless system("kldstat -q -m ggate") then
47
+ # No, so tell the caller
48
+ return nil
49
+ end
50
+ end
51
+
52
+ # Attach the image
53
+ #
54
+ # NOTE: There appears to be a bug in the output of ggatel, which
55
+ # fails to report the newly created device name. Instead we have
56
+ # to reconstruct the new name, and report it to the caller.
57
+
58
+ current_devices = `ggatel list`.split
59
+ `sudo ggatel create #{image_name}`
60
+ updated_devices = `ggatel list`.split
61
+
62
+ device_name = updated_devices - current_devices
63
+
64
+ return device_name[0].to_s
65
+ end
66
+
67
+ # Detach a disk image
68
+ def self.detach_image(device_name)
69
+ device_number = device_name[-1]
70
+ system("sudo ggatel destroy -u #{device_number}")
71
+ end
72
+
73
+ # Create a blank disk image, backed by the named file
74
+ def self.make_image(image_name, image_size)
75
+ # Work out how many 512 bit blocks we need
76
+ blocks = image_size / 512
77
+
78
+ # Create a spare image of the required size
79
+ puts "Image size: #{image_size} bytes"
80
+ `dd of=#{image_name} bs=512 count=0 seek=#{blocks}`
81
+ end
82
+
83
+ # Mount the image slices in known locations
84
+ def self.mount_image(device_name)
85
+
86
+ # Sanity check the FreeBSD environment, making sure the
87
+ # ext2fs kernel module is loaded (or can be loaded) before
88
+ # we do anything else
89
+
90
+ unless system("kldstat -q -m ext2fs") then
91
+
92
+ # The kernel module isn't loaded, so lets try to
93
+ # load it
94
+ unless system("sudo kldload ext2fs") then
95
+ # OK now we are really stuck. The correct module
96
+ # isn't available, and we can't load it either.
97
+ # Not much else we can do now.
98
+ return false
99
+ end
100
+
101
+ # Did that work?
102
+ unless system("kldstat -q -m ext2fs") then
103
+ # No, so tell the caller
104
+ return false
105
+ end
106
+ end
107
+
108
+ # Mount the boot slice
109
+ unless File.exists?("/mnt/pi-boot") then
110
+ # Use sudo to assume root powers, instead of the
111
+ # native ruby method
112
+ `sudo mkdir -p /mnt/pi-boot`
113
+ end
114
+
115
+ unless system("sudo mount_msdosfs /dev/#{device_name}s1 /mnt/pi-boot") then
116
+ return false
117
+ end
118
+
119
+ # Mount the boot slice
120
+ unless File.exists?("/mnt/pi-system1") then
121
+ # Use sudo to assume root powers, instead of the
122
+ # native ruby method
123
+ `sudo mkdir -p /mnt/pi-system1`
124
+ end
125
+
126
+ unless system("sudo mount -t ext2fs /dev/#{device_name}s2 /mnt/pi-system1")
127
+ return false
128
+ end
129
+
130
+ # Mount the boot slice
131
+ unless File.exists?("/mnt/pi-system2") then
132
+ # Use sudo to assume root powers, instead of the
133
+ # native ruby method
134
+ `sudo mkdir -p /mnt/pi-system2`
135
+ end
136
+
137
+ unless system("sudo mount -t ext2fs /dev/#{device_name}s3 /mnt/pi-system2")
138
+ return false
139
+ end
140
+
141
+ # Mount the boot slice
142
+ unless File.exists?("/mnt/pi-data") then
143
+ # Use sudo to assume root powers, instead of the
144
+ # native ruby method
145
+ `sudo mkdir -p /mnt/pi-data`
146
+ end
147
+
148
+ unless system("sudo mount -t ext2fs /dev/#{device_name}s4 /mnt/pi-data")
149
+ return false
150
+ end
151
+
152
+ return true
153
+
154
+ end
155
+
156
+ # Set-up the basic disk partition table, and file systems
157
+ def self.prepare_image(device_name, image_size)
158
+
159
+ ##
160
+ ## Partition the disk image
161
+ ##
162
+
163
+ # Calculate the size of a block that is 1% of the total
164
+ # disk space
165
+ block_size = image_size.to_f / 100.0
166
+
167
+ # Calculate the number of cylinders based on 512 sector
168
+ # size, 255 heads and 63 sectors per track
169
+ cylinders = (image_size.to_f / 255.0 / 63.0 / 512.0).floor
170
+
171
+ # Tell the user what we have done
172
+ puts "Heads: 255"
173
+ puts "Sectors/Track: 63"
174
+ puts "Cylinder: #{cylinders}"
175
+ puts
176
+ puts "Block size: #{(block_size / 1024.0 / 1024.0).floor}MB"
177
+ puts
178
+ puts "Layout"
179
+ puts "------------------------------------------"
180
+ puts "P1: #{((block_size * 10) / 1024.0 / 1024.0).floor}MB"
181
+ puts "P2: #{((block_size * 25) / 1024.0 / 1024.0).floor}MB"
182
+ puts "P3: #{((block_size * 25) / 1024.0 / 1024.0).floor}MB"
183
+ puts "P4: #{((block_size * 40) / 1024.0 / 1024.0).floor}MB"
184
+ puts
185
+
186
+ config_file = String.new
187
+ config_file << "g s63 h255 c" + cylinders.floor.to_s + "\n"
188
+ config_file << "p \t 1 \t 0x0C \t 63 \t #{((block_size * 10) / 1024.0 / 1024.0).floor}M\n"
189
+ config_file << "p \t 2 \t 0x83 \t * \t #{((block_size * 25) / 1024.0 / 1024.0).floor}M\n"
190
+ config_file << "p \t 3 \t 0x83 \t * \t #{((block_size * 25) / 1024.0 / 1024.0).floor}M\n"
191
+ config_file << "p \t 4 \t 0x83 \t * \t *\n"
192
+ config_file << "a 1\n"
193
+
194
+ cmd = "sudo fdisk -f - -i " + device_name
195
+ status = open4.spawn(cmd, :stdin => config_file)
196
+
197
+ ##
198
+ ## Format the partitions
199
+ ##
200
+
201
+ # Create a FAT-32 file system in the boot partition
202
+ puts "Formatting #{device_name}s1 as FAT-32..."
203
+ `sudo newfs_msdos -F 32 -L PI-BOOT /dev/#{device_name}s1`
204
+
205
+ # Everything else is EXT2
206
+ puts "Formatting #{device_name}s2 as ext2..."
207
+ `sudo mkfs.ext2 -I 128 /dev/#{device_name}s2`
208
+ puts "Formatting #{device_name}s3 as ext2..."
209
+ `sudo mkfs.ext2 -I 128 /dev/#{device_name}s3`
210
+ puts "Formatting #{device_name}s4 as ext2..."
211
+ `sudo mkfs.ext2 -I 128 /dev/#{device_name}s4`
212
+
213
+ end
214
+
215
+ def self.umount_image_dirs
216
+ unless system("sudo umount /mnt/pi-boot") then
217
+ return false
218
+ end
219
+ unless system("sudo umount /mnt/pi-system1") then
220
+ return false
221
+ end
222
+ unless system("sudo umount /mnt/pi-system2") then
223
+ return false
224
+ end
225
+ unless system("sudo umount /mnt/pi-data") then
226
+ return false
227
+ end
228
+
229
+ return true
230
+ end
231
+
232
+ end
data/lib/pi-bake.rb ADDED
File without changes
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pi-bake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Love
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: d.love@shu.ac.uk
16
+ executables:
17
+ - bake
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.markdown
21
+ files:
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - README.markdown
25
+ - bin/bake
26
+ - lib/actions/update.rb
27
+ - lib/actions/image.rb
28
+ - lib/actions/attach.rb
29
+ - lib/actions/detach.rb
30
+ - lib/actions/info.rb
31
+ - lib/actions/unmount.rb
32
+ - lib/actions/mount.rb
33
+ - lib/actions/all.rb
34
+ - lib/fs/geom.rb
35
+ - lib/deb/scripts/wheezy
36
+ - lib/deb/functions
37
+ - lib/deb/debootstrap
38
+ - lib/pi-bake.rb
39
+ homepage: http://yoursite.example.com
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --main
44
+ - README.markdown
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ segments:
54
+ - 0
55
+ hash: -468393075
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.24
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: FreeBSD Image Builder for Raspbery Pi
68
+ test_files: []