Class: Tpkg::OS

Inherits:
Object
  • Object
show all
Defined in:
lib/tpkg/os.rb

Direct Known Subclasses

Debian, FreeBSD, MacOSX, RedHat, Solaris, Windows

Defined Under Namespace

Classes: Debian, FreeBSD, MacOSX, RedHat, Solaris, Windows

Constant Summary collapse

@@implementations =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OS

Returns a new instance of OS.



24
25
26
27
28
29
30
31
# File 'lib/tpkg/os.rb', line 24

def initialize(options={})
  @debug = options[:debug]
  @os = nil
  @os_name = nil
  @os_version = nil
  @arch = nil
  Facter.loadfacts
end

Class Method Details

.create(options = {}) ⇒ Object



19
20
21
22
# File 'lib/tpkg/os.rb', line 19

def self.create(options={})
  impl = @@implementations.detect{|i| i.supported?} || raise(NotImplementedError)
  impl.new(options)
end

.register_implementation(impl) ⇒ Object



15
16
17
# File 'lib/tpkg/os.rb', line 15

def self.register_implementation(impl)
  @@implementations << impl
end

Instance Method Details

#archObject



118
119
120
121
122
123
# File 'lib/tpkg/os.rb', line 118

def arch
  if !@arch
    @arch = Facter['hardwaremodel'].value
  end
  @arch.dup
end

#available_native_packages(pkgname) ⇒ Object

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/tpkg/os.rb', line 47

def available_native_packages(pkgname)
  raise NotImplementedError
end

#cron_dot_d_directoryObject

Systems with cron.d support should override this



135
136
# File 'lib/tpkg/os.rb', line 135

def cron_dot_d_directory
end

#fqdnObject



124
125
126
127
128
129
130
131
132
133
# File 'lib/tpkg/os.rb', line 124

def fqdn
  # Note that we intentionally do not cache the fqdn.  The hostname of a
  # machine can change at any time and it would be unexpected if the user
  # had to restart a tpkg-based application to pick up a hostname change.
  if Facter['fqdn'] && Facter['fqdn'].value
    Facter['fqdn'].value
  else
    Facter['hostname'].value << '.' << Facter['domain'].value
  end
end

Given info for a init script from a package’s metadata return an array of paths where that init script should linked to on the system



39
40
41
42
43
44
45
46
# File 'lib/tpkg/os.rb', line 39

def init_links(installed_path, tpkgfile)
  # I think users would rather have packages install without their init
  # scripts enabled than have them fail to install on platforms where we
  # don't have init script support.
  # raise NotImplementedError
  warn "No init script support for OS #{os}"
  []
end

#install_native_package(pkg) ⇒ Object

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/tpkg/os.rb', line 50

def install_native_package(pkg)
  raise NotImplementedError
end

#native_pkg_to_install_string(pkg) ⇒ Object

This also rarely works as-is



90
91
92
93
94
95
96
97
98
99
# File 'lib/tpkg/os.rb', line 90

def native_pkg_to_install_string(pkg)
  name = pkg[:metadata][:name]
  version = pkg[:metadata][:version]
  package_version = pkg[:metadata][:package_version]
  pkgname = "#{name}-#{version}"
  if package_version
     pkgname << "-#{package_version}"
  end
  pkgname
end

#osObject

These methods have implementations that work in most cases, but OS-specific classes may modify these definitions if needed.



106
107
108
109
110
111
# File 'lib/tpkg/os.rb', line 106

def os
  if !@os
    @os = "#{os_name}-#{os_version}"
  end
  @os.dup
end

#os_nameObject



112
113
114
115
116
117
# File 'lib/tpkg/os.rb', line 112

def os_name
  if !@os_name
    @os_name = Facter['operatingsystem'].value
  end
  @os_name.dup
end

#os_versionObject

This rarely works as-is, most platforms need something more specific



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/tpkg/os.rb', line 77

def os_version
  if !@os_version
    if Facter['operatingsystemrelease'] &&
       Facter['operatingsystemrelease'].value &&
       !Facter['operatingsystemrelease'].value.empty?
      @os_version = Facter['operatingsystemrelease'].value
    else
      raise "Unable to determine proper OS value on this platform"
    end
  end
  @os_version.dup
end

#remove_native_stub_pkg(pkg) ⇒ Object

Remove the native dependency stub package (if there is one) associated with pkg



72
73
74
75
# File 'lib/tpkg/os.rb', line 72

def remove_native_stub_pkg(pkg)
  # raise NotImplementedError
  warn "No native stub support for OS #{os}"
end

#stub_native_pkg(pkg) ⇒ Object

Create and install a native stub package, if pkg has native dependencies, to express those dependencies to the native package system. This helps ensure that users don’t inadvertently remove native packages that tpkg packages depend on.



60
61
62
63
64
65
66
67
68
69
# File 'lib/tpkg/os.rb', line 60

def stub_native_pkg(pkg)
  # I think users would rather have packages install without a native stub
  # than have them fail to install on platforms where we don't have native
  # stub support.
  # raise NotImplementedError
  native_deps = pkg[:metadata].get_native_deps
  if !native_deps.empty?
    warn "No native stub support for OS #{os}"
  end
end

#sudo_default?Boolean

Should sudo be on by default?

Returns:

  • (Boolean)


138
139
140
# File 'lib/tpkg/os.rb', line 138

def sudo_default?
  true
end

Utility methods



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/tpkg/os.rb', line 146

def sys_v_init_links(installed_path, tpkgfile, default_levels, init_directory)
  start = '99'
  if tpkgfile[:init][:start]
    start = tpkgfile[:init][:start]
  end
  levels = default_levels
  if tpkgfile[:init][:levels]
    levels = tpkgfile[:init][:levels]
    # In case the user specified levels in yaml as string/integer
    # instead of array
    if !levels.kind_of?(Array)
      levels = levels.to_s.split(//)
    end
  end
  levels.collect do |level|
    File.join(init_directory, "rc#{level}.d", 'S' + start.to_s + File.basename(installed_path))
  end
end

#upgrade_native_package(pkg) ⇒ Object

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/tpkg/os.rb', line 53

def upgrade_native_package(pkg)
  raise NotImplementedError
end