Merge pull request #82 from ceph/wip-rm-blkin
[autobuild-ceph.git] / build-ceph-rpm.sh
1 #!/bin/sh -x
2 set -e
3
4 rm -rf rpmbuild
5 bindir=`dirname $0`
6 . $bindir/reset-modules.sh
7
8 DISTS=`cat ../../dists`
9 TARGET="$(cat ../../rsync-target)"
10 TARGET="$(basename $TARGET)"
11 REV="$(git rev-parse HEAD)"
12 VER="$(git describe)"
13
14 # Reformat version if needed to match RPM version and release
15 desc=$(git describe --always | sed 's/^v//')
16 if expr index $desc '-' > /dev/null ; then
17     RPM_VER=$(echo $desc | cut -d'-' -f1)
18     RPM_REL=$(echo $desc | cut -d- -f2- | tr '-' '.')
19 else
20     RPM_VER=$desc
21     RPM_REL=0
22 fi
23 VER=${RPM_VER}-${RPM_REL}
24
25 # Try to determine branch name
26 BRANCH=$(../branches.sh -v | grep $REV | awk '{print $2}') || BRANCH="unknown"
27 BRANCH=$(basename $BRANCH)
28 echo "Building branch=$BRANCH, sha1=$REV, version=$VER"
29
30 # set up key for signing RPMs
31 export GNUPGHOME=/srv/gnupg
32 KEYID=03C3951A
33 if ! gpg --list-keys 2>&1 | grep $KEYID  > /dev/null
34 then
35     echo "Can not find RPM signing key" 1>&2
36     exit 4
37 fi
38
39
40 # clear out any $@ potentially passed in
41 set --
42
43 # enable ccache if it is installed
44 export CCACHE_DIR="$PWD/../../ccache"
45 if command -v ccache >/dev/null; then
46   if [ ! -e "$CCACHE_DIR" ]; then
47     echo "$0: have ccache but cache directory does not exist: $CCACHE_DIR" 1>&2
48   else
49     set -- CC='ccache gcc' CXX='ccache g++'
50   fi
51 else
52   echo "$0: no ccache found, compiles will be slower." 1>&2
53 fi
54
55 echo --START-IGNORE-WARNINGS
56 [ ! -x install-deps.sh ] || ./install-deps.sh
57
58 # we only need to use autogen here if we need a dist tarball
59 if [ -x make-dist ]; then
60     echo --STOP-IGNORE-WARNINGS
61     ./make-dist $RPM_VER
62 else    
63     [ ! -x autogen.sh ] || ./autogen.sh || exit 1
64     autoconf || true
65     echo --STOP-IGNORE-WARNINGS
66
67     [ -z "$CEPH_EXTRA_CONFIGURE_ARGS" ] && CEPH_EXTRA_CONFIGURE_ARGS=--with-tcmalloc
68     [ ! -x configure ] || ./configure --with-debug --with-radosgw --with-fuse --with-libatomic-ops --with-gtk2 --with-nss $CEPH_EXTRA_CONFIGURE_ARGS || exit 2
69
70     if [ ! -e Makefile ]; then
71         echo "$0: no Makefile, aborting." 1>&2
72         exit 3
73     fi
74
75     #
76     #  Build Source tarball.  We do this after runing autogen/configure so that
77     #  ceph.spec has the correct version number filled in.
78     echo "**** Building Tarball ***"
79     make dist-bzip2
80 fi
81
82 # Set up build area
83 BUILDAREA=./rpmbuild
84 mkdir -p ${BUILDAREA}/SOURCES
85 mkdir -p ${BUILDAREA}/SRPMS
86 mkdir -p ${BUILDAREA}/SPECS
87 mkdir -p ${BUILDAREA}/RPMS
88 mkdir -p ${BUILDAREA}/BUILD
89 cp -a ceph-*.tar.bz2 ${BUILDAREA}/SOURCES/.
90 cp -a rpm/*.patch ${BUILDAREA}/SOURCES || true
91
92 # If this is a release candidate, identified by having -rc[0-9] appended to
93 # the version number, then fix up the generated rpm spec file by moving the
94 # the rc tag from the version field to the release field. '-' is an illegal
95 # char in the rpm version number.
96 rpm_version=`grep ^Version: ceph.spec | awk '{print $2}'`
97 if [[ "$rpm_version" =~  .*-rc[1-9]$ ]] ; then
98     rpm_rc=$(echo $rpm_version | cut -d- -f2)
99     rpm_version=$(echo $rpm_version | cut -d- -f1)
100     rpm_release=`grep ^Release: ceph.spec | awk '{print $2}'`
101     # patch ceph.spec
102     sed -i "s/^Version:.*/Version:        $rpm_version/" ceph.spec
103     if [[ ! $rpm_release =~ rc[1-9].* ]] ; then
104         sed -i "s/^Release:.*/Release:        $rpm_rc.$rpm_release/" ceph.spec
105     fi
106     sed -i "s/^Source0:.*/Source0:        http:\/\/ceph.com\/download\/%{name}-%{version}-$rpm_rc.tar.bz2/" ceph.spec
107     sed -i "s/^%setup.*/%setup -q -n %{name}-%{version}-$rpm_rc/" ceph.spec
108 else
109     # fix up spec file for non-rc builds too
110     sed -i "s/^Version:.*/Version:        $RPM_VER/" ceph.spec
111     sed -i "s/^Release:.*/Release:        $RPM_REL/" ceph.spec
112 fi
113 cp ceph.spec /tmp/ceph.spec
114
115 # Build RPMs
116 BUILDAREA=`readlink -fn ${BUILDAREA}`   ### rpm wants absolute path
117 rpmbuild -ba --define "_topdir ${BUILDAREA}" ceph.spec
118
119 # Create and build an RPM for the repository
120
121 cat <<EOF > ${BUILDAREA}/SPECS/ceph-release.spec
122 Name:           ceph-release       
123 Version:        1
124 Release:        0%{?dist}
125 Summary:        Ceph repository configuration
126 Group:          System Environment/Base 
127 License:        GPLv2
128 URL:            http://gitbuilder.ceph.com/$dist
129 Source0:        ceph.repo       
130 #Source0:        RPM-GPG-KEY-CEPH
131 #Source1:        ceph.repo      
132 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
133 BuildArch:      noarch
134
135 %description
136 This package contains the Ceph repository GPG key as well as configuration
137 for yum and up2date.  
138
139 %prep
140
141 %setup -q  -c -T
142 install -pm 644 %{SOURCE0} .
143 #install -pm 644 %{SOURCE1} .
144
145 %build
146
147 %install
148 rm -rf %{buildroot}
149 #install -Dpm 644 %{SOURCE0} \
150 #    %{buildroot}/%{_sysconfdir}/pki/rpm-gpg/RPM-GPG-KEY-CEPH
151 %if 0%{defined suse_version}
152 install -dm 755 %{buildroot}/%{_sysconfdir}/zypp
153 install -dm 755 %{buildroot}/%{_sysconfdir}/zypp/repos.d
154 install -pm 644 %{SOURCE0} \
155     %{buildroot}/%{_sysconfdir}/zypp/repos.d
156 %else
157 install -dm 755 %{buildroot}/%{_sysconfdir}/yum.repos.d
158 install -pm 644 %{SOURCE0} \
159     %{buildroot}/%{_sysconfdir}/yum.repos.d
160 %endif
161
162 %clean
163 #rm -rf %{buildroot}
164
165 %post
166
167 %postun 
168
169 %files
170 %defattr(-,root,root,-)
171 #%doc GPL
172 %if 0%{defined suse_version}
173 /etc/zypp/repos.d/*
174 %else
175 /etc/yum.repos.d/*
176 %endif
177 #/etc/pki/rpm-gpg/*
178
179 %changelog
180 * Sun Mar 10 2013 Gary Lowell <glowell@inktank.com> 1-1
181 - Handle both yum and zypper
182 - Use URL to ceph git repo for key
183 - remove config attribute from repo file
184 * Mon Aug 27 2012 Gary Lowell <glowell@inktank.com> 1-0
185 - Initial Package
186 EOF
187 #  End of ceph-release.spec file.
188
189 # GPG Key
190 #gpg --export --armor $keyid > ${BUILDAREA}/SOURCES/RPM-GPG-KEY-CEPH
191 #chmod 644 ${BUILDAREA}/SOURCES/RPM-GPG-KEY-CEPH
192
193 # Install ceph.repo file
194 cat <<EOF > $BUILDAREA/SOURCES/ceph.repo
195 [Ceph]
196 name=Ceph packages for \$basearch
197 baseurl=http://gitbuilder.ceph.com/${TARGET}/ref/${BRANCH}/\$basearch
198 enabled=1
199 gpgcheck=1
200 type=rpm-md
201 gpgkey=https://download.ceph.com/keys/autobuild.asc
202
203 [Ceph-noarch]
204 name=Ceph noarch packages
205 baseurl=http://gitbuilder.ceph.com/${TARGET}/ref/${BRANCH}/noarch
206 enabled=1
207 gpgcheck=1
208 type=rpm-md
209 gpgkey=https://download.ceph.com/keys/autobuild.asc
210
211 [ceph-source]
212 name=Ceph source packages
213 baseurl=http://gitbuilder.ceph.com/${TARGET}/ref/${BRANCH}/SRPMS
214 enabled=1
215 gpgcheck=1
216 type=rpm-md
217 gpgkey=https://download.ceph.com/keys/autobuild.asc
218 EOF
219 # End of ceph.repo file
220
221 rpmbuild -bb --define "_topdir ${BUILDAREA}" ${BUILDAREA}/SPECS/ceph-release.spec
222
223 # Add Dependencies.
224
225 if [ -d /srv/deps ]
226 then
227     cp -avf /srv/deps/* ${BUILDAREA}/RPMS/x86_64/
228 fi
229
230 # Sign RPMS
231 export GNUPGHOME=/srv/gnupg
232 echo "Signing RPMS ..."
233 for file in `find ${BUILDAREA} -name "*.rpm"`
234 do
235     /srv/autobuild-ceph/rpm-autosign.exp --define "_gpg_name $KEYID" $file
236 done
237
238 # Create repo index for yum/zypper
239 for dir in ${BUILDAREA}/SRPMS ${BUILDAREA}/RPMS/*
240 do
241     createrepo ${dir}
242     gpg --detach-sign --armor -u $KEYID ${dir}/repodata/repomd.xml
243 done
244
245 #REV="$(git rev-parse HEAD)"
246 OUTDIR="../out/output/sha1/$REV"
247 OUTDIR_TMP="${OUTDIR}.tmp"
248 install -d -m0755 -- "$OUTDIR_TMP"
249 printf '%s\n' "$REV" >"$OUTDIR_TMP/sha1"
250 printf '%s\n' "$VER" >"$OUTDIR_TMP/version"
251 printf '%s\n' "ceph" >"$OUTDIR_TMP/name"
252 #mkdir -p $OUTDIR_TMP/conf
253
254 # Copy RPMS to output repo
255 for dir in ${BUILDAREA}/SRPMS ${BUILDAREA}/RPMS/*
256 do
257     cp -a ${dir} $OUTDIR_TMP
258 done
259
260 rm -rf -- "$BUILDAREA"
261
262 # put our temp files inside .git/ so ls-files doesn't see them
263 git ls-files --modified >.git/modified-files
264 if [ -s .git/modified-files ]; then
265     rm -rf "$OUTDIR_TMP"
266     echo "error: Modified files:" 1>&2
267     cat .git/modified-files 1>&2
268     exit 6
269 fi
270
271 git ls-files --exclude-standard --others >.git/added-files
272 if [ -s .git/added-files ]; then
273     rm -rf "$OUTDIR_TMP"
274     echo "error: Added files:" 1>&2
275     cat .git/added-files 1>&2
276     exit 7
277 fi
278
279 # we're successful, the files are ok to be published; try to be as
280 # atomic as possible about replacing potentially existing OUTDIR
281 if [ -e "$OUTDIR" ]; then
282     rm -rf -- "$OUTDIR.old"
283     mv -- "$OUTDIR" "$OUTDIR.old"
284 fi
285 mv -- "$OUTDIR_TMP" "$OUTDIR"
286 rm -rf -- "$OUTDIR.old"
287
288 exit 0