From b54c0bc00f11887864205e7abc87e57371385a1d Mon Sep 17 00:00:00 2001
From: Jochen Schalanda <jochen@schalanda.name>
Date: Wed, 21 Jul 2010 16:19:41 +0300
Subject: [PATCH] * Added rake task pkg:deb to build a Debian package for Foreman with debuild.
 * Relaxed dependencies in Debian control file to hopefully allow installation
   of the foreman DEB under Ubuntu karmic, Ubuntu lucid, Debian lenny and
   Debian sid.
 * Fixed error in preinst script when Puppet is not installed and group
   'puppet' doesn't exist yet.

---
 extras/debian/control  |    2 +-
 extras/debian/postinst |    5 +++++
 extras/debian/preinst  |    5 -----
 lib/tasks/pkg.rake     |   19 +++++++++++++++++++
 4 files changed, 25 insertions(+), 6 deletions(-)
 create mode 100644 lib/tasks/pkg.rake

diff --git a/extras/debian/control b/extras/debian/control
index 788c6a8..1e62c55 100644
--- a/extras/debian/control
+++ b/extras/debian/control
@@ -9,7 +9,7 @@ Homepage: http://www.theforeman.org/
 Package: foreman
 Architecture: all
 Pre-Depends: debconf
-Depends: ruby, ruby1.8 (>= 1.8.7), rubygems, rubygems1.8, rake (>=0.8.3), libjs-prototype (>= 1.6.1), libjs-scriptaculous (>= 1.8.2), puppet (>=0.24.4), dbconfig-common, foreman-sqlite3 | foreman-mysql | foreman-pgsql, ${misc:Depends}
+Depends: ruby, ruby1.8 (>= 1.8.7), rubygems, rubygems1.8, rake (>=0.8.1), libjs-prototype (>= 1.6.0), libjs-scriptaculous (>= 1.8.1), puppet (>=0.24.4), dbconfig-common, foreman-sqlite3 | foreman-mysql | foreman-pgsql, ${misc:Depends}
 Recommends: libfcgi-ruby, libapache2-mod-passenger | libapache2-mod-fcgid
 Suggests: thin | mongrel | httpd-cgi
 Description: Systems management web interface
diff --git a/extras/debian/postinst b/extras/debian/postinst
index 78c85e9..cd2787d 100755
--- a/extras/debian/postinst
+++ b/extras/debian/postinst
@@ -9,6 +9,11 @@ set -e
 . /usr/share/debconf/confmodule
 . /usr/share/dbconfig-common/dpkg/postinst
 
+# Add the "foreman" user and group
+getent group foreman >/dev/null || groupadd -r foreman
+getent passwd foreman >/dev/null || \
+    useradd -r -g foreman -G puppet -d /usr/share/foreman -s /usr/sbin/nologin -c "Foreman" foreman
+
 chown -Rf foreman:foreman '/var/log/foreman'
 chown -Rf foreman:foreman '/var/cache/foreman'
 chown -Rf foreman:foreman '/var/lib/foreman'
diff --git a/extras/debian/preinst b/extras/debian/preinst
index d69a5be..b661f20 100755
--- a/extras/debian/preinst
+++ b/extras/debian/preinst
@@ -3,11 +3,6 @@
 set -e
 #set -x
 
-# Add the "foreman" user and group
-getent group foreman >/dev/null || groupadd -r foreman
-getent passwd foreman >/dev/null || \
-    useradd -r -g foreman -G puppet -d /usr/share/foreman -s /usr/sbin/nologin -c "Foreman" foreman
-
 #DEBHELPER#
 
 exit 0
diff --git a/lib/tasks/pkg.rake b/lib/tasks/pkg.rake
new file mode 100644
index 0000000..ec7559f
--- /dev/null
+++ b/lib/tasks/pkg.rake
@@ -0,0 +1,19 @@
+require 'fileutils'
+
+namespace :pkg do
+  desc 'Create DEB package with `debuild`.'
+  task :deb do
+    # copy 'debian' directory from 'extras' into main directory
+    FileUtils.cp_r 'extras/debian/', Rake.application.original_dir + '/debian'
+
+    # run 'debuild'
+    system 'debuild'
+
+    if $? == 0
+      # remove 'debian' directory
+      FileUtils.rm_r Rake.application.original_dir + '/debian', :force => true
+    else
+      abort 'Error while building the DEB package with `debuild`. Please check the output.'
+    end
+  end
+end
-- 
1.7.0.4

