Commit e5d5f420 authored by Markus Frosch's avatar Markus Frosch 📣

Add RPM scripts

parent 0b07d66e
#!/bin/bash
detect_project() {
specs=($(ls *.spec))
if [ "${#specs[@]}" -eq 0 ]; then
echo "No Spec file found!" >&2
exit 1
elif [ "${#specs[@]}" -gt 1 ]; then
echo "More than one spec file found!" >&2
exit 1
else
echo "$(basename "${specs[0]}" .spec)"
fi
}
detect_os() {
os=$(awk -F"=" '/^ID=/ {print $2}' /etc/os-release | sed -e 's/^"//' -e 's/"$//')
if [ -n "$os" ]; then
echo "$os"
else
echo "Could not detect os (ID) from /etc/os-release" >&2
exit 1
fi
}
detect_dist() {
# TODO: verify for SUSE
dist=$(awk -F= '/^VERSION_ID=/ {print $2}' /etc/os-release | sed -e 's/^"//' -e 's/"$//')
if [ -n "$dist" ]; then
echo "$dist"
else
echo "Could not detect dist (VERSION_ID) from /etc/os-release" >&2
exit 1
fi
}
detect_arch() {
# TODO: verify for SUSE
arches=($(rpm -qa "*-release" --qf "%{arch}\n" | sort -u | grep -v noarch))
if [ "${#arches[@]}" -eq 0 ]; then
echo "No basearch found while looking for *-release packages!" >&2
exit 1
elif [ "${#arches[@]}" -gt 1 ]; then
echo "More than one base arch found with *-release packages!" >&2
exit 1
else
echo "${arches[0]}"
fi
}
print_build_env() {
echo "[ Icinga Build Environment ]"
(set -o posix; set) | grep -E ^ICINGA
}
require_var() {
err=0
for var in "$@"; do
if [ -z "${!var}" ]; then
echo "Variable $var is not set!" >&2
err+=1
fi
done
[ "$err" -eq 0 ] || exit 1
echo
}
get_rpmbuild() {
local RPMBUILD dist setarch
dist=`rpm -E '%{?dist}' | sed 's/\(\.centos\)\?$/.icinga/'`
setarch=''
# TODO: target_arch
if [ -n "$target_arch" ]; then
setarch="setarch ${target_arch}"
fi
RPMBUILD=(
${setarch} \
/usr/bin/rpmbuild \
--define "vendor Icinga.com" \
--define "dist $dist" \
--define "_topdir ${WORKDIR}/rpmbuild" \
"$@"
)
declare -p RPMBUILD
}
rpmbuild() {
local RPMBUILD
eval "$(get_rpmbuild "$@")"
"${RPMBUILD[@]}"
}
find_compilers() {
local location=${1:-/usr/bin}
cd "$location"
ls {cc,cpp,[gc]++,gcc}{,-*} 2>/dev/null || true
}
# repair/prepare ccache (needed on some distros like CentOS 5 + 6, SUSE, OpenSUSE)
preconfigure_ccache() {
CCACHE_LINKS=`rpm -E %_libdir`/ccache
compilers=($(find_compilers))
if [ -e /opt/rh/devtoolset-2/enable ]; then
compilers+=($(find_compilers /opt/rh/devtoolset-2/root/usr/bin))
fi
sudo sh -ex <<CCACHEREPAIR
test -d ${CCACHE_LINKS} || mkdir ${CCACHE_LINKS}
cd ${CCACHE_LINKS}
echo 'Preparing/Repairing ccache symlinks...'
for comp in ${compilers[@]}; do
[ ! -e \${comp} ] || continue
ln -svf /usr/bin/ccache \${comp}
done
CCACHEREPAIR
if [ -e /opt/rh/devtoolset-2/enable ]; then
echo "Patching devtoolset-2 to use ccache..."
# This is the only good way to re-add ccache to top of PATH
# scl enable (inside icinga2.spec) will set its own path first
sudo sh -ex <<SUDOSCRIPT
echo 'PATH="${CCACHE_LINKS}:\${PATH}" to /opt/rh/devtoolset-2/enable'
echo 'PATH="${CCACHE_LINKS}:\${PATH}"' >> /opt/rh/devtoolset-2/enable
SUDOSCRIPT
else
# Enable ccache as a default wrapper for compilers
PATH="${CCACHE_LINKS}:${PATH}"
fi
}
: ${ICINGA_BUILD_PROJECT:=`detect_project`}
: ${ICINGA_BUILD_OS:=`detect_os`}
: ${ICINGA_BUILD_DIST:=`detect_dist`}
: ${ICINGA_BUILD_ARCH:=`detect_arch`}
: ${ICINGA_BUILD_TYPE:="release"}
: ${ICINGA_BUILD_UPSTREAM_BRANCH:="master"}
print_build_env
require_var ICINGA_BUILD_PROJECT ICINGA_BUILD_OS ICINGA_BUILD_DIST ICINGA_BUILD_ARCH ICINGA_BUILD_TYPE
export LANG=C
WORKDIR=`pwd`
BUILDDIR='rpmbuild'
# vi: ts=2 sw=2 expandtab
......@@ -7,8 +7,21 @@ FILES_DEBIAN="$(ls */debian 2>/dev/null)"
if [ -n "${FILES_SPEC}" ]; then
echo "Detected RPM source: ${FILES_SPEC}"
echo
#TODO
exit 1
echo "[ running source build ]"
icinga-build-rpm-source
if [ $? -ne 0 ]; then
echo "[ source build failed! ]"
exit 1
fi
echo "[ source build completed ]"
echo
echo "[ running binary build ]"
icinga-build-rpm-binary
if [ $? -ne 0 ]; then
echo "[ binary build failed! ]"
exit 1
fi
echo "[ binary build completed ]"
elif [ -n "${FILES_DEBIAN}" ]; then
echo "Detected Debian source files: ${FILES_DEBIAN}"
echo
......@@ -28,7 +41,6 @@ elif [ -n "${FILES_DEBIAN}" ]; then
exit 1
fi
echo "[ binary build completed ]"
echo
else
echo "Could not detect build type!" >&2
exit 1
......
#!/bin/bash
set -e
source "$(dirname "$(readlink -f "$0")")"/functions-rpm.sh
source_rpm="$(ls rpmbuild/SRPMS/*.src.rpm)"
if [ $(echo "${source_rpm}" | wc -l) -gt 1 ]; then
echo "More than one spec file found:" >&2
ls -al rpmbuild/SRPMS >&2
exit 1
fi
echo "[ Update package cache ]"
(
set -ex
case "$os" in
opensuse|sles)
# TODO: can we downgrade this to a simple ref again?
# images should be build with clean meta data in the future...
sudo zypper clean -a
sudo zypper --non-interactive --no-gpg-checks --gpg-auto-import-keys ref
;;
*)
sudo yum clean expire-cache
sudo yum makecache fast
;;
esac
)
echo "[ Installing build dependencies ]"
(
set -ex
case "$os" in
opensuse|sles)
sudo zypper --non-interactive install `rpm -qpR "${source_rpm}"`
;;
*)
sudo yum-builddep -y "${source_rpm}"
;;
esac
)
echo "[ Preparing ccache for our environment ]"
export CCACHE_DIR="${WORKDIR}/ccache"
preconfigure_ccache
# reset ccache statistics
# so we now the statistics of the new build
ccache -z # (--zero-stats)
echo "[ Building binary package ]"
eval "$(get_rpmbuild --rebuild "${source_rpm}")"
(
set -ex
# explicitly unset arch, it may conflict with internal scripts
# of the tools we build (happens with Icinga 2 and wxWidgets)
unset arch
if [ -e /opt/rh/devtoolset-2 ]; then
# Run in a newer compiler environment
# Environment needs to be set here for ccache to find the compiler to use...
scl enable devtoolset-2 -- "${RPMBUILD[@]}"
else
"${RPMBUILD[@]}"
fi
)
# save ccache statistics
ccache -s | tee ccache.stats # (--show-stats)
# TODO: rpmlint for binary packages
#!/bin/bash
set -e
source "$(dirname "$(readlink -f "$0")")"/functions-rpm.sh
(
set -ex
rm -f *.version *.tar*
rm -rf "${BUILDDIR}/"
)
echo "[ git show ]"
GIT_PAGER=cat git show -s
echo
echo "[ git status ]"
GIT_PAGER=cat git status
echo
(
set -ex
mkdir "${BUILDDIR}"/{,SPECS,SOURCES,BUILD,SRPMS,RPMS}
cp -v *.spec rpmbuild/SPECS/
source_files=($(find -maxdepth 1 -type f ! -name "*.spec"))
cp -v -t rpmbuild/SOURCES/ "${source_files[@]}"
)
# download archive
if [ "$release_type" == "release" ] ; then
echo "[ Downloading current sources with spectool ]"
(
set -ex
cd rpmbuild/SOURCES/
spectool -g ../SPECS/*.spec
)
else
echo "[ Creating snapshot tarball ]"
(
set -ex
UPSTREAM_GIT_BRANCH="$ICINGA_BUILD_UPSTREAM_BRANCH" ./get_snapshot
mv -t "${BUILDDIR}/SOURCES/" *.version *.tar*
)
echo "[ Building snapshot version ]"
(
set -ex
cd rpmbuild/
version=`cat SOURCES/"${ICINGA_BUILD_PROJECT}.version" | cut -f1`
revision="0.`date +%Y%m%d.%H%M`"
git_commit=`cat SOURCES/"${ICINGA_BUILD_PROJECT}.version" | cut -f2`
tarball=`cat SOURCES/"${ICINGA_BUILD_PROJECT}.version" | cut -f3`
sed -i \
-e "0,/^Version: /{s/Version: .*/Version: ${version}/}" \
-e "0,/^Release: /{s/Release: .*/Release: ${revision}%{?dist}/}" \
-e "0,/^Source0\?: /{s/\(Source0\?\): .*/Source0: ${tarball}/}" \
"SPECS/${ICINGA_BUILD_PROJECT}.spec"
)
fi
echo "[ Building source RPM ]"
(
set -ex
cd rpmbuild/
rpmbuild --nodeps -bs "SPECS/${ICINGA_BUILD_PROJECT}.spec"
# TODO: when a package is already releases this might be problems in test
# (he could test the package in repository)
rpm -qp --queryformat "%{VERSION}-%{RELEASE}" "SRPMS/${ICINGA_BUILD_PROJECT}"*".src.rpm" \
>../"${ICINGA_BUILD_PROJECT}-package.version"
)
echo "[ Running rpmlint ]"
(
set -ex
cd rpmbuild/
rpmlint --info --verbose "SPECS/${ICINGA_BUILD_PROJECT}.spec" || true
# TODO: rpmlint for binary packages
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment