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

Last change on this file since 2799 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
RevLine 
[2297]1# Interface: define variables name, ivversionappend, and function
[2296]2# hack_package ().
3
4set -e
5
[2300]6dist=hardy
7chroot=$dist-amd64
[2296]8
[2297]9: ${section=invirt-system}
10: ${ivname=$name}
[2300]11: ${release=unstable}
[2296]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
[2297]33        echo | dch -v"${ivversion}" -D unstable "$@"
[2296]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
[2297]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."
[2296]50}
51
52rename_source () {
[2297]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
[2296]56}
57
[2300]58find_arch () {
59    if grep -iq '^Architecture: all' "${ivname}_$ivfilever.dsc"; then
60        a=-A
61    fi
62}
63
[2296]64cmd_source () {
[2300]65    echo "Building source for $ivname-$ivfilever on ${dist}-amd64" >&2
[2296]66   
[2300]67    if ! [ -e "${name}_$filever.dsc" ]; then
[2296]68        sch apt-get -d source "$name"
69    fi
70   
[2300]71    if ! [ -e "${ivname}_$ivfilever.dsc" ]; then
[2296]72        (
[2297]73            tmpdir=$(mktemp -td "invirtify.$$.XXXXXXXXXX")
[2296]74            trap 'rm -rf "$tmpdir"' EXIT
[2300]75            origversion=$(echo "$filever" | sed 's/-[^-]*$//')
[2296]76            cp -a "${name}_$origversion.orig.tar.gz" "$tmpdir/"
77            dscdir=$(pwd)
78            cd "$tmpdir/"
[2300]79            dpkg-source -x "$dscdir/${name}_$filever.dsc" "$tmpdir/$name-$origversion"
[2296]80            cd "$tmpdir/$name-$origversion"
81            dch_done=
82            hack_package
[2297]83            if [ "$name" != "$ivname" ]; then
[2296]84                rename_source
[2297]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"
[2296]87            fi
88            [ -n "$dch_done" ]
89            schr apt-get -q -y install devscripts pbuilder
90            schr /usr/lib/pbuilder/pbuilder-satisfydepends
[2300]91            sch debuild -S -sa -us -uc -i -I.svn && cp -a "../${ivname}_$ivfilever"* "$dscdir"
[2296]92        )
93        [ $? -eq 0 ] || exit 1
94       
[2297]95        if [ -n "$IV_CHECK_DIFFS" ]; then
[2300]96            interdiff -z "${name}_$filever.diff.gz" "${ivname}_$ivfilever.diff.gz" | \
[2296]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 () {
[2300]106    find_arch
107
108    if [ "$a" = "-A" ]; then
109        sbuild -d "$dist" --arch-all "${ivname}_$ivfilever.dsc"
110    else
[2319]111        sbuild -d "$dist" --arch amd64 --arch-all "${ivname}_$ivfilever.dsc"
[2300]112        sbuild -d "$dist" --arch i386 "${ivname}_$ivfilever.dsc"
113    fi
[2296]114}
115
116v () {
117    echo "$@"
118    "$@"
119}
120
121cmd_upload () {
[2300]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"
[2296]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
[2297]136            if [ $(expr "$newversion" : '.*invirt') = 0 ] && \
[2296]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    )
[2297]148ivversion=$version$ivversionappend
[2296]149
[2300]150filever=$(echo "$version" | perl -pe 's/([^:]*:)?//')
151ivfilever=$(echo "$ivversion" | perl -pe 's/([^:]*:)?//')
152
[2296]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.
[2300]158pkgfiles="/srv/repository/dists/$release/$section/binary-*/Packages.gz"
159if { zcat $pkgfiles | \
[2297]160    dpkg-awk -f - "Package:^$ivname\$" "Version:^$(quote "$ivversion")\$" -- Architecture;
[2296]161    zcat $pkgfiles | \
[2297]162    dpkg-awk -f - "Source:^$ivname\$" "Version:^$(quote "$ivversion")\$" -- Architecture; } \
[2296]163    | if [ "$a" = "-A" ]; then cat; else fgrep -vx 'Architecture: all'; fi \
164    | grep -q .; then
[2300]165    echo "$ivname $ivversion already exists." >&2
[2296]166    exit 0
167fi
168
169for cmd; do
170    "cmd_$cmd"
171done
Note: See TracBrowser for help on using the repository browser.