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,74 @@
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 Linux
14
+ LOCAL_FS_TYPES = ['ext2', 'ext3', 'ext4', 'xfs', 'jfs', 'reiserfs', 'tmpfs']
15
+ class Mtab
16
+ class Entry
17
+ REGEX = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$/
18
+ attr_reader :device # mounted device.
19
+ attr_reader :mpoint # mount point.
20
+ attr_reader :fstype # file system type.
21
+ attr_reader :options # options
22
+ attr_reader :value # entire line
23
+
24
+
25
+ def initialize(dev, mnt_point, fs_type, opts, line)
26
+ @device = dev
27
+ @mpoint = mnt_point
28
+ @fstype = fs_type
29
+ @options= opts
30
+ @value = line
31
+ end
32
+
33
+ def self.parse(line)
34
+ return nil if line[0,1] == '#'
35
+ if (m = REGEX.match(line))
36
+ parts = m.captures
37
+ return Entry.new(parts[0], parts[1], parts[2], parts[3], line.strip)
38
+ else
39
+ return nil
40
+ end
41
+ end
42
+
43
+ def to_s
44
+ value
45
+ end
46
+
47
+ def print
48
+ puts(to_s)
49
+ end
50
+ end
51
+
52
+ attr_reader :entries
53
+ LOCATION = '/etc/mtab'
54
+
55
+ def initialize(filename = LOCATION)
56
+ begin
57
+ f = File.new(filename, File::RDONLY)
58
+ rescue SystemCallError => e
59
+ raise FileError(filename, "could not open #{filename} to read mount table", e)
60
+ end
61
+ @entries = Hash.new
62
+ f.readlines.each do |line|
63
+ entry = Entry.parse(line)
64
+ @entries[entry.mpoint] = entry unless entry.nil?
65
+ end
66
+ end
67
+
68
+ def self.load
69
+ self.new()
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,40 @@
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 'ec2/platform/base/pipeline'
13
+
14
+ #------------------------------------------------------------------------------
15
+ module EC2
16
+ #----------------------------------------------------------------------------
17
+ module Platform
18
+ #--------------------------------------------------------------------------
19
+ module Linux
20
+ #------------------------------------------------------------------------
21
+ class Pipeline < EC2::Platform::Base::Pipeline
22
+
23
+ #----------------------------------------------------------------------
24
+ # Given a pipeline of commands, modify it so that we can obtain
25
+ # the exit status of each pipeline stage by reading the tempfile
26
+ # associated with that stage.
27
+ def pipestatus(cmd)
28
+ command = cmd
29
+ command << ';' unless cmd.rstrip[-1,1] == ';'
30
+ command << ' ' unless cmd[-1,1] == ' '
31
+ list = []
32
+ @tempfiles.each_with_index do |file, index|
33
+ list << "echo ${PIPESTATUS[#{index}]} > #{file.path}"
34
+ end
35
+ command + list.join(' & ')
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,114 @@
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
+ require 'ec2/amitools/fileutil'
12
+ module EC2
13
+ module Platform
14
+ module Linux
15
+ class Rsync
16
+ class Command
17
+ EXECUTABLE='rsync'
18
+ def initialize(e = EXECUTABLE)
19
+ @src = nil
20
+ @dst = nil
21
+ @options = []
22
+ @executable = e
23
+ @quiet = false
24
+ end
25
+
26
+ def archive; @options << '-rlpgoD'; self; end
27
+ def times; @options << '-t'; self; end
28
+ def recursive; @options << '-r'; self; end
29
+ def sparse; @options << '-S'; self; end
30
+ def links; @options << '-l'; self; end
31
+ def dereference; @options << '-L'; self; end
32
+ def xattributes; @options << '-X'; self; end
33
+ def version; @options << '--version'; self; end
34
+ def src(path) @src = path; self; end
35
+ def dst(path) @dst = path; self; end
36
+ def quietly; @quiet = true; self; end
37
+
38
+ alias :source :src
39
+ alias :from :src
40
+ alias :destination :dst
41
+ alias :to :dst
42
+
43
+ def exclude(files)
44
+ if files.is_a? Array
45
+ files.each {|file| exclude file }
46
+ else
47
+ @options << "--exclude '#{files}'" unless files.nil?
48
+ end
49
+ self
50
+ end
51
+
52
+ def include(files)
53
+ if files.is_a? Array
54
+ files.each {|file| include file }
55
+ else
56
+ @options << "--include '#{files}'" unless files.nil?
57
+ end
58
+ self
59
+ end
60
+
61
+ def expand
62
+ "#{@executable} #{@options.join(' ')} #{@src} #{@dst} #{'2>&1 > /dev/null' if @quiet}".strip
63
+ end
64
+ end
65
+
66
+ def self.symlinking?
67
+ begin
68
+ src = FileUtil.tempdir('ec2-ami-tools-rsync-test-src')
69
+ dst = FileUtil.tempdir('ec2-ami-tools-rsync-test-dst')
70
+ FileUtils.mkdir(src)
71
+ FileUtils.touch("#{src}/foo")
72
+ FileUtils.symlink("#{src}/foo", "#{src}/bar")
73
+ FileUtils.mkdir("#{src}/baz")
74
+ File.open("#{src}/baz/food", 'w+'){|io| io << IO.read(__FILE__) }
75
+ FileUtils.symlink("#{src}/baz/food", "#{src}/baz/bard")
76
+ FileUtils.mkdir(dst)
77
+ incantation = Command.new.archive.recursive.sparse.links.src("#{src}/").dst("#{dst}")
78
+ `#{incantation.expand} 2>&1`
79
+ rc = $?.exitstatus
80
+ return true if rc == 0
81
+ if rc == 23
82
+ #check that the structure was copied reasonably anyway
83
+ slist = Dir["#{src}/**/**"]
84
+ dlist = Dir["#{dst}/**/**"]
85
+ return false unless dlist == dlist
86
+ slist.each do |sitem|
87
+ ditem = item.gsub(src, dst)
88
+ return false unless dlist.include? ditem
89
+ if File.file?(sitem) or File.symlink?(sitem)
90
+ @out.print "comparing #{sitem} to #{ditem}" if @out
91
+ return false unless IO.read(ditem) == IO.read(sitem)
92
+ end
93
+ if ['food', 'bard'].include? File.basename(ditem)
94
+ return false unless IO.read(sitem) == IO.read(__FILE__)
95
+ end
96
+ end
97
+ return true
98
+ end
99
+ return false
100
+ rescue Exception
101
+ return false
102
+ ensure
103
+ FileUtils.rm_rf src
104
+ FileUtils.rm_rf dst
105
+ end
106
+ end
107
+
108
+ def self.usable?()
109
+ @@usable ||= self.symlinking?
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,124 @@
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
+ require 'ec2/platform/linux/constants'
12
+ module EC2
13
+ module Platform
14
+ module Linux
15
+ class Tar
16
+ class Command
17
+ EXECUTABLE=EC2::Platform::Linux::Constants::Utility::TAR
18
+ def initialize(e = EXECUTABLE)
19
+ @files = []
20
+ @options = []
21
+ @executable = e
22
+ end
23
+
24
+ def version; @options << '--version'; self; end
25
+ def verbose; @options << '-v'; self; end
26
+ def create; @options << '-c'; self; end
27
+ def bzip2; @options << '-j'; self; end
28
+ def diff; @options << '-d'; self; end
29
+ def gzip; @options << '-z'; self; end
30
+ def extract; @options << '-x'; self; end
31
+ def update; @options << '-u'; self; end
32
+ def sparse; @options << '-S'; self; end
33
+ def dereference; @options << '-h'; self; end
34
+
35
+ def archive(filename)
36
+ filename = '-' if filename.nil?
37
+ @options << "-f #{filename}"
38
+ self
39
+ end
40
+
41
+ def owner(user)
42
+ @options << "--owner #{user}"
43
+ self
44
+ end
45
+
46
+ def group(grp)
47
+ @options << "--group #{grp}"
48
+ self
49
+ end
50
+
51
+ def chdir(dir)
52
+ @options << "-C #{dir}" unless dir.nil?
53
+ self
54
+ end
55
+
56
+ def add(filename, dir = nil)
57
+ item = dir.nil? ? filename : "-C #{dir} #{filename}"
58
+ @files << item
59
+ self
60
+ end
61
+ def expand
62
+ "#{@executable} #{@options.join(' ')} #{@files.join(' ')}".strip
63
+ end
64
+ end
65
+ class Version
66
+ RECOMMENDED = 'tar 1.15'
67
+ REGEX = /(?:tar).*?(\d+)\.(\d+)\.?(\d*)/
68
+ attr_reader :values
69
+ attr_reader :string
70
+
71
+ def initialize(str=nil)
72
+ @string = str
73
+ @string = default if str.nil? or str.empty?
74
+ @values = Version.parse @string
75
+ end
76
+ def default
77
+ s = `#{Command.new.version.expand}`.strip
78
+ s = nil unless $? == 0
79
+ s
80
+ end
81
+ def string= (str)
82
+ @string = str
83
+ @values = Version.parse @string
84
+ end
85
+ def >= (other)
86
+ return nil if @values.nil?
87
+ if other.nil? or not other.is_a? Version
88
+ raise ArgumentError, "Cannot compare with invalid version #{other}"
89
+ end
90
+ @values.zip(other.values).each do |mine, others|
91
+ return false if mine < others
92
+ return true if mine > others
93
+ end
94
+ return true
95
+ end
96
+ def usable?
97
+ self >= Version.new(Version::RECOMMENDED)
98
+ end
99
+ def self.parse(str)
100
+ match = REGEX.match(str)
101
+ return nil if match.nil?
102
+ begin
103
+ items = match.captures.collect do |cap|
104
+ cap.sub!(/^0*/, "")
105
+ case cap
106
+ when ""
107
+ num = 0
108
+ else
109
+ num = Integer(cap)
110
+ end
111
+ end
112
+ rescue ArgumentError
113
+ return nil
114
+ end
115
+ items
116
+ end
117
+ def self.current
118
+ Version.new
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,50 @@
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
+ require 'ostruct'
12
+ require 'ec2/platform'
13
+
14
+ module EC2
15
+ module Platform
16
+ module Linux
17
+ class Uname
18
+ @@uname ||= OpenStruct.new
19
+ def self.all
20
+ @@uname.all ||= `uname -a`.strip
21
+ end
22
+ def self.platform
23
+ @@uname.platform ||= `uname -i`.strip
24
+ end
25
+ def self.nodename
26
+ @@uname.nodename ||= `uname -n`.strip
27
+ end
28
+ def self.processor
29
+ @@uname.processor ||= `uname -p`.strip
30
+ end
31
+ def self.release
32
+ @@uname.release ||= `uname -r`.strip
33
+ end
34
+ def self.os
35
+ @@uname.os ||= `uname -s`.strip
36
+ end
37
+ def self.machine
38
+ @@uname.machine ||= `uname -m`.strip
39
+ end
40
+ def self.uname
41
+ @@uname
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ if __FILE__ == $0
48
+ include EC2::Platform::Linux
49
+ puts "Uname = #{Uname.all.inspect}"
50
+ end
@@ -0,0 +1,83 @@
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 'ec2/platform/base'
13
+ require 'ec2/platform/linux/identity'
14
+ require 'ec2/platform/linux/architecture'
15
+ require 'ec2/platform/linux/fstab'
16
+ require 'ec2/platform/linux/mtab'
17
+ require 'ec2/platform/linux/image'
18
+ require 'ec2/platform/linux/rsync'
19
+ require 'ec2/platform/linux/tar'
20
+ require 'ec2/platform/linux/uname'
21
+ require 'ec2/platform/linux/pipeline'
22
+ require 'ec2/platform/linux/constants'
23
+
24
+ module EC2
25
+ module Platform
26
+ module Linux
27
+ module Distribution
28
+ include EC2::Platform::Base::Distribution
29
+ AMAZON = 'Amazon Linux'
30
+ REDHAT = 'Red Hat Linux'
31
+ GENTOO = 'Gentoo'
32
+ DEBIAN = 'Debian'
33
+ UBUNTU = 'Ubuntu'
34
+ FEDORA = 'Fedora'
35
+ SLACKWARE = 'Slackware'
36
+ SUSE = 'SuSE Linux'
37
+ MANDRAKE = 'Mandrake'
38
+ CAOS = 'Caos Linux'
39
+
40
+ IDENTITIES= [
41
+ # file distro regex
42
+ ['/etc/system-release-cpe', Distribution::AMAZON, /amazon/],
43
+ ['/etc/caos-release', Distribution::CAOS, nil],
44
+ ['/etc/debian-release', Distribution::DEBIAN, nil],
45
+ ['/etc/debian_version', Distribution::DEBIAN, nil],
46
+ ['/etc/fedora-release', Distribution::FEDORA, nil],
47
+ ['/etc/gentoo-release', Distribution::GENTOO, nil],
48
+ ['/etc/redhat-release', Distribution::REDHAT, nil],
49
+ ['/etc/slackware-version', Distribution::SLACKWARE, nil],
50
+ ['/etc/slackware-release', Distribution::SLACKWARE, nil],
51
+ ['/etc/SuSE-release', Distribution::SUSE, nil],
52
+ ['/etc/ubuntu-release', Distribution::UBUNTU, nil],
53
+ ['/etc/ubuntu-version', Distribution::UBUNTU, nil],
54
+ ['/etc/mandrake-release', Distribution::MANDRAKE, nil],
55
+ ]
56
+ end
57
+
58
+ class System < EC2::Platform::Base::System
59
+
60
+ BUNDLING_ARCHITECTURE = EC2::Platform::Linux::Architecture.bundling
61
+
62
+ #---------------------------------------------------------------------#
63
+ def self.distribution
64
+ Distribution::IDENTITIES.each do |file, distro, regex|
65
+ if File.exists? file
66
+ if regex.is_a? Regexp
67
+ return distro if regex.match((IO.read file rescue nil))
68
+ else
69
+ return distro
70
+ end
71
+ end
72
+ end
73
+ return Distribution::UNKNOWN
74
+ end
75
+
76
+ #---------------------------------------------------------------------#
77
+ def self.superuser?()
78
+ return `id -u`.strip == '0'
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end