]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/kernel-install/90-loaderentry.install
kernel-install: Add KERNEL_INSTALL_NOOP (#4103)
[thirdparty/systemd.git] / src / kernel-install / 90-loaderentry.install
1 #!/bin/bash
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4
5 COMMAND="$1"
6 KERNEL_VERSION="$2"
7 BOOT_DIR_ABS="$3"
8 KERNEL_IMAGE="$4"
9
10 if [[ -f /etc/machine-id ]]; then
11 read MACHINE_ID < /etc/machine-id
12 fi
13
14 if ! [[ $MACHINE_ID ]]; then
15 exit 1
16 fi
17
18 BOOT_DIR="/$MACHINE_ID/$KERNEL_VERSION"
19 BOOT_ROOT=${BOOT_DIR_ABS%$BOOT_DIR}
20 LOADER_ENTRY="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
21
22 if [[ $COMMAND == remove ]]; then
23 exec rm -f "$LOADER_ENTRY"
24 fi
25
26 if ! [[ $COMMAND == add ]]; then
27 exit 1
28 fi
29
30 if ! [[ $KERNEL_IMAGE ]]; then
31 exit 1
32 fi
33
34 if [[ -f /etc/os-release ]]; then
35 . /etc/os-release
36 elif [[ -f /usr/lib/os-release ]]; then
37 . /usr/lib/os-release
38 fi
39
40 if ! [[ $PRETTY_NAME ]]; then
41 PRETTY_NAME="Linux $KERNEL_VERSION"
42 fi
43
44 declare -a BOOT_OPTIONS
45
46 if [[ -f /etc/kernel/cmdline ]]; then
47 read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline
48 fi
49
50 if ! [[ ${BOOT_OPTIONS[*]} ]]; then
51 read -r -d '' -a line < /proc/cmdline
52 for i in "${line[@]}"; do
53 [[ "${i#initrd=*}" != "$i" ]] && continue
54 BOOT_OPTIONS+=("$i")
55 done
56 fi
57
58 if ! [[ ${BOOT_OPTIONS[*]} ]]; then
59 echo "Could not determine the kernel command line parameters." >&2
60 echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
61 exit 1
62 fi
63
64 cp "$KERNEL_IMAGE" "$BOOT_DIR_ABS/linux" &&
65 chown root:root "$BOOT_DIR_ABS/linux" &&
66 chmod 0644 "$BOOT_DIR_ABS/linux" || {
67 echo "Could not copy '$KERNEL_IMAGE to '$BOOT_DIR_ABS/linux'." >&2
68 exit 1
69 }
70
71 mkdir -p "${LOADER_ENTRY%/*}" || {
72 echo "Could not create loader entry directory '${LOADER_ENTRY%/*}'." >&2
73 exit 1
74 }
75
76 {
77 echo "title $PRETTY_NAME"
78 echo "version $KERNEL_VERSION"
79 echo "machine-id $MACHINE_ID"
80 echo "options ${BOOT_OPTIONS[*]}"
81 echo "linux $BOOT_DIR/linux"
82 [[ -f $BOOT_DIR_ABS/initrd ]] && \
83 echo "initrd $BOOT_DIR/initrd"
84 :
85 } > "$LOADER_ENTRY" || {
86 echo "Could not create loader entry '$LOADER_ENTRY'." >&2
87 exit 1
88 }
89 exit 0