Merge pull request #4 from joernott/main

Cleaning up/streamlining RPM builds
This commit is contained in:
Björn Lässig 2023-06-29 09:01:38 +02:00 committed by GitHub
commit 5c18bce01f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 132 additions and 15 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
SPECS/*
SOURCES/*
BUILD/*
BUILDROOT/*
RPMS/*
SRPMS/*

101
contrib/build.sh Executable file
View File

@ -0,0 +1,101 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$(dirname "$0")" ; pwd -P )"
LOGLEVEL=5
source "${SCRIPT_DIR}/version.sh"
function init() {
LOGLEVEL_TEXT[0]="Panic"
LOGLEVEL_TEXT[1]="Fatal"
LOGLEVEL_TEXT[2]="Error"
LOGLEVEL_TEXT[3]="Warning"
LOGLEVEL_TEXT[4]="Info"
LOGLEVEL_TEXT[5]="Debug"
LOGLEVEL=4
RPMBUILD_DIR="$(dirname "${SCRIPT_DIR}")"
SPECS_DIR="${RPMBUILD_DIR}/SPECS"
RPMS_DIR="${RPMBUILD_DIR}/RPMS"
SRPMS_DIR="${RPMBUILD_DIR}/SRPMS"
BUILD_DIR="${RPMBUILD_DIR}/BUILD"
SOURCES_DIR="${RPMBUILD_DIR}/SOURCES"
for DIR in "${SPECS_DIR}" "${RPMS_DIR}" "${SRPMS_DIR}" "${BUILD_DIR}" "${SOURCES_DIR}"; do
if [ ! -d "${DIR}" ]; then
echo "$DIR not found. Creating it."
mkdir -p "${DIR}"
fi
done
}
function log() {
local LEVEL=$1
if [ ${LEVEL} -le ${LOGLEVEL} ]; then
shift 1
local DATE=$(date +"%Y-%m-%d %H:%M:%S")
printf "%s %s %s\n" "${DATE}" "${LOGLEVEL_TEXT[${LEVEL}]}" "$@"
fi
}
function get_archive() {
local URL="$1"
local APP="$2"
local VERSION="$3"
local TARGET_DIR="$4"
if [ -z "${URL}" ]; then
echo "get_archive: No URL provided"
exit 1
fi
if [ -z "${APP}" ]; then
echo "get_archive: No application provided"
exit 1
fi
if [ -z "${VERSION}" ]; then
echo "get_archive: No version provided"
exit 1
fi
if [ -n "${TARGET_DIR}" ]; then
cd "${TARGET_DIR}"
fi
log 4 "Downloading ${APP}-${VERSION}.tar.gz into ${TARGET_DIR}"
curl -sSkjL "${URL}" -o "${APP}-${VERSION}.tar.gz"
RESULT=$?
local SIZE=$(cat "${APP}-${VERSION}.tar.gz"|wc -c)
if [ $SIZE -le 512 ]; then
# 112 is the size of a tar.gz with an empty file in it, the average bitbucket error is around 150 bytes
log 2 "Download of ${APP}-${VERSION}.tar.gz failed or is damaged: File too small."
exit 1
fi
return ${RESULT}
}
function build() {
local APP="$1"
local VERSION="$2"
local RELEASE="$3"
local ARCH="$4"
cp "${SCRIPT_DIR}/${APP}.spec" "${SPECS_DIR}/"
cd "${RPMBUILD_DIR}"
log 4 "Building ${APP} ${VERSION}-${RELEASE}"
rpmbuild --define="_topdir ${RPMBUILD_DIR}" \
--define="version ${VERSION}" \
--define="release ${RELEASE}" \
--define="app ${APP}" \
--define="arch ${ARCH}" \
-ba "${SPECS_DIR}/${APP}.spec"
local RESULT=$?
if [ ${RESULT} -ne 0 ]; then
log 2 "Building the RPM failed"
return ${RESULT}
fi
log 4 "${APP} RPM built successfully"
return 0
}
init
get_archive "${URL}" "${APP}" "${VERSION}" "${SOURCES_DIR}"
if [ $? -ne 0 ]; then
exit 1
fi
build "${APP}" "${VERSION}" "${RELEASE}" "${ARCH}"
exit $?

View File

@ -1,20 +1,23 @@
%define version 1.1.1
%define plugindir /usr/lib64/nagios/plugins/
Name: check-systemd-service
Name: monitoring-check-systemd-service
Version: %{version}
Release: 1
Release: %{release}.el%{?rhel}
Epoch: 1
Summary: Nagios/Icinga check for systemd services
AutoReqProv: no
BuildRoot: %buildroot
BuildArch: noarch
Source0: https://github.com/joernott/monitoring-check-systemd-service/archive/v%{version}.tar.gz#/monitoring-check-systemd-service-%{version}.tar.gz
License: BSD
URL: https://github.com/joernott/monitoring-check-systemd-service
%if 0%{?rhel} == 8
Requires: python36
Requires: python3-gobject
Requires: python3-nagiosplugin
%else
Requires: rh-python36
Requires: python36-gobject
Requires: python3-nagiosplugin
%endif
%description
This script is intended for icinga/nagios/icinga2 to check the state of a
@ -25,17 +28,16 @@ Lennart Poettering says it is the right way to do and cli output is not stable
and should not be parsed.
%prep
%autosetup -n monitoring-check-systemd-service-%{version}
%setup -q monitoring-check-systemd-service-%{version}
%build
%install
mkdir -p $RPM_BUILD_ROOT%{plugindir}
mv %{_builddir}/monitoring-check-systemd-service-%{version}/check-systemd-service $RPM_BUILD_ROOT%{plugindir}/
rm -rf $RPM_BUILD_ROOT/monitoring-check-systemd-service-%{version}
%clean
rm -rf $RPM_BUILD_ROOT/*
mkdir -p "$RPM_BUILD_ROOT/usr/lib64/nagios/plugins"
cp check-systemd-service "$RPM_BUILD_ROOT/usr/lib64/nagios/plugins/"
%files
%attr(755,root,root) %{plugindir}/check-systemd-service
%attr(755,root,root) /usr/lib64/nagios/plugins/check-systemd-service
%changelog
* Wed Apr 27 2022 Joern Ott <joern.ott@ott-consult.de>
- Standardize builds for plugins

7
contrib/version.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
# see https://github.com/joernott/monitoring-check-systemd-service/tags
APP="monitoring-check-systemd-service"
VERSION="1.2.0"
RELEASE="1"
URL="https://github.com/joernott/monitoring-check-systemd-service/archive/refs/tags/v${VERSION}.tar.gz"
ARCH="noarch"