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 if [[ ! $COMMAND ]] ||
[[ ! $KERNEL_VERSION ]]; then
89 echo "Not enough arguments" >&2
93 if [ -r "/etc/kernel/install.conf" ]; then
94 .
/etc
/kernel
/install.conf
95 elif [ -r "/usr/lib/kernel/install.conf" ]; then
96 .
/usr
/lib
/kernel
/install.conf
99 # Prefer to use an existing machine ID from /etc/machine-info or /etc/machine-id. If we're using the machine
100 # ID /etc/machine-id, try to persist it in /etc/machine-info. If no machine ID is found, try to generate
101 # a new machine ID in /etc/machine-info. If that fails, use "Default".
103 [ -z "$MACHINE_ID" ] && [ -f /etc
/machine-info
] && source /etc
/machine-info
&& MACHINE_ID
="$KERNEL_INSTALL_MACHINE_ID"
104 [ -z "$MACHINE_ID" ] && [ -f /etc
/machine-id
] && read -r MACHINE_ID
</etc
/machine-id
105 [ -n "$MACHINE_ID" ] && [ -z "$KERNEL_INSTALL_MACHINE_ID" ] && echo "KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID" >>/etc
/machine-info
106 [ -z "$MACHINE_ID" ] && NEW_MACHINE_ID
="$(systemd-id128 new)" && echo "KERNEL_INSTALL_MACHINE_ID=$NEW_MACHINE_ID" >>/etc
/machine-info
107 [ -z "$MACHINE_ID" ] && [ -f /etc
/machine-info
] && source /etc
/machine-info
&& MACHINE_ID
="$KERNEL_INSTALL_MACHINE_ID"
108 [ -z "$MACHINE_ID" ] && MACHINE_ID
="Default"
110 [ -z "$BOOT_ROOT" ] && for suff
in "$MACHINE_ID" "loader/entries"; do
111 for pref
in "/efi" "/boot" "/boot/efi" ; do
112 if [ -d "$pref/$suff" ]; then
119 [ -z "$BOOT_ROOT" ] && for pref
in "/efi" "/boot/efi"; do
120 if mountpoint
-q "$pref"; then
125 [ -z "$BOOT_ROOT" ] && BOOT_ROOT
="/boot"
128 ENTRY_DIR_ABS
="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION"
130 export KERNEL_INSTALL_MACHINE_ID
="$MACHINE_ID"
131 export KERNEL_INSTALL_BOOT_ROOT
="$BOOT_ROOT"
133 if [ -z "$layout" ]; then
134 # Administrative decision: if not present, some scripts generate into /boot.
135 if [ -d "$BOOT_ROOT/$MACHINE_ID" ]; then
143 ENTRY_DIR_ABS
="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION"
145 export KERNEL_INSTALL_MACHINE_ID
="$MACHINE_ID"
146 export KERNEL_INSTALL_BOOT_ROOT
="$BOOT_ROOT"
147 export KERNEL_INSTALL_LAYOUT
="$layout"
149 [ "$layout" = "bls" ]
150 MAKE_ENTRY_DIR_ABS
=$?
155 readarray
-t PLUGINS
<<<"$(
156 dropindirs_sort ".
install" \
157 "/etc
/kernel
/install.d
" \
158 "/usr
/lib
/kernel
/install.d
"
163 if [[ ! "$KERNEL_IMAGE" ]]; then
164 echo "Command 'add' requires an argument" >&2
168 if [[ ! -f "$KERNEL_IMAGE" ]]; then
169 echo "Kernel image argument ${KERNEL_IMAGE} not a file" >&2
173 if [ "$MAKE_ENTRY_DIR_ABS" -eq 0 ]; then
174 # Compatibility with earlier versions that used the presence of $BOOT_ROOT/$MACHINE_ID
175 # to signal to 00-entry-directory to create $ENTRY_DIR_ABS
176 # to serve as the indication to use or to not use the BLS
177 if [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ]; then
178 echo "+mkdir -v -p $ENTRY_DIR_ABS"
179 mkdir
-v -p "$ENTRY_DIR_ABS"
181 mkdir
-p "$ENTRY_DIR_ABS"
185 for f
in "${PLUGINS[@]}"; do
187 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
188 echo "+$f add $KERNEL_VERSION $ENTRY_DIR_ABS $KERNEL_IMAGE ${INITRD_OPTIONS[@]}"
189 "$f" add
"$KERNEL_VERSION" "$ENTRY_DIR_ABS" "$KERNEL_IMAGE" "${INITRD_OPTIONS[@]}"
191 if [[ $x == $SKIP_REMAINING ]]; then
200 for f
in "${PLUGINS[@]}"; do
202 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
203 echo "+$f remove $KERNEL_VERSION $ENTRY_DIR_ABS"
204 "$f" remove
"$KERNEL_VERSION" "$ENTRY_DIR_ABS"
206 if [[ $x == $SKIP_REMAINING ]]; then
213 if [ "$MAKE_ENTRY_DIR_ABS" -eq 0 ]; then
214 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Removing $ENTRY_DIR_ABS/"
215 rm -rf "$ENTRY_DIR_ABS"
220 echo "Unknown command '$COMMAND'" >&2