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

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