From 7812874ed77c593bbbc912311d2483cb362f44dd Mon Sep 17 00:00:00 2001 From: Thomas Deutschmann Date: Tue, 4 Aug 2020 23:59:17 +0200 Subject: sys-apps/kexec-tools: runscript: fix style Package-Manager: Portage-3.0.1, Repoman-2.3.23 Signed-off-by: Thomas Deutschmann --- sys-apps/kexec-tools/files/kexec-r2.init | 188 ++++++++++++++++++++++ sys-apps/kexec-tools/kexec-tools-2.0.20-r2.ebuild | 110 +++++++++++++ sys-apps/kexec-tools/kexec-tools-9999.ebuild | 2 +- 3 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 sys-apps/kexec-tools/files/kexec-r2.init create mode 100644 sys-apps/kexec-tools/kexec-tools-2.0.20-r2.ebuild (limited to 'sys-apps/kexec-tools') diff --git a/sys-apps/kexec-tools/files/kexec-r2.init b/sys-apps/kexec-tools/files/kexec-r2.init new file mode 100644 index 000000000000..ea6b790d324f --- /dev/null +++ b/sys-apps/kexec-tools/files/kexec-r2.init @@ -0,0 +1,188 @@ +#!/sbin/openrc-run +# Copyright 1999-2020 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# Set up some defaults. +: "${LOAD_DURING_SHUTDOWN:=yes}" +: "${BOOTPART:=/boot}" +: "${DONT_MOUNT_BOOT:=no}" + +depend() { + need localmount +} + +auto_prefix_bootpath() { + # Only auto-add prefix to relative paths. + case $1 in + */*) echo "$1";; + *) echo "${BOOTPART}/$1" ;; + esac +} + +get_genkernel_arch() { + case $1 in + x86_64) echo "amd64" ;; + i[3456]86) echo "x86" ;; + *) echo "$1" ;; + esac +} + +image_path() { + # Do no sanity checking if the user has set a value. + if [ -n "${KNAME}" ]; then + auto_prefix_bootpath "${KNAME}" + return + fi + + local x kver="$(uname -r)" karch="$(uname -m)" + local gkarch="$(get_genkernel_arch $karch)" + for x in \ + "bzImage" \ + "vmlinux" \ + "vmlinuz" \ + "bzImage-${kver}" \ + "vmlinux-${kver}" \ + "vmlinuz-${kver}" \ + "kernel-genkernel-${karch}-${kver}" \ + "kernel-genkernel-${gkarch}-${kver}" \ + "kernel-${kver}" \ + "kernel-${karch}"; do + if [ -e "${BOOTPART}/${x}" ]; then + echo "${BOOTPART}/${x}" + return + fi + done + + return 1 +} + +initrd_path() { + # Do no sanity checking if the user has set a value. + if [ -n "${INITRD}" ]; then + auto_prefix_bootpath "${INITRD}" + return 0 + fi + + local x kver="$(uname -r)" karch="$(uname -m)" + local gkarch="$(get_genkernel_arch $karch)" + for x in \ + "initrd" \ + "initrd.img-${kver}" \ + "initrd-${kver}.img" \ + "initrd-${kver}" \ + "initramfs-${kver}.img" \ + "initramfs-genkernel-${karch}-${kver}" \ + "initramfs-genkernel-${gkarch}-${kver}"; do + if [ -e "${BOOTPART}/${x}" ]; then + echo "${BOOTPART}/${x}" + return 0 + fi + done + + return 1 +} + +mount_boot() { + [ "${DONT_MOUNT_BOOT}" != "no" ] && return 1 + mountinfo -q "${BOOTPART}" && return 1 + + ebegin "Mounting ${BOOTPART}" + mount "${BOOTPART}" + eend $? +} + +load_image() { + if [ "${KNAME}" = "-" ]; then + ebegin "Disabling kexec" + kexec -u + eend $? + return # eend preserved $? for us. + fi + + local img initrd="$(initrd_path)" mounted=false kparamopt initrdopt + + if ! img="$(image_path)"; then + if mount_boot; then + if img="$(image_path)"; then + mounted=true + initrd="$(initrd_path)" + else + eerror "No kernel image found in ${BOOTPART}!" + umount "${BOOTPART}" + return 1 + fi + else + eerror "No kernel image found in ${BOOTPART}!" + return 1 + fi + fi + + if [ -z "${ROOTPART}" ]; then + ROOTPART="$(readlink -f "$(sed -n '/^\/[^ ]* \/ / s,^\([^ ]*\).*,\1,p' /proc/mounts)")" + fi + + if [ -z "${KPARAM}" ]; then + kparamopt="--reuse-cmdline" + fi + + if [ -n "${initrd}" ]; then + initrdopt="--initrd=${initrd}" + fi + + local msg + [ -n "${initrd}" ] && \ + msg=" (with ${initrd})" + ebegin "Using kernel image ${img}${msg} for kexec" + + kexec ${KEXEC_OPT_ARGS} ${kparamopt} \ + -l "${img}" --append="root=${ROOTPART} ${KPARAM}" ${initrdopt} + local ret=$? + + ${mounted} && umount "${BOOTPART}" + eend ${ret} + return ${ret} +} + +start() { + if [ "${LOAD_DURING_SHUTDOWN}" = "yes" ]; then + local mounted + if mount_boot; then + mounted=true + fi + if ! image_path >/dev/null; then + ewarn "Cannot find kernel image!" + ewarn "Please make sure a valid kernel image is present before reboot." + return 0 + fi + if [ -n "${mounted}" ]; then + ebegin "Unmounting ${BOOTPART}" + umount "${BOOTPART}" + eend $? + fi + # $? is already set to the previous calls. + return + else + load_image + fi +} + +stop() { + if ! yesno ${RC_REBOOT}; then + ebegin "Not rebooting; disabling kexec" + kexec -u + eend $? + return + fi + + if [ -f /nokexec ]; then + ebegin "Rebooting; disabling kexec due to /nokexec" + rm -f /nokexec + kexec -u + eend $? + return + fi + + if [ "${LOAD_DURING_SHUTDOWN}" = "yes" ]; then + load_image + fi +} diff --git a/sys-apps/kexec-tools/kexec-tools-2.0.20-r2.ebuild b/sys-apps/kexec-tools/kexec-tools-2.0.20-r2.ebuild new file mode 100644 index 000000000000..3a25aced9f07 --- /dev/null +++ b/sys-apps/kexec-tools/kexec-tools-2.0.20-r2.ebuild @@ -0,0 +1,110 @@ +# Copyright 1999-2020 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=7 + +inherit libtool linux-info systemd + +if [[ ${PV} == "9999" ]] ; then + inherit git-r3 autotools + EGIT_REPO_URI="https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git" +else + SRC_URI="https://www.kernel.org/pub/linux/utils/kernel/kexec/${P/_/-}.tar.xz" + [[ "${PV}" == *_rc* ]] || \ + KEYWORDS="~amd64 ~arm64 ~ppc64 ~x86" +fi + +DESCRIPTION="Load another kernel from the currently executing Linux kernel" +HOMEPAGE="https://kernel.org/pub/linux/utils/kernel/kexec/" + +LICENSE="GPL-2" +SLOT="0" +IUSE="booke lzma xen zlib" + +REQUIRED_USE="lzma? ( zlib )" + +DEPEND=" + lzma? ( app-arch/xz-utils ) + zlib? ( sys-libs/zlib )" +RDEPEND="${DEPEND}" + +S="${WORKDIR}/${P/_/-}" + +CONFIG_CHECK="~KEXEC" + +PATCHES=( + "${FILESDIR}"/${PN}-2.0.4-disable-kexec-test.patch + "${FILESDIR}"/${PN}-2.0.4-out-of-source.patch + "${FILESDIR}"/${P}-remove-duplicated-variable-declarations.patch + "${FILESDIR}"/${P}-build-multiboot2-for-i386.patch +) + +pkg_setup() { + # GNU Make's $(COMPILE.S) passes ASFLAGS to $(CCAS), CCAS=$(CC) + export ASFLAGS="${CCASFLAGS}" +} + +src_prepare() { + default + + # Append PURGATORY_EXTRA_CFLAGS flags set by configure, instead of overriding them completely. + sed -e "/^PURGATORY_EXTRA_CFLAGS =/s/=/+=/" -i Makefile.in || die + + if [[ "${PV}" == 9999 ]] ; then + eautoreconf + else + elibtoolize + fi +} + +src_configure() { + local myeconfargs=( + $(use_with booke) + $(use_with lzma) + $(use_with xen) + $(use_with zlib) + ) + econf "${myeconfargs[@]}" +} + +src_compile() { + # Respect CFLAGS for purgatory. + # purgatory/Makefile uses PURGATORY_EXTRA_CFLAGS variable. + # -mfunction-return=thunk and -mindirect-branch=thunk conflict with + # -mcmodel=large which is added by build system. + # Replace them with -mfunction-return=thunk-inline and -mindirect-branch=thunk-inline. + local flag flags=() + for flag in ${CFLAGS}; do + [[ ${flag} == -mfunction-return=thunk ]] && flag="-mfunction-return=thunk-inline" + [[ ${flag} == -mindirect-branch=thunk ]] && flag="-mindirect-branch=thunk-inline" + flags+=("${flag}") + done + local -x PURGATORY_EXTRA_CFLAGS="${flags[*]}" + + default +} + +src_install() { + default + + dodoc "${FILESDIR}"/README.Gentoo + + newinitd "${FILESDIR}"/kexec-r2.init kexec + newconfd "${FILESDIR}"/kexec.conf-2.0.4 kexec + + insinto /etc + doins "${FILESDIR}"/kexec.conf + + insinto /etc/kernel/postinst.d + doins "${FILESDIR}"/90_kexec + + systemd_dounit "${FILESDIR}"/kexec.service +} + +pkg_postinst() { + if systemd_is_booted || has_version sys-apps/systemd; then + elog "For systemd support the new config file is" + elog " /etc/kexec.conf" + elog "Please adopt it to your needs as there is no autoconfig anymore" + fi +} diff --git a/sys-apps/kexec-tools/kexec-tools-9999.ebuild b/sys-apps/kexec-tools/kexec-tools-9999.ebuild index 77c5d7c6e590..cb3f3b6f1c4a 100644 --- a/sys-apps/kexec-tools/kexec-tools-9999.ebuild +++ b/sys-apps/kexec-tools/kexec-tools-9999.ebuild @@ -87,7 +87,7 @@ src_install() { dodoc "${FILESDIR}"/README.Gentoo - newinitd "${FILESDIR}"/kexec.init-2.0.13-r1 kexec + newinitd "${FILESDIR}"/kexec-r2.init kexec newconfd "${FILESDIR}"/kexec.conf-2.0.4 kexec insinto /etc -- cgit v1.2.3-65-gdbad