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

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