-
Notifications
You must be signed in to change notification settings - Fork 18
/
rebuild_swift.sh
executable file
·101 lines (88 loc) · 3.55 KB
/
rebuild_swift.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
#!/bin/sh
# If you need to build a specific version - specify it as bzr build # (digits only).
# If build # is not specified, latest available tarball will be built
GithubUserProject="griddynamics/openstack-rhel"
RPMSANDBOX=`grep topdir $HOME/.rpmmacros 2>/dev/null | awk '{print ($2)}'`
[ "$RPMSANDBOX" == "" ] && RPMSANDBOX="$HOME/rpmbuild/"
SpecOrig="openstack-swift.spec"
TarballsHome="http://swift.openstack.org/tarballs"
Spec="$RPMSANDBOX/SPECS/$SpecOrig"
Version=$(grep '^Version:' $SpecOrig | sed 's/^Version:\s\+//')
if [ $1 ]; then
BUILD=$1
else
BUILD=`curl -s $TarballsHome'/?C=M;O=D'|grep bzr|perl -pi -e 's/^.*bzr(\d+).*$/$1/'|head -n 1`
fi
SrcFile="swift-$Version-dev+bzr$BUILD.tar.gz"
RPMSrc="$RPMSANDBOX/SOURCES/$SrcFile"
TarballURL="$TarballsHome/$SrcFile"
if [ ! -d ".git" ]; then
echo "Need to run from Git repo openstack-nova-rhel6 !"
exit -1
fi
GitDevBranch="master"
GitCurBranch=$(git branch|grep '*'|cut -f2 -d' ')
REPOPATH="/home/build/repo/$GitCurBranch/openstack"
abspath="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
cd `dirname $abspath`
if [ "$GitDevBranch" == "$GitCurBranch" ]; then
have_trunk=1
perl -pi -e "s,^Source0:.*$,Source0: http://swift.openstack.org/tarballs/swift-%{version}-dev+bzr$BUILD.tar.gz," $SpecOrig
if [ ! -f "$RPMSrc" ]; then
wget -O "$RPMSrc" "$TarballURL"
fi
SpecRelease=$(grep '^Release:' $SpecOrig | sed 's/^Release:\s\+//' | sed 's/%{?dist}$//')
SPECBUILD=$(echo "$SpecRelease" | cut -d. -f3 | sed 's/bzr//')
if [ "$SPECBUILD" -ne "$BUILD" ]; then
# Need to increase build in specfile and update changelog
perl -pi -e 's,^(Release:.+bzr)\d+,${1}'$BUILD',' $SpecOrig
rpmdev-bumpspec --comment="- Update to bzr$BUILD" $SpecOrig
fi
else
have_trunk=0
#perl -pi -e "s,^Source0:.*$,Source0: swift-%{version}.tar.gz,"
fi
SpecReleaseNew=$(grep '^Release:' $SpecOrig | sed 's/^Release:\s\+//' | sed 's/%{?dist}$//')
rm -f "$RPMSANDBOX/RPMS/*/*-$Version-$SpecReleaseNew*.rpm" 2>/dev/null
rpmbuild -bb $SpecOrig
if [ "$?" != "0" ]; then
git checkout -- "$SpecOrig"
exit -1
else
git add "$SpecOrig"
git commit -m "Update to bzr$BUILD"
if [ "$?" != "1" ]; then
git push
if [ "$?" != "0" ]; then
# Somebody pushed a commit to origin since we last time pulled.
# Need to check - if that commit was to our file or to some other file?
GitHubUrl="http://github.com/api/v2/json/commits/list/$GithubUserProject/$GitCurBranch"
LastRepoCommit="$(curl -s $GitHubUrl | perl -MJSON::XS -e "\$a='';while(<>){\$a.=\$_} \$d=decode_json(\$a);print \$d->{'commits'}[0]->{'id'}")"
LastSpecCommit="$(curl -s $GitHubUrl/$SpecOrig | perl -MJSON::XS -e "\$a='';while(<>){\$a.=\$_} \$d=decode_json(\$a);print \$d->{'commits'}[0]->{'id'}")"
if [[ "$LastRepoCommit" != "$LastSpecCommit" ]]; then
# Last Git repo commit was not to our specfile
# Probably we can safely do git pull to merge following by git push
git pull
if [ "$?" != "0" ]; then
echo "Sorry, automatic merge failed"
echo "Human intervention required, giving up here"
exit -1
fi
git push
else
# Last commit was to our specfile
git pull
echo "There should be a conflict above, please fix by hands and commit"
exit -1
fi
fi
fi
fi
rpmbuild -bs $SpecOrig
for fn in $RPMSANDBOX/RPMS/noarch/openstack-swift-*$Version-*.rpm; do ./sign_rpm $fn; done
if [ ! -d "$REPOPATH" ];
then
mkdir -p "$REPOPATH"
fi
rm -fr $REPOPATH/openstack-swift-$Version-*.rpm $REPOPATH/openstack-swift-{account,auth,container,object,proxy,doc}-$Version-*.rpm
mv $RPMSANDBOX/RPMS/noarch/*$Version-$SpecReleaseNew*.rpm "$REPOPATH"