Re: [PATCH] Add the possibility for building a debian package

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

 



On Sun, 21 Jul 2013 09:43:04 +0300
Roi Dayan <roid@xxxxxxxxxxxx> wrote:

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

Debian officially has tgt package? If so, the debian specific files
(e.g. rules) in this patch is identical to one in the official
package?

If not, what's your plan?

> Signed-off-by: Roi Dayan <roid@xxxxxxxxxxxx>
> ---
>  Makefile             |   14 +++--
>  debian/changelog     |    6 ++
>  debian/compat        |    1 +
>  debian/control       |   15 +++++
>  debian/copyright     |   14 +++++
>  debian/init          |  157 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  debian/rules         |   12 ++++
>  debian/source/format |    1 +
>  scripts/build-pkg.sh |  111 +++++++++++++++++++++++++++++++++++
>  scripts/build-rpm.sh |   72 -----------------------
>  10 files changed, 326 insertions(+), 77 deletions(-)
>  create mode 100644 debian/changelog
>  create mode 100644 debian/compat
>  create mode 100644 debian/control
>  create mode 100644 debian/copyright
>  create mode 100755 debian/init
>  create mode 100755 debian/rules
>  create mode 100644 debian/source/format
>  create mode 100755 scripts/build-pkg.sh
>  delete mode 100755 scripts/build-rpm.sh
> 
> diff --git a/Makefile b/Makefile
> index 0325d52..ebc26d8 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/debian/changelog b/debian/changelog
> new file mode 100644
> index 0000000..66534e9
> --- /dev/null
> +++ b/debian/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/debian/compat b/debian/compat
> new file mode 100644
> index 0000000..45a4fb7
> --- /dev/null
> +++ b/debian/compat
> @@ -0,0 +1 @@
> +8
> diff --git a/debian/control b/debian/control
> new file mode 100644
> index 0000000..6a854cf
> --- /dev/null
> +++ b/debian/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/debian/copyright b/debian/copyright
> new file mode 100644
> index 0000000..d2c5a83
> --- /dev/null
> +++ b/debian/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/debian/init b/debian/init
> new file mode 100755
> index 0000000..534c9a8
> --- /dev/null
> +++ b/debian/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/debian/rules b/debian/rules
> new file mode 100755
> index 0000000..3a06b3d
> --- /dev/null
> +++ b/debian/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/debian/source/format b/debian/source/format
> new file mode 100644
> index 0000000..163aaf8
> --- /dev/null
> +++ b/debian/source/format
> @@ -0,0 +1 @@
> +3.0 (quilt)
> diff --git a/scripts/build-pkg.sh b/scripts/build-pkg.sh
> new file mode 100755
> index 0000000..c724a16
> --- /dev/null
> +++ b/scripts/build-pkg.sh
> @@ -0,0 +1,111 @@
> +#!/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() {
> +    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
> +
> +    cp -a debian $_TOP/$name
> +    cd $_TOP/$name
> +    ls -l ..
> +    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."
> -- 
> 1.7.9.5
> 
> --
> 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
--
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