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 http://www.freedesktop.org/software/systemd/man/os-release.html" >&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 http://www.freedesktop.org/software/systemd/man/machine-id.html" >&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="/boot/$MACHINE_ID/$KERNEL_VERSION"
76 readarray -t files< <(
78 for i in "${d}/"*${suffix}; do
79 [[ -e $i ]] && echo ${i##*/}
84 for f in "${files[@]}"; do
86 if [[ -e "$d/$f" ]]; then
94 readarray -t PLUGINS < <(
95 dropindirs_sort ".install" \
96 "/etc/kernel/install.d" \
97 "/usr/lib/kernel/install.d"
102 mkdir -p "$BOOT_DIR" || exit 1
104 for f in "${PLUGINS[@]}"; do
105 [[ -x $f ]] && "$f" add "$KERNEL_VERSION" "$BOOT_DIR"
109 if ! cp --preserve "$KERNEL_IMAGE" "$BOOT_DIR"/linux; then
110 echo "Can't copy '$KERNEL_IMAGE to '$BOOT_DIR/linux'!" >&2
113 [[ -d /boot/loader/entries ]] || mkdir -p /boot/loader/entries
116 echo "title $PRETTY_NAME"
117 echo "version $KERNEL_VERSION"
118 echo "machine-id $MACHINE_ID"
119 echo "options $BOOT_OPTIONS"
120 echo "linux $BOOT_DIR/linux"
121 [[ -f "${BOOT_DIR}"/initrd ]] && \
122 echo "initrd $BOOT_DIR/initrd"
124 } > "/boot/loader/entries/${ID}-${KERNEL_VERSION}-${MACHINE_ID}.conf"
128 if ! [[ -f "/boot/loader/entries/${ID}-${KERNEL_VERSION}-${MACHINE_ID}.conf" ]]; then
129 echo "Could not create '/boot/loader/entries/${ID}-${KERNEL_VERSION}-${MACHINE_ID}.conf'!" >&2
134 for f in "${PLUGINS[@]}"; do
135 [[ -x $f ]] && "$f" remove "$KERNEL_VERSION" "$BOOT_DIR"
140 rm -f "/boot/loader/entries/${ID}-${KERNEL_VERSION}-${MACHINE_ID}.conf"