-
Notifications
You must be signed in to change notification settings - Fork 437
/
pkg.rb
69 lines (60 loc) · 2 KB
/
pkg.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
require 'travis/build/addons/base'
require 'shellwords'
module Travis
module Build
class Addons
class Pkg < Base
SUPPORTED_OPERATING_SYSTEMS = %w[
freebsd
].freeze
def before_prepare?
SUPPORTED_OPERATING_SYSTEMS.any? do |os_match|
data[:config][:os].to_s == os_match
end
end
def before_prepare
return if config_pkg.empty?
sh.newline
sh.fold('pkg') do
install_pkg
end
sh.newline
end
def before_configure?
config
end
def before_configure
sh.echo "Configuring default pkg options", ansi: :yellow
tmp_dest = "${TRAVIS_TMPDIR}/99-travis-pkg-conf"
sh.file tmp_dest, <<~PKG_CONF
ASSUME_ALWAYS_YES=YES
FETCH_RETRY=5
FETCH_TIMEOUT=30
PKG_CONF
sh.cmd %Q{su -m root -c "mv #{tmp_dest} ${TRAVIS_ROOT}/usr/local/etc/pkg.conf"}
if config[:branch] && config[:branch].to_s.downcase != 'quarterly'
sed_find = 'pkg+http://pkg.FreeBSD.org/\([^/]*\)/quarterly'
sed_replace = 'pkg+http://pkg.FreeBSD.org/\1/' + config[:branch]
sed_cmd = %Q{sed -i'' -e 's,#{sed_find},#{sed_replace},' /etc/pkg/FreeBSD.conf}
sh.cmd %Q{su -m root -c "#{sed_cmd}"}
end
end
def config
@config ||= Hash(super)
end
def install_pkg
sh.echo "Installing #{config_pkg.count} packages", ansi: :yellow
packages = config_pkg.map{|v| Shellwords.escape(v)}.join(' ')
sh.cmd "su -m root -c 'pkg install #{packages}'", echo: true, timing: true, assert: true
end
def config_pkg
@config_pkg ||= Array(config[:packages]).flatten.compact
rescue TypeError => e
if e.message =~ /no implicit conversion of Symbol into Integer/
raise Travis::Build::PkgConfigError.new
end
end
end
end
end
end