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