Debian Codegraph @

debian/do-dfsg-tarball

raw
1 #!/bin/sh
2 set -e
3
4 if ! egrep -qv "^(#| *)$" debian/sourceless; then
5 echo "No sourceless files specified. Skipping the dfsg tarball creation."
6 exit 0
7 fi
8
9 while [ $1 ]; do
10 case $1 in
11 --upstream-version)
12 shift
13 VERSION=$1
14 ;;
15 *)
16 FILE=$1
17 esac
18 shift
19 done
20
21 if ! [ ${FILE} ]; then
22 echo "Usage: $0 [--upstream-version <version>] <filename>"
23 exit 0
24 fi
25
26 UPSTREAM_FILE=$(basename $(readlink -f ${FILE}))
27 NAME=$(dpkg-parsechangelog | sed -n 's/^Source: //p')
28 if [ $VERSION ]; then
29 DFSG_FILE=${NAME}_${VERSION}
30 else
31 DFSG_FILE=${FILE%%.orig*}
32 VERSION=${DFSG_FILE##*_}
33 fi
34
35 DFSG_NUM=$(dpkg-parsechangelog --show-field Changes --from ${VERSION} | grep ^${NAME} | head -n 1 | grep -o "${VERSION}.*-" | grep -E -o "dfsg[[:digit:]]*" | sed 's/dfsg//')
36 DFSG_FILE=${DFSG_FILE}+dfsg${DFSG_NUM}.orig.tar
37
38 EXT=${UPSTREAM_FILE##*.}
39 case ${EXT} in
40 "gz")
41 PACK="gzip -vf"
42 UNPACK="gunzip -vf"
43 ;;
44 "bz2")
45 PACK="bzip2 -vf"
46 UNPACK="bunzip2 -vf"
47 ;;
48 "lzma")
49 PACK="lzma -vf"
50 UNPACK="unzlma -vf"
51 ;;
52 "xz")
53 PACK="xz -vf"
54 UNPACK="unxz -vf"
55 ;;
56 *)
57 echo "Compression type not supported. Nothing to do..."
58 exit 0
59 esac
60
61 cp -i ../${UPSTREAM_FILE} ../${DFSG_FILE}.${EXT}
62
63 echo "Unpacking tarball... "
64 ${UNPACK} ../${DFSG_FILE}.${EXT}
65
66 OLDIFS=$IFS
67 IFS='
68 ' # don't remove this
69 SOURCELESS=$(grep -v ^# debian/sourceless)
70 for ITEM in $SOURCELESS; do
71 echo -n "Deleting '${ITEM}' from tarball... "
72 if ! tar --delete --wildcards -f ../${DFSG_FILE} "${ITEM}"; then
73 echo "WARNING! THE CONTENT OF THE DEBIAN/SOURCELESS MAY BE WRONG!"
74 else
75 echo "done"
76 fi
77 done
78 IFS=$OLDIFS
79
80 echo "Packing tarball... "
81 ${PACK} ../${DFSG_FILE}