source: trunk/third/common/invirtificator.sh @ 2495

Last change on this file since 2495 was 2319, checked in by broder, 16 years ago

Pass --arch-all to one of the builds for non-arch-all packages.

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