1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-21 05:57:34 +03:00

Merge pull request from наб

A trivial merge conflict was fixed manually.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-01-18 15:20:37 +01:00
commit 8513c34bec
3 changed files with 112 additions and 150 deletions

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
# SPDX-License-Identifier: LGPL-2.1-or-later
@ -20,23 +20,27 @@
COMMAND="$1"
KERNEL_VERSION="$2"
ENTRY_DIR_ABS="$3"
KERNEL_IMAGE="$4"
INITRD_OPTIONS_START="5"
[[ $KERNEL_VERSION ]] || exit 1
case "$COMMAND" in
add)
[[ -d "/lib/modules/${KERNEL_VERSION}/kernel" ]] || exit 0
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "Running depmod -a ${KERNEL_VERSION}"
exec depmod -a "${KERNEL_VERSION}"
[ -d "/lib/modules/$KERNEL_VERSION/kernel" ] || exit 0
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "+depmod -a $KERNEL_VERSION"
exec depmod -a "$KERNEL_VERSION"
;;
remove)
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "Removing /lib/modules/${KERNEL_VERSION}/modules.dep and associated files"
exec rm -f /lib/modules/"${KERNEL_VERSION}"/modules.{alias{,.bin},builtin{,.alias}.bin,dep{,.bin},devname,softdep,symbols{,.bin}}
exec rm -f \
"/lib/modules/$KERNEL_VERSION/modules.alias" \
"/lib/modules/$KERNEL_VERSION/modules.alias.bin" \
"/lib/modules/$KERNEL_VERSION/modules.builtin.bin" \
"/lib/modules/$KERNEL_VERSION/modules.builtin.alias.bin" \
"/lib/modules/$KERNEL_VERSION/modules.dep" \
"/lib/modules/$KERNEL_VERSION/modules.dep.bin" \
"/lib/modules/$KERNEL_VERSION/modules.devname" \
"/lib/modules/$KERNEL_VERSION/modules.softdep" \
"/lib/modules/$KERNEL_VERSION/modules.symbols" \
"/lib/modules/$KERNEL_VERSION/modules.symbols.bin"
;;
*)
exit 0

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
# SPDX-License-Identifier: LGPL-2.1-or-later
@ -22,68 +22,53 @@ COMMAND="$1"
KERNEL_VERSION="$2"
ENTRY_DIR_ABS="$3"
KERNEL_IMAGE="$4"
INITRD_OPTIONS_START="5"
INITRD_OPTIONS_SHIFT=4
if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then
exit 0
fi
if [ "$KERNEL_INSTALL_LAYOUT" != "bls" ]; then
exit 0
fi
[ "$KERNEL_INSTALL_LAYOUT" = "bls" ] || exit 0
MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
BOOT_ROOT="$KERNEL_INSTALL_BOOT_ROOT"
BOOT_MNT="$(stat -c %m "$BOOT_ROOT")"
if [[ "$BOOT_MNT" == '/' ]]; then
if [ "$BOOT_MNT" = '/' ]; then
ENTRY_DIR="$ENTRY_DIR_ABS"
else
ENTRY_DIR="${ENTRY_DIR_ABS#$BOOT_MNT}"
fi
if [[ $COMMAND == remove ]]; then
rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+"*".conf"
exit 0
fi
case "$COMMAND" in
remove)
exec rm -f \
"$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf" \
"$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+"*".conf"
;;
add)
;;
*)
exit 1
;;
esac
if ! [[ $COMMAND == add ]]; then
exit 1
fi
if ! [[ $KERNEL_IMAGE ]]; then
exit 1
fi
if [[ -f /etc/os-release ]]; then
if [ -r /etc/os-release ]; then
. /etc/os-release
elif [[ -f /usr/lib/os-release ]]; then
elif [ -r /usr/lib/os-release ]; then
. /usr/lib/os-release
fi
if ! [[ $PRETTY_NAME ]]; then
PRETTY_NAME="Linux $KERNEL_VERSION"
fi
[ -n "$PRETTY_NAME" ] || PRETTY_NAME="Linux $KERNEL_VERSION"
if [[ -f /etc/kernel/cmdline ]]; then
read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline
elif [[ -f /usr/lib/kernel/cmdline ]]; then
read -r -d '' -a BOOT_OPTIONS < /usr/lib/kernel/cmdline
if [ -r /etc/kernel/cmdline ]; then
BOOT_OPTIONS="$(tr -s "$IFS" ' ' </etc/kernel/cmdline)"
elif [ -r /usr/lib/kernel/cmdline ]; then
BOOT_OPTIONS="$(tr -s "$IFS" ' ' </usr/lib/kernel/cmdline)"
else
declare -a BOOT_OPTIONS
read -r -d '' -a line < /proc/cmdline
for i in "${line[@]}"; do
[[ "${i#initrd=*}" != "$i" ]] && continue
[[ "${i#BOOT_IMAGE=*}" != "$i" ]] && continue
BOOT_OPTIONS+=("$i")
done
BOOT_OPTIONS="$(tr -s "$IFS" '\n' </proc/cmdline | grep -ve '^BOOT_IMAGE=' -e '^initrd=' | tr '\n' ' ')"
fi
BOOT_OPTIONS="${BOOT_OPTIONS% }"
if [[ -f /etc/kernel/tries ]]; then
if [ -r /etc/kernel/tries ]; then
read -r TRIES </etc/kernel/tries
if ! [[ "$TRIES" =~ ^[0-9]+$ ]] ; then
if ! echo "$TRIES" | grep -q '^[0-9][0-9]*$'; then
echo "/etc/kernel/tries does not contain an integer." >&2
exit 1
fi
@ -106,43 +91,40 @@ install -g root -o root -m 0644 "$KERNEL_IMAGE" "$ENTRY_DIR_ABS/linux" || {
exit 1
}
INITRD_OPTIONS=( "${@:${INITRD_OPTIONS_START}}" )
shift "$INITRD_OPTIONS_SHIFT"
for initrd; do
[ -f "$initrd" ] || {
echo "Initrd '$initrd' not a file." >&2
exit 1
}
for initrd in "${INITRD_OPTIONS[@]}"; do
if [[ -f "${initrd}" ]]; then
initrd_basename="$(basename ${initrd})"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "Installing $ENTRY_DIR_ABS/${initrd_basename}"
install -g root -o root -m 0644 "${initrd}" "$ENTRY_DIR_ABS/${initrd_basename}" || {
echo "Could not copy '${initrd}' to '$ENTRY_DIR_ABS/${initrd_basename}'." >&2
exit 1
}
fi
initrd_basename="${initrd##*/}"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Installing $ENTRY_DIR_ABS/$initrd_basename"
install -g root -o root -m 0644 "$initrd" "$ENTRY_DIR_ABS/$initrd_basename" || {
echo "Could not copy '$initrd' to '$ENTRY_DIR_ABS/$initrd_basename'." >&2
exit 1
}
done
# If no initrd option is supplied, fall back to "initrd" which is
# the name used by dracut when generating it in its kernel-install hook
[[ ${#INITRD_OPTIONS[@]} == 0 ]] && INITRD_OPTIONS=( initrd )
mkdir -p "${LOADER_ENTRY%/*}" || {
echo "Could not create loader entry directory '${LOADER_ENTRY%/*}'." >&2
exit 1
}
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "Creating $LOADER_ENTRY"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Creating $LOADER_ENTRY"
{
echo "title $PRETTY_NAME"
echo "version $KERNEL_VERSION"
echo "machine-id $MACHINE_ID"
echo "options ${BOOT_OPTIONS[*]}"
echo "options $BOOT_OPTIONS"
echo "linux $ENTRY_DIR/linux"
for initrd in "${INITRD_OPTIONS[@]}"; do
[[ -f $ENTRY_DIR_ABS/$(basename ${initrd}) ]] && \
echo "initrd $ENTRY_DIR/$(basename ${initrd})"
for initrd; do
echo "initrd $ENTRY_DIR/${initrd##*/}"
done
# Try "initrd", generated by dracut in its kernel-install hook, if no initrds were supplied
[ $# -eq 0 ] && [ -f "$ENTRY_DIR_ABS/initrd" ] && echo "initrd $ENTRY_DIR/initrd"
:
} > "$LOADER_ENTRY" || {
} >"$LOADER_ENTRY" || {
echo "Could not create loader entry '$LOADER_ENTRY'." >&2
exit 1
}

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
# SPDX-License-Identifier: LGPL-2.1-or-later
@ -18,7 +18,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
SKIP_REMAINING=77
skip_remaining=77
usage()
{
@ -26,30 +26,23 @@ usage()
echo " $0 [OPTIONS...] add KERNEL-VERSION KERNEL-IMAGE [INITRD-FILE ...]"
echo " $0 [OPTIONS...] remove KERNEL-VERSION"
echo "Options:"
echo " -h,--help Print this help"
echo " -v,--verbose Increase verbosity"
echo " -h, --help Print this help"
echo " -v, --verbose Increase verbosity"
}
dropindirs_sort()
{
local suffix=$1; shift
local -a files
local f d i
suffix="$1"
shift
readarray -t files <<<"$(
for d in "$@"; do
for i in "$d/"*"$suffix"; do
if [[ -e "$i" ]]; then
echo "${i##*/}"
fi
done
done | sort -Vu
)"
for f in "${files[@]}"; do
for d in "$@"; do
if [[ -e "$d/$f" ]]; then
echo "$d/$f"
for d; do
for i in "$d/"*"$suffix"; do
[ -e "$i" ] && echo "${i##*/}"
done
done | sort -Vu | while read -r f; do
for d; do
if [ -e "$d/$f" ]; then
[ -x "$d/$f" ] && echo "$d/$f"
continue 2
fi
done
@ -58,38 +51,35 @@ dropindirs_sort()
export LC_COLLATE=C
for i in "$@"; do
if [ "$i" == "--help" -o "$i" == "-h" ]; then
for i; do
if [ "$i" = "--help" ] || [ "$i" = "-h" ]; then
usage
exit 0
fi
done
KERNEL_INSTALL_VERBOSE=0
if [ "$1" == "--verbose" -o "$1" == "-v" ]; then
export KERNEL_INSTALL_VERBOSE=0
if [ "$1" = "--verbose" ] || [ "$1" = "-v" ]; then
shift
KERNEL_INSTALL_VERBOSE=1
fi
export KERNEL_INSTALL_VERBOSE
if [[ "${0##*/}" == 'installkernel' ]]; then
COMMAND='add'
# make install doesn't pass any parameter wrt initrd handling
INITRD_OPTIONS=()
if [ "${0##*/}" = "installkernel" ]; then
COMMAND=add
# make install doesn't pass any initrds
else
COMMAND="$1"
shift
INITRD_OPTIONS=( "${@:3}" )
[ $# -ge 1 ] && shift
fi
KERNEL_VERSION="$1"
KERNEL_IMAGE="$2"
if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then
if [ $# -lt 1 ]; then
echo "Not enough arguments" >&2
exit 1
fi
KERNEL_VERSION="$1"
shift
if [ -r "/etc/kernel/install.conf" ]; then
. /etc/kernel/install.conf
elif [ -r "/usr/lib/kernel/install.conf" ]; then
@ -99,12 +89,11 @@ fi
# Prefer to use an existing machine ID from /etc/machine-info or /etc/machine-id. If we're using the machine
# ID /etc/machine-id, try to persist it in /etc/machine-info. If no machine ID is found, try to generate
# a new machine ID in /etc/machine-info. If that fails, use "Default".
[ -z "$MACHINE_ID" ] && [ -f /etc/machine-info ] && source /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
[ -z "$MACHINE_ID" ] && [ -f /etc/machine-id ] && read -r MACHINE_ID </etc/machine-id
[ -n "$MACHINE_ID" ] && [ -z "$KERNEL_INSTALL_MACHINE_ID" ] && echo "KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID" >>/etc/machine-info
[ -z "$MACHINE_ID" ] && [ -r /etc/machine-info ] && . /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
[ -z "$MACHINE_ID" ] && [ -r /etc/machine-id ] && read -r MACHINE_ID </etc/machine-id
[ -n "$MACHINE_ID" ] && [ -z "$KERNEL_INSTALL_MACHINE_ID" ] && echo "KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID" >>/etc/machine-info
[ -z "$MACHINE_ID" ] && NEW_MACHINE_ID="$(systemd-id128 new)" && echo "KERNEL_INSTALL_MACHINE_ID=$NEW_MACHINE_ID" >>/etc/machine-info
[ -z "$MACHINE_ID" ] && [ -f /etc/machine-info ] && source /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
[ -z "$MACHINE_ID" ] && [ -r /etc/machine-info ] && . /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
[ -z "$MACHINE_ID" ] && MACHINE_ID="Default"
[ -z "$BOOT_ROOT" ] && for suff in "$MACHINE_ID" "loader/entries"; do
@ -125,11 +114,6 @@ done
[ -z "$BOOT_ROOT" ] && BOOT_ROOT="/boot"
ENTRY_DIR_ABS="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION"
export KERNEL_INSTALL_MACHINE_ID="$MACHINE_ID"
export KERNEL_INSTALL_BOOT_ROOT="$BOOT_ROOT"
if [ -z "$layout" ]; then
# Administrative decision: if not present, some scripts generate into /boot.
if [ -d "$BOOT_ROOT/$MACHINE_ID" ]; then
@ -152,21 +136,23 @@ MAKE_ENTRY_DIR_ABS=$?
ret=0
readarray -t PLUGINS <<<"$(
PLUGINS="$(
dropindirs_sort ".install" \
"/etc/kernel/install.d" \
"/usr/lib/kernel/install.d"
)"
IFS="
"
case $COMMAND in
case "$COMMAND" in
add)
if [[ ! "$KERNEL_IMAGE" ]]; then
echo "Command 'add' requires an argument" >&2
if [ $# -lt 1 ]; then
echo "Command 'add' requires a kernel image" >&2
exit 1
fi
if [[ ! -f "$KERNEL_IMAGE" ]]; then
echo "Kernel image argument ${KERNEL_IMAGE} not a file" >&2
if ! [ -f "$1" ]; then
echo "Kernel image argument $1 not a file" >&2
exit 1
fi
@ -182,32 +168,22 @@ case $COMMAND in
fi
fi
for f in "${PLUGINS[@]}"; do
if [[ -x $f ]]; then
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "+$f add $KERNEL_VERSION $ENTRY_DIR_ABS $KERNEL_IMAGE ${INITRD_OPTIONS[@]}"
"$f" add "$KERNEL_VERSION" "$ENTRY_DIR_ABS" "$KERNEL_IMAGE" "${INITRD_OPTIONS[@]}"
x=$?
if [[ $x == $SKIP_REMAINING ]]; then
break
fi
((ret+=$x))
fi
for f in $PLUGINS; do
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "+$f add $KERNEL_VERSION $ENTRY_DIR_ABS $*"
"$f" add "$KERNEL_VERSION" "$ENTRY_DIR_ABS" "$@"
err=$?
[ $err -eq $skip_remaining ] && break
ret=$(( ret + err ))
done
;;
remove)
for f in "${PLUGINS[@]}"; do
if [[ -x $f ]]; then
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "+$f remove $KERNEL_VERSION $ENTRY_DIR_ABS"
"$f" remove "$KERNEL_VERSION" "$ENTRY_DIR_ABS"
x=$?
if [[ $x == $SKIP_REMAINING ]]; then
break
fi
((ret+=$x))
fi
for f in $PLUGINS; do
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "+$f remove $KERNEL_VERSION $ENTRY_DIR_ABS"
"$f" remove "$KERNEL_VERSION" "$ENTRY_DIR_ABS"
err=$?
[ $err -eq $skip_remaining ] && break
ret=$(( ret + err ))
done
if [ "$MAKE_ENTRY_DIR_ABS" -eq 0 ]; then
@ -222,4 +198,4 @@ case $COMMAND in
;;
esac
exit $ret
exit "$ret"