source: trunk/debathena/third/common/debathenificator.sh @ 24261

Revision 24261, 5.9 KB checked in by broder, 14 years ago (diff)
Teach the debathenificator about nobuild.
Line 
1# Interface: define variables name, daversionappend, and function
2# hack_package ().
3
4set -e
5
6: ${DEBATHENA_APT=/mit/debathena/apt}
7
8# Process arguments.
9dist_arch=$1; shift
10a=
11if [ "$1" = "-A" ]; then a=-A; shift; fi
12chroot=$dist_arch-sbuild
13
14if [ -z "$dist_arch" -o $# -eq 0 ]; then
15    echo 'No arguments!' >&2
16    exit 2
17fi
18
19dist=$(echo "$dist_arch" | sed 's/^\(.*\)-\([^-]*\)$/\1/')
20arch=$(echo "$dist_arch" | sed 's/^\(.*\)-\([^-]*\)$/\2/')
21: ${section=debathena-system}
22: ${daname=$name}
23: ${release=-proposed}
24: ${maint=Debathena Project <debathena@mit.edu>}
25. /mit/debathena/bin/debian-versions.sh
26tag=$(gettag $dist)
27
28if [ -e nobuild ] && fgrep -q "$dist" nobuild; then
29  echo "Skipping $dist since it is listed in ./nobuild."
30  exit
31fi
32
33# Create a chroot and define functions for using it.
34sid=$(schroot -b -c "$chroot")
35trap 'schroot -e -c "$sid"' EXIT
36sch() { schroot -r -c "$sid" -- "$@"; }           # Run in the chroot
37schq() { schroot -q -r -c "$sid" -- "$@"; }       # Run in the chroot quietly
38schr() { schroot -r -c "$sid" -u root -- "$@"; }  # Run in the chroot as root
39schr apt-get -qq -y update || exit 3
40
41quote() {
42  echo "$1" | sed 's/[^[:alnum:]]/\\&/g'
43}
44
45munge_sections () {
46    perl -0pe "s/^Section: /Section: $section\\//gm or die" -i debian/control
47}
48
49add_changelog () {
50    if [ -n "$dch_done" ]; then
51        dch "$@"
52    else
53        echo | dch -v"${daversion}" -D unstable "$@"
54        dch_done=1
55    fi
56}
57
58append_description () {
59    perl -0pe 'open THREE, "</dev/fd/3"; $x = <THREE>; s/(^Description:.*\n( .*\S.*\n)*)/$1$x/gm or die' -i debian/control 3<&0
60}
61
62add_build_depends () {
63    perl -0pe 's/^(Build-Depends:.*(?:\n[ \t].*)*)$/$1, '"$1"'/m or die' -i debian/control
64}
65
66add_debathena_provides () {
67    [ "$name" = "$daname" ]
68    perl -0pe 's/^(Package: (.*)\n(?:(?!Provides:).+\n)*)(?:Provides: (.*)\n((?:.+\n)*))?(?=\n|\z)/$1Provides: $3, debathena-$2\n$4/mg or die; s/^Provides: , /Provides: /mg' -i debian/control
69    add_changelog "Provide debathena-$name."
70}
71
72set_debathena_maintainer() {
73    orig_maint="$(python -c 'from rfc822 import Message, AddressList as al; f = open("debian/control"); m=Message(f); print al(m.get("Maintainer")) + al(m.get("XSBC-Original-Maintainer"))')"
74    sed -i -e '/^\(XSBC-Original-Maintainer\|Maintainer\)/d' debian/control
75    MAINT="$maint" ORIG_MAINT="$orig_maint" perl -0pe 's/\n\n/\nMaintainer: $ENV{MAINT}\nXSBC-Original-Maintainer: $ENV{ORIG_MAINT}\n\n/' -i debian/control
76    add_changelog "Update Maintainer to $maint."
77}
78
79rename_source () {
80    perl -pe "s{^Source: $name\$}{Source: $daname}" -i debian/control
81    add_changelog "Rename package to $daname."
82    perl -0pe "s/^$name/$daname/" -i debian/changelog
83}
84
85cmd_source () {
86    if [ "$a" != "-A" ]; then
87        echo "Not building source package for $dist_arch." >&2
88        return
89    fi
90    echo "Building source for $daname-$daversion on $dist_arch" >&2
91   
92    if ! [ -e "${name}_$version.dsc" ]; then
93        sch apt-get -d source "$name"
94    fi
95   
96    if ! [ -e "${daname}_$daversion.dsc" ]; then
97        (
98            tmpdir=$(mktemp -td "debathenify.$$.XXXXXXXXXX")
99            trap 'rm -rf "$tmpdir"' EXIT
100            origversion=$(echo "$version" | sed 's/-[^-]*$//')
101            cp -a "${name}_$origversion.orig.tar.gz" "$tmpdir/"
102            dscdir=$(pwd)
103            cd "$tmpdir/"
104            dpkg-source -x "$dscdir/${name}_$version.dsc" "$tmpdir/$name-$origversion"
105            cd "$tmpdir/$name-$origversion"
106            dch_done=
107            schr apt-get -q -y install python
108            hack_package
109            if [ "$name" != "$daname" ]; then
110                rename_source
111                cp -a "$tmpdir/${name}_$origversion.orig.tar.gz" "$tmpdir/${daname}_$origversion.orig.tar.gz"
112                cp -a "$tmpdir/${daname}_$origversion.orig.tar.gz" "$dscdir"
113            fi
114            [ -n "$dch_done" ]
115            schr apt-get -q -y install devscripts pbuilder
116            schr /usr/lib/pbuilder/pbuilder-satisfydepends
117            sch debuild -S -sa -us -uc -i -I.svn && cp -a "../${daname}_$daversion"* "$dscdir"
118        )
119        [ $? -eq 0 ] || exit 1
120       
121        if [ -n "$DA_CHECK_DIFFS" ]; then
122            interdiff -z "${name}_$version.diff.gz" "${daname}_$daversion.diff.gz" | \
123                enscript --color --language=ansi --highlight=diffu --output=- -q | \
124                less -R
125            echo -n "Press Enter to continue: " >&2
126            read dummy
127        fi
128    fi
129}
130
131cmd_binary () {
132    sbuildhack "$dist_arch" $a "${daname}_$daversion.dsc"
133}
134
135v () {
136    echo "$@"
137    "$@"
138}
139
140cmd_upload () {
141    REPREPRO="v reprepro -Vb $DEBATHENA_APT"
142    REPREPROI="$REPREPRO --ignore=wrongdistribution --ignore=missingfield"
143
144    if [ "$a" = "-A" ]; then
145        $REPREPROI include "${dist}${release}" "${daname}_${daversion}_source.changes"
146    fi
147    $REPREPROI include "${dist}${release}" "${daname}_${daversion}${tag}_${arch}.changes"
148}
149
150version=$(
151    sch apt-cache showsrc "$name" | \
152        sed -n 's/^Version: \(.*\)$/\1/ p' | (
153        version='~~~'
154        while read -r newversion; do
155            if [ $(expr "$newversion" : '.*debathena') = 0 ] && \
156                dpkg --compare-versions "$newversion" '>' "$version"; then
157                version=$newversion
158            fi
159        done
160        if [ "$version" = '~~~' ]; then
161            echo "No version of $name found." >&2
162            exit 1
163        fi
164        echo "$version"
165        )
166    )
167daversion=$version$daversionappend
168
169# Look for binary packages built from the named package with the right
170# version, and exit out if we find one (an architecture-specific one
171# if we weren't run with the -A flag).  We need to look for either a
172# Source: or a Package: header matching $name since there is no
173# Source: header for a package whose name matches its source.
174pkgfiles="$DEBATHENA_APT/dists/$dist/$section/binary-$arch/Packages.gz $DEBATHENA_APT/dists/${dist}-proposed/$section/binary-$arch/Packages.gz"
175if { zcat $pkgfiles | \
176    dpkg-awk -f - "Package:^$daname\$" "Version:^$(quote "$daversion$tag")\$" -- Architecture;
177    zcat $pkgfiles | \
178    dpkg-awk -f - "Source:^$daname\$" "Version:^$(quote "$daversion$tag")\$" -- Architecture; } \
179    | if [ "$a" = "-A" ]; then cat; else fgrep -vx 'Architecture: all'; fi \
180    | grep -q .; then
181    echo "$daname $daversion already exists for $dist_arch." >&2
182    exit 0
183fi
184
185for cmd; do
186    "cmd_$cmd"
187done
Note: See TracBrowser for help on using the repository browser.