~awstools-dev/ubuntu/maverick/ec2-ami-tools/maverick

« back to all changes in this revision

Viewing changes to lib/ec2/platform/linux.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2008-10-14 08:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20081014083525-c0n69wr7r7aqfb8w
Tags: 1.3-26357-0ubuntu2
* New upstream version.
* Update the debian copyright file.
* Added quilt patch system to make it easier to maintain. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2008 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
        REDHAT    = 'Red Hat Linux'
 
30
        GENTOO    = 'Gentoo'
 
31
        DEBIAN    = 'Debian'
 
32
        UBUNTU    = 'Ubuntu'
 
33
        FEDORA    = 'Fedora'
 
34
        SLACKWARE = 'Slackware'
 
35
        SUSE      = 'SuSE Linux'
 
36
        MANDRAKE  = 'Mandrake'
 
37
        CAOS      = 'Caos Linux'
 
38
        
 
39
        IDENTITIES= [
 
40
          # file                    distro                    regex
 
41
          ['/etc/caos-release',     Distribution::CAOS,       nil],
 
42
          ['/etc/debian-release',   Distribution::DEBIAN,     nil],
 
43
          ['/etc/debian_version',   Distribution::DEBIAN,     nil],
 
44
          ['/etc/fedora-release',   Distribution::FEDORA,     nil],
 
45
          ['/etc/gentoo-release',   Distribution::GENTOO,     nil],
 
46
          ['/etc/redhat-release',   Distribution::REDHAT,     nil],
 
47
          ['/etc/slackware-version',Distribution::SLACKWARE,  nil],
 
48
          ['/etc/slackware-release',Distribution::SLACKWARE,  nil],
 
49
          ['/etc/SuSE-release',     Distribution::SUSE,       nil],
 
50
          ['/etc/ubuntu-release',   Distribution::UBUNTU,     nil],
 
51
          ['/etc/ubuntu-version',   Distribution::UBUNTU,     nil],
 
52
          ['/etc/mandrake-release', Distribution::MANDRAKE,   nil],
 
53
        ]
 
54
      end
 
55
      
 
56
      class System < EC2::Platform::Base::System
 
57
        
 
58
        BUNDLING_ARCHITECTURE = EC2::Platform::Linux::Architecture.bundling    
 
59
        
 
60
        #---------------------------------------------------------------------#
 
61
        def self.distribution
 
62
          Distribution::IDENTITIES.each do |file, distro, regex|
 
63
            if File.exists? file 
 
64
              if regex.is_a? Regexp
 
65
                return distro if regex.match((IO.read file rescue nil))
 
66
              else              
 
67
                return distro
 
68
              end
 
69
            end
 
70
          end
 
71
          return Distribution::UNKNOWN
 
72
        end
 
73
        
 
74
        #---------------------------------------------------------------------#              
 
75
        def self.superuser?()
 
76
          return `id -u`.strip == '0'
 
77
        end
 
78
      end
 
79
    end
 
80
  end
 
81
end