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.
RevLine 
[22698]1# Interface: define variables name, daversionappend, and function
2# hack_package ().
3
4set -e
5
[22763]6: ${DEBATHENA_APT=/mit/debathena/apt}
[24683]7: ${DEBATHENA_RELEASE=production}
[24680]8export DEBATHENA_APT
9export DEBATHENA_RELEASE
[22763]10
[23041]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/')
[23078]24: ${section=debathena-system}
[23732]25: ${daname=$name}
[24211]26: ${maint=Debathena Project <debathena@mit.edu>}
[23759]27. /mit/debathena/bin/debian-versions.sh
28tag=$(gettag $dist)
[23041]29
[24261]30if [ -e nobuild ] && fgrep -q "$dist" nobuild; then
31  echo "Skipping $dist since it is listed in ./nobuild."
32  exit
33fi
34
[23041]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
[23117]41schr apt-get -qq -y update || exit 3
[23041]42
[23626]43quote() {
44  echo "$1" | sed 's/[^[:alnum:]]/\\&/g'
45}
46
[22698]47munge_sections () {
[23066]48    perl -0pe "s/^Section: /Section: $section\\//gm or die" -i debian/control
[22698]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 () {
[22990]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
[22698]62}
63
64add_build_depends () {
[23217]65    perl -0pe 's/^(Build-Depends:.*(?:\n[ \t].*)*)$/$1, '"$1"'/m or die' -i debian/control
[22698]66}
67
68add_debathena_provides () {
[23732]69    [ "$name" = "$daname" ]
[22698]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
[24211]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
[23732]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
[22698]87cmd_source () {
88    if [ "$a" != "-A" ]; then
[22791]89        echo "Not building source package for $dist_arch." >&2
90        return
[22698]91    fi
[23732]92    echo "Building source for $daname-$daversion on $dist_arch" >&2
[22698]93   
94    if ! [ -e "${name}_$version.dsc" ]; then
[23041]95        sch apt-get -d source "$name"
[22698]96    fi
97   
[23732]98    if ! [ -e "${daname}_$daversion.dsc" ]; then
[22698]99        (
[23041]100            tmpdir=$(mktemp -td "debathenify.$$.XXXXXXXXXX")
101            trap 'rm -rf "$tmpdir"' EXIT
102            origversion=$(echo "$version" | sed 's/-[^-]*$//')
[22772]103            cp -a "${name}_$origversion.orig.tar.gz" "$tmpdir/"
[22995]104            dscdir=$(pwd)
105            cd "$tmpdir/"
106            dpkg-source -x "$dscdir/${name}_$version.dsc" "$tmpdir/$name-$origversion"
[22698]107            cd "$tmpdir/$name-$origversion"
108            dch_done=
[24211]109            schr apt-get -q -y install python
[22698]110            hack_package
[23732]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
[22698]116            [ -n "$dch_done" ]
[23041]117            schr apt-get -q -y install devscripts pbuilder
118            schr /usr/lib/pbuilder/pbuilder-satisfydepends
[23732]119            sch debuild -S -sa -us -uc -i -I.svn && cp -a "../${daname}_$daversion"* "$dscdir"
[22698]120        )
[23041]121        [ $? -eq 0 ] || exit 1
[22698]122       
123        if [ -n "$DA_CHECK_DIFFS" ]; then
[23732]124            interdiff -z "${name}_$version.diff.gz" "${daname}_$daversion.diff.gz" | \
[22698]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 () {
[23732]134    sbuildhack "$dist_arch" $a "${daname}_$daversion.dsc"
[22698]135}
136
137v () {
138    echo "$@"
139    "$@"
140}
141
142cmd_upload () {
143    if [ "$a" = "-A" ]; then
[24680]144        v dareprepro include "${dist}${DEBATHENA_RELEASE}" "${daname}_${daversion}_source.changes"
[22698]145    fi
[24680]146    v dareprepro include "${dist}${DEBATHENA_RELEASE}" "${daname}_${daversion}${tag}_${arch}.changes"
[22698]147}
148
149version=$(
[23041]150    sch apt-cache showsrc "$name" | \
[22698]151        sed -n 's/^Version: \(.*\)$/\1/ p' | (
152        version='~~~'
153        while read -r newversion; do
[23073]154            if [ $(expr "$newversion" : '.*debathena') = 0 ] && \
[23071]155                dpkg --compare-versions "$newversion" '>' "$version"; then
[22698]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
[23062]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.
[23592]173pkgfiles="$DEBATHENA_APT/dists/$dist/$section/binary-$arch/Packages.gz $DEBATHENA_APT/dists/${dist}-proposed/$section/binary-$arch/Packages.gz"
174if { zcat $pkgfiles | \
[23760]175    dpkg-awk -f - "Package:^$daname\$" "Version:^$(quote "$daversion$tag")\$" -- Architecture;
[23592]176    zcat $pkgfiles | \
[23760]177    dpkg-awk -f - "Source:^$daname\$" "Version:^$(quote "$daversion$tag")\$" -- Architecture; } \
[23062]178    | if [ "$a" = "-A" ]; then cat; else fgrep -vx 'Architecture: all'; fi \
179    | grep -q .; then
[23732]180    echo "$daname $daversion already exists for $dist_arch." >&2
[22698]181    exit 0
182fi
183
184for cmd; do
185    "cmd_$cmd"
186done
Note: See TracBrowser for help on using the repository browser.