[PATCH V1] Add the possibility for building a debian package

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Added support files needed for building the package.
Updated the rpm build script to build also deb package.

Signed-off-by: Roi Dayan <roid@xxxxxxxxxxxx>
---

Hi Tomo,

I updated the commit as suggested.
The debian files are in scripts/deb and shouldn't interfere anyone.

Thanks,
Roi


 Makefile                  |   14 +++--
 scripts/build-pkg.sh      |  115 +++++++++++++++++++++++++++++++++
 scripts/build-rpm.sh      |   72 ---------------------
 scripts/deb/changelog     |    6 ++
 scripts/deb/compat        |    1 +
 scripts/deb/control       |   15 ++++
 scripts/deb/copyright     |   14 ++++
 scripts/deb/init          |  157 +++++++++++++++++++++++++++++++++++++++++++++
 scripts/deb/rules         |   12 ++++
 scripts/deb/source/format |    1 +
 10 files changed, 330 insertions(+), 77 deletions(-)
 create mode 100755 scripts/build-pkg.sh
 delete mode 100755 scripts/build-rpm.sh
 create mode 100644 scripts/deb/changelog
 create mode 100644 scripts/deb/compat
 create mode 100644 scripts/deb/control
 create mode 100644 scripts/deb/copyright
 create mode 100755 scripts/deb/init
 create mode 100755 scripts/deb/rules
 create mode 100644 scripts/deb/source/format

diff --git a/Makefile b/Makefile
index 95af23a..4913f1f 100644
--- a/Makefile
+++ b/Makefile
@@ -66,14 +66,18 @@ install: install-programs install-doc install-conf install-scripts
 
 .PHONY: rpm
 rpm:
-	@./scripts/build-rpm.sh
+	@./scripts/build-pkg.sh rpm
 
-.PHONY: clean-rpm
-clean-rpm:
-	rm -fr rpmtop
+.PHONY: deb
+deb:
+	@./scripts/build-pkg.sh deb
 
 .PHONY: clean
-clean: clean-programs clean-doc clean-conf clean-scripts clean-rpm
+clean-pkg:
+	rm -fr pkg
+
+.PHONY: clean
+clean: clean-programs clean-doc clean-conf clean-scripts clean-pkg
 
 .PHONY:check
 check: ARCH=$(shell sh script/checkarch.sh)
diff --git a/scripts/build-pkg.sh b/scripts/build-pkg.sh
new file mode 100755
index 0000000..c6776c7
--- /dev/null
+++ b/scripts/build-pkg.sh
@@ -0,0 +1,115 @@
+#!/bin/bash
+#
+# Copyright (C) 2012 Roi Dayan <roid@xxxxxxxxxxxx>
+#
+
+TARGET=$1
+
+usage() {
+    echo "Usage: `basename $0` [rpm|deb]"
+    exit 1
+}
+
+if [ "$TARGET" != "rpm" -a "$TARGET" != "deb" ]; then
+    usage
+fi
+
+DIR=$(cd `dirname $0`; pwd)
+BASE=`cd $DIR/.. ; pwd`
+_TOP="$BASE/pkg"
+SPEC="tgtd.spec"
+LOG=/tmp/`basename $0`-$$.log
+
+# get branch name
+branch=`git branch | grep '^*' | sed 's/^..\(.*\)/\1/'`
+# get version tag
+version=`git describe --tags --abbrev=0 | sed "s/^v//g"`
+# release is number of commits since the version tag
+release=`git describe --tags | cut -d- -f2 | tr - _`
+
+if [ "$version" = "$release" ]; then
+    # no commits and release can't be empty
+    release=0
+fi
+
+if [ "$branch" != "master" ]; then
+    # if not under master branch include hash tag
+    hash=`git rev-parse HEAD | cut -c 1-6`
+    release="$release.$hash"
+fi
+
+echo "Building version: $version-$release"
+
+
+cp_src() {
+    local dest=$1
+    cp -a conf $dest
+    cp -a doc $dest
+    cp -a scripts $dest
+    cp -a usr $dest
+    cp -a README $dest
+    cp -a Makefile $dest
+}
+
+check() {
+    local rc=$?
+    local msg="$1"
+    if (( rc )) ; then
+        echo $msg
+        exit 1
+    fi
+}
+
+build_rpm() {
+    name=scsi-target-utils-$version-$release
+    TARBALL=$name.tgz
+    SRPM=$_TOP/SRPMS/$name.src.rpm
+
+    echo "Creating rpm build dirs under $_TOP"
+    mkdir -p $_TOP/{RPMS,SRPMS,SOURCES,BUILD,SPECS,tmp}
+    mkdir -p $_TOP/tmp/$name
+
+    cp_src $_TOP/tmp/$name
+
+    echo "Creating tgz $TARBALL"
+    tar -czf $_TOP/SOURCES/$TARBALL -C $_TOP/tmp $name
+
+    echo "Creating rpm"
+    sed -r "s/^Version:(\s*).*/Version:\1$version/;s/^Release:(\s*).*/Release:\1$release/" scripts/$SPEC > $_TOP/SPECS/$SPEC
+    rpmbuild -bs --define="_topdir $_TOP" $_TOP/SPECS/$SPEC
+    check "Failed to create source rpm."
+
+    rpmbuild -bb --define="_topdir $_TOP" $_TOP/SPECS/$SPEC > $LOG 2>&1
+    check "Failed to build rpm. LOG: $LOG"
+    # display created rpm files
+    grep ^Wrote $LOG
+
+    rm -fr $LOG
+}
+
+build_deb() {
+    if ! which debuild >/dev/null 2>&1 ; then
+        echo "Missing debuild. Please install devscripts package."
+        exit 1
+    fi
+    name=tgt_$version
+    TARBALL=$name.orig.tar.gz
+
+    echo "Building under $_TOP/$name"
+    mkdir -p $_TOP/$name
+    cp_src $_TOP/$name
+    tar -czf $_TOP/$TARBALL -C $_TOP $name
+
+    mkdir -p $_TOP/$name/debian
+    cp -a scripts/deb/* $_TOP/$name/debian
+    cd $_TOP/$name
+    sed -i -r "s/^tgt \(([0-9.-]+)\) (.*)/tgt \($version-$release\) \2/" debian/changelog
+    debuild -uc -us
+    check "Failed building deb package."
+    cd ../..
+    ls -l $_TOP/$name*.deb
+}
+
+cd $BASE
+build_$TARGET
+echo "Done."
diff --git a/scripts/build-rpm.sh b/scripts/build-rpm.sh
deleted file mode 100755
index 36ef364..0000000
--- a/scripts/build-rpm.sh
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/bin/sh
-#
-# Copyright (C) 2012 Roi Dayan <roid@xxxxxxxxxxxx>
-#
-
-
-DIR=$(cd `dirname $0`; pwd)
-BASE=`cd $DIR/.. ; pwd`
-RPMTOP="$BASE/rpmtop"
-SPEC="tgtd.spec"
-LOG=/tmp/`basename $0`-$$.log
-
-# get branch name
-branch=`git branch | grep '^*' | sed 's/^..\(.*\)/\1/'`
-# get version tag
-version=`git describe --tags --abbrev=0 | sed "s/^v//g"`
-# release is number of commits since the version tag
-release=`git describe --tags | cut -d- -f2 | tr - _`
-
-if [ "$version" = "$release" ]; then
-    # no commits and release can't be empty
-    release=0
-fi
-
-if [ "$branch" != "master" ]; then
-    # if not under master branch include hash tag
-    hash=`git rev-parse HEAD | cut -c 1-6`
-    release+=".$hash"
-fi
-
-echo "Building version: $version-$release"
-
-name=scsi-target-utils-$version-$release
-TARBALL=$name.tgz
-SRPM=$RPMTOP/SRPMS/$name.src.rpm
-
-echo "Creating rpm build dirs under $RPMTOP"
-mkdir -p $RPMTOP/{RPMS,SRPMS,SOURCES,BUILD,SPECS,tmp}
-mkdir -p $RPMTOP/tmp/$name
-
-echo "Creating tgz $TARBALL"
-cd $BASE
-cp -a conf $RPMTOP/tmp/$name
-cp -a doc $RPMTOP/tmp/$name
-cp -a scripts $RPMTOP/tmp/$name
-cp -a usr $RPMTOP/tmp/$name
-cp -a README $RPMTOP/tmp/$name
-cp -a Makefile $RPMTOP/tmp/$name
-
-tar -czf $RPMTOP/SOURCES/$TARBALL -C $RPMTOP/tmp $name
-
-check() {
-    local rc=$?
-    local msg="$1"
-    if (( rc )); then
-        echo $msg
-        exit 1
-    fi
-}
-
-echo "Creating rpm"
-sed -r "s/^Version:(\s*).*/Version:\1$version/;s/^Release:(\s*).*/Release:\1$release/" scripts/$SPEC > $RPMTOP/SPECS/$SPEC
-rpmbuild -bs --define="_topdir $RPMTOP" $RPMTOP/SPECS/$SPEC
-check "Failed to create source rpm."
-
-rpmbuild -bb --define="_topdir $RPMTOP" $RPMTOP/SPECS/$SPEC > $LOG 2>&1
-check "Failed to build rpm. LOG: $LOG"
-# display created rpm files
-grep ^Wrote $LOG
-
-rm -fr $LOG
-echo "Done."
diff --git a/scripts/deb/changelog b/scripts/deb/changelog
new file mode 100644
index 0000000..66534e9
--- /dev/null
+++ b/scripts/deb/changelog
@@ -0,0 +1,6 @@
+tgt (1.0.37-1) UNRELEASED; urgency=low
+  * Non-maintainer upload.
+  *
+  * Initial release. (Closes: #XXXXXX)
+
+ -- Roi Dayan <roid@xxxxxxxxxxxx>  Thu, 18 Jul 2013 09:31:00 +0300
diff --git a/scripts/deb/compat b/scripts/deb/compat
new file mode 100644
index 0000000..45a4fb7
--- /dev/null
+++ b/scripts/deb/compat
@@ -0,0 +1 @@
+8
diff --git a/scripts/deb/control b/scripts/deb/control
new file mode 100644
index 0000000..6a854cf
--- /dev/null
+++ b/scripts/deb/control
@@ -0,0 +1,15 @@
+Source: tgt
+Maintainer: FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx>
+Section: net
+Priority: optional
+Standards-Version: 3.9.1
+Build-Depends: debhelper (>= 8), dpkg-dev (>= 1.13.19),
+    librdmacm-dev, libibverbs-dev, xsltproc
+Homepage: http://stgt.berlios.de/
+
+Package: tgt
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, librdmacm1, libconfig-general-perl
+Description: The SCSI target daemon and utility programs
+ The SCSI target package contains the daemon and tools to setup a SCSI targets.
+ Currently, software iSCSI targets are supported.
diff --git a/scripts/deb/copyright b/scripts/deb/copyright
new file mode 100644
index 0000000..d2c5a83
--- /dev/null
+++ b/scripts/deb/copyright
@@ -0,0 +1,14 @@
+License:
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or (at
+    your option) any later version.
+
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, see http://www.gnu.org/licenses/.
diff --git a/scripts/deb/init b/scripts/deb/init
new file mode 100755
index 0000000..534c9a8
--- /dev/null
+++ b/scripts/deb/init
@@ -0,0 +1,157 @@
+#!/bin/sh
+# This is an example init.d script for stopping/starting/reconfiguring tgtd.
+
+### BEGIN INIT INFO
+# Provides: tgtd
+# Required-Start: $network
+# Required-Stop: $network
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Starts and stops the generic storage target daemon
+# Description: tgtd provides the SCSI and software transport target state machine daemon.
+### END INIT INFO
+
+TGTD_CONFIG=/etc/tgt/targets.conf
+
+TASK=$1
+
+start()
+{
+	echo "Starting target framework daemon"
+	# Start tgtd first.
+	tgtd &>/dev/null
+	RETVAL=$?
+	if [ "$RETVAL" -ne 0 ] ; then
+	    echo "Could not start tgtd (is tgtd already running?)"
+	    exit 1
+	fi
+        sleep 1
+	# Put tgtd into "offline" state until all the targets are configured.
+	# We don't want initiators to (re)connect and fail the connection
+	# if it's not ready.
+	tgtadm --op update --mode sys --name State -v offline
+	# Configure the targets.
+	tgt-admin -e -c $TGTD_CONFIG
+	# Put tgtd into "ready" state.
+	tgtadm --op update --mode sys --name State -v ready
+}
+
+stop()
+{
+	if [ -n "$RUNLEVEL" ] && [ "$RUNLEVEL" -eq 0 -o "$RUNLEVEL" -eq 6 ] ; then
+	    forcedstop
+	fi
+	echo "Stopping target framework daemon"
+	# Remove all targets. It only removes targets which are not in use.
+	tgt-admin --update ALL -c /dev/null &>/dev/null
+	# tgtd will exit if all targets were removed
+	tgtadm --op delete --mode system &>/dev/null
+	RETVAL=$?
+	if [ "$RETVAL" -eq 107 ] ; then
+	    echo "tgtd is not running"
+	    [ "$TASK" != "restart" ] && exit 1
+	elif [ "$RETVAL" -ne 0 ] ; then
+	    echo "Some initiators are still connected - could not stop tgtd"
+	    exit 2
+	fi
+	echo -n
+}
+
+forcedstop()
+{
+	# NOTE: Forced shutdown of the iscsi target may cause data corruption
+	# for initiators that are connected.
+	echo "Force-stopping target framework daemon"
+	# Offline everything first. May be needed if we're rebooting, but
+	# expect the initiators to reconnect cleanly when we boot again
+	# (i.e. we don't want them to reconnect to a tgtd which is still
+	# working, but the target is gone).
+	tgtadm --op update --mode sys --name State -v offline &>/dev/null
+	RETVAL=$?
+	if [ "$RETVAL" -eq 107 ] ; then
+	    echo "tgtd is not running"
+	    [ "$TASK" != "restart" ] && exit 1
+	else
+	    tgt-admin --offline ALL
+	    # Remove all targets, even if they are still in use.
+	    tgt-admin --update ALL -c /dev/null -f
+	    # It will shut down tgtd only after all targets were removed.
+	    tgtadm --op delete --mode system
+	    RETVAL=$?
+	    if [ "$RETVAL" -ne 0 ] ; then
+		echo "Failed to shutdown tgtd"
+		exit 1
+	    fi
+	fi
+	echo -n
+}
+
+reload()
+{
+	echo "Updating target framework daemon configuration"
+	# Update configuration for targets. Only targets which
+	# are not in use will be updated.
+	tgt-admin --update ALL -c $TGTD_CONFIG &>/dev/null
+	RETVAL=$?
+	if [ "$RETVAL" -eq 107 ] ; then
+	    echo "tgtd is not running"
+	    exit 1
+	fi
+}
+
+forcedreload()
+{
+	echo "Force-updating target framework daemon configuration"
+	# Update configuration for targets, even those in use.
+	tgt-admin --update ALL -f -c $TGTD_CONFIG &>/dev/null
+	RETVAL=$?
+	if [ "$RETVAL" -eq 107 ] ; then
+	    echo "tgtd is not running"
+	    exit 1
+	fi
+}
+
+status()
+{
+	# Don't name this script "tgtd"...
+	TGTD_PROC=$(ps -C tgtd | grep -c tgtd)
+	if [ "$TGTD_PROC" -eq 2 ] ; then
+	    echo "tgtd is running. Run 'tgt-admin -s' to see detailed target info."
+	else
+	    echo "tgtd is NOT running."
+	fi
+}
+
+case $1 in
+	start)
+		start
+		;;
+	stop)
+		stop
+		;;
+	forcedstop)
+		forcedstop
+		;;
+	restart)
+		TASK=restart
+		stop && start
+		;;
+	forcedrestart)
+		TASK=restart
+		forcedstop && start
+		;;
+	reload)
+		reload
+		;;
+	force-reload)
+		forcedreload
+		;;
+	status)
+		status
+		;;
+	*)
+		echo "Usage: $0 {start|stop|forcedstop|restart|forcedrestart|reload|forcedreload|status}"
+		exit 2
+		;;
+esac
+
diff --git a/scripts/deb/rules b/scripts/deb/rules
new file mode 100755
index 0000000..3a06b3d
--- /dev/null
+++ b/scripts/deb/rules
@@ -0,0 +1,12 @@
+#!/usr/bin/make -f
+
+DEB_MAKE_ENVVARS += ISCSI_RDMA=1
+
+%:
+	dh $@
+
+override_dh_auto_build:
+	dh_auto_build -- $(DEB_MAKE_ENVVARS)
+
+override_dh_auto_install:
+	dh_auto_install -- $(DEB_MAKE_ENVVARS)
diff --git a/scripts/deb/source/format b/scripts/deb/source/format
new file mode 100644
index 0000000..163aaf8
--- /dev/null
+++ b/scripts/deb/source/format
@@ -0,0 +1 @@
+3.0 (quilt)
-- 
1.7.8.2

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux