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-or-later
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 [OPTIONS...] add KERNEL-VERSION KERNEL-IMAGE [INITRD-FILE ...]"
27 echo " $0 [OPTIONS...] remove KERNEL-VERSION"
29 echo " -h,--help Print this help"
30 echo " -v,--verbose Increase verbosity"
35 local suffix
=$1; shift
39 readarray
-t files
<<<"$(
41 for i in "$d/"*"$suffix"; do
42 if [[ -e "$i" ]]; then
49 for f
in "${files[@]}"; do
51 if [[ -e "$d/$f" ]]; then
62 if [ "$i" == "--help" -o "$i" == "-h" ]; then
68 KERNEL_INSTALL_VERBOSE
=0
69 if [ "$1" == "--verbose" -o "$1" == "-v" ]; then
71 KERNEL_INSTALL_VERBOSE
=1
73 export KERNEL_INSTALL_VERBOSE
75 if [[ "${0##*/}" == 'installkernel' ]]; then
77 # make install doesn't pass any parameter wrt initrd handling
82 INITRD_OPTIONS
=( "${@:3}" )
88 # Reuse directory created without a machine ID present if it exists.
89 if [[ -d /efi
/Default
]] ||
[[ -d /boot
/Default
]] ||
[[ -d /boot
/efi
/Default
]]; then
91 elif [[ -f /etc
/machine-id
]]; then
92 read MACHINE_ID
< /etc
/machine-id
97 if [[ ! $COMMAND ]] ||
[[ ! $KERNEL_VERSION ]]; then
98 echo "Not enough arguments" >&2
102 if [[ -d /efi
/loader
/entries
]] ||
[[ -d /efi
/$MACHINE_ID ]]; then
103 ENTRY_DIR_ABS
="/efi/$MACHINE_ID/$KERNEL_VERSION"
104 elif [[ -d /boot
/loader
/entries
]] ||
[[ -d /boot
/$MACHINE_ID ]]; then
105 ENTRY_DIR_ABS
="/boot/$MACHINE_ID/$KERNEL_VERSION"
106 elif [[ -d /boot
/efi
/loader
/entries
]] ||
[[ -d /boot
/efi
/$MACHINE_ID ]]; then
107 ENTRY_DIR_ABS
="/boot/efi/$MACHINE_ID/$KERNEL_VERSION"
108 elif mountpoint
-q /efi
; then
109 ENTRY_DIR_ABS
="/efi/$MACHINE_ID/$KERNEL_VERSION"
110 elif mountpoint
-q /boot
/efi
; then
111 ENTRY_DIR_ABS
="/boot/efi/$MACHINE_ID/$KERNEL_VERSION"
113 ENTRY_DIR_ABS
="/boot/$MACHINE_ID/$KERNEL_VERSION"
116 export KERNEL_INSTALL_MACHINE_ID
=$MACHINE_ID
120 readarray
-t PLUGINS
<<<"$(
121 dropindirs_sort ".
install" \
122 "/etc
/kernel
/install.d
" \
123 "/usr
/lib
/kernel
/install.d
"
128 if [[ ! "$KERNEL_IMAGE" ]]; then
129 echo "Command 'add' requires an argument" >&2
133 if [[ ! -f "$KERNEL_IMAGE" ]]; then
134 echo "Kernel image argument ${KERNEL_IMAGE} not a file" >&2
138 for f
in "${PLUGINS[@]}"; do
140 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
141 echo "+$f add $KERNEL_VERSION $ENTRY_DIR_ABS $KERNEL_IMAGE ${INITRD_OPTIONS[@]}"
142 "$f" add
"$KERNEL_VERSION" "$ENTRY_DIR_ABS" "$KERNEL_IMAGE" "${INITRD_OPTIONS[@]}"
144 if [[ $x == $SKIP_REMAINING ]]; then
154 for f
in "${PLUGINS[@]}"; do
156 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
157 echo "+$f remove $KERNEL_VERSION $ENTRY_DIR_ABS"
158 "$f" remove
"$KERNEL_VERSION" "$ENTRY_DIR_ABS"
160 if [[ $x == $SKIP_REMAINING ]]; then
168 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
169 echo "Removing $ENTRY_DIR_ABS"
171 rm -rf "$ENTRY_DIR_ABS"
176 echo "Unknown command '$COMMAND'" >&2