pi-bake 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +39 -0
- data/Gemfile.lock +36 -0
- data/README.markdown +26 -0
- data/bin/bake +64 -0
- data/lib/actions/all.rb +31 -0
- data/lib/actions/attach.rb +42 -0
- data/lib/actions/detach.rb +36 -0
- data/lib/actions/image.rb +87 -0
- data/lib/actions/info.rb +61 -0
- data/lib/actions/mount.rb +58 -0
- data/lib/actions/unmount.rb +38 -0
- data/lib/actions/update.rb +156 -0
- data/lib/deb/debootstrap +682 -0
- data/lib/deb/functions +1570 -0
- data/lib/deb/scripts/wheezy +191 -0
- data/lib/fs/geom.rb +232 -0
- data/lib/pi-bake.rb +0 -0
- metadata +68 -0
data/Gemfile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
###
|
2
|
+
### Sources
|
3
|
+
###
|
4
|
+
|
5
|
+
# Main Ruby Gems site
|
6
|
+
source "http://rubygems.org"
|
7
|
+
|
8
|
+
###
|
9
|
+
### Core Gems. These are required in _all_ environments (additional environments
|
10
|
+
### follow).
|
11
|
+
###
|
12
|
+
|
13
|
+
# Core Application Frameworks
|
14
|
+
gem "facets", "~> 2.9.3"
|
15
|
+
gem "thor", "~> 0.15.0"
|
16
|
+
gem "open4", "~> 1.3.0"
|
17
|
+
|
18
|
+
# Core parsing libraries
|
19
|
+
gem "psych", "~> 1.3.2"
|
20
|
+
gem "nokogiri"
|
21
|
+
|
22
|
+
# Core archive library
|
23
|
+
gem "rubyzip", "~> 0.9.8"
|
24
|
+
|
25
|
+
###
|
26
|
+
### Development Gems. All _additional_ gems required by development (as opposed to
|
27
|
+
### production environments). If it is required at run-time, it
|
28
|
+
### belongs above.
|
29
|
+
group :development do
|
30
|
+
|
31
|
+
# Gem management tools
|
32
|
+
gem "bundler", "~> 1.1.0"
|
33
|
+
gem "gemcutter"
|
34
|
+
gem "gem-this"
|
35
|
+
|
36
|
+
# Documentation Tools
|
37
|
+
gem "vclog"
|
38
|
+
|
39
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ansi (1.4.3)
|
5
|
+
facets (2.9.3)
|
6
|
+
gem-this (0.3.7)
|
7
|
+
gemcutter (0.7.1)
|
8
|
+
json (1.7.3)
|
9
|
+
nokogiri (1.5.5)
|
10
|
+
open4 (1.3.0)
|
11
|
+
psych (1.3.3)
|
12
|
+
rdoc (3.12)
|
13
|
+
json (~> 1.4)
|
14
|
+
rubyzip (0.9.9)
|
15
|
+
thor (0.15.4)
|
16
|
+
vclog (1.9.2)
|
17
|
+
ansi (>= 1.2)
|
18
|
+
facets (>= 2.4)
|
19
|
+
rdoc
|
20
|
+
xml-simple
|
21
|
+
xml-simple (1.1.1)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
bundler (~> 1.1.0)
|
28
|
+
facets (~> 2.9.3)
|
29
|
+
gem-this
|
30
|
+
gemcutter
|
31
|
+
nokogiri
|
32
|
+
open4 (~> 1.3.0)
|
33
|
+
psych (~> 1.3.2)
|
34
|
+
rubyzip (~> 0.9.8)
|
35
|
+
thor (~> 0.15.0)
|
36
|
+
vclog
|
data/README.markdown
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# FreeBSD Raspbery Pi Image Builder #
|
2
|
+
|
3
|
+
This builder creates pre-prepared SD cards for the Raspbery PI, based on the official Debian build provided by the Raspbery PI foundation. However it also includes several customisations, aimed at supporting the use of the Raspbery PI within the Networking Labs, at the Department of Computing at Sheffield Hallam University.
|
4
|
+
|
5
|
+
**Note:** This means this build is *not* suitable as a general-use/media machine. We don't have any graphical interfaces or other applications you will find in other builds. If you are not interested in something that might fall under the title "embedded router", please try [something else][http://www.raspberrypi.org/downloads].
|
6
|
+
|
7
|
+
# Contributing to pi-bake #
|
8
|
+
|
9
|
+
* Check out the latest master to make sure the feature hasn't been
|
10
|
+
implemented or the bug hasn't been fixed yet
|
11
|
+
* Check out the issue tracker to make sure someone already hasn't
|
12
|
+
requested it and/or contributed it
|
13
|
+
* Fork the project
|
14
|
+
* Start a feature/bugfix branch
|
15
|
+
* Commit and push until you are happy with your contribution
|
16
|
+
* Make sure to add tests for it. This is important so I don't break it
|
17
|
+
in a future version unintentionally.
|
18
|
+
* Please try not to mess with the Rakefile, version, or history. If you
|
19
|
+
want to have your own version, or is otherwise necessary, that is
|
20
|
+
fine, but please isolate to its own commit so I can cherry-pick around
|
21
|
+
it.
|
22
|
+
|
23
|
+
# Copyright #
|
24
|
+
|
25
|
+
Copyright (c) 2012 David Love. See LICENSE.txt for
|
26
|
+
further details.
|
data/bin/bake
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
### Copyright (c) 2012 David Love <david@homeunix.org.uk>
|
4
|
+
###
|
5
|
+
### Permission to use, copy, modify, and/or distribute this software for
|
6
|
+
### any purpose with or without fee is hereby granted, provided that the
|
7
|
+
### above copyright notice and this permission notice appear in all copies.
|
8
|
+
###
|
9
|
+
### THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
10
|
+
### WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
11
|
+
### MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
12
|
+
### ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
13
|
+
### WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
14
|
+
### ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
15
|
+
### OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
16
|
+
###
|
17
|
+
|
18
|
+
### @author David Love
|
19
|
+
###
|
20
|
+
### Bake Command. Creates disk images and provides the bootstrapping
|
21
|
+
### environment needed for setting up a Raspberry Pi model B as an
|
22
|
+
### embedded router.
|
23
|
+
###
|
24
|
+
|
25
|
+
# Add lib to load path
|
26
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
|
27
|
+
|
28
|
+
# Make sure we can find the libraries installed by Ruby Gems
|
29
|
+
require "rubygems"
|
30
|
+
|
31
|
+
# Add core and standard library requires
|
32
|
+
require 'digest'
|
33
|
+
require 'find'
|
34
|
+
require 'fileutils'
|
35
|
+
require 'tempfile'
|
36
|
+
|
37
|
+
# Add the command line parsing framework
|
38
|
+
require "thor"
|
39
|
+
|
40
|
+
# Add the YAML processing libraries
|
41
|
+
#require 'psych'
|
42
|
+
require 'yaml'
|
43
|
+
|
44
|
+
# Add utilities from the Facets library
|
45
|
+
#require 'facets'
|
46
|
+
|
47
|
+
# Add the library needed to handle .zip files
|
48
|
+
require 'zip/zip'
|
49
|
+
|
50
|
+
##
|
51
|
+
## Core Command Line Application
|
52
|
+
##
|
53
|
+
|
54
|
+
# Load in the enabled sub-commands
|
55
|
+
require "actions/all"
|
56
|
+
|
57
|
+
class Bake < Thor
|
58
|
+
|
59
|
+
include Thor::Actions
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
# Run the application
|
64
|
+
Bake.start
|
data/lib/actions/all.rb
ADDED
@@ -0,0 +1,31 @@
|
|
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
|
+
### List of all defined command. Holding area for all commands that should be
|
19
|
+
### included by the main `bake` binary. This also enables you to
|
20
|
+
### temporarily enable/disable commands in the main application.
|
21
|
+
###
|
22
|
+
|
23
|
+
# List of Enabled Commands
|
24
|
+
require "actions/attach"
|
25
|
+
require "actions/detach"
|
26
|
+
require "actions/image"
|
27
|
+
require "actions/info"
|
28
|
+
require "actions/mount"
|
29
|
+
require "actions/unmount"
|
30
|
+
require "actions/update"
|
31
|
+
|
@@ -0,0 +1,42 @@
|
|
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
|
+
### Attach an image to the device tree. Creates a device node for an
|
19
|
+
### existing image, allowing the image to be accessed using the standard
|
20
|
+
### file and disk manipulation commands.
|
21
|
+
###
|
22
|
+
|
23
|
+
# File handling classes
|
24
|
+
require "fs/geom"
|
25
|
+
|
26
|
+
class Bake < Thor
|
27
|
+
|
28
|
+
desc "attach [IMAGE NAME]", "Create a device node to access the named image"
|
29
|
+
|
30
|
+
def attach(image_name = "pi.img")
|
31
|
+
say("Attaching image #{image_name}")
|
32
|
+
|
33
|
+
device_name = Geom.attach_image(image_name)
|
34
|
+
|
35
|
+
unless device_name.nil? then
|
36
|
+
say("...Image attached to #{device_name}")
|
37
|
+
else
|
38
|
+
say("ERROR: Could not attach #{image_name}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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
|
+
### Attach an image to the device tree. Creates a device node for an
|
19
|
+
### existing image, allowing the image to be accessed using the standard
|
20
|
+
### file and disk manipulation commands.
|
21
|
+
###
|
22
|
+
|
23
|
+
# File handling classes
|
24
|
+
require "fs/geom"
|
25
|
+
|
26
|
+
class Bake < Thor
|
27
|
+
|
28
|
+
desc "detach [DEVICE]", "Detach the image linked to the named device"
|
29
|
+
|
30
|
+
def detach(device_name)
|
31
|
+
say("Detaching device #{device_name}")
|
32
|
+
|
33
|
+
Geom.detach_image(device_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,87 @@
|
|
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
|
+
### Image command. Creates the core disk image used as the master
|
19
|
+
### for the SD Card, booted by the Pi board.
|
20
|
+
###
|
21
|
+
|
22
|
+
# File handling classes
|
23
|
+
require "fs/geom"
|
24
|
+
|
25
|
+
class Bake < Thor
|
26
|
+
|
27
|
+
desc "image [IMAGE NAME] [IMAGE SIZE]", "Prepare the SD Card image"
|
28
|
+
|
29
|
+
def image(image_name = "pi", image_size = 4)
|
30
|
+
# Create the full image name
|
31
|
+
full_image_name = image_name + ".img"
|
32
|
+
say("Creating the image file #{full_image_name}", :blue)
|
33
|
+
|
34
|
+
# Work out the image size in bytes
|
35
|
+
image_size_bytes = image_size * 1024 * 1024 * 1024
|
36
|
+
|
37
|
+
## Check for the existence of the named image in the current
|
38
|
+
## directory. If the image doesn't exist (or the user confirms
|
39
|
+
## an overwrite of the existing image), the image file is created
|
40
|
+
|
41
|
+
if File.exists?(full_image_name) then
|
42
|
+
if file_collision(full_image_name) then
|
43
|
+
Geom.make_image(full_image_name, image_size_bytes)
|
44
|
+
else
|
45
|
+
say("Cannot create the requested image", :red)
|
46
|
+
exit(1)
|
47
|
+
end
|
48
|
+
else
|
49
|
+
Geom.make_image(full_image_name, image_size_bytes)
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
## Now we need to partition the image, to create the basic disk
|
54
|
+
## structures
|
55
|
+
##
|
56
|
+
|
57
|
+
say("Creating a device node for the image file...", :blue)
|
58
|
+
|
59
|
+
# Attach the image to the kernel device tree
|
60
|
+
device_name = Geom.attach_image(full_image_name)
|
61
|
+
if device_name.nil? then
|
62
|
+
say("Cannot create the device node needed to access the requested image", :red)
|
63
|
+
exit(1)
|
64
|
+
end
|
65
|
+
|
66
|
+
say("... Image file attached to #{device_name}", :blue)
|
67
|
+
|
68
|
+
# Partition the disk image, creating the boot partition
|
69
|
+
# and two system partition and a data partition. The basic
|
70
|
+
# disk structures should like like the following
|
71
|
+
#
|
72
|
+
# partition 1: FAT32, 10% of the total disk
|
73
|
+
# partition 2: EXT2, 25% of the total disk
|
74
|
+
# partition 3: EXT2, 25% of the total disk
|
75
|
+
# partition 4: EXT2, 40% of the total disk
|
76
|
+
#
|
77
|
+
say("Partitioning the image file", :blue)
|
78
|
+
|
79
|
+
Geom.prepare_image(device_name, image_size_bytes)
|
80
|
+
|
81
|
+
# Finally detach the image
|
82
|
+
say("Detaching the image file attached to #{device_name}", :blue)
|
83
|
+
|
84
|
+
Geom.detach_image(device_name)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/lib/actions/info.rb
ADDED
@@ -0,0 +1,61 @@
|
|
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
|
+
### Display image command. Shows information about the image file, obtained
|
19
|
+
### from the file system wherever possible. This command is principally
|
20
|
+
### used to debug problems during development.
|
21
|
+
###
|
22
|
+
|
23
|
+
# File handling classes
|
24
|
+
require "fs/geom"
|
25
|
+
|
26
|
+
class Bake < Thor
|
27
|
+
|
28
|
+
desc "info [IMAGE NAME]", "Display information about the image file"
|
29
|
+
|
30
|
+
def info(image_name = "pi")
|
31
|
+
full_image_name = image_name + ".img"
|
32
|
+
|
33
|
+
# Attach the image to the device tree so that we can have a
|
34
|
+
# look at it
|
35
|
+
|
36
|
+
say("Creating a device node for the image file #{full_image_name}...", :blue)
|
37
|
+
|
38
|
+
# Attach the image to the kernel device tree
|
39
|
+
device_name = Geom.attach_image(full_image_name)
|
40
|
+
if device_name.nil? then
|
41
|
+
say("Cannot create the device node needed to access the requested image", :red)
|
42
|
+
exit(1)
|
43
|
+
end
|
44
|
+
|
45
|
+
say("... Image file attached to #{device_name}", :blue)
|
46
|
+
|
47
|
+
# Display the structures reported by FDisk
|
48
|
+
|
49
|
+
puts
|
50
|
+
puts " Summary of the image partition layout"
|
51
|
+
puts "--------------------------------------------------------------------"
|
52
|
+
puts `sudo fdisk -s #{device_name}`
|
53
|
+
puts
|
54
|
+
|
55
|
+
# Finally detach the image
|
56
|
+
say("Detaching the image file attached to #{device_name}", :blue)
|
57
|
+
|
58
|
+
Geom.detach_image(device_name)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,58 @@
|
|
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
|
+
### Attach an image to the device tree. Creates a device node for an
|
19
|
+
### existing image, allowing the image to be accessed using the standard
|
20
|
+
### file and disk manipulation commands.
|
21
|
+
###
|
22
|
+
|
23
|
+
# File handling classes
|
24
|
+
require "fs/geom"
|
25
|
+
|
26
|
+
class Bake < Thor
|
27
|
+
|
28
|
+
desc "mount [IMAGE NAME]", "Make an image accessible through the /mnt directories"
|
29
|
+
|
30
|
+
def mount(image_name = "pi.img")
|
31
|
+
say("Attaching image #{image_name}", :blue)
|
32
|
+
|
33
|
+
device_name = Geom.attach_image(image_name)
|
34
|
+
|
35
|
+
unless device_name.nil? then
|
36
|
+
say("...Image attached to #{device_name}", :blue)
|
37
|
+
else
|
38
|
+
say("ERROR: Could not attach #{image_name}", :red)
|
39
|
+
end
|
40
|
+
|
41
|
+
say("Mounting image #{image_name}...", :blue)
|
42
|
+
|
43
|
+
if Geom.mount_image(device_name) then
|
44
|
+
say("...Image mounted under /mnt", :blue)
|
45
|
+
else
|
46
|
+
say("ERROR: Could not mount #{image_name}", :blue)
|
47
|
+
|
48
|
+
# try to unmount and detach the failed image
|
49
|
+
unless Geom.umount_image_dirs then
|
50
|
+
say("ERROR: Unable to unmount all the image directories", :red)
|
51
|
+
end
|
52
|
+
unless Geom.detach_image(device_name) then
|
53
|
+
say("ERROR: Failed to detach device #{device_name}", :red)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|