#!/bin/sh ###################################################################### # dpkg-unpack-build December 2005 # Horms horms@verge.net.au # # dpkg-unpack-build # Unpack a tarball or dsc file and build a debian package using # debuild(1) # Copyright (C) 2005 Horms # # 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, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # 02111-1307 USA # ###################################################################### set -e NAME="`basename $0`" usage () { echo "Usage: $NAME TARBALL|DSC [DEBBUILD_ARGS]" >&2 exit 1 } unpack_tar () { local TAR TARDIR TARFLAGS UNPACKDIR BUILDDIR TAR="$1" case $TAR in *gz) TARFLAGS="--gzip" ;; *bz2) TARFLAGS="--bzip2" ;; *) TARFLAGS="" ;; esac TARDIR=`tar "$TARFLAGS" -stf "$TAR" | head -1` if [ "$TARDIR" = "./" ]; then UNPACKDIR="$PWD/t" BUILDDIR="$PWD/t" else UNPACKDIR="$PWD" BUILDDIR="$PWD/$TARDIR" fi if ! tar "$TARFLAGS" -tf "$TAR" "${TARDIR}debian/" >& /dev/null; then echo "No debian/ directory in tarball" >&2 exit 1 fi if [ -e "$BUILDDIR" ]; then echo -n "$NAME: $BUILDDIR already exists, please move it " >&2 echo "out of the way or build by debuild in that directory" >&2 exit 1 fi tar "$TARFLAGS" -C "$UNPACKDIR" -xf "$TAR" echo "$BUILDDIR" } unpack_dsc () { local DSC BUILDDIR NAME_VERSION VERSION NAME DSC="$1" NAME_VERSION="${DSC%-*}" VERSION="${NAME_VERSION##*_}" NAME="${NAME_VERSION%_*}" BUILDDIR="$PWD/$NAME-$VERSION" if [ -e "$BUILDDIR" ]; then echo -n "$NAME: $BUILDDIR already exists, please move it " >&2 echo "out of the way or build by debuild in that directory" >&2 exit 1 fi dpkg-source -x "$DSC" > /dev/null echo "$BUILDDIR" } if [ $# == 0 ]; then usage fi FILE="$1" shift case $FILE in *dsc) BUILDDIR="`unpack_dsc $FILE`" ;; *) BUILDDIR="`unpack_tar $FILE`" ;; esac echo "Building in $BUILDDIR" (cd "$BUILDDIR" && debuild $@; ) rm -r "$BUILDDIR"