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