]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/kernel-install/90-loaderentry.install
os-release: define /usr/lib/os-release as fallback for /etc/os-release
[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"
9
10if [[ -f /etc/machine-id ]]; then
11 read MACHINE_ID < /etc/machine-id
12fi
13
14if ! [[ $MACHINE_ID ]]; then
15 exit 1
16fi
17
18BOOT_DIR="/$MACHINE_ID/$KERNEL_VERSION"
19LOADER_ENTRY="/boot/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
20
21if [[ $COMMAND == remove ]]; then
22 exec rm -f "$LOADER_ENTRY"
23fi
24
25if ! [[ $COMMAND == add ]]; then
26 exit 1
27fi
28
29if ! [[ $KERNEL_IMAGE ]]; then
30 exit 1
31fi
32
33if [[ -f /etc/os-release ]]; then
34 . /etc/os-release
5ae4d543
LP
35elif [[ -f /usr/lib/os-release ]]; then
36 . /usr/lib/os-release
8f51399e
HH
37fi
38
39if ! [[ $PRETTY_NAME ]]; then
40 PRETTY_NAME="Linux $KERNEL_VERSION"
41fi
42
6c10d399
HH
43declare -a BOOT_OPTIONS
44
8f51399e
HH
45if [[ -f /etc/kernel/cmdline ]]; then
46 readarray -t BOOT_OPTIONS < /etc/kernel/cmdline
47fi
48
49if ! [[ ${BOOT_OPTIONS[*]} ]]; then
6c10d399
HH
50 readarray -t line < /proc/cmdline
51 for i in ${line[*]}; do
52 if [[ "${i#initrd=*}" == "$i" ]]; then
53 BOOT_OPTIONS[${#BOOT_OPTIONS[@]}]="$i"
54 fi
55 done
8f51399e
HH
56fi
57
6c10d399 58if ! [[ ${BOOT_OPTIONS[*]} ]]; then
8f51399e
HH
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
62fi
63
8b179a83
TG
64cp "$KERNEL_IMAGE" "$BOOT_DIR_ABS/linux" &&
65 chown root:root "$BOOT_DIR_ABS/linux" &&
66 chmod 0644 "$BOOT_DIR_ABS/linux" || {
8f51399e
HH
67 echo "Could not copy '$KERNEL_IMAGE to '$BOOT_DIR_ABS/linux'." >&2
68 exit 1
69}
70
71mkdir -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"
852752fc 84 :
8f51399e
HH
85} > "$LOADER_ENTRY" || {
86 echo "Could not create loader entry '$LOADER_ENTRY'." >&2
87 exit 1
88}
89exit 0