containerd-packaging/scripts/.rpm-helpers

92 строки
2.7 KiB
Bash

#!/usr/bin/env sh
gen_test_ver() (
version=$1
suffix=$2
base_release_ver=$3
spec_file=${SPEC_FILE:-SPECS/containerd.spec}
test_num=${version#*-${suffix}.}
without_rpm_ver="${base_release_ver}.${test_num}.${suffix}.${test_num}"
# This only really matters for blessed builds (i.e. builds that are only rpm specific or have a version specific in the spec)
# should output the latest rpm build number so that it gets placed accordingly in the repo
if grep -q "${version%-${suffix}.*}-${without_rpm_ver}" "${spec_file}"; then
grep -o "${version%-${suffix}.*}-${without_rpm_ver}.[0-9]*" "${spec_file}" | head -n 1 | cut -d"-" -f 2
else
echo "${without_rpm_ver}.1"
fi
)
gen_rpm_ver_bits() (
version=$1
ver_dot=$(gen_rpm_release_ver_dot "${version}")
case "${version}" in
*beta*)
result="${version%-beta.*} $(gen_test_ver "${version}" beta 1)${ver_dot}"
;;
*rc*)
result="${version%-rc.*} $(gen_test_ver "${version}" rc 2)${ver_dot}"
;;
*)
result="${version} 3${ver_dot}"
;;
esac
echo "$result"
)
gen_rpm_release_ver_dot() (
version=$1
spec_file=${SPEC_FILE:-SPECS/containerd.spec}
# Find if the version is just releasing a package version
if grep -q "${version}-" "${spec_file}"; then
echo ".$(grep -c "${version}-" "${spec_file}")"
fi
)
install_build_deps() (
set -e -x
SPEC_FILE="${1?USAGE: install_build_deps SPEC_FILE}"
# set dummy NPM_VERSION and RPM_RELEASE_VERSION if they're not set to make the spec valid
export RPM_VERSION="${RPM_VERSION:=0.0.1}"
export RPM_RELEASE_VERSION="${RPM_RELEASE_VERSION:=dev}"
if type yum-builddep >/dev/null 2>/dev/null; then
# shellcheck disable=SC2086
yum-builddep -y ${EXTRA_REPOS} "${SPEC_FILE}"
elif type dnf >/dev/null 2>/dev/null; then
# shellcheck disable=SC2086
dnf builddep -y ${EXTRA_REPOS} "${SPEC_FILE}"
else
# either yum-utils is not installed, or we're running on SUSE/openSuSE.
# Zypper does not have a proper equivalent for installing build dependencies.
#
# This manual approach does an attempt to install dependencies
if type yum >/dev/null 2>/dev/null; then
pkg_manager="yum -y ${EXTRA_REPOS}"
elif type zypper >/dev/null 2>/dev/null; then
pkg_manager="zypper -n ${EXTRA_REPOS}"
else
echo "unable to detect package manager";
exit 1;
fi
# shellcheck disable=SC2046
${pkg_manager} install $(rpmspec -P "${SPEC_FILE}" | grep BuildRequires | cut -d' ' -f2 | xargs)
fi
)
install_package() (
if type yum >/dev/null 2>/dev/null; then
pkg_manager="yum -y"
elif type dnf >/dev/null 2>/dev/null; then
pkg_manager="dnf -y"
elif type zypper >/dev/null 2>/dev/null; then
pkg_manager="zypper -n"
else
echo "unable to detect package manager"
exit 1
fi
# shellcheck disable=SC2046
${pkg_manager} install "$@"
)