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

Revision 23041, 4.0 KB checked in by ghudson, 16 years ago (diff)
In debathenificator, use a single chroot for all operations except sbuildhack, and run "apt-get update" inside it before starting. Eliminates the need to run "all-schroots upgrade-schroot" before using debathenificator.
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
22# Create a chroot and define functions for using it.
23sid=$(schroot -b -c "$chroot")
24trap 'schroot -e -c "$sid"' EXIT
25sch() { schroot -r -c "$sid" -- "$@"; }           # Run in the chroot
26schq() { schroot -q -r -c "$sid" -- "$@"; }       # Run in the chroot quietly
27schr() { schroot -r -c "$sid" -u root -- "$@"; }  # Run in the chroot as root
28schr apt-get -qq -y update
29
30munge_sections () {
31    perl -0pe 's/^Section: /Section: debathena-system\//gm or die' -i debian/control
32}
33
34add_changelog () {
35    if [ -n "$dch_done" ]; then
36        dch "$@"
37    else
38        echo | dch -v"${daversion}" -D unstable "$@"
39        dch_done=1
40    fi
41}
42
43append_description () {
44    perl -0pe 'open THREE, "</dev/fd/3"; $x = <THREE>; s/(^Description:.*\n( .*\S.*\n)*)/$1$x/gm or die' -i debian/control 3<&0
45}
46
47add_build_depends () {
48    perl -0pe 's/^(Build-Depends:.*)$/$1, '"$1"'/m or die' -i debian/control
49}
50
51add_debathena_provides () {
52    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
53    add_changelog "Provide debathena-$name."
54}
55
56cmd_source () {
57    if [ "$a" != "-A" ]; then
58        echo "Not building source package for $dist_arch." >&2
59        return
60    fi
61    echo "Building source for $name-$daversion on $dist_arch" >&2
62   
63    if ! [ -e "${name}_$version.dsc" ]; then
64        sch apt-get -d source "$name"
65    fi
66   
67    if ! [ -e "${name}_$daversion.dsc" ]; then
68        (
69            tmpdir=$(mktemp -td "debathenify.$$.XXXXXXXXXX")
70            trap 'rm -rf "$tmpdir"' EXIT
71            origversion=$(echo "$version" | sed 's/-[^-]*$//')
72            cp -a "${name}_$origversion.orig.tar.gz" "$tmpdir/"
73            dscdir=$(pwd)
74            cd "$tmpdir/"
75            dpkg-source -x "$dscdir/${name}_$version.dsc" "$tmpdir/$name-$origversion"
76            cd "$tmpdir/$name-$origversion"
77            dch_done=
78            hack_package
79            [ -n "$dch_done" ]
80            schr apt-get -q -y install devscripts pbuilder
81            schr /usr/lib/pbuilder/pbuilder-satisfydepends
82            sch debuild -S -sa -us -uc -i -I.svn && cp -a "../${name}_$daversion"* "$dscdir"
83        )
84        [ $? -eq 0 ] || exit 1
85       
86        if [ -n "$DA_CHECK_DIFFS" ]; then
87            interdiff -z "${name}_$version.diff.gz" "${name}_$daversion.diff.gz" | \
88                enscript --color --language=ansi --highlight=diffu --output=- -q | \
89                less -R
90            echo -n "Press Enter to continue: " >&2
91            read dummy
92        fi
93    fi
94}
95
96cmd_binary () {
97    sbuildhack "$dist_arch" $a "${name}_$daversion.dsc"
98}
99
100v () {
101    echo "$@"
102    "$@"
103}
104
105cmd_upload () {
106    REPREPRO="v reprepro -Vb $DEBATHENA_APT"
107    REPREPROI="$REPREPRO --ignore=wrongdistribution --ignore=missingfield"
108
109    . /mit/debathena/bin/debian-versions.sh
110    tag=$(gettag $dist)
111
112    if [ "$a" = "-A" ]; then
113        $REPREPROI include "$dist" "${name}_${daversion}_source.changes"
114    fi
115    $REPREPRO include "$dist" "${name}_${daversion}${tag}_${arch}.changes"
116}
117
118version=$(
119    sch apt-cache showsrc "$name" | \
120        sed -n 's/^Version: \(.*\)$/\1/ p' | (
121        version='~~~'
122        while read -r newversion; do
123            if dpkg --compare-versions "$newversion" '>' "$version"; then
124                version=$newversion
125            fi
126        done
127        if [ "$version" = '~~~' ]; then
128            echo "No version of $name found." >&2
129            exit 1
130        fi
131        echo "$version"
132        )
133    )
134daversion=$version$daversionappend
135
136if zcat "$DEBATHENA_APT/dists/$dist/debathena-system/binary-$arch/Packages.gz" | \
137    dpkg-awk -f - "Source:^$name\$" "Version:^$daversion~" -- Architecture | \
138    if [ "$a" = "-A" ]; then cat; else fgrep -vx 'Architecture: all'; fi | \
139    grep -q .; then
140    echo "$name $daversion already exists for $dist_arch." >&2
141    exit 0
142fi
143
144for cmd; do
145    "cmd_$cmd"
146done
Note: See TracBrowser for help on using the repository browser.