-
Notifications
You must be signed in to change notification settings - Fork 7
/
make-rpm.sh
executable file
·264 lines (230 loc) · 6.66 KB
/
make-rpm.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
#!/bin/bash
#
# Copyright (C) 2015 Red Hat <contact@redhat.com>
#
# Author: Loic Dachary <loic@dachary.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library Public License for more details.
#
#
# Create and upload a RPM repository with the same naming conventions
# as https://github.com/ceph/autobuild-ceph/blob/master/build-ceph-rpm.sh
#
set -xe
base=/tmp/release
gitbuilder_host=$1
codename=$2
git_ceph_url=$3
sha1=$4
flavor=$5
arch=$6
suse=false
[[ $codename =~ suse ]] && suse=true
if [ "$suse" = true ] ; then
sudo zypper -n install git
else
sudo yum install -y git
fi
source $(dirname $0)/common.sh
init_ceph $git_ceph_url $sha1
#id=$(lsb_release -s -i | tr A-Z a-z)
#major=$(lsb_release -s -r | sed -s "s;\..*;;g")
#codename="${id}${major}"
releasedir=$base/$(lsb_release -si | tr ' ' '_')/WORKDIR
#
# git describe provides a version that is
# a) human readable
# b) is unique for each commit
# c) compares higher than any previous commit
# d) contains the short hash of the commit
#
vers=$(git describe --match "v*" | sed s/^v//)
ceph_dir=$(pwd)
#
# Create a repository in a directory with a name structured
# as
#
base=ceph-rpm-$codename-$arch-$flavor
function setup_rpmmacros() {
if ! grep -q find_debuginfo_dwz_opts $HOME/.rpmmacros ; then
echo '%_find_debuginfo_dwz_opts %{nil}' >> $HOME/.rpmmacros
fi
if lsb_release -d -s | grep CentOS | grep -q 'release 7' ; then
if ! grep -q '%dist .el7' $HOME/.rpmmacros ; then
echo '%dist .el7' >> $HOME/.rpmmacros
fi
fi
}
function build_package() {
rm -fr $releasedir
mkdir -p $releasedir
#
# remove all files not under git so they are not
# included in the distribution.
#
git clean -qdxff
#
# creating the distribution tarbal requires some configure
# options (otherwise parts of the source tree will be left out).
#
if [ "$suse" = true ] ; then
sudo zypper -n install bzip2
else
sudo yum install -y bzip2
fi
./autogen.sh
./configure $(flavor2configure $flavor) --with-debug --with-radosgw --with-fuse --with-libatomic-ops --with-gtk2 --with-nss
#
# use distdir= to set the name of the top level directory of the
# tarbal to match the desired version
#
make dist-bzip2
# Set up build area
setup_rpmmacros
if [ "$suse" = true ] ; then
sudo zypper -n install rpm-build
else
sudo yum install -y rpm-build
fi
local buildarea=$releasedir
mkdir -p ${buildarea}/SOURCES
mkdir -p ${buildarea}/SRPMS
mkdir -p ${buildarea}/SPECS
cp ceph.spec ${buildarea}/SPECS
mkdir -p ${buildarea}/RPMS
mkdir -p ${buildarea}/BUILD
cp -a ceph-*.tar.bz2 ${buildarea}/SOURCES/.
cp -a rpm/*.patch ${buildarea}/SOURCES || true
(
cd ${buildarea}/SPECS
ccache=$(echo /usr/lib*/ccache)
# Build RPMs
buildarea=`readlink -fn ${releasedir}` ### rpm wants absolute path
PATH=$ccache:$PATH rpmbuild -ba --define "_unpackaged_files_terminate_build 0" --define "_topdir ${buildarea}" ceph.spec
)
}
function build_rpm_release() {
local buildarea=$1
local sha1=$2
local gitbuilder_host=$3
local base=$4
cat <<EOF > ${buildarea}/SPECS/ceph-release.spec
Name: ceph-release
Version: 1
Release: 0%{?dist}
Summary: Ceph repository configuration
Group: System Environment/Base
License: GPLv2
URL: http://gitbuilder.ceph.com/$dist
Source0: ceph.repo
#Source0: RPM-GPG-KEY-CEPH
#Source1: ceph.repo
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
%description
This package contains the Ceph repository GPG key as well as configuration
for yum and up2date.
%prep
%setup -q -c -T
install -pm 644 %{SOURCE0} .
#install -pm 644 %{SOURCE1} .
%build
%install
rm -rf %{buildroot}
#install -Dpm 644 %{SOURCE0} \
# %{buildroot}/%{_sysconfdir}/pki/rpm-gpg/RPM-GPG-KEY-CEPH
%if 0%{defined suse_version}
install -dm 755 %{buildroot}/%{_sysconfdir}/zypp
install -dm 755 %{buildroot}/%{_sysconfdir}/zypp/repos.d
install -pm 644 %{SOURCE0} \
%{buildroot}/%{_sysconfdir}/zypp/repos.d
%else
install -dm 755 %{buildroot}/%{_sysconfdir}/yum.repos.d
install -pm 644 %{SOURCE0} \
%{buildroot}/%{_sysconfdir}/yum.repos.d
%endif
%clean
#rm -rf %{buildroot}
%post
%postun
%files
%defattr(-,root,root,-)
#%doc GPL
%if 0%{defined suse_version}
/etc/zypp/repos.d/*
%else
/etc/yum.repos.d/*
%endif
#/etc/pki/rpm-gpg/*
%changelog
* Tue Mar 10 2013 Gary Lowell <glowell@inktank.com> - 1-0
- Handle both yum and zypper
- Use URL to ceph git repo for key
- remove config attribute from repo file
* Tue Aug 27 2012 Gary Lowell <glowell@inktank.com> - 1-0
- Initial Package
EOF
cat <<EOF > $buildarea/SOURCES/ceph.repo
[Ceph]
name=Ceph packages for \$basearch
baseurl=http://${gitbuilder_host}/${base}/sha1/${sha1}/\$basearch
enabled=1
gpgcheck=0
type=rpm-md
[Ceph-noarch]
name=Ceph noarch packages
baseurl=http://${gitbuilder_host}/${base}/sha1/${sha1}/noarch
enabled=1
gpgcheck=0
type=rpm-md
[ceph-source]
name=Ceph source packages
baseurl=http://${gitbuilder_host}/${base}/sha1/${sha1}/SRPMS
enabled=1
gpgcheck=0
type=rpm-md
EOF
rpmbuild -bb --define "_topdir ${buildarea}" ${buildarea}/SPECS/ceph-release.spec
}
function build_rpm_repo() {
local buildarea=$1
local gitbuilder_host=$2
local base=$3
if [ "$suse" = true ] ; then
sudo zypper -n install createrepo
else
sudo yum install -y createrepo
fi
for dir in ${buildarea}/SRPMS ${buildarea}/RPMS/*
do
createrepo ${dir}
done
local sha1_dir=${buildarea}/../$codename/$base/sha1/$sha1
mkdir -p $sha1_dir
echo $vers > $sha1_dir/version
echo $sha1 > $sha1_dir/sha1
echo ceph > $sha1_dir/name
for dir in ${buildarea}/SRPMS ${buildarea}/RPMS/*
do
cp -fla ${dir} $sha1_dir
done
link_same ${buildarea}/../$codename/$base/ref $ceph_dir $sha1
if test "$gitbuilder_host" ; then
(
cd ${buildarea}/../$codename
RSYNC_RSH='ssh -o StrictHostKeyChecking=false' rsync -av $base/ ubuntu@$gitbuilder_host:/usr/share/nginx/html/$base/
)
fi
}
setup_rpmmacros
build_package
build_rpm_release $releasedir $sha1 $gitbuilder_host $base
build_rpm_repo $releasedir $gitbuilder_host $base