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
|
# File 'puppet/modules/wmflib/lib/puppet/parser/functions/ubuntu_version.rb', line 60
newfunction(:ubuntu_version, :type => :rvalue, :arity => 1) do |args|
return false unless lookupvar('lsbdistid') == 'Ubuntu'
unless args.length <= 2 && args.map(&:class).uniq == [String]
fail(ArgumentError, 'ubuntu_version() requires a string argument')
end
expr = args.join(' ')
unless expr =~ /^([<>=]*) *([\w\.]+)$/
fail(ArgumentError, "ubuntu_version(): invalid expression '#{expr}'")
end
current = lookupvar('lsbdistrelease')
operator = $1
other = ubuntu_releases[$2.downcase] || $2
unless /^[\d.]+$/ =~ other
fail(ArgumentError, "ubuntu_version(): unknown release '#{other}'")
end
cmp = Puppet::Util::Package.versioncmp(current, other)
case operator
when '', '=', '==' then cmp == 0
when '!=', '!' then cmp != 0
when '>' then cmp == 1
when '<' then cmp == -1
when '>=' then cmp >= 0
when '<=' then cmp <= 0
else fail(ArgumentError, "ubuntu_version(): unknown comparison operator '#{operator}'")
end
end
|