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/>.
28 [[ -f /etc/os-release ]] && . /etc/os-release
30 echo "Can't determine the name of your distribution. Please create /etc/os-release." >&2
31 echo "See man:os-release(5)" >&2
35 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
36 if ! [[ $MACHINE_ID ]]; then
37 echo "Can't determine your machine id. Please create /etc/machine-id!" >&2
38 echo "See man:machine-id(5)" >&2
42 if [[ -f /etc/kernel/cmdline ]]; then
43 readarray -t BOOT_OPTIONS < /etc/kernel/cmdline
46 if ! [[ "${BOOT_OPTIONS[@]}" ]]; then
47 readarray -t BOOT_OPTIONS < /proc/cmdline
50 if ! [[ $BOOT_OPTIONS ]]; then
51 echo "Can't determine the kernel command line parameters." >&2
52 echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
60 echo " $0 add <kernel-version> <kernel-image>"
61 echo " $0 remove <kernel-version> <kernel-image>"
65 if ! ( [[ $COMMAND ]] && [[ $KERNEL_VERSION ]] && [[ $KERNEL_IMAGE ]] ); then
70 BOOT_DIR="/${MACHINE_ID}/${KERNEL_VERSION}"
71 BOOT_DIR_ABS="/boot${BOOT_DIR}"
72 LOADER_ENTRY="/boot/loader/entries/${MACHINE_ID}-${KERNEL_VERSION}.conf"
78 readarray -t files< <(
80 for i in "${d}/"*${suffix}; do
81 [[ -e $i ]] && echo ${i##*/}
86 for f in "${files[@]}"; do
88 if [[ -e "$d/$f" ]]; then
96 readarray -t PLUGINS < <(
97 dropindirs_sort ".install" \
98 "/etc/kernel/install.d" \
99 "/usr/lib/kernel/install.d"
104 mkdir -p "$BOOT_DIR_ABS" || exit 1
106 for f in "${PLUGINS[@]}"; do
107 [[ -x $f ]] && "$f" add "$KERNEL_VERSION" "$BOOT_DIR_ABS"
111 if ! cp --preserve "$KERNEL_IMAGE" "$BOOT_DIR_ABS"/linux; then
112 echo "Can't copy '$KERNEL_IMAGE to '$BOOT_DIR_ABS/linux'!" >&2
115 [[ -d /boot/loader/entries ]] || mkdir -p /boot/loader/entries
118 echo "title $PRETTY_NAME"
119 echo "version $KERNEL_VERSION"
120 echo "machine-id $MACHINE_ID"
121 echo "options ${BOOT_OPTIONS[@]}"
122 echo "linux $BOOT_DIR/linux"
123 [[ -f "${BOOT_DIR_ABS}"/initrd ]] && \
124 echo "initrd $BOOT_DIR/initrd"
130 if ! [[ -f $LOADER_ENTRY ]]; then
131 echo "Could not create '$LOADER_ENTRY'!" >&2
136 for f in "${PLUGINS[@]}"; do
137 [[ -x $f ]] && "$f" remove "$KERNEL_VERSION" "$BOOT_DIR_ABS"
141 rm -fr "$BOOT_DIR_ABS"
142 rm -f "$LOADER_ENTRY"