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/>.
25 echo " $0 add <kernel-version> <kernel-image>" >&2
26 echo " $0 remove <kernel-version> <kernel-image>" >&2
31 local suffix=$1; shift
35 readarray -t files < <(
37 for i in "$d/"*"$suffix"; do
38 if [[ -e "$i" ]]; then
45 for f in "${files[@]}"; do
47 if [[ -e "$d/$f" ]]; then
61 if [[ -f /etc/os-release ]]; then
66 echo "Could not determine the distribution name from /etc/os-release." >&2
67 echo "Please specify ID=... in /etc/os-release. See man:os-release(5)" >&2
71 if [[ -f /etc/machine-id ]]; then
72 read MACHINE_ID < /etc/machine-id
75 if ! [[ $MACHINE_ID ]]; then
76 echo "Could not determine your machine ID from /etc/machine-id." >&2
77 echo "Please run 'systemd-machine-id-setup' as root. See man:machine-id(5)" >&2
81 if [[ -f /etc/kernel/cmdline ]]; then
82 readarray -t BOOT_OPTIONS < /etc/kernel/cmdline
85 if ! [[ ${BOOT_OPTIONS[*]} ]]; then
86 readarray -t BOOT_OPTIONS < /proc/cmdline
89 if ! [[ $BOOT_OPTIONS ]]; then
90 echo "Could not determine the kernel command line parameters." >&2
91 echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
95 if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then
100 BOOT_DIR="/$MACHINE_ID/$KERNEL_VERSION"
101 BOOT_DIR_ABS="/boot$BOOT_DIR"
102 LOADER_ENTRY="/boot/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
105 readarray -t PLUGINS < <(
106 dropindirs_sort ".install" \
107 "/etc/kernel/install.d" \
108 "/usr/lib/kernel/install.d"
113 if [[ ! $KERNEL_IMAGE ]]; then
118 mkdir -p "$BOOT_DIR_ABS" || {
119 echo "Could not create boot directory '$BOOT_DIR_ABS'." >&2
123 for f in "${PLUGINS[@]}"; do
124 [[ -x $f ]] && "$f" add "$KERNEL_VERSION" "$BOOT_DIR_ABS"
128 cp --preserve "$KERNEL_IMAGE" "$BOOT_DIR_ABS/linux" || {
129 echo "Could not copy '$KERNEL_IMAGE to '$BOOT_DIR_ABS/linux'." >&2
133 mkdir -p "${LOADER_ENTRY%/*}" || {
134 echo "Could not create loader entry directory '${LOADER_ENTRY%/*}'." >&2
139 echo "title $PRETTY_NAME"
140 echo "version $KERNEL_VERSION"
141 echo "machine-id $MACHINE_ID"
142 echo "options ${BOOT_OPTIONS[*]}"
143 echo "linux $BOOT_DIR/linux"
144 [[ -f $BOOT_DIR_ABS/initrd ]] && \
145 echo "initrd $BOOT_DIR/initrd"
146 } > "$LOADER_ENTRY" || {
147 echo "Could not create loader entry '$LOADER_ENTRY'." >&2
153 for f in "${PLUGINS[@]}"; do
154 [[ -x $f ]] && "$f" remove "$KERNEL_VERSION" "$BOOT_DIR_ABS"
158 rm -rf "$LOADER_ENTRY" "$BOOT_DIR_ABS"