-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-xorg-git
executable file
·470 lines (418 loc) · 15 KB
/
auto-xorg-git
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
#!/bin/bash
# A script to automate http://wiki.debian.org/XTips
# 2007 Tormod Volden, Bryce Harrington
# Defaults
DISTRIBUTION=${DISTRIBUTION:-$(lsb_release -c -s)}
DISTRIBUTION=${DISTRIBUTION:-UNRELEASED}
if [ "$(lsb_release -i -s)" = "Ubuntu" ]; then
ADDVERSION=${ADDVERSION:-0ubuntu0$USER}
else
ADDVERSION=${ADDVERSION:-0.1}
fi
DEBIANREPO="origin/debian-experimental"
DATE_PREFIX="~"
BRANCH="master"
WORKING_DIR="."
INTERACTIVE="yes"
MANUAL_MERGE="no"
NO_MERGE="no"
MERGE_STRATEGY=""
DROP_DEBIAN_PATCHES="no"
PACKAGE_VERSION=
EPOCH=AUTO
QUIET=0
URGENCY="low"
declare -a CHANGES
# Include the bash library functions
. $(dirname $0)/xorg-pkg-tools.lib
interact() {
if [ "$INTERACTIVE" = "yes" ]; then
echo -n "Press enter to $1 ..."
read nothing
fi
}
discard() {
local file=$1
local head=$2
local dest=$(dirname $file)
msg "+ Discarding Debian differences in ${file}"
mv ./${file} ./${file}.merge
cp "${head}/${file}" $dest
git add "./${file}"
git commit -m "Dropping Debian's ${file} in favor of X.org's"
CHANGES+=("Dropped Debian's ${file}")
}
get_debian() {
msg "Cloning from Debian repository..."
git clone $DEBIANGIT || die "git clone: code $?"
cd $DEBPKG
git checkout $DEBIANREPO
cd ..
}
update_debian() {
msg "Updating from Debian repository"
cd $DEBPKG
git checkout $DEBIANREPO
git fetch
cd ..
}
get_upstream() {
msg "Fetching from freedesktop repository..."
git remote add freedesktop $FDOGIT
git fetch freedesktop refs/heads/$BRANCH:refs/heads/upstream-head-$BRANCH || die "git fetch freedesktop: $?"
git checkout -b autoxorggit upstream-head-$BRANCH || die "git checkout -b autoxorggit upstream-head-$BRANCH: $?"
LASTCOMMIT=$(git log|head -1)
echo $LASTCOMMIT > .lastcommit
}
update_upstream() {
msg "Updating from freedesktop repository"
git fetch freedesktop refs/heads/$BRANCH:refs/heads/upstream-head-$BRANCH || die "git fetch freedesktop: $?"
git branch -D autoxorggit
git checkout -b autoxorggit upstream-head-$BRANCH || die "git checkout -b autoxorggit upstream-head-$BRANCH: $?"
LASTCOMMIT=$(git log|head -1)
if [ "$LASTCOMMIT" = "$(< .lastcommit)" ]; then
warn "Nothing new from freedesktop"
[ $NOREBUILD ] && exit
fi
echo $LASTCOMMIT > .lastcommit
}
hooks () {
if [ -n "$HOOKS" ]; then
hook=$HOOKS/${DEBPKG}.$1
if [ -r $hook ]; then
msg "Sourcing hook for $1"
. $hook
fi
fi
}
merge_debian() {
msg "Merging Debian changes..."
git merge ${MERGE_STRATEGY} $DEBIANREPO
if [ $? -ne 0 ]; then
msg "Merges needed"
git status
if [ $MANUAL_MERGE = "yes" ]; then
msg "Perform merges manually in ${DEBPKG} using git diff and git commit -a, then press enter to continue"
read nothing
elif [ $INTERACTIVE = "yes" ]; then
msg "Interactively merging..."
git mergetool
msg "Press enter to continue with packaging"
read nothing
else
msg "Attempting to address merge issues automatically..."
ISSUES=0
# 0. Retrieve a copy of upstream's git HEAD
HEAD="../${DEBPKG}-FDO-HEAD"
rm -rf ${HEAD}
git clone ${FDOGIT} ${HEAD}
# 1. Upstream has dropped ChangeLog, but Debian hasn't
if git status | grep "unmerged: *ChangeLog" ; then
msg "+ unmerged ChangeLog from Debian - attempting to delete"
git rm ChangeLog
git commit -m "Dropping Debian-provided ChangeLog in favor of generated one"
CHANGES+=("Dropped Debian-provided ChangeLog")
ISSUES=$(( ISSUES + 1 ))
fi
# 2. Debian Makefile.am changes can be discarded
if git status | grep "unmerged: *Makefile.am" ; then
discard "Makefile.am" ${HEAD}
ISSUES=$(( ISSUES + 1 ))
fi
# 3. Debian man/Makefile.am changes can be discarded
if git status | grep "unmerged: *man/Makefile.am" ; then
discard "man/Makefile.am" ${HEAD}
ISSUES=$(( ISSUES + 1 ))
fi
# 4. Debian man page differences can be discarded
if git status | grep "unmerged: *man/.*\.man" ; then
msg "+ Discarding Debian differences in man pages"
cp "$HEAD/man/*.man" ./man/
git add man/*.man
git commit -m "Dropping Debian customized man pages"
CHANGES+=("Dropped Debian customized man pages")
ISSUES=$(( ISSUES + 1 ))
fi
# 5. If Debian's xsfbs dir missing, copy it into place
if [ ! -d "debian/xsfbs" ]; then
msg "+ Copying missing xsfbs into place"
if [ ! -d "../xsfbs" ]; then
msg " - No available dir ../xsfbs from " $((pwd))
else
# TODO: Why didn't xsfbs come in with the merge anyway??
msg " - Copying ../xsfbs to debian/"
cp -r ../xsfbs debian/
git add debian/xsfbs
git commit -m "Copying in missing xsfbs"
CHANGES+=("Added missing xsfbs")
ISSUES=$(( ISSUES + 1 ))
fi
fi
# 6. Debian configure.ac changes can be discarded
if git status | grep "unmerged: *configure.ac" ; then
discard "configure.ac" $HEAD
ISSUES=$(( ISSUES + 1 ))
fi
# 7. Debian COPYING changes can be discarded
if git status | grep "unmerged: *COPYING" ; then
discard "COPYING" $HEAD
ISSUES=$(( ISSUES + 1 ))
fi
if [ $ISSUES -gt 0 ]; then
if [ $ISSUES -gt 1 ]; then S=s; fi
git merge ${MERGE_STRATEGY} $DEBIANREPO
if [ $? -ne 0 ]; then
die "$ISSUES merge issue$S addressed, but more remain"
else
msg "Success resolving $ISSUES merge issue$S in $DEBPKG"
fi
else
die "Cannot address any of the merge issues"
fi
fi
fi
CHANGES+=("Merge with $DEBIANREPO")
}
add_debian() {
git checkout $DEBIANREPO debian
git add debian
git commit -m "Add debian tree from $DEBIANREPO"
CHANGES+=("Only added debian/ tree from $DEBIANREPO")
}
# To be used by package hooks
drop () {
local PATCH=$1
shift
if grep -q "^$PATCH" debian/patches/series ; then
sed -i "/^$PATCH/s/^/#/" debian/patches/series
CHANGES+=("hook: Drop $PATCH ($*)")
else
warn "no $PATCH to drop"
fi
}
debian_patches() {
if [ -d ./debian/patches ]; then
if [ $DROP_DEBIAN_PATCHES = "yes" ]; then
msg "Dropping debian/patches/*"
rm ./debian/patches/*
CHANGES+=('Dropped debian/patches/*')
else
msg "Applying Debian patches..."
fakeroot ./debian/rules prepare || warn "fakeroot: $?"
QUILT_PATCHES=debian/patches quilt push -a || ./debian/rules patch || die "patching failed: $?"
fi
fi
}
update_changelogs() {
# After merging, this will include the merge commit
git log > ChangeLog
msg "Updating changelog..."
local TODAY=`date +%Y%m%d`
if [ -z "$PACKAGE_VERSION" ]; then
eval `grep PACKAGE_VERSION= configure`
fi
[ -z "$PACKAGE_VERSION" ] && die "No PACKAGE_VERSION in configure"
# Force "~" before date if version has increased
# (you should use the -l option or create a .lastversion if you
# use -t "+")
if [ -z "$LASTVERSION" ] && [ -e .lastversion ]; then
LASTVERSION=$(< .lastversion)
fi
if [ -n "$LASTVERSION" ] && [ $PACKAGE_VERSION \> $LASTVERSION ]; then
DATE_PREFIX="~"
fi
LASTCOMMIT=$(< .lastcommit)
GITVER="${PACKAGE_VERSION}${DATE_PREFIX}git${TODAY}${ADDBRANCH}.${LASTCOMMIT:7:8}"
NO_EPOCH_VER=`echo $GITVER | sed 's/^.://'`
if [ "$EPOCH" = "AUTO" ]; then
EPOCH=$(dpkg-parsechangelog | sed -n 's/^Version: \(.\):.*/\1/p')
fi
# -b forces version even if missing epoch, --force-distribution allows
# non-interactive updating when the release is not known
dch --force-distribution --urgency $URGENCY -b --distribution $DISTRIBUTION --newversion ${EPOCH:+$EPOCH:}${GITVER}-$ADDVERSION "Checkout from git $TODAY ($BRANCH branch) up to $LASTCOMMIT" || die "dch: $?"
# Change Maintainer if on Ubuntu
if [ "$(lsb_release -i -s)" = "Ubuntu" ] &&
! grep -q "^Maintainer: .*ubuntu" debian/control; then
sed -i -e "s/^Maintainer:/Maintainer: Ubuntu Core Developers <[email protected]>\nXSBC-Original-Maintainer:/" debian/control
fi
# Add previously generated changelog entries
for text in "${CHANGES[@]}"; do
dch --append "$text"
done
}
make_orig_tarball() {
local CURDIR=$(basename $(pwd))
local TARDIR=${DEBPKG}-${NO_EPOCH_VER}
cd ..
if [ $CURDIR != $TARDIR ]; then
msg "Our current working directory has the wrong name,"
msg "renaming to $TARDIR"
mv $CURDIR $TARDIR
fi
tar --exclude=debian --exclude=debian/* \
--exclude=.git --exclude=.git/* $TAR_EXCLUDE \
-cf - $TARDIR \
| gzip -9 >${DEBPKG}_${NO_EPOCH_VER}.orig.tar.gz
if [ $CURDIR != $TARDIR ]; then
msg "renaming back to ${CURDIR}"
mv ${TARDIR} ${CURDIR}
fi
cd ${CURDIR}
}
usage() {
echo "Usage: $0 [opts] < driver | xorg-server >"
echo
echo "opts:"
echo " -a <add-version> Extra version tag to add ('0ubuntu0me')"
echo " -b <branch> Upstream git branch"
echo " -d <git branch> Debian git branch [origin/debian-experimental]"
echo " -D Drop existing debian patches before merging"
echo " -e <epoch> Add epoch to autodetected package version"
echo " -f Delete old directories instead of updating"
echo " -g No merge, just add debian/ tree"
echo " -G <git repo> Debian git repository [defaults to git.debian.org...]"
echo " -h This help text"
echo " -H <hooks-dir> Adds hooks from directory"
echo " -l <version> Force ~ separator if new upstream version is higher"
echo " -m Pause for manual merging"
echo " -n Non-interactive"
echo " -o No rebuild if up to date with upstream"
echo " -p <pkg-name> Explicit package name (no automunge)"
echo " -q Operate quietly"
echo " -r <release> Distro release (feisty, gutsy, hardy, etc.)"
echo " -s <version> Force Build-depends to xserver-xorg-dev <version>"
echo " -t <separator> Separator between version and date [~]"
echo " -u <upstream-repo> Specify non-standard git repository"
echo " -U <urgency> Specify the urgency for the changelog (default: low)"
echo " -S <strategy> Override merge strategy"
echo " -v <pkg-version> Override package version (don't autodetect)"
echo " -w <working-dir> Tmp location for checkouts (defaults to cwd)"
exit $1
}
# main starts here
# Command line options
while getopts "a:b:d:De:fgG:H:l:mnop:qr:s:t:u:U:S:v:w:h\?" opt; do
case "$opt" in
a ) ADDVERSION="$OPTARG" ;;
b ) BRANCH="$OPTARG";
ADDBRANCH="+${BRANCH//_/-}" ;;
D ) DROP_DEBIAN_PATCHES="yes" ;;
d ) DEBIANREPO="$OPTARG" ;;
e ) EPOCH="$OPTARG" ;;
f ) FORCE_OVERWRITE=1 ;;
g ) NO_MERGE="yes" ;;
G ) DEBIANGIT="$OPTARG" ;;
H ) HOOKS="$OPTARG" ;;
l ) LASTVERSION="$OPTARG" ;;
m ) MANUAL_MERGE="yes" ;;
n ) INTERACTIVE="no" ;;
o ) NOREBUILD=1 ;;
p ) PACKAGE="$OPTARG" ;;
q ) QUIET=$(($QUIET + 1)) ;;
r ) DISTRIBUTION="$OPTARG" ;;
S ) MERGE_STRATEGY="-s $OPTARG" ;;
s ) XSERVER_VERSION="$OPTARG" ;;
t ) DATE_PREFIX="$OPTARG" ;;
u ) UPSTREAMGIT="$OPTARG" ;;
U ) URGENCY="$OPTARG" ;;
v ) PACKAGE_VERSION="$OPTARG" ;;
w ) WORKING_DIR="$OPTARG" ;;
h ) usage 0; ;;
\?) usage 1; ;;
* ) warn "Unknown option '$opt'"; usage 1; ;;
esac
done
shift $(($OPTIND -1))
msg "Package=$PACKAGE"
msg "Merge_Strategy=$MERGE_STRATEGY"
msg "Interactive=$INTERACTIVE"
msg "QUIET=$QUIET"
msg "Package_version=$PACKAGE_VERSION"
msg "MANUAL_MERGE=$MANUAL_MERGE"
msg "NO_MERGE=$NO_MERGE"
if [ -n "$PACKAGE" ]; then
DEBPKG=$PACKAGE
else
if [ -n "$1" ]; then
# Fix up driver short names
DEBPKG="xserver-xorg-video-$1"
else
usage 1
fi
fi
msg "Making package $DEBPKG"
DEBDIR=$(debgitdir_for_debpkg $DEBPKG)
if [ -z "$DEBIANGIT" ]; then
DEBIANGIT=git://git.debian.org/git/$DEBDIR/$DEBPKG
fi
if [ -z "$UPSTREAMGIT" ]; then
FDOPKG=$(debpkg_to_fdopkg $DEBPKG)
FDODIR=$(fdogitdir_for_fdopkg $FDOPKG)
FDOGIT=git://anongit.freedesktop.org/git/${FDODIR:+$FDODIR/}$FDOPKG
else
FDOGIT=$UPSTREAMGIT
CHANGES+=("Source: $UPSTREAMGIT")
fi
msg "Debian: $DEBIANGIT"
msg "Freedesktop: $FDOGIT"
# make absolute path
if [ -n "$HOOKS" ]; then
if cd $HOOKS; then
HOOKS=$PWD
cd $OLDPWD
else
die "Can not find hooks directory: $HOOKS"
fi
fi
cd $WORKING_DIR || die "Could not cd to $WORKING_DIR"
if [ "$DONE_MERGING" != 1 ]; then
if [ -d $DEBPKG ] && [ $FORCE_OVERWRITE ]; then
warn "Removing old directory"
rm -rf $DEBPKG
fi
if [ ! -d $DEBPKG ]; then
get_debian
cd $DEBPKG
hooks preupstream
get_upstream
else
[ "$NO_MERGE" = "yes" ] && rm -rf $DEBPKG/debian $DEBPKG/ChangeLog
update_debian
cd $DEBPKG
hooks preupstream
update_upstream
fi
hooks premerge
if [ "$NO_MERGE" != "yes" ]; then
interact "merge"
merge_debian
else
add_debian
fi
else
cd $DEBPKG || die "Could not find existing $DEBPKG"
fi
hooks prepatch
interact "apply patches and reconfigure"
debian_patches
if [ -e configure.ac ] || [ -e configure.in ]; then
msg "Running autoreconf"
autoreconf -i -f || die "autoreconf: $?"
fi
# Relax Build-depends (for backporting) in debian/control
if [ -n "$XSERVER_VERSION" ]; then
sed -i -e "/^Build-Depends:/s/xserver-xorg-dev (>= [0-9:.]*)/xserver-xorg-dev (>= $XSERVER_VERSION)/" debian/control
sed -i -e "/^ xserver-xorg-dev /s/xserver-xorg-dev (>= [0-9:.]*)/xserver-xorg-dev (>= $XSERVER_VERSION)/" debian/control
CHANGES+=("Forcing Build-depends to xserver-xorg-dev $XSERVER_VERSION")
fi
hooks prebuild
update_changelogs
fakeroot ./debian/rules clean || die "rules clean: $?"
make_orig_tarball
# Commit all changes
git commit -a -m "Packaged for $DISTRIBUTION"
interact "build packages"
msg "Building source package"
# -d forces building even if missing (version) dependency
debuild -S -sa -i -d
exit 0