add linebreaks after wrap(), otherwise they are eaten
[pkg-perl/packages/pkg-perl-tools.git] / examples / check-build
1 #!/bin/bash
2
3 # Copyright: 2010-2014, gregor herrmann <gregoa@debian.org>
4 # Licensed under the same terms as Perl (Artistic | GPL-1+)
5
6 # to be run from source directory
7
8 # environment:
9 # - BUILDDIR, defaults to ".."
10 # - ARCH, defaults to arch of .changes file
11
12 BUILDDIR=${BUILDDIR:-".."}
13 if [ ! -d "$BUILDDIR" ] ; then
14         echo "E: Build directory \"$BUILDDIR\" does not exist."
15         echo "   Maybe you forgot to set the BUILDDIR variable?"
16         echo "   Exiting ..."
17         exit 1
18 fi
19
20 rm -rf $BUILDDIR/*obsolete*
21 rm -f  $BUILDDIR/*_source.changes
22 rm -f  $BUILDDIR/*.dsc.asc
23
24 PACKAGE=$(head -1 debian/changelog | perl -pe 's|^([^\s]+) .*|$1|')
25 VERSION=$(head -1 debian/changelog | perl -pe 's|^.+ \((?:\d:)?(.+)\) .*|$1|')
26
27 if [ -z "$ARCH" ] ; then
28         CHANGES=$(ls -1rt $BUILDDIR/${PACKAGE}_${VERSION}_*.changes | tail -n 1)
29         ARCH=$(basename ${CHANGES##$BUILDDIR/${PACKAGE}_${VERSION}_} .changes)
30 else
31         CHANGES=$BUILDDIR/${PACKAGE}_${VERSION}_${ARCH}.changes
32 fi
33
34 BUILD=$BUILDDIR/${PACKAGE}_${VERSION}_${ARCH}.build
35 DSC=$BUILDDIR/${PACKAGE}_${VERSION}.dsc
36
37 if [ ! -r "$CHANGES" -o ! -r "$DSC" ] ; then
38         echo "E: Can't read \"$CHANGES\" or \"$DSC\"."
39         echo "   Is BUILDDIR set correctly: \"$BUILDDIR\"?"
40         echo "   Exiting ..."
41         exit 1
42 fi
43
44 FORMAT=$(grep ^Format: $DSC | cut -f2 -d" ")
45
46 if [ -x /usr/bin/lintian ]; then
47         echo "lintian:"
48         echo "========"
49         #lintian -i -I --show-overrides --pedantic --color auto "$CHANGES"
50         #~/.lintianrc, lintian 2.5.1
51         lintian "$CHANGES"
52 fi
53
54 if [ -x /usr/bin/blhc -a -r "$BUILD" ] && ! egrep -q "^Architecture: all$" "$DSC" ; then
55         echo "blhc:"
56         echo "====="
57         blhc --buildd "$BUILD"
58 fi
59
60 if [ -x /usr/bin/duck ] ; then
61         echo "duck:"
62         echo "====="
63         duck
64 fi
65
66 read -n 1 -p "debc? y/N " DEBC
67 if [ "$DEBC" = "y" ]; then 
68         debc -a $ARCH $CHANGES | less
69 fi
70 echo
71
72 read -n 1 -p "piuparts? y/N " PIU
73 if [ "$PIU" = "y" ]; then
74         CHROOT=
75         [ -f /var/cache/pbuilder/base.tar.gz ] && CHROOT="--pbuilder"
76         [ -d /var/cache/pbuilder/base.cow ] && CHROOT="--existing-chroot /var/cache/pbuilder/base.cow"
77         sudo /usr/sbin/piuparts \
78                 $CHROOT -t ${TMPDIR:-/tmp} \
79                 --warn-on-others --skip-logrotatefiles-test --minimize \
80                 --log-file="${CHANGES}_piuparts.log" \
81                 "$CHANGES"
82 fi
83 echo
84
85 PKGVER=$(echo ${PACKAGE}-${VERSION} | perl -pe 's;^(.+)(?:-.+)$;$1;')
86 AUTOPATCH=debian/patches/debian-changes-${VERSION}
87 DIFFGZ=$BUILDDIR/${PACKAGE}_${VERSION}.diff.gz
88 DEBGZ=$BUILDDIR/${PACKAGE}_${VERSION}.debian.tar.gz
89 DEBBZ2=$BUILDDIR/${PACKAGE}_${VERSION}.debian.tar.bz2
90 DEBXZ=$BUILDDIR/${PACKAGE}_${VERSION}.debian.tar.xz
91 [ -e "$DEBGZ" ] || DEBGZ="$DEBBZ2"
92 [ -e "$DEBGZ" ] || DEBGZ="$DEBXZ"
93
94 if [ "$FORMAT" = "1.0" -a -e "$DIFFGZ" ] && zgrep -E "^\+\+\+ " "$DIFFGZ" | grep -q -v $PKGVER/debian; then
95         echo
96         echo "changes in .diff.gz outside debian/!"
97         read -n 1 -p "view .diff.gz? y/N " VIEWDIFFGZ
98         if [ "$VIEWDIFFGZ" = "y" ]; then
99                 filterdiff -z -x "$PKGVER/debian/*" "$DIFFGZ" | colordiff | /usr/bin/less -R
100         fi
101         echo
102         echo "maybe: mkdir -p debian/patches && diff2patches $DIFFGZ"
103         echo
104 elif [ "$FORMAT" = "3.0" -a -e "$DEBGZ" ] && tar tvf "$DEBGZ" | grep -q "$AUTOPATCH"; then
105         echo
106         echo "automatically created patch in .debian.tar.gz/.bz2/.xz!"
107         read -n 1 -p "view .debian.tar.gz/.bz2/.xz? y/N " VIEWDEBGZ
108         if [ "$VIEWDEBGZ" = "y" ]; then
109                 tar xf "$DEBGZ" "$AUTOPATCH" --to-stdout | colordiff | /usr/bin/less -R
110         fi
111         echo
112         echo "maybe: tar xf $DEBGZ $AUTOPATCH"
113         echo
114 else
115         read -n 1 -p "ready for upload? y/N " UPLOAD
116         if [ "$UPLOAD" = "y" ]; then
117                 echo
118                 cat "$CHANGES"
119                 echo
120                 echo dput $(readlink -f "$CHANGES")
121         fi
122         echo
123 fi