-
Notifications
You must be signed in to change notification settings - Fork 2
/
send_to_OBS.sh
executable file
·322 lines (267 loc) · 8.37 KB
/
send_to_OBS.sh
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
#!/bin/bash
#set -x
set -e
require_clean_work_tree () {
# Update the index
git update-index -q --ignore-submodules --refresh
err=0
# Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules --
then
echo >&2 "cannot $1: you have unstaged changes."
git diff-files --name-status -r --ignore-submodules -- >&2
err=1
fi
# Disallow uncommitted changes in the index
if ! git diff-index --cached --quiet HEAD --ignore-submodules --
then
echo >&2 "cannot $1: your index contains uncommitted changes."
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
err=1
fi
if [ $err = 1 ]
then
echo >&2 "Please commit or stash them."
exit 1
fi
}
add_sha1_to_version() {
sed -i "1s/)/git${HEADSHA1})/" debian/changelog
sed -i "/Release:/s/$/git${HEADSHA1}/" rpm/*.spec || true
git branch -f tmp_sha1
git checkout tmp_sha1
git add debian/changelog
git add rpm/*.spec || true
git commit -m"Temporary sha1 version"
}
rm_sha1_from_version() {
git checkout -f $BRANCH
git branch -D tmp_sha1
git branch -D patch-queue/tmp_sha1 2>/dev/null || true
}
usage()
{
cat <<EOF
usage: $1 [-r] -p project [pkg]
-p specifies the project
-r specifies a 'real' release (no sha1)
Send the current package to OBS
if pkg is omitted uses the CWD name.
git can be setup to have a pristine branch and a packaging branch
There should be a debian/gbp.conf file specifing
debian-branch (typically pkg or debian)
upstream-branch (typically master)
In this case the .spec will use the .orig tarball and the .spec from
the rpm/ directory. Patches should be extracted from the debian/patches dir
and applied with the .spec too.
You should be on the pkg branch to build a 'real' build.
If you do not specify -r then the debian-branch and upstream-branch
will be ignored and both will be force-set to the current branch.
If you are on any other branch then the current sha1 will be appended
to the Release.
EOF
return 0
}
# Local config
# Base directory where project checkouts are placed
OBSBASE="~/obs/"
# Where git-buidlpackage is setup to produce builds, configured in
# /etc/git-buildpackage
BUILDAREA=/some/tmp/build-area
# NAMESPACE is optional dir under OBSBASE also used as apiurl alias with osc
# (setup in oscrc)
#NAMESPACE=
# Override above with personal values
if [ -e "$HOME/.send_to_OBS.conf" ]; then
. $HOME/.send_to_OBS.conf
else
cat <<EOF >>$HOME/.send_to_OBS.conf
# Base directory where project checkouts are placed
OBSBASE=
# Where git-buidlpackage is setup to produce builds, configured in
# /etc/git-buildpackage
BUILDAREA=
# NAMESPACE is an optional apiurl alias with osc which is also used as a dir under OBSBASE
# (setup in oscrc)
NAMESPACE=
EOF
echo "Please set the required configuration values in $HOME/.send_to_OBS.conf"
exit 1
fi
if [[ ! -e $NAMESPACE ]] ; then
OBSBASE=$OBSBASE/$NAMESPACE/
fi
OSC()
{
if [[ $NAMESPACE ]] ; then
osc -A $NAMESPACE $@
else
osc $@
fi
}
# We need to be in a git repo
[[ ! -d .git ]] && { echo Not in a .git project ; exit 1 ; }
require_clean_work_tree
GITWD=$(pwd)
HEAD=$(git rev-parse HEAD)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
trap "git checkout -f $BRANCH; exit" INT TERM EXIT
HEADSHA1=$(git rev-parse --short HEAD)
# Override the upstream/debian specified in gbp.conf (unless -r later)
USING_BRANCHES=" --git-debian-branch=$BRANCH --git-upstream-branch=$BRANCH "
if [ -x /usr/bin/git-buildpackage ]; then
# Behaviour changed starting from 0.5.27
GBP_MIN_VER=$(git-buildpackage --version | cut -d ' ' -f 2 | cut -d '.' -f 2)
GBP_MIC_VER=$(git-buildpackage --version | cut -d ' ' -f 2 | cut -d '.' -f 3)
if [[ $GBP_MIN_VER -ge 5 ]] && [[ $GBP_MIC_VER -ge 27 ]] ; then
UPSTREAM_TREE=" --git-upstream-tree=branch "
fi
fi
REAL=no
while getopts "p:r" opt; do
case $opt in
p )
[[ -d $OBSBASE ]] || { echo no such dir $OBSBASE; exit 1; }
[[ -d $OBSBASE/$OPTARG ]] || {
echo attempt to get $OPTARG
( cd $OBSBASE && OSC co $OPTARG )
}
OBSPROJ=$(cd $OBSBASE/$OPTARG;pwd)
;;
r ) REAL=yes
# This is real - don't override the upstream/debian specified in gbp.conf
USING_BRANCHES=""
;;
\? ) usage
exit 1;;
* ) usage
exit 1;;
esac
done
shift $(($OPTIND - 1))
PACKAGE=${1:-$(basename $(pwd))}
OBSDIR=$OBSPROJ/$PACKAGE
[[ -d $OBSDIR ]] || {
echo attempt to get $PACKAGE from OBS
( cd $OBSPROJ && {
OSC co $PACKAGE || OSC mkpac $PACKAGE
} )
}
[[ ! -d $OBSDIR ]] && { echo $OBSDIR not present ; exit 1 ; }
[[ ! -d $BUILDAREA ]] && mkdir $BUILDAREA
BUILD=$(readlink -e $BUILDAREA)
# BAD IDEA
#rm -rf $BUILD/*
[ "$(ls -A $BUILD)" ] && echo "BUILDAREA $BUILD is not empty, please check the contents and clean it." && exit 1
cd $GITWD
VERSION=$(dpkg-parsechangelog -c1 | grep Version | cut -f2 -d" ")
# Check and tidy up hangover branches
git rev-parse -q --verify tmp_sha1 > /dev/null && git branch -D tmp_sha1
git rev-parse -q --verify patch-queue/tmp_sha1 > /dev/null && git branch -D patch-queue/tmp_sha1
echo "################################################################"
echo Make debian package
echo Debian : $VERSION
# Clean any old build stuff
if [[ -f debian/gbp.conf ]]; then
GBP="yes"
UP_BRANCH=$(grep upstream-branch= debian/gbp.conf | cut -f2 -d=)
#PKG_BRANCH=$(grep debian-branch= debian/gbp.conf | cut -f2 -d=)
PKG_BRANCH=${PKG_BRANCH:-${BRANCH}}
echo About to build
# Make the debian.tar.gz and dsc
git checkout $PKG_BRANCH
if [[ $REAL == "no" ]]; then
add_sha1_to_version
fi
git-buildpackage --git-export-dir="$BUILD" $UPSTREAM_TREE $USING_BRANCHES --git-ignore-new -S -uc -us -tc
else
GBP="no"
if [[ $REAL == "no" ]]; then
add_sha1_to_version
fi
dpkg-buildpackage -S -uc -us -tc -i -I
fi
# If we have GBP then apply patches (in debian/) for any gem build
if [[ $GBP == "yes" ]]; then
if [ -d "debian/patches" ] ; then
gbp-pq import
fi
fi
# See if we're ruby
RUBY=no
if [[ -n "$(find . -maxdepth 1 -name '*.gemspec' -print -quit)" ]]; then
echo Building *.gemspec
for i in *.gemspec; do
gem build $i
RUBY=yes
done
elif [[ -n "$(find . -maxdepth 1 -name '*.yml' -print -quit)" ]]; then
echo Building *.yml
for i in *.yml; do
gem build $i
RUBY=yes
done
elif [[ -e Rakefile ]]; then
# Try a rake gem
rake gem
RUBY=yes
fi
# Copy over anything in rpm/ to BUILD so we pickup possible sha1sum version
# modification later
cp rpm/* $BUILD/ 2>/dev/null || true
# And restore us to the debian branch
if [[ $GBP == "yes" ]]; then
git checkout $PKG_BRANCH
gbp-pq drop || true
fi
echo "################################################################"
echo Sending to OBS in $OBSDIR
# Update to ensure we can overwrite - git is master
(cd $OBSDIR && OSC up) || true
# Build succeeded - clean out the OBS dir and use new tarballs
find $OBSDIR -mindepth 1 -maxdepth 1 -type f -name "[^_]*" -print0 | xargs -0 rm -f
if [[ $GBP == "yes" ]]; then
mv $BUILD/* $OBSDIR/
else
# Move any version specifics
mv ../*$VERSION* $OBSDIR
# copy any orig tarballs
cp -a ../*orig* $OBSDIR || true
# pickup the rpm related files
mv $BUILD/* $OBSDIR/
fi
# and over any gem file, possibly in pkg/
mv *.gem $OBSDIR/ 2>/dev/null || true
mv pkg/*.gem $OBSDIR/ 2>/dev/null || true
# Send it to the OBS (should this use the changelog entry?)
dpkg-parsechangelog -c1 | (
cd $OBSDIR
# Rename symlinks to truename for OBS
#(l=$(find . -maxdepth 1 -type l -print -quit) && t=$(readlink $l) && rm $l && mv $t $l) || true
(l=$(find . -maxdepth 1 -type l -print -quit); [[ $l ]] && t=$(readlink $l) && rm $l && mv $t $l) || true
OSC ar
OSC ci --skip-validation -F -
)
if [[ $REAL == "no" ]]; then
rm_sha1_from_version
fi
# Debian Package Dependencies
# git-buildpackage
# gem2deb
# Using send_to_OBS.sh to update a gem
######################################
# Checkout master
# pull from remote
# git pull master
# git checkout debian
# git merge master
# Go to debian/
## Edit changelog, increase version
## include upstream change comments
## Update control if Rakefile changed deps
# Go to rpm/
## Manually update rpm Version
## include upstream change comments
# Commit changelog/spec changes
# Stay on debian/pkg branch
# run /maemo/devel/BOSS/send_to_OBS.sh -p home:lbt:MINT