srpm task builds a srpm without deps so it can be built using mock or
some other formal build system tool.

rpm builds the binary and srouce rpm locally and of course will require
all of the rpmbuild lity set and whatever puppet requires to be built.

This is designed to work on any linux with rpm.  Tested on Fedora and
RHEL for full rpmbuild.

Debian based systems tested for srpm creation.

Signed-off-by: Michael Stahnke <[email protected]>
---
 tasks/rake/rpm.rake |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 80 insertions(+), 0 deletions(-)
 create mode 100644 tasks/rake/rpm.rake

diff --git a/tasks/rake/rpm.rake b/tasks/rake/rpm.rake
new file mode 100644
index 0000000..c4f4fc8
--- /dev/null
+++ b/tasks/rake/rpm.rake
@@ -0,0 +1,80 @@
+PWD=`pwd`.strip!
+RPM_DEFINES = " --define \"_specdir #{PWD}/rpmsetup/SPECS\" --define \"_rpmdir 
#{PWD}/rpmsetup/RPMS\" --define \"_sourcedir #{PWD}/rpmsetup/SOURCES\" --define 
\" _srcrpmdir #{PWD}/rpmsetup/SRPMS\" --define \"_builddir 
#{PWD}/rpmsetup/BUILD\""
+
+def rpmbuild_setup
+  # Ensure we're on linux and that rpm exists
+  unless File.exists?('/usr/bin/rpm') or RUBY_PLATFORM.downcase != "linux"
+    puts "Not an rpm based linux system"
+    exit 1
+  end
+  # Ensure rpmsetup is available
+  rpmbuil = %x{which rpmbuild}
+  unless $? == 0
+    puts "rpmbuild not found in $PATH."
+    exit 2
+  end
+  # See whether or not you'll need md5 signing or sha1 for rpms
+  sign = 'sha1'
+  if File.exists?('/etc/redhat-release')
+    majorver = %x{awk '{print $3}' /etc/redhat-release}
+    sign = 'md5' if  majorver.to_i < 6
+  else 
+    sign = 'sha1'
+  end
+  # Create directory structure for rpmbuild
+   FileUtils.mkdir_p "#{PWD}/rpmsetup"
+   dirs = [ 'BUILD', 'SPECS', 'SOURCES', 'RPMS', 'SRPMS' ]
+   dirs.each do |d|
+     FileUtils.mkdir_p "#{PWD}/rpmsetup/#{d}"
+   end
+   # Manage the spec file
+   spec =  PWD + '/conf/redhat/puppet.spec'
+   newspecfile = ""
+   File.open(spec, 'r').each do  |line|
+     if  line =~ /^Version/
+       newspecfile << "Version:     #{Puppet::PUPPETVERSION}\n"
+     # Remove the .sign as a required source because this is not an official 
release with a .sign file
+     elsif line =~ /^Source1/
+       next
+     else 
+       newspecfile << line 
+     end 
+   end
+   File.open(PWD + '/rpmsetup/SPECS/puppet.spec', 'w')  {|f| 
f.write(newspecfile) }
+
+   # Copy tarball
+   FileUtils.cp(Dir.glob(PWD + '/pkg/puppet-*.tar.gz'), PWD + 
'/rpmsetup/SOURCES') 
+   sign
+end
+
+desc "Create a SRPM"
+task :srpm => :puppetpackages  do
+  sign = rpmbuild_setup  
+  if sign == 'md5'
+    sh "rpmbuild-md5 #{RPM_DEFINES} -bs --nodeps 
#{PWD}/rpmsetup/SPECS/puppet.spec"
+  else
+    sh "rpmbuild #{RPM_DEFINES} -bs --nodeps #{PWD}/rpmsetup/SPECS/puppet.spec"
+  end
+  sh "mv -f #{PWD}/rpmsetup/SRPMS/* #{PWD}"
+  sh "rm -rf rpmsetup"
+  puts "SRPM written."
+end
+
+desc "Create a binary and source RPM."
+task :rpm => :puppetpackages do
+  sign = rpmbuild_setup  
+  if sign == 'md5'
+    sh "rpmbuild-md5 #{RPM_DEFINES} -ba  #{PWD}/rpmsetup/SPECS/puppet.spec"
+  else
+    sh "rpmbuild #{RPM_DEFINES} -ba  #{PWD}/rpmsetup/SPECS/puppet.spec"
+  end
+  sh "mv -f #{PWD}/rpmsetup/SRPMS/*rpm #{PWD}"
+  sh "mv -f #{PWD}/rpmsetup/RPMS/*/*rpm #{PWD}"
+  sh "rm -rf rpmsetup"
+  puts "SRPM and RPM written."
+end
+
+desc "Clean up pkg and rpm directories and files."
+task :clean => :clobber_package do 
+  sh "rm -rf rpmsetup puppet*rpm"
+end
-- 
1.7.2.3

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to