debian2dsc.sh 3.44 KB
Newer Older
Joachim Breitner's avatar
Joachim Breitner committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/bin/sh

set -e

until [ -z "$1" ]
do
    case "$1" in
        *)
            DIRS="$DIRS $1"
            ;;
    esac
    shift
done

if [ -z "$DIRS" ]
then 
Joachim Breitner's avatar
Joachim Breitner committed
17 18 19 20 21 22
   cat <<__END__
Usage: $0 [dir ...]

Expects directories containing the contents of the debian/ directory of a
Debian source package (i.e. control, changelog, watch, ...). Uses the watch
file to retrieve the upstream tarball (unless it already exists in the local
23
directory), creates a debian.tar.xz tarball from the given directory (ignoring
Joachim Breitner's avatar
Joachim Breitner committed
24 25 26
the ususal suspects like _darcs and *~) and creates a corresponding .dsc file;
all without unpacking the upstream tarball.
__END__
Joachim Breitner's avatar
Joachim Breitner committed
27 28 29 30 31 32 33 34 35 36 37 38
   exit 1
fi

for DIR in $DIRS
do
    if [ ! -e $DIR/control -o ! -e $DIR/changelog ]
    then
      echo "Did not find $DIR/control or $DIR/changelog."
      echo "Is the repository in the debian/-only format?"
      exit 1
    fi

39 40
    VERSION=`dpkg-parsechangelog -l$DIR/changelog -c1 -SVersion`
    PACKAGE=`dpkg-parsechangelog -l$DIR/changelog -c1 -SSource`
Joachim Breitner's avatar
Joachim Breitner committed
41 42 43
    UPSTREAM=`echo $VERSION | cut -d- -f1` # this could be improved
    if echo $UPSTREAM | fgrep -q : ; then
    	UPSTREAM=`echo $UPSTREAM | cut -d: -f2-`
Joachim Breitner's avatar
Joachim Breitner committed
44
    	VERSION=`echo $VERSION | cut -d: -f2-`
Joachim Breitner's avatar
Joachim Breitner committed
45 46 47 48 49 50 51 52 53 54 55 56 57
    fi
    TARBALL_GZ=${PACKAGE}_$UPSTREAM.orig.tar.gz
    TARBALL_BZ2=${PACKAGE}_$UPSTREAM.orig.tar.bz2
    TARBALL_XZ=${PACKAGE}_$UPSTREAM.orig.tar.xz
    # see 375138 for why this doesn't work as well as it could. Fall back to apt-get source
    # as a last resort.
    [ ! -e $TARBALL_GZ -a ! -e $TARBALL_BZ2 -a ! -e $TARBALL_XZ ] && \
       ( uscan \
        --rename \
        --force-download \
        --package "$PACKAGE" \
        --download \
        --watchfile $DIR/watch \
58
        --copyright-file $DIR/copyright \
Joachim Breitner's avatar
Joachim Breitner committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
        --download-version "$UPSTREAM" \
        --upstream-version "$UPSTREAM" \
        --destdir . \
	--rename ||
        apt-get source "$PACKAGE" --tar-only )

    if [ ! -e $TARBALL_GZ -a ! -e $TARBALL_BZ2 -a ! -e $TARBALL_XZ ]
    then
      echo "Couldn't download tarball with uscan or apt-get source. See above for errors"
      exit 1
    fi

    TARBALL=""

    if [ -e $TARBALL_GZ ]
    then
    	TARBALL="$TARBALL_GZ"
    else
    	if [ -e $TARBALL_XZ ]
	then
	    TARBALL="$TARBALL_XZ"
	else
	    if [ -e $TARBALL_BZ2 ]
	    then
		TARBALL="$TARBALL_BZ2"
	    else
		echo "Unreachable code"
		exit 1
	    fi
	fi
    fi
    
91
    DEBIAN_TARBALL=${PACKAGE}_${VERSION}.debian.tar.xz
92 93
    # -I line taken from "man dpkg-source"
    tar --create \
94
	--xz \
95
	--transform s,^.,debian, \
Joachim Breitner's avatar
Joachim Breitner committed
96
	--force-local \
97 98 99 100
	--file $DEBIAN_TARBALL \
	--directory $DIR \
	"--exclude=*.a" "--exclude=*.la" "--exclude=*.o" "--exclude=*.so" "--exclude=.*.sw?" "--exclude=*/*~" "--exclude=,,*" "--exclude=.[#~]*" "--exclude=.arch-ids" "--exclude=.arch-inventory" "--exclude=.be" "--exclude=.bzr" "--exclude=.bzr.backup" "--exclude=.bzr.tags" "--exclude=.bzrignore" "--exclude=.cvsignore" "--exclude=.deps" "--exclude=.git" "--exclude=.gitattributes" "--exclude=.gitignore" "--exclude=.gitmodules" "--exclude=.hg" "--exclude=.hgignore" "--exclude=.hgsigs" "--exclude=.hgtags" "--exclude=.shelf" "--exclude=.svn" "--exclude=CVS" "--exclude=DEADJOE" "--exclude=RCS" "--exclude=_MTN" "--exclude=_darcs" "--exclude={arch}" \
	.
Joachim Breitner's avatar
Joachim Breitner committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
    dpkg-source \
	-c$DIR/control -l$DIR/changelog \
	--format="3.0 (custom)" --target-format="3.0 (quilt)" \
	-b / \
	$DEBIAN_TARBALL \
	$TARBALL

    DSC=${PACKAGE}_${VERSION}.dsc
    if [ -e $DSC ]
    then
	echo "Successfully created $DSC."
    else
	echo "Failed to create $DSC."
    fi
done