/
rpm.erb
99 lines (87 loc) · 2.62 KB
/
rpm.erb
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
Name: <%= name %>
Version: <%= version %>
<% if epoch -%>
Epoch: <%= epoch %>
<% end -%>
Release: <%= iteration or 1 %>
<%# use the first line of the description as the summary -%>
Summary: <%= description.split("\n").first %>
BuildArch: <%= architecture %>
AutoReqProv: no
Group: <%= category %>
<%#
TODO: [Jay] rpms require a license
let's detect it intelligently
-%>
License: <%= license %>
URL: <%= url or "http://nourlgiven.example.com/" %>
Source0: %{_sourcedir}/data.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
<% if !dependencies.empty? -%>
<%
properdeps = dependencies.collect do |d|
# Convert gem ~> X.Y.Z to '>= X.Y.Z' and < X.Y+1.0
if d =~ /\~>/
name, version = d.gsub(/[()~>]/, "").split(/ +/)[0..1]
nextversion = version.split(".").collect { |v| v.to_i }
l = nextversion.length
nextversion[l-2] += 1
nextversion[l-1] = 0
nextversion = nextversion.join(".")
["#{name} >= #{version}", "#{name} < #{nextversion}"]
elsif d =~ /\d [<>]=? [0-9.+] [<>]=? \d/
# Convert gem >= A.B.C <= X.Y.Z to '>= A.B.C' and '<= X.Y.Z'
puts d
# split out version numbers with their equality sign
name, lower_version, upper_version = d.scan(/([\w-]+) ([<>]=? [\d\.]+) ([<>]=? [\d\.]+)/)[0]
["#{name} #{lower_version}", "#{name} #{upper_version}"]
else
d
end
end
-%>Requires: <%= properdeps.join(", ") %>
<% end -%>
<% provides.each do |prov| -%>
Provides: <%= prov %>
<% end -%>
<% replaces.each do |repl| -%>
<%# The closes equivalent in RPM to "replaces" is "Obsoletes" -%>
Obsoletes: <%= repl %>
<% end -%>
<%# rpm rejects descriptions with blank lines (even between content), so hack
around it by replacing blank lines with ' .' -%>
%description
<%= description.gsub(/^\s*$/, " .") %>
%prep
# noop
%build
# some rpm implementations delete the build dir and then recreate it by
# default, for some reason. Whatever, let's work around it.
cd $RPM_BUILD_ROOT
tar -zxf %SOURCE0
%install
#noop
%clean
rm -rf $RPM_BUILD_ROOT
<% if scripts["pre-install"] -%>
%pre
<%= File.read(scripts["pre-install"]) %>
<% end -%>
<% if scripts["post-install"] -%>
%post
<%= File.read(scripts["post-install"]) %>
<% end -%>
<% if scripts["pre-uninstall"] -%>
%preun
<%= File.read(scripts["pre-uninstall"]) %>
<% end -%>
<% if scripts["post-uninstall"] -%>
%postun
<%= File.read(scripts["post-uninstall"]) %>
<% end -%>
%files
%defattr(-,root,root,-)
<%# Trim leading '.' from paths if they are './blah...' -%>
<%# Also ensure paths start with '/' -%>
<%= @source.paths.collect { |p| p.gsub(/^\.\//, "/").gsub(/^[^\/]/, "/\\0") }.join("\n") %>
%changelog