-
Notifications
You must be signed in to change notification settings - Fork 77
/
solaris_11.rb
130 lines (116 loc) · 5.88 KB
/
solaris_11.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
class Vanagon
class Platform
class Solaris11 < Vanagon::Platform
# The specific bits used to generate a solaris package for a given project
#
# @param project [Vanagon::Project] project to build a solaris package of
# @return [Array] list of commands required to build a solaris package for the given project from a tarball
def generate_package(project) # rubocop:disable Metrics/AbcSize
target_dir = project.repo ? output_dir(project.repo) : output_dir
name_and_version = "#{project.name}-#{project.version}"
pkg_name = package_name(project)
[
# Set up our needed directories
"mkdir -p $(tempdir)/#{name_and_version}",
"mkdir -p $(tempdir)/pkg",
"mkdir -p output/#{target_dir}",
# Unpack the project and stage the packaging artifacts
"gunzip -c #{name_and_version}.tar.gz | '#{@tar}' -C '$(tempdir)' -xf -",
"cp -r packaging $(tempdir)/",
"pkgrepo create $(tempdir)/repo",
"pkgrepo set -s $(tempdir)/repo publisher/prefix=#{project.identifier}",
"(cd $(tempdir); pkgsend generate #{name_and_version} | pkgfmt >> packaging/#{project.name}.p5m.1)",
# Actually build the package
"(cd $(tempdir)/packaging; pkgmogrify -DARCH=`uname -p` #{project.name}.p5m.1 #{project.name}.p5m | pkgfmt > #{project.name}.p5m.2)",
"pkglint $(tempdir)/packaging/#{project.name}.p5m.2",
"pkgsend -s 'file://$(tempdir)/repo' publish -d '$(tempdir)/#{name_and_version}' --fmri-in-manifest '$(tempdir)/packaging/#{project.name}.p5m.2'",
"pkgrecv -s 'file://$(tempdir)/repo' -a -d 'output/#{target_dir}/#{pkg_name}' '#{project.name}@#{ips_version(project.version, project.release)}'",
# Now make sure the package we built isn't totally broken (but not when cross-compiling)
%(if [ "#{@architecture}" = `uname -p` ]; then pkg install -nv -g 'output/#{target_dir}/#{pkg_name}' '#{project.name}@#{ips_version(project.version, project.release)}'; fi),
]
end
# Method to generate the files required to build a solaris package for the project
#
# @param workdir [String] working directory to stage the evaluated templates in
# @param name [String] name of the project
# @param binding [Binding] binding to use in evaluating the packaging templates
# @param project [Vanagon::Project] Vanagon::Project we are building for
def generate_packaging_artifacts(workdir, name, binding, project)
target_dir = File.join(workdir, 'packaging')
FileUtils.mkdir_p(target_dir)
erb_file(File.join(VANAGON_ROOT, "resources/solaris/11/p5m.erb"), File.join(target_dir, "#{name}.p5m"), false, { :binding => binding })
end
# Generate the scripts required to add a group to the package generated.
# This will also update the group if it has changed.
#
# @param user [Vanagon::Common::User] the user to reference for the group
# @return [String] the commands required to add a group to the system
def add_group(user)
"group groupname=#{user.group}"
end
# Helper to setup an IPS build repo on a target system
# http://docs.oracle.com/cd/E36784_01/html/E36802/gkkek.html
#
# @param uri [String] uri of the repository to add
# @param origin [String] origin of the repository
# @return [String] the command required to add an ips build repository
def add_repository(uri, origin)
"pkg set-publisher -G '*' -g #{uri} #{origin}"
end
# Generate the scripts required to add a user to the package generated.
# This will also update the user if it has changed.
#
# @param user [Vanagon::Common::User] the user to create
# @return [String] the commands required to add a user to the system
def add_user(user)
command = "user username=#{user.name}"
command << " group=#{user.group}" if user.group
command << " home-dir=#{user.homedir}" if user.homedir
if user.shell
command << " login-shell=#{user.shell}"
elsif user.is_system
command << " login-shell=/usr/bin/false"
end
command
end
# Method to derive the package name for the project
#
# @param project [Vanagon::Project] project to name
# @return [String] name of the solaris package for this project
def package_name(project)
"#{project.name}@#{ips_version(project.version, project.release)}.#{@architecture}.p5p"
end
# Method to transform a standard version into the format expected by IPS
# packages
#
# @param version [String] Standard package version
# @param release [String] Standard package release
# @return [String] version in IPS format
def ips_version(version, release)
version = version.gsub(/[a-zA-Z]/, '')
version = version.gsub(/(^-)|(-$)/, '')
# Here we strip leading 0 from version components but leave singular 0 on their own.
version = version.split('.').map(&:to_i).join('.')
"#{version},5.11-#{release}"
end
# Constructor. Sets up some defaults for the solaris 11 platform and calls the parent constructor
#
# @param name [String] name of the platform
# @return [Vanagon::Platform::Solaris] the solaris 11 derived platform with the given name
def initialize(name)
@name = name
@make = "/usr/bin/gmake"
@tar = "/usr/bin/gtar"
@patch = "/usr/bin/gpatch"
@sed = "/usr/gnu/bin/sed"
@num_cores = "/usr/bin/kstat cpu_info | /usr/bin/ggrep -E '[[:space:]]+core_id[[:space:]]' | wc -l"
super(name)
if @architecture == "sparc"
@platform_triple = "sparc-sun-solaris2.#{@os_version}"
elsif @architecture == "i386"
@platform_triple = "i386-pc-solaris2.#{@os_version}"
end
end
end
end
end