]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/kernel-install/90-loaderentry.install
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / kernel-install / 90-loaderentry.install
CommitLineData
8f51399e
HH
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
5COMMAND="$1"
6KERNEL_VERSION="$2"
7BOOT_DIR_ABS="$3"
8KERNEL_IMAGE="$4"
0912c0b8 9INITRD_OPTIONS_START="5"
8f51399e 10
9d8813b3
YW
11if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then
12 exit 0
8f51399e
HH
13fi
14
81818461
JMC
15if ! [[ -d "$BOOT_DIR_ABS" ]]; then
16 exit 0
17fi
18
9d8813b3 19MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID
8f51399e
HH
20
21BOOT_DIR="/$MACHINE_ID/$KERNEL_VERSION"
340defcd 22BOOT_ROOT=${BOOT_DIR_ABS%$BOOT_DIR}
8f51399e
HH
23
24if [[ $COMMAND == remove ]]; then
bf7b6d28
LP
25 rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
26 rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+"*".conf"
27 exit 0
8f51399e
HH
28fi
29
30if ! [[ $COMMAND == add ]]; then
31 exit 1
32fi
33
34if ! [[ $KERNEL_IMAGE ]]; then
35 exit 1
36fi
37
38if [[ -f /etc/os-release ]]; then
39 . /etc/os-release
5ae4d543
LP
40elif [[ -f /usr/lib/os-release ]]; then
41 . /usr/lib/os-release
8f51399e
HH
42fi
43
44if ! [[ $PRETTY_NAME ]]; then
45 PRETTY_NAME="Linux $KERNEL_VERSION"
46fi
47
6c10d399
HH
48declare -a BOOT_OPTIONS
49
8f51399e 50if [[ -f /etc/kernel/cmdline ]]; then
6fd2ccc9 51 read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline
8f51399e
HH
52fi
53
54if ! [[ ${BOOT_OPTIONS[*]} ]]; then
6fd2ccc9 55 read -r -d '' -a line < /proc/cmdline
2f3a215f
HH
56 for i in "${line[@]}"; do
57 [[ "${i#initrd=*}" != "$i" ]] && continue
6fd2ccc9 58 BOOT_OPTIONS+=("$i")
6c10d399 59 done
8f51399e
HH
60fi
61
6c10d399 62if ! [[ ${BOOT_OPTIONS[*]} ]]; then
8f51399e
HH
63 echo "Could not determine the kernel command line parameters." >&2
64 echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
65 exit 1
66fi
67
bf7b6d28
LP
68if [[ -f /etc/kernel/tries ]]; then
69 read -r TRIES </etc/kernel/tries
70 if ! [[ "$TRIES" =~ ^[0-9]+$ ]] ; then
71 echo "/etc/kernel/tries does not contain an integer." >&2
72 exit 1
73 fi
74 LOADER_ENTRY="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+$TRIES.conf"
75else
76 LOADER_ENTRY="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
77fi
78
8b179a83
TG
79cp "$KERNEL_IMAGE" "$BOOT_DIR_ABS/linux" &&
80 chown root:root "$BOOT_DIR_ABS/linux" &&
81 chmod 0644 "$BOOT_DIR_ABS/linux" || {
8f51399e
HH
82 echo "Could not copy '$KERNEL_IMAGE to '$BOOT_DIR_ABS/linux'." >&2
83 exit 1
84}
85
d279b185
MAP
86INITRD_OPTIONS=( "${@:${INITRD_OPTIONS_START}}" )
87
88for initrd in "${INITRD_OPTIONS[@]}"; do
0912c0b8
MA
89 if [[ -f "${initrd}" ]]; then
90 initrd_basename="$(basename ${initrd})"
91 cp "${initrd}" "$BOOT_DIR_ABS/${initrd_basename}" &&
92 chown root:root "$BOOT_DIR_ABS/${initrd_basename}" &&
93 chmod 0644 "$BOOT_DIR_ABS/${initrd_basename}" || {
94 echo "Could not copy '${initrd}' to '$BOOT_DIR_ABS/${initrd_basename}'." >&2
95 exit 1
96 }
97 fi
98done
04ca4d19 99
d279b185
MAP
100# If no initrd option is supplied, fallback to "initrd" which is
101# the name used by dracut when generating it in its kernel-install hook
102[[ ${#INITRD_OPTIONS[@]} == 0 ]] && INITRD_OPTIONS=( initrd )
103
8f51399e
HH
104mkdir -p "${LOADER_ENTRY%/*}" || {
105 echo "Could not create loader entry directory '${LOADER_ENTRY%/*}'." >&2
106 exit 1
107}
108
109{
110 echo "title $PRETTY_NAME"
111 echo "version $KERNEL_VERSION"
112 echo "machine-id $MACHINE_ID"
113 echo "options ${BOOT_OPTIONS[*]}"
114 echo "linux $BOOT_DIR/linux"
d279b185 115 for initrd in "${INITRD_OPTIONS[@]}"; do
0912c0b8
MA
116 [[ -f $BOOT_DIR_ABS/$(basename ${initrd}) ]] && \
117 echo "initrd $BOOT_DIR/$(basename ${initrd})"
118 done
852752fc 119 :
8f51399e
HH
120} > "$LOADER_ENTRY" || {
121 echo "Could not create loader entry '$LOADER_ENTRY'." >&2
122 exit 1
123}
124exit 0