forked from coreos/mcbs-hackweek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
override-builder.sh
executable file
·97 lines (84 loc) · 2.21 KB
/
override-builder.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
#!/bin/bash
# Given a source directory, generate a set of overlay/override RPMs into destdir
set -euo pipefail
fatal() {
echo 1>&2 "$@"
exit 1
}
# builds a new RPM and adds it to the testdir's repo
# $1 - name
# $2+ - optional, treated as directive/value pairs
build_rpm() {
local tmpdir=$(mktemp -d)
local name=$1; shift
local srcdir=$(cd $1 && pwd); shift
# Unset, not zero https://github.com/projectatomic/rpm-ostree/issues/349
local epoch=""
local version=1.0
local release=1
local arch=$(uname -m)
local spec=$name.spec
# write out the header
cat > $tmpdir/$spec << EOF
Name: $name
Version: $version
Release: $release
License: MIT
${epoch:+Epoch: $epoch}
BuildArch: $arch
Summary: Autogenerated overrides from coreos-override-builder
Provides: rpmostree(override)
%description
%{summary}
%build
%install
cp -pr $srcdir/* %{buildroot}
(cd %{buildroot} && find . -type f) | sed -e 's,^.,,' > files.list
%files -f files.list
EOF
local outdir=$PWD
(cd $srcdir
set -x
rpmbuild --target $arch -ba $tmpdir/$name.spec \
--define "_topdir $tmpdir" \
--define "_sourcedir $tmpdir" \
--define "_specdir $tmpdir" \
--define "_builddir $tmpdir/.build" \
--define "_srcrpmdir $tmpdir" \
--define "_rpmdir $tmpdir" \
--define "_buildrootdir $tmpdir"
mv $tmpdir/*/*.rpm $outdir
)
rm "${tmpdir}" -rf
}
srcdir=${1:-}
if test "$#" != 2; then
fatal "usage: $0 SRCDIR DESTDIR"
fi
shift
outdir=${1:-}
mkdir ${outdir}
echo '{"version": 0}' > ${outdir}/meta.json
rpmdir=${outdir}/rpms
found=0
for d in overlay overrides; do
if test -d ${srcdir}/rpms/$d; then
found=1
rpmd=${rpmdir}/${d}
mkdir -p $rpmd
cp -a ${srcdir}/rpms/$d/* ${rpmd}
fi
done
if test -d "${srcdir}/rootfs/overlay"; then
found=1
build_rpm coreos-rootfs-overlay ${srcdir}/rootfs/overlay
mkdir -p ${rpmdir}/overlay
mv coreos-rootfs-overlay*.rpm ${rpmdir}/overlay
fi
if test "${found}" = 0; then
# Verify we're going to remove the right directory
if test -f "${outdir}/meta.json"; then
rm "${outdir}" -rf
fi
fatal "No rpms/overlay or rootfs/overlay directories found in ${srcdir}"
fi