forked from RedHatProductSecurity/advisory-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_rpm.sh
66 lines (51 loc) · 1.5 KB
/
build_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
#!/usr/bin/env bash
target_os=$1
spec_file=$2
if [ -z "$spec_file" ]; then
echo 'ERROR: spec file not specified.'
exit 1
fi
prep_env() {
# Prepare environment
mkdir -p ./{RPMS,SRPMS}
mkdir -p ~/rpmbuild/{SPECS,SOURCES,SRPMS,RPMS}
# Copy created source archive to sources
cp dist/* ~/rpmbuild/SOURCES
}
deps_fedora() {
# Install RPM building dependencies; skips Recommends or Supplements
# ("weak dep") packages
dnf install --setopt install_weak_deps=false -y rpm-build rpmlint dnf-plugins-core findutils
prep_env
# Install missing dependencies for building an RPM package; skips
# Recommends or Supplements ("weak dep") packages
dnf builddep --setopt install_weak_deps=false -y --spec "$spec_file"
}
deps_el7() {
# Install EPEL (for python-rpm-macros)
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# Install RPM building dependencies
yum install -y rpm-build rpmlint findutils python-rpm-macros
prep_env
# Install missing dependencies for building an RPM package
yum-builddep -y "$spec_file"
}
case "$target_os" in
fedora)
deps_fedora
;;
el7)
deps_el7
;;
*)
echo "ERROR: unknown target OS specified."
exit 1
;;
esac
# Build source and binary packages from spec file
rpmbuild -ba "$spec_file"
# Move to standard locations
mv ~/rpmbuild/RPMS/* ./RPMS
mv ~/rpmbuild/SRPMS/* ./SRPMS
# Lint created RPMs
rpmlint $(find ./RPMS -name *.rpm)