repack.sh: update mime-types
[pkg-perl/scripts.git] / examples / check-build
1 #!/bin/bash
3 # Copyright: 2010-2012, gregor herrmann <gregoa@debian.org>
4 # Licensed under the same terms as Perl (Artistic | GPL-1+)
6 # to be run from source directory
8 # environment:
9 # - BUILDDIR, defaults to ".."
10 # - ARCH, defaults to arch of .changes file
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
20 rm -rf $BUILDDIR/*obsolete*
21 rm -f  $BUILDDIR/*_source.changes
22 rm -f  $BUILDDIR/*.dsc.asc
24 PACKAGE=$(head -1 debian/changelog | perl -pe 's|^([^\s]+) .*|$1|')
25 VERSION=$(head -1 debian/changelog | perl -pe 's|^.+ \((?:\d:)?(.+)\) .*|$1|')
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
34 BUILD=$BUILDDIR/${PACKAGE}_${VERSION}_${ARCH}.build
35 DSC=$BUILDDIR/${PACKAGE}_${VERSION}.dsc
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
44 FORMAT=$(grep ^Format: $DSC | cut -f2 -d" ")
46 echo "lintian:"
47 echo "========"
48 #lintian -i -I --show-overrides --pedantic --color auto "$CHANGES"
49 #~/.lintianrc, lintian 2.5.1
50 lintian "$CHANGES"
52 if [ "$FORMAT" = "1.0" -a -x /usr/bin/linda ] ; then
53         echo "linda:"
54         echo "======"
55         linda -i -s -t E,W,I "$CHANGES"
56 fi
58 if [ -x /usr/bin/blhc -a -r "$BUILD" ] && ! egrep -q "^Architecture: all$" "$DSC" ; then
59         echo "blhc:"
60         echo "===="
61         blhc --buildd "$BUILD"
62 fi
64 read -n 1 -p "debc? y/N " DEBC
65 if [ "$DEBC" = "y" ]; then 
66         debc -a $ARCH $CHANGES | less
67 fi
68 echo
70 read -n 1 -p "piuparts? y/N " PIU
71 if [ "$PIU" = "y" ]; then
72         CHROOT=
73         [ -f /var/cache/pbuilder/base.tar.gz ] && CHROOT="--pbuilder"
74         [ -d /var/cache/pbuilder/base.cow ] && CHROOT="--existing-chroot /var/cache/pbuilder/base.cow"
75         sudo /usr/sbin/piuparts \
76                 $CHROOT -t ${TMPDIR:-/tmp} \
77                 --warn-on-others --skip-logrotatefiles-test --minimize \
78                 --log-file="${CHANGES}_piuparts.log" \
79                 "$CHANGES"
80 fi
81 echo
83 PKGVER=$(echo ${PACKAGE}-${VERSION} | perl -pe 's;^(.+)(?:-.+)$;$1;')
84 AUTOPATCH=debian/patches/debian-changes-${VERSION}
85 DIFFGZ=$BUILDDIR/${PACKAGE}_${VERSION}.diff.gz
86 DEBGZ=$BUILDDIR/${PACKAGE}_${VERSION}.debian.tar.gz
87 DEBBZ2=$BUILDDIR/${PACKAGE}_${VERSION}.debian.tar.bz2
88 DEBXZ=$BUILDDIR/${PACKAGE}_${VERSION}.debian.tar.xz
89 [ -e "$DEBGZ" ] || DEBGZ="$DEBBZ2"
90 [ -e "$DEBGZ" ] || DEBGZ="$DEBXZ"
92 if [ "$FORMAT" = "1.0" -a -e "$DIFFGZ" ] && zgrep -E "^\+\+\+ " "$DIFFGZ" | grep -q -v $PKGVER/debian; then
93         echo
94         echo "changes in .diff.gz outside debian/!"
95         read -n 1 -p "view .diff.gz? y/N " VIEWDIFFGZ
96         if [ "$VIEWDIFFGZ" = "y" ]; then
97                 filterdiff -z -x "$PKGVER/debian/*" "$DIFFGZ" | colordiff | /usr/bin/less -R
98         fi
99         echo
100         echo "maybe: mkdir -p debian/patches && diff2patches $DIFFGZ"
101         echo
102 elif [ "$FORMAT" = "3.0" -a -e "$DEBGZ" ] && tar tvf "$DEBGZ" | grep -q "$AUTOPATCH"; then
103         echo
104         echo "automatically created patch in .debian.tar.gz/.bz2/.xz!"
105         read -n 1 -p "view .debian.tar.gz/.bz2/.xz? y/N " VIEWDEBGZ
106         if [ "$VIEWDEBGZ" = "y" ]; then
107                 tar xf "$DEBGZ" "$AUTOPATCH" --to-stdout | colordiff | /usr/bin/less -R
108         fi
109         echo
110         echo "maybe: tar xf $DEBGZ $AUTOPATCH"
111         echo
112 else
113         read -n 1 -p "ready for upload? y/N " UPLOAD
114         if [ "$UPLOAD" = "y" ]; then
115                 echo
116                 cat "$CHANGES"
117                 echo
118                 echo dput $(readlink -f "$CHANGES")
119         fi
120         echo
121 fi