Class: Tpkg::OS::Solaris

Inherits:
Tpkg::OS show all
Defined in:
lib/tpkg/os/solaris.rb

Overview

tpkg package management system License: MIT (www.opensource.org/licenses/mit-license.php)

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tpkg::OS

#arch, create, #cron_dot_d_directory, #fqdn, #os, #os_name, #os_version, register_implementation, #remove_native_stub_pkg, #stub_native_pkg, #sudo_default?, #sys_v_init_links

Constructor Details

#initialize(options = {}) ⇒ Solaris

Returns a new instance of Solaris.



11
12
13
14
15
# File 'lib/tpkg/os/solaris.rb', line 11

def initialize(options={})
  @pkginfocmd = options[:pkginfocmd] || options[:testcmd] || 'pkginfo'
  @pkgutilcmd = options[:pkgutilcmd] || options[:testcmd] || '/opt/csw/bin/pkgutil'
  super
end

Class Method Details

.supported?Boolean

Returns:

  • (Boolean)


5
6
7
8
# File 'lib/tpkg/os/solaris.rb', line 5

def self.supported?
  Facter.loadfacts
  Facter['operatingsystem'].value == 'Solaris'
end

Instance Method Details

#available_native_packages(pkgname) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/tpkg/os/solaris.rb', line 20

def available_native_packages(pkgname)
  native_packages = []
  # Example of pkginfo -x output:
  # SUNWzfsu                      ZFS (Usr)
  #                               (i386) 11.10.0,REV=2006.05.18.01.46
  cmd = "#{@pkginfocmd} -x #{pkgname}"
  puts "available_native_packages running '#{cmd}'" if @debug
  IO.popen(cmd) do |pipe|
    name = nil
    pipe.each_line do |line|
      if line =~ /^\w/
        name = line.split(' ').first
      else
        arch, solversion = line.split(' ')
        # Lots of Sun and some third party packages (including CSW)
        # seem to use this REV= convention in the version.  I've
        # never seen it documented, but since it seems to be a
        # widely used convention we'll go with it.
        version, package_version = solversion.split(',REV=')
        native_packages <<
          Tpkg.pkg_for_native_package(
            name, version, package_version, :native_installed)
        name = nil
      end
    end
  end
  if !$?.success?
    raise "available_native_packages error running pkginfo"
  end
  if File.exist?(@pkgutilcmd)
    cmd = "#{@pkgutilcmd} -a --parse #{pkgname}"
    puts "available_native_packages running '#{cmd}'" if @debug
    IO.popen(cmd) do |pipe|
      pipe.each_line do |line|
        shortname, name, solversion, size = line.chomp.split("\t")
        # pkgutil treats the specified name as a regular expression, so we
        # have filter for the ones that are an exact match
        next if name != pkgname
        # Lots of Sun and some third party packages (including CSW)
        # seem to use this REV= convention in the version.  I've
        # never seen it documented, but since it seems to be a
        # widely used convention we'll go with it.
        version, package_version = solversion.split(',REV=')
        native_packages <<
          Tpkg.pkg_for_native_package(
            name, version, package_version, :native_available)
      end
    end
  end
  native_packages
end


17
18
19
# File 'lib/tpkg/os/solaris.rb', line 17

def init_links(installed_path, tpkgfile)
  sys_v_init_links(installed_path, tpkgfile, ['2', '3'], '/etc')
end

#install_native_package(pkg) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/tpkg/os/solaris.rb', line 81

def install_native_package(pkg)
  pkgname = native_pkg_to_install_string(pkg)
  if File.exist?(@pkgutilcmd)
    cmd = "#{@pkgutilcmd} -y -i #{pkgname}"
    puts "Running '#{cmd}' to install native package" if @debug
    system(cmd)
  else
    raise "No supported native package tool available on #{os}"
  end
end

#native_pkg_to_install_string(pkg) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/tpkg/os/solaris.rb', line 71

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 << ",REV=#{package_version}"
  end
  pkgname
end

#upgrade_native_package(pkg) ⇒ Object



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

def upgrade_native_package(pkg)
  pkgname = native_pkg_to_install_string(pkg)
  if File.exist?(@pkgutilcmd)
    cmd = "#{@pkgutilcmd} -y -u #{pkgname}"
    puts "Running '#{cmd}' to upgrade native package" if @debug
    system(cmd)
  else
    raise "No supported native package tool available on #{os}"
  end
end