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

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