2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4 # SPDX-License-Identifier: LGPL-2.1+
6 # This file is part of systemd.
8 # systemd is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation; either version 2.1 of the License, or
11 # (at your option) any later version.
13 # systemd is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
26 echo " $0 add KERNEL-VERSION KERNEL-IMAGE [INITRD-FILE ...]"
27 echo " $0 remove KERNEL-VERSION"
32 local suffix
=$1; shift
36 readarray
-t files
<<<"$(
38 for i in "$d/"*"$suffix"; do
39 if [[ -e "$i" ]]; then
46 for f
in "${files[@]}"; do
48 if [[ -e "$d/$f" ]]; then
59 if [ "$i" == "--help" -o "$i" == "-h" ]; then
65 KERNEL_INSTALL_VERBOSE
=0
66 if [ "$1" == "--verbose" -o "$1" == "-v" ]; then
68 KERNEL_INSTALL_VERBOSE
=1
70 export KERNEL_INSTALL_VERBOSE
72 if [[ "${0##*/}" == 'installkernel' ]]; then
74 # make install doesn't pass any parameter wrt initrd handling
79 INITRD_OPTIONS
=( "${@:3}" )
85 if [[ -f /etc
/machine-id
]]; then
86 read MACHINE_ID
< /etc
/machine-id
89 if [[ ! $COMMAND ]] ||
[[ ! $KERNEL_VERSION ]]; then
90 echo "Not enough arguments" >&2
94 if ! [[ $MACHINE_ID ]]; then
95 ENTRY_DIR_ABS
=$
(mktemp
-d /tmp
/kernel-install.XXXXX
) ||
exit 1
96 trap "rm -rf '$ENTRY_DIR_ABS'" EXIT INT QUIT PIPE
97 elif [[ -d /efi
/loader
/entries
]] ||
[[ -d /efi
/$MACHINE_ID ]]; then
98 ENTRY_DIR_ABS
="/efi/$MACHINE_ID/$KERNEL_VERSION"
99 elif [[ -d /boot
/loader
/entries
]] ||
[[ -d /boot
/$MACHINE_ID ]]; then
100 ENTRY_DIR_ABS
="/boot/$MACHINE_ID/$KERNEL_VERSION"
101 elif [[ -d /boot
/efi
/loader
/entries
]] ||
[[ -d /boot
/efi
/$MACHINE_ID ]]; then
102 ENTRY_DIR_ABS
="/boot/efi/$MACHINE_ID/$KERNEL_VERSION"
103 elif mountpoint
-q /efi
; then
104 ENTRY_DIR_ABS
="/efi/$MACHINE_ID/$KERNEL_VERSION"
105 elif mountpoint
-q /boot
/efi
; then
106 ENTRY_DIR_ABS
="/boot/efi/$MACHINE_ID/$KERNEL_VERSION"
108 ENTRY_DIR_ABS
="/boot/$MACHINE_ID/$KERNEL_VERSION"
111 export KERNEL_INSTALL_MACHINE_ID
=$MACHINE_ID
115 readarray
-t PLUGINS
<<<"$(
116 dropindirs_sort ".
install" \
117 "/etc
/kernel
/install.d
" \
118 "/usr
/lib
/kernel
/install.d
"
123 if [[ ! "$KERNEL_IMAGE" ]]; then
124 echo "Command 'add' requires an argument" >&2
128 if [[ ! -f "$KERNEL_IMAGE" ]]; then
129 echo "Kernel image argument ${KERNEL_IMAGE} not a file" >&2
133 for f
in "${PLUGINS[@]}"; do
135 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
136 echo "+$f add $KERNEL_VERSION $ENTRY_DIR_ABS $KERNEL_IMAGE ${INITRD_OPTIONS[@]}"
137 "$f" add
"$KERNEL_VERSION" "$ENTRY_DIR_ABS" "$KERNEL_IMAGE" "${INITRD_OPTIONS[@]}"
139 if [[ $x == $SKIP_REMAINING ]]; then
147 if ! [[ $MACHINE_ID ]] && ! rmdir "$ENTRY_DIR_ABS"; then
148 echo "Warning: In kernel-install plugins, requiring ENTRY_DIR_ABS to be preset is deprecated." >&2
149 echo " All plugins should not put anything in ENTRY_DIR_ABS if the environment" >&2
150 echo " variable KERNEL_INSTALL_MACHINE_ID is empty." >&2
151 rm -rf "$ENTRY_DIR_ABS"
157 for f
in "${PLUGINS[@]}"; do
159 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
160 echo "+$f remove $KERNEL_VERSION $ENTRY_DIR_ABS"
161 "$f" remove
"$KERNEL_VERSION" "$ENTRY_DIR_ABS"
163 if [[ $x == $SKIP_REMAINING ]]; then
171 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
172 echo "Removing $ENTRY_DIR_ABS"
174 rm -rf "$ENTRY_DIR_ABS"
179 echo "Unknown command '$COMMAND'" >&2