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"
39 for i
in "$d/"*"$suffix"; do
40 [ -e "$i" ] && echo "${i##*/}"
42 done |
sort -Vu |
while read -r f
; do
44 if [ -e "$d/$f" ]; then
45 [ -x "$d/$f" ] && echo "$d/$f"
55 if [ "$i" = "--help" ] ||
[ "$i" = "-h" ]; then
61 export KERNEL_INSTALL_VERBOSE
=0
62 if [ "$1" = "--verbose" ] ||
[ "$1" = "-v" ]; then
64 KERNEL_INSTALL_VERBOSE
=1
67 if [ "${0##*/}" = "installkernel" ]; then
69 # make install doesn't pass any initrds
76 echo "Not enough arguments" >&2
83 if [ -r "/etc/kernel/install.conf" ]; then
84 .
/etc
/kernel
/install.conf
85 elif [ -r "/usr/lib/kernel/install.conf" ]; then
86 .
/usr
/lib
/kernel
/install.conf
89 # Prefer to use an existing machine ID from /etc/machine-info or /etc/machine-id. If we're using the machine
90 # ID /etc/machine-id, try to persist it in /etc/machine-info. If no machine ID is found, try to generate
91 # a new machine ID in /etc/machine-info. If that fails, use "Default".
92 [ -z "$MACHINE_ID" ] && [ -r /etc
/machine-info
] && .
/etc
/machine-info
&& MACHINE_ID
="$KERNEL_INSTALL_MACHINE_ID"
93 [ -z "$MACHINE_ID" ] && [ -r /etc
/machine-id
] && read -r MACHINE_ID
</etc
/machine-id
94 [ -n "$MACHINE_ID" ] && [ -z "$KERNEL_INSTALL_MACHINE_ID" ] && echo "KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID" >>/etc
/machine-info
95 [ -z "$MACHINE_ID" ] && NEW_MACHINE_ID
="$(systemd-id128 new)" && echo "KERNEL_INSTALL_MACHINE_ID=$NEW_MACHINE_ID" >>/etc
/machine-info
96 [ -z "$MACHINE_ID" ] && [ -r /etc
/machine-info
] && .
/etc
/machine-info
&& MACHINE_ID
="$KERNEL_INSTALL_MACHINE_ID"
97 [ -z "$MACHINE_ID" ] && MACHINE_ID
="Default"
99 [ -z "$BOOT_ROOT" ] && for suff
in "$MACHINE_ID" "loader/entries"; do
100 for pref
in "/efi" "/boot" "/boot/efi" ; do
101 if [ -d "$pref/$suff" ]; then
108 [ -z "$BOOT_ROOT" ] && for pref
in "/efi" "/boot/efi"; do
109 if mountpoint
-q "$pref"; then
114 [ -z "$BOOT_ROOT" ] && BOOT_ROOT
="/boot"
117 if [ -z "$layout" ]; then
118 # Administrative decision: if not present, some scripts generate into /boot.
119 if [ -d "$BOOT_ROOT/$MACHINE_ID" ]; then
127 ENTRY_DIR_ABS
="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION"
129 export KERNEL_INSTALL_MACHINE_ID
="$MACHINE_ID"
130 export KERNEL_INSTALL_BOOT_ROOT
="$BOOT_ROOT"
131 export KERNEL_INSTALL_LAYOUT
="$layout"
133 [ "$layout" = "bls" ]
134 MAKE_ENTRY_DIR_ABS
=$?
140 dropindirs_sort ".
install" \
141 "/etc
/kernel
/install.d
" \
142 "/usr
/lib
/kernel
/install.d
"
149 if [ $# -lt 1 ]; then
150 echo "Command 'add' requires a kernel image" >&2
154 if ! [ -f "$1" ]; then
155 echo "Kernel image argument $1 not a file" >&2
159 if [ "$MAKE_ENTRY_DIR_ABS" -eq 0 ]; then
160 # Compatibility with earlier versions that used the presence of $BOOT_ROOT/$MACHINE_ID
161 # to signal to 00-entry-directory to create $ENTRY_DIR_ABS
162 # to serve as the indication to use or to not use the BLS
163 if [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ]; then
164 echo "+mkdir -v -p $ENTRY_DIR_ABS"
165 mkdir
-v -p "$ENTRY_DIR_ABS"
167 mkdir
-p "$ENTRY_DIR_ABS"
171 for f
in $PLUGINS; do
172 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "+$f add $KERNEL_VERSION $ENTRY_DIR_ABS $*"
173 "$f" add
"$KERNEL_VERSION" "$ENTRY_DIR_ABS" "$@"
175 [ $err -eq $skip_remaining ] && break
181 for f
in $PLUGINS; do
182 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "+$f remove $KERNEL_VERSION $ENTRY_DIR_ABS"
183 "$f" remove
"$KERNEL_VERSION" "$ENTRY_DIR_ABS"
185 [ $err -eq $skip_remaining ] && break
189 if [ "$MAKE_ENTRY_DIR_ABS" -eq 0 ]; then
190 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Removing $ENTRY_DIR_ABS/"
191 rm -rf "$ENTRY_DIR_ABS"
196 echo "Unknown command '$COMMAND'" >&2