2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # This file is part of systemd.
7 # Copyright 2013 Harald Hoyer
9 # systemd is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU Lesser General Public License as published by
11 # the Free Software Foundation; either version 2.1 of the License, or
12 # (at your option) any later version.
14 # systemd is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public License
20 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 echo " $0 add KERNEL-VERSION KERNEL-IMAGE"
28 echo " $0 remove KERNEL-VERSION"
33 local suffix
=$1; shift
37 readarray
-t files
<<<"$(
39 for i in "$d/"*"$suffix"; do
40 if [[ -e "$i" ]]; then
47 for f
in "${files[@]}"; do
49 if [[ -e "$d/$f" ]]; then
60 if [ "$i" == "--help" -o "$i" == "-h" ]; then
66 if [[ "${0##*/}" == 'installkernel' ]]; then
76 if [[ -f /etc
/machine-id
]]; then
77 read MACHINE_ID
< /etc
/machine-id
80 if [[ ! $COMMAND ]] ||
[[ ! $KERNEL_VERSION ]]; then
81 echo "Not enough arguments" >&2
85 if ! [[ $MACHINE_ID ]]; then
86 BOOT_DIR_ABS
=$
(mktemp
-d /tmp
/kernel-install.XXXXX
) ||
exit 1
87 trap "rm -rf '$BOOT_DIR_ABS'" EXIT INT QUIT PIPE
88 elif [[ -d /efi
/loader
/entries
]] ||
[[ -d /efi
/$MACHINE_ID ]]; then
89 BOOT_DIR_ABS
="/efi/$MACHINE_ID/$KERNEL_VERSION"
90 elif [[ -d /boot
/loader
/entries
]] ||
[[ -d /boot
/$MACHINE_ID ]]; then
91 BOOT_DIR_ABS
="/boot/$MACHINE_ID/$KERNEL_VERSION"
92 elif [[ -d /boot
/efi
/loader
/entries
]] ||
[[ -d /boot
/efi
/$MACHINE_ID ]]; then
93 BOOT_DIR_ABS
="/boot/efi/$MACHINE_ID/$KERNEL_VERSION"
94 elif mountpoint
-q /efi
; then
95 BOOT_DIR_ABS
="/efi/$MACHINE_ID/$KERNEL_VERSION"
96 elif mountpoint
-q /boot
/efi
; then
97 BOOT_DIR_ABS
="/boot/efi/$MACHINE_ID/$KERNEL_VERSION"
99 BOOT_DIR_ABS
="/boot/$MACHINE_ID/$KERNEL_VERSION"
102 export KERNEL_INSTALL_MACHINE_ID
=$MACHINE_ID
106 readarray
-t PLUGINS
<<<"$(
107 dropindirs_sort ".
install" \
108 "/etc
/kernel
/install.d
" \
109 "/usr
/lib
/kernel
/install.d
"
114 if [[ ! "$KERNEL_IMAGE" ]]; then
115 echo "Command 'add' requires an argument" >&2
119 mkdir
-p "$BOOT_DIR_ABS" ||
{
120 echo "Could not create boot directory '$BOOT_DIR_ABS'." >&2
124 for f
in "${PLUGINS[@]}"; do
126 "$f" add
"$KERNEL_VERSION" "$BOOT_DIR_ABS" "$KERNEL_IMAGE"
128 if [[ $x == $SKIP_REMAINING ]]; then
136 if ! [[ $MACHINE_ID ]] && ! rmdir "$BOOT_DIR_ABS"; then
137 echo "Warning: In kernel-install plugins, requiring BOOT_DIR_ABS to be preset is deprecated." >&2
138 echo " All plugins should not put anything in BOOT_DIR_ABS if the environment" >&2
139 echo " variable KERNEL_INSTALL_MACHINE_ID is empty." >&2
140 rm -rf "$BOOT_DIR_ABS"
146 for f
in "${PLUGINS[@]}"; do
148 "$f" remove
"$KERNEL_VERSION" "$BOOT_DIR_ABS"
150 if [[ $x == $SKIP_REMAINING ]]; then
158 rm -rf "$BOOT_DIR_ABS"
163 echo "Unknown command '$COMMAND'" >&2