Skip to content

Commit

Permalink
Merge pull request jordansissel#208 from jacaetevha/master
Browse files Browse the repository at this point in the history
RPM user and group setting for %files section
  • Loading branch information
jordansissel committed May 23, 2012
2 parents fc3f5d7 + c1c8d32 commit b82540f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/fpm/package/rpm.rb
Expand Up @@ -29,6 +29,17 @@ class FPM::Package::RPM < FPM::Package
"bzip2" => "w9.bzdio"
} unless defined?(COMPRESSION_MAP)

option "--user", "USER",
"Set the user to USER in the %files section.",
:default => 'root' do |value|
value
end

option "--group", "GROUP",
"Set the group to GROUP in the %files section.",
:default => 'root' do |value|
value
end

option "--rpmbuild-define", "DEFINITION",
"Pass a --define argument to rpmbuild." do |define|
Expand Down
42 changes: 42 additions & 0 deletions spec/fpm/package/rpm_spec.rb
Expand Up @@ -57,6 +57,48 @@
end
end

describe "#templating" do
context "default user and group" do
before :all do

# set the list of files for this RPM
def subject.files; [__FILE__]; end
def subject.rpmspec; @rpmspec; end
def subject.render_template; @rpmspec = template("rpm.erb").result(binding); end
subject.render_template
end

after :all do
subject.cleanup
end

it "should set the user and group of each file in the RPM" do
subject.rpmspec.should include('%defattr(-,root,root,-')
end
end # context

context "non-default user and group" do
before :all do
subject.attributes[:rpm_user] = "some_user"
subject.attributes[:rpm_group] = "some_group"

# set the list of files for this RPM
def subject.files; [__FILE__]; end
def subject.rpmspec; @rpmspec; end
def subject.render_template; @rpmspec = template("rpm.erb").result(binding); end
subject.render_template
end

after :all do
subject.cleanup
end

it "should set the user and group of each file in the RPM" do
subject.rpmspec.should include('%defattr(-,some_user,some_group,-')
end
end # context
end

describe "#output", :if => program_in_path?("rpmbuild") do
context "package attributes" do
before :all do
Expand Down
2 changes: 1 addition & 1 deletion templates/rpm.erb
Expand Up @@ -96,7 +96,7 @@ fi
<% end -%>
%files
%defattr(-,root,root,-)
%defattr(-,<%= attributes[:rpm_user] %>,<%= attributes[:rpm_group] %>,-)
<%# Output config files and then regular files. -%>
<% config_files.each do |path| -%>
%config(noreplace) <%= path %>
Expand Down

0 comments on commit b82540f

Please sign in to comment.