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