ec2_amitools 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +54 -0
  3. data/bin/console +14 -0
  4. data/bin/ec2-ami-tools-version +6 -0
  5. data/bin/ec2-bundle-image +6 -0
  6. data/bin/ec2-bundle-vol +6 -0
  7. data/bin/ec2-delete-bundle +6 -0
  8. data/bin/ec2-download-bundle +6 -0
  9. data/bin/ec2-migrate-bundle +6 -0
  10. data/bin/ec2-migrate-manifest +6 -0
  11. data/bin/ec2-unbundle +6 -0
  12. data/bin/ec2-upload-bundle +6 -0
  13. data/bin/setup +8 -0
  14. data/etc/ec2/amitools/cert-ec2-cn-north-1.pem +28 -0
  15. data/etc/ec2/amitools/cert-ec2-gov.pem +17 -0
  16. data/etc/ec2/amitools/cert-ec2.pem +23 -0
  17. data/etc/ec2/amitools/mappings.csv +9 -0
  18. data/lib/ec2/amitools/bundle.rb +251 -0
  19. data/lib/ec2/amitools/bundle_base.rb +58 -0
  20. data/lib/ec2/amitools/bundleimage.rb +94 -0
  21. data/lib/ec2/amitools/bundleimageparameters.rb +42 -0
  22. data/lib/ec2/amitools/bundlemachineparameters.rb +60 -0
  23. data/lib/ec2/amitools/bundleparameters.rb +120 -0
  24. data/lib/ec2/amitools/bundlevol.rb +240 -0
  25. data/lib/ec2/amitools/bundlevolparameters.rb +164 -0
  26. data/lib/ec2/amitools/crypto.rb +379 -0
  27. data/lib/ec2/amitools/decryptmanifest.rb +20 -0
  28. data/lib/ec2/amitools/defaults.rb +12 -0
  29. data/lib/ec2/amitools/deletebundle.rb +212 -0
  30. data/lib/ec2/amitools/deletebundleparameters.rb +78 -0
  31. data/lib/ec2/amitools/downloadbundle.rb +161 -0
  32. data/lib/ec2/amitools/downloadbundleparameters.rb +84 -0
  33. data/lib/ec2/amitools/exception.rb +86 -0
  34. data/lib/ec2/amitools/fileutil.rb +219 -0
  35. data/lib/ec2/amitools/format.rb +127 -0
  36. data/lib/ec2/amitools/instance-data.rb +97 -0
  37. data/lib/ec2/amitools/manifest_wrapper.rb +132 -0
  38. data/lib/ec2/amitools/manifestv20070829.rb +361 -0
  39. data/lib/ec2/amitools/manifestv20071010.rb +403 -0
  40. data/lib/ec2/amitools/manifestv3.rb +331 -0
  41. data/lib/ec2/amitools/mapids.rb +148 -0
  42. data/lib/ec2/amitools/migratebundle.rb +222 -0
  43. data/lib/ec2/amitools/migratebundleparameters.rb +173 -0
  44. data/lib/ec2/amitools/migratemanifest.rb +225 -0
  45. data/lib/ec2/amitools/migratemanifestparameters.rb +118 -0
  46. data/lib/ec2/amitools/minimalec2.rb +116 -0
  47. data/lib/ec2/amitools/parameter_exceptions.rb +34 -0
  48. data/lib/ec2/amitools/parameters_base.rb +168 -0
  49. data/lib/ec2/amitools/region.rb +93 -0
  50. data/lib/ec2/amitools/s3toolparameters.rb +183 -0
  51. data/lib/ec2/amitools/showversion.rb +12 -0
  52. data/lib/ec2/amitools/syschecks.rb +27 -0
  53. data/lib/ec2/amitools/tool_base.rb +224 -0
  54. data/lib/ec2/amitools/unbundle.rb +107 -0
  55. data/lib/ec2/amitools/unbundleparameters.rb +65 -0
  56. data/lib/ec2/amitools/uploadbundle.rb +361 -0
  57. data/lib/ec2/amitools/uploadbundleparameters.rb +108 -0
  58. data/lib/ec2/amitools/util.rb +532 -0
  59. data/lib/ec2/amitools/version.rb +33 -0
  60. data/lib/ec2/amitools/xmlbuilder.rb +237 -0
  61. data/lib/ec2/amitools/xmlutil.rb +55 -0
  62. data/lib/ec2/common/constants.rb +16 -0
  63. data/lib/ec2/common/curl.rb +110 -0
  64. data/lib/ec2/common/headers.rb +95 -0
  65. data/lib/ec2/common/headersv4.rb +173 -0
  66. data/lib/ec2/common/http.rb +333 -0
  67. data/lib/ec2/common/s3support.rb +231 -0
  68. data/lib/ec2/common/signature.rb +68 -0
  69. data/lib/ec2/oem/LICENSE.txt +58 -0
  70. data/lib/ec2/oem/open4.rb +399 -0
  71. data/lib/ec2/platform/base/architecture.rb +26 -0
  72. data/lib/ec2/platform/base/constants.rb +54 -0
  73. data/lib/ec2/platform/base/pipeline.rb +181 -0
  74. data/lib/ec2/platform/base.rb +57 -0
  75. data/lib/ec2/platform/current.rb +55 -0
  76. data/lib/ec2/platform/linux/architecture.rb +35 -0
  77. data/lib/ec2/platform/linux/constants.rb +23 -0
  78. data/lib/ec2/platform/linux/fstab.rb +99 -0
  79. data/lib/ec2/platform/linux/identity.rb +16 -0
  80. data/lib/ec2/platform/linux/image.rb +811 -0
  81. data/lib/ec2/platform/linux/mtab.rb +74 -0
  82. data/lib/ec2/platform/linux/pipeline.rb +40 -0
  83. data/lib/ec2/platform/linux/rsync.rb +114 -0
  84. data/lib/ec2/platform/linux/tar.rb +124 -0
  85. data/lib/ec2/platform/linux/uname.rb +50 -0
  86. data/lib/ec2/platform/linux.rb +83 -0
  87. data/lib/ec2/platform/solaris/architecture.rb +28 -0
  88. data/lib/ec2/platform/solaris/constants.rb +30 -0
  89. data/lib/ec2/platform/solaris/fstab.rb +43 -0
  90. data/lib/ec2/platform/solaris/identity.rb +16 -0
  91. data/lib/ec2/platform/solaris/image.rb +327 -0
  92. data/lib/ec2/platform/solaris/mtab.rb +29 -0
  93. data/lib/ec2/platform/solaris/pipeline.rb +40 -0
  94. data/lib/ec2/platform/solaris/rsync.rb +24 -0
  95. data/lib/ec2/platform/solaris/tar.rb +36 -0
  96. data/lib/ec2/platform/solaris/uname.rb +21 -0
  97. data/lib/ec2/platform/solaris.rb +38 -0
  98. data/lib/ec2/platform.rb +69 -0
  99. data/lib/ec2/version.rb +8 -0
  100. data/lib/ec2_amitools +1 -0
  101. data/lib/ec2_amitools.rb +7 -0
  102. metadata +184 -0
@@ -0,0 +1,26 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ module EC2
12
+ module Platform
13
+ module Base
14
+ class Architecture
15
+ I386 = 'i386'
16
+ X86_64 = 'x86_64'
17
+ UNKNOWN = 'unknown'
18
+ SUPPORTED = [I386, X86_64]
19
+
20
+ def self.supported? arch
21
+ SUPPORTED.include? arch
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,54 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ #--------------------------------------------------------------------------
12
+ # Definition of constant values used by the AMI tools
13
+ #------------------------------------------------------------------------
14
+ module EC2
15
+ module Platform
16
+ module Base
17
+ module Constants
18
+ module Bundling
19
+ EC2_HOME = ENV["EC2_AMITOOL_HOME"] || ENV["EC2_HOME"]
20
+ EC2_X509_CERT = File.join(EC2_HOME.to_s, '/etc/ec2/amitools/cert-ec2.pem')
21
+ EC2_X509_GOV_CERT = File.join(EC2_HOME.to_s, '/etc/ec2/amitools/cert-ec2-gov.pem')
22
+ EC2_X509_CN_NORTH_1_CERT = File.join(EC2_HOME.to_s, '/etc/ec2/amitools/cert-ec2-cn-north-1.pem')
23
+ EC2_MAPPING_FILE = File.join(EC2_HOME.to_s, '/etc/ec2/amitools/mappings.csv')
24
+ EC2_MAPPING_URL = 'https://ec2-downloads.s3.amazonaws.com/mappings.csv'
25
+ DESTINATION = '/tmp'
26
+ end
27
+ module Utility
28
+ OPENSSL = 'openssl'
29
+ RSYNC = 'rsync'
30
+ TAR = 'tar'
31
+ TEE = 'tee'
32
+ GZIP = 'gzip'
33
+ end
34
+ module Security
35
+ FILE_FILTER = [
36
+ '*/#*#',
37
+ '*/.#*',
38
+ '*.sw',
39
+ '*.swo',
40
+ '*.swp',
41
+ '*~',
42
+ '*.pem',
43
+ '*.priv',
44
+ '*id_rsa*',
45
+ '*id_dsa*',
46
+ '*.gpg',
47
+ '*.jks',
48
+ '*/.ssh/authorized_keys',
49
+ '*/.bash_history']
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,181 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ #------------------------------------------------------------------------------
12
+ require 'English'
13
+ require 'fileutils'
14
+ require 'tempfile'
15
+
16
+ #------------------------------------------------------------------------------
17
+ module EC2
18
+ #----------------------------------------------------------------------------
19
+ module Platform
20
+ #--------------------------------------------------------------------------
21
+ module Base
22
+ #------------------------------------------------------------------------
23
+ class Pipeline
24
+ #----------------------------------------------------------------------
25
+ class ExecutionError < RuntimeError
26
+ def initialize(pipeline=nil, stage=nil, message=nil)
27
+ word = 'Execution failed'
28
+ word << ", pipeline: #{pipeline}" unless pipeline.nil?
29
+ word << ", stage: #{stage}" unless stage.nil?
30
+ word << ', mesage:' + message.to_s unless message.nil?
31
+ word << '.'
32
+ super word
33
+ end
34
+ end
35
+ #----------------------------------------------------------------------
36
+ class Stage
37
+ class Result
38
+ attr :name
39
+ attr :rc
40
+ attr :successful
41
+ def initialize(name, rc, successful)
42
+ @name = name
43
+ @rc = rc
44
+ @successful = successful
45
+ end
46
+ def successful?
47
+ @successful
48
+ end
49
+ def to_s
50
+ "Result(name=#{@name}, rc=#{@rc}, successful=#{@successful})"
51
+ end
52
+ end
53
+
54
+ attr :name
55
+ attr :command
56
+ attr :success
57
+
58
+ def initialize(name, command, success=0)
59
+ @name = name
60
+ @command = command
61
+ @success = success
62
+ end
63
+ def to_s()
64
+ "Stage(name=#{@name}, command=#{@command}, success=#{@success})"
65
+ end
66
+ end
67
+ attr_accessor :verbose
68
+ attr_reader :basename
69
+
70
+ #----------------------------------------------------------------------
71
+ def initialize(basename='pipeline', is_verbose=false)
72
+ @stages = []
73
+ @results = []
74
+ @tempfiles = []
75
+ @basename = basename
76
+ @verbose = is_verbose
77
+ end
78
+
79
+ #----------------------------------------------------------------------
80
+ def add(name, command, success=0)
81
+ @stages << Stage.new(name, command, success)
82
+ self
83
+ end
84
+
85
+ #----------------------------------------------------------------------
86
+ def concat(arr)
87
+ if arr.is_a? Array
88
+ arr.each do |e|
89
+ self.add(e[0], e[1], e[2] || 0)
90
+ end
91
+ end
92
+ self
93
+ end
94
+
95
+ #----------------------------------------------------------------------
96
+ # Given a pipeline of commands, modify it so that we can obtain
97
+ # the exit status of each pipeline stage by reading the tempfile
98
+ # associated with that stage. Must be implemented by subclasses
99
+ def pipestatus(cmd)
100
+ raise 'unimplemented method'
101
+ end
102
+
103
+ #----------------------------------------------------------------------
104
+ def command
105
+ # Create the pipeline incantation
106
+ pipeline = @stages.map { |s| s.command }.join(' | ') + '; '
107
+
108
+ # Fudge pipeline incantation to make return codes for each
109
+ # stage accessible from the associated pipeline stage
110
+ pipestatus(pipeline)
111
+ end
112
+
113
+ #----------------------------------------------------------------------
114
+ def execute()
115
+ @results = []
116
+ create_tempfiles
117
+ escaped_command = command.gsub("'","'\"'\"'")
118
+ invocation = "/bin/bash -c '#{escaped_command}'"
119
+
120
+ # Execute the pipeline invocation
121
+ STDERR.puts("Pipeline.execute: command = [#{invocation}]") if verbose
122
+ output = `#{invocation}`
123
+ STDERR.puts("Pipeline.execute: output = [#{output.strip}]") if verbose
124
+
125
+ unless $CHILD_STATUS.success?
126
+ raise ExecutionError.new(@basename)
127
+ end
128
+
129
+ # Collect the pipeline's exit codes and see if they're good
130
+ successful = true
131
+ offender = nil
132
+ @results = @tempfiles.zip(@stages).map do |file, stage|
133
+ file.open()
134
+ status = file.read().strip.to_i
135
+ file.close(false)
136
+ success = (stage.success == status)
137
+ successful &&= success
138
+ offender = stage.name unless successful
139
+ Stage::Result.new(stage.name, status, success)
140
+ end
141
+ unless successful
142
+ raise ExecutionError.new(@basename, offender)
143
+ end
144
+ output
145
+ end
146
+
147
+ #----------------------------------------------------------------------
148
+ def cleanup
149
+ @tempfiles.each do |file|
150
+ file.close(true) if file.is_a? Tempfile
151
+ FileUtils.rm_f(file.path) if File.exist?(file.path)
152
+ end
153
+ end
154
+
155
+ #----------------------------------------------------------------------
156
+ def errors
157
+ @results.reject { |r| r.success }
158
+ end
159
+
160
+ #----------------------------------------------------------------------
161
+ def create_tempfiles
162
+ @tempfiles = (0...@stages.length).map do |index|
163
+ file = Tempfile.new("#{@basename}-pipestatus-#{index}")
164
+ file.close(false)
165
+ file
166
+ end
167
+ unless @tempfiles.length == @stages.length
168
+ raise ExecutionError.new(
169
+ @basename, nil,
170
+ "Temp files count(#{@tempfiles.length}) != stages count(#{@stages.length})")
171
+ end
172
+ end
173
+
174
+ #----------------------------------------------------------------------
175
+ def to_s
176
+ "Pipeline(stages=[#{@stages.join(', ')}], results=[#{@results.join(', ')}])"
177
+ end
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,57 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ #------------------------------------------------------------------------------
12
+ module EC2
13
+ module Platform
14
+ class PartitionType < String
15
+ MBR = new 'mbr'
16
+ GPT = new 'gpt'
17
+ NONE = new 'none'
18
+
19
+ def self.list()
20
+ [MBR, GPT, NONE]
21
+ end
22
+
23
+ def self.valid?(input)
24
+ return false if input == NONE
25
+ self.list.include?(input)
26
+ end
27
+ end
28
+
29
+ module Base
30
+ module Distribution
31
+ UNKNOWN = 'Unknown'
32
+ GENERIC = 'Generic'
33
+ end
34
+
35
+ class System
36
+ MOUNT_POINT = '/mnt/img-mnt'
37
+ def self.distribution
38
+ Distribution::UNKNOWN
39
+ end
40
+
41
+ def self.superuser?
42
+ false
43
+ end
44
+
45
+ def self.exec(cmd, debug)
46
+ if debug
47
+ puts( "Executing: #{cmd} " )
48
+ suffix = ''
49
+ else
50
+ suffix = ' 2>&1 > /dev/null'
51
+ end
52
+ raise "execution failed: \"#{cmd}\"" unless system( cmd + suffix )
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ #------------------------------------------------------------------------------
12
+ require 'pathname'
13
+ require 'ec2/platform'
14
+
15
+ module EC2
16
+ module Platform
17
+ class Unknown < RuntimeError
18
+ def initialize(name)
19
+ super("Unknown platform: #{name}")
20
+ @name = name
21
+ end
22
+ attr_reader :name
23
+ end
24
+
25
+ class Unsupported < RuntimeError
26
+ def initialize(name)
27
+ super("Unsupported or unimplemented platform: #{name}")
28
+ @name = name
29
+ end
30
+ attr_reader :name
31
+ end
32
+
33
+ def self.initialize
34
+ return EC2::Platform::PEER if defined? EC2::Platform::PEER
35
+ impl = Platform::IMPL
36
+ base = impl.to_s
37
+
38
+ # must be a known architecture
39
+ raise Unknown.new(base), caller if base.nil? or impl == :unknown
40
+
41
+ # base file must exist in same directory as this one
42
+ file = Pathname.new(__FILE__).dirname + base
43
+ raise Unsupported.new(base), caller unless File.exists? file
44
+
45
+ # a require statement must succeed
46
+ implemented = require "ec2/platform/#{base}" rescue false
47
+ raise Unsupported.new(impl), caller unless implemented
48
+
49
+ # cross fingers and hope the 'required' peer set the PEER constant
50
+ raise Unsupported.new(impl), caller unless defined? EC2::Platform::PEER
51
+ EC2::Platform::PEER
52
+ end
53
+ Current = initialize
54
+ end
55
+ end
@@ -0,0 +1,35 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ #------------------------------------------------------------------------------
12
+ # Machine architectures as seen by EC2 in Linux
13
+
14
+ require 'ec2/platform/base/architecture'
15
+ require 'ec2/platform/linux/uname'
16
+
17
+ module EC2
18
+ module Platform
19
+ module Linux
20
+ class Architecture < EC2::Platform::Base::Architecture
21
+
22
+ #----------------------------------------------------------------------
23
+ # Returns the EC2-equivalent of the architecture of the platform this is
24
+ # running on.
25
+ def self.bundling
26
+ processor = Uname.platform
27
+ processor = Uname.machine if processor =~ /unknown/i
28
+ return Architecture::I386 if processor =~ /^i\d86$/
29
+ return Architecture::X86_64 if processor =~ /^x86_64$/
30
+ return Architecture::UNKNOWN
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ #------------------------------------------------------------------------
12
+ # Linux overrides for constants go here
13
+ #------------------------------------------------------------------------
14
+ require 'ec2/platform/base/constants'
15
+ module EC2
16
+ module Platform
17
+ module Linux
18
+ module Constants
19
+ include EC2::Platform::Base::Constants
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,99 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ #------------------------------------------------------------------------------
12
+ # An abstraction of the File-System Table (fstab)
13
+
14
+ require 'ec2/amitools/version'
15
+
16
+ module EC2
17
+ module Platform
18
+ module Linux
19
+ class Fstab
20
+
21
+ include EC2Version
22
+
23
+ class Entry
24
+ REGEX = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$/
25
+ attr_reader :device # mounted device.
26
+ attr_reader :mpoint # mount point.
27
+ attr_reader :fstype # file system type.
28
+ attr_reader :options # options
29
+ attr_reader :value # everything on line
30
+
31
+ def initialize(dev, mnt_point, fs_type, opts, line)
32
+ @device = dev
33
+ @mpoint = mnt_point
34
+ @fstype = fs_type
35
+ @options= opts
36
+ @value = line
37
+ end
38
+
39
+ def self.parse(line)
40
+ return nil if line[0,1] == '#'
41
+ if (m = REGEX.match(line))
42
+ parts = m.captures
43
+ return Entry.new(parts[0], parts[1], parts[2], parts[3], line.strip)
44
+ else
45
+ return nil
46
+ end
47
+ end
48
+
49
+ def to_s
50
+ value
51
+ end
52
+
53
+ def print
54
+ puts(to_s)
55
+ end
56
+ end
57
+
58
+ LOCATION = '/etc/fstab'
59
+ attr_reader :entries
60
+
61
+ def initialize(filename = LOCATION)
62
+ begin
63
+ f = File.new(filename, File::RDONLY)
64
+ rescue SystemCallError => e
65
+ raise FileError(filename, "could not open #{filename} to read file system table", e)
66
+ end
67
+ @entries = Hash.new
68
+ f.readlines.each do |line|
69
+ entry = Entry.parse(line)
70
+ @entries[entry.mpoint] = entry unless entry.nil?
71
+ end
72
+ end
73
+
74
+ def self.load
75
+ self.new()
76
+ end
77
+
78
+ DEFAULT = <<TEXT
79
+ # Default /etc/fstab
80
+ # Supplied by: #{PKG_NAME}-#{PKG_VERSION}-#{PKG_RELEASE}
81
+ /dev/sda1 / ext3 defaults 1 1
82
+ /dev/sdb /mnt ext3 defaults 0 0
83
+ none /dev/pts devpts gid=5,mode=620 0 0
84
+ none /proc proc defaults 0 0
85
+ none /sys sysfs defaults 0 0
86
+ TEXT
87
+ LEGACY = <<TEXT
88
+ # Legacy /etc/fstab
89
+ # Supplied by: #{PKG_NAME}-#{PKG_VERSION}-#{PKG_RELEASE}
90
+ /dev/sda1 / ext3 defaults 1 1
91
+ /dev/sda2 /mnt ext3 defaults 0 0
92
+ /dev/sda3 swap swap defaults 0 0
93
+ none /proc proc defaults 0 0
94
+ none /sys sysfs defaults 0 0
95
+ TEXT
96
+ end
97
+ end
98
+ end
99
+ end