-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-rpm
executable file
·125 lines (109 loc) · 3.58 KB
/
build-rpm
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
#!/bin/bash
#
# Build RPM
#
# Copyright (c) 2024 Jun Futagawa (jfut)
#
# This software is released under the 2-Clause BSD License.
# https://opensource.org/license/bsd-2-clause
set -euo pipefail
export LC_ALL=C
BUILD_PACKAGES="autoconf automake libtool gcc make procps-ng rpm-build rpmdevtools"
MAX_RETRY="10"
if [[ $# -lt 2 ]]; then
echo $0 RPMBUILD_DIR SPEC_FILE_NAME [REPOSITORY] [MODULE_VERSION]
exit 1
fi
RPMBUILD_DIR="${1}"
SPEC_FILE_NAME="${2}"
REPOSITORY="${3:-}"
MODULE_VERSION="${4:-}"
pushd "${RPMBUILD_DIR}"
# RPM macros
RPM_MACROS=/usr/lib/rpm/macros.d/macros.dist
if [[ -f /etc/rpm/macros.dist ]]; then
# el8
RPM_MACROS=/etc/rpm/macros.dist
fi
RPM_DIST=.$(egrep -o "^%el[0-9]*" "${RPM_MACROS}" | tr -d '%')
echo "RPM_DIST: ${RPM_DIST} (${RPM_MACROS})"
# Install nginx and setup spec file
echo
echo "Installing nginx"
if [[ -z "${REPOSITORY}" ]]; then
# Non-modular package version
dnf -y install nginx
else
# Modular package version
if [[ -z "${MODULE_VERSION}" ]]; then
echo "Error: MODULE_VERSION is required for el8 or later"
exit 1
fi
# EPEL 8 Modularity was going away on February 15, 2023
if [[ "${REPOSITORY}" = "epel-modular" ]]; then
dnf -y install epel-release
dnf config-manager --enable epel-modular
dnf clean all
fi
dnf -y module reset nginx
echo "Installing nginx:${MODULE_VERSION} on ${REPOSITORY}"
dnf -y module install nginx:${MODULE_VERSION}/common
fi
# 2:1.20.1-20.el9.alma.1 -> 2
NGINX_EPOCH_VERSION=$(dnf info -q nginx | grep ^Epoch | awk '{ print $3 }')
sed -e "s/@NGINX_EPOCH_VERSION@/${NGINX_EPOCH_VERSION}/g" "SPECS/${SPEC_FILE_NAME}.in" > "SPECS/${SPEC_FILE_NAME}.tmp"
# 2:1.20.1-20.el9.alma.1 -> 1.20.0
NGINX_VERSION=$(dnf info -q nginx | grep ^Version | awk '{ print $3 }')
sed -e "s/@NGINX_VERSION@/${NGINX_VERSION}/g" "SPECS/${SPEC_FILE_NAME}.tmp" > "SPECS/${SPEC_FILE_NAME}"
rm -f "SPECS/${SPEC_FILE_NAME}.tmp"
# Install dependencies
echo
echo "Installing build tools and dependencies: ${BUILD_PACKAGES} dnf-plugins-core"
RETRY=0
until dnf -y install ${BUILD_PACKAGES} dnf-plugins-core || [[ "${RETRY}" -eq "${MAX_RETRY}" ]];
do
echo
sleep $((RETRY++))
echo "Retry: dnf -y install ${BUILD_PACKAGES} (retry: ${RETRY})"
done
until dnf -y builddep "SPECS/${SPEC_FILE_NAME}" || [[ "${RETRY}" -eq "${MAX_RETRY}" ]];
do
sleep $((RETRY++))
echo
echo "Retry: dnf -y builddep \"SPECS/${SPEC_FILE_NAME}\" (retry: ${RETRY})"
done
# Build RPM files
if [[ ! -d SOURCES ]]; then
mkdir SOURCES
fi
if [[ "${RPM_DIST}" = ".el9" ]]; then
# el9 or later
spectool -g -a "SPECS/${SPEC_FILE_NAME}" -C SOURCES/
else
# el8
spectool -g -A "SPECS/${SPEC_FILE_NAME}" -C SOURCES/
fi
echo "Building RPM files:"
if [[ ! -z "${REPOSITORY}" ]]; then
if [[ "${REPOSITORY}" = "epel-modular" ]]; then
RPM_DIST=$(echo "${RPM_DIST}" | sed -r "s/^\.(.*)/.module_\1.epel.${MODULE_VERSION}/")
else
RPM_DIST=$(echo "${RPM_DIST}" | sed -r "s/^\.(.*)/.module_\1.${MODULE_VERSION}/")
fi
fi
echo rpmbuild \
--define \"%_topdir ${RPMBUILD_DIR}\" \
--define \"%dist ${RPM_DIST}\" \
-ba \"SPECS/${SPEC_FILE_NAME}\"
rpmbuild \
--define "%_topdir ${RPMBUILD_DIR}" \
--define "%dist ${RPM_DIST}" \
-ba "SPECS/${SPEC_FILE_NAME}"
echo "Change permissions to delete conflicting files when releasing via GitHub Actions:"
chmod 777 "${RPMBUILD_DIR}/SRPMS"
find "${RPMBUILD_DIR}/SRPMS" -name "*.rpm" -print0 | xargs -r -0 chmod 666
echo "ls -al \"${RPMBUILD_DIR}/\""
ls -al "${RPMBUILD_DIR}/"
echo "ls -al \"${RPMBUILD_DIR}/SRPMS\""
ls -al "${RPMBUILD_DIR}/SRPMS"
popd