Skip to content

Commit 5c1b961

Browse files
*: avoid hardcoding "gentoo", use os-release
useful for downstream distro's or folks who simply like to customize Signed-off-by: Andrew Ammerlaan <[email protected]>
1 parent f19c625 commit 5c1b961

5 files changed

+67
-10
lines changed

hooks/95-refind-copy-icon.install

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ver=${1}
1111
img=${2}
1212

13-
: "${REFIND_ICON:=/usr/lib64/refind/refind/icons/os_gentoo.png}"
13+
: "${REFIND_ICON:=/usr/lib64/refind/refind/icons/os_${ID}.png}"
1414

1515
# familiar helpers, we intentionally don't use Gentoo functions.sh
1616
die() {
@@ -24,6 +24,10 @@ main() {
2424

2525
[[ ${EUID} -eq 0 ]] || die "Please run this script as root"
2626

27+
if [[ ! -f ${REFIND_ICON} ]]; then
28+
die "REFIND_ICON=${REFIND_ICON} not found"
29+
fi
30+
2731
cp "${REFIND_ICON}" "${img%.efi}.png" || die "Failed to copy icon file"
2832
}
2933

hooks/systemd/90-compat.install

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,19 @@ if [[ ${KERNEL_INSTALL_LAYOUT} == "grub" || ${KERNEL_INSTALL_LAYOUT} == "compat"
2525
KERNEL_INSTALL_ROOT="/boot"
2626
SUFFIX=
2727
elif [[ ${KERNEL_INSTALL_LAYOUT} == "efistub" ]]; then
28+
if [[ -f /etc/os-release ]]; then
29+
# shellcheck source=/dev/null
30+
. /etc/os-release
31+
elif [[ -f /usr/lib/os-release ]]; then
32+
# shellcheck source=/dev/null
33+
. /usr/lib/os-release
34+
fi
35+
36+
# Set sane default if no or broken os-release
37+
: "${NAME:=Linux}"
38+
2839
# For efistub layout, we relocate /boot to the ESP
29-
KERNEL_INSTALL_ROOT="${KERNEL_INSTALL_BOOT_ROOT}/EFI/Gentoo"
40+
KERNEL_INSTALL_ROOT="${KERNEL_INSTALL_BOOT_ROOT}/EFI/${NAME}"
3041
# Some vendors enforce that booted EFI executables have the .efi suffix.
3142
# We also want to be able to distinguish between an UKI and a regular
3243
# kernel image with an .efi suffix.

hooks/systemd/95-efistub-kernel-bootcfg.install

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,20 @@ if [[ ${KERNEL_INSTALL_LAYOUT} == "uki" ]]; then
4141
kernel-bootcfg "${LOGLEVEL}" --remove-uki "${UKI}" || exit 1
4242
fi
4343
elif [[ ${KERNEL_INSTALL_LAYOUT} == "efistub" ]]; then
44-
KERNEL_IMAGE="${KERNEL_INSTALL_BOOT_ROOT}/EFI/Gentoo/kernel-${KERNEL_VERSION}.efi"
45-
INITRD="${KERNEL_INSTALL_BOOT_ROOT}/EFI/Gentoo/initramfs-${KERNEL_VERSION}.img"
44+
45+
if [[ -f /etc/os-release ]]; then
46+
# shellcheck source=/dev/null
47+
. /etc/os-release
48+
elif [[ -f /usr/lib/os-release ]]; then
49+
# shellcheck source=/dev/null
50+
. /usr/lib/os-release
51+
fi
52+
53+
# Set sane default if no or broken os-release
54+
: "${NAME:=Linux}"
55+
56+
KERNEL_IMAGE="${KERNEL_INSTALL_BOOT_ROOT}/EFI/${NAME}/kernel-${KERNEL_VERSION}.efi"
57+
INITRD="${KERNEL_INSTALL_BOOT_ROOT}/EFI/${NAME}/initramfs-${KERNEL_VERSION}.img"
4658

4759
if [[ ${COMMAND} == add ]]; then
4860
if [[ ! -f ${KERNEL_IMAGE} ]]; then

hooks/systemd/95-refind-copy-icon.install

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,24 @@ KERNEL_VERSION="${2}"
1212
BOOT_DIR_ABS="${3}"
1313
KERNEL_IMAGE="${4}"
1414

15-
: "${REFIND_ICON:=/usr/lib64/refind/refind/icons/os_gentoo.png}"
15+
if [[ -f /etc/os-release ]]; then
16+
# shellcheck source=/dev/null
17+
. /etc/os-release
18+
elif [[ -f /usr/lib/os-release ]]; then
19+
# shellcheck source=/dev/null
20+
. /usr/lib/os-release
21+
fi
22+
23+
# Set sane default if no or broken os-release
24+
: "${NAME:=Linux}"
25+
: "${ID:=linux}"
26+
27+
: "${REFIND_ICON:=/usr/lib64/refind/refind/icons/os_${ID}.png}"
28+
29+
if [[ ! -f ${REFIND_ICON} ]]; then
30+
echo "REFIND_ICON=${REFIND_ICON} not found"
31+
exit 1
32+
fi
1633

1734
# Refind does not discover kernels in the bls layout
1835
if [[ ${KERNEL_INSTALL_LAYOUT} == "compat" ]]; then
@@ -30,7 +47,7 @@ elif [[ ${KERNEL_INSTALL_LAYOUT} == "uki" ]]; then
3047
rm -f "${UKI_DIR}/${KERNEL_INSTALL_ENTRY_TOKEN}-${KERNEL_VERSION}.png" || exit 1
3148
fi
3249
elif [[ ${KERNEL_INSTALL_LAYOUT} == "efistub" ]]; then
33-
EFISTUB_DIR="${KERNEL_INSTALL_BOOT_ROOT}/EFI/Gentoo"
50+
EFISTUB_DIR="${KERNEL_INSTALL_BOOT_ROOT}/EFI/${NAME}"
3451
if [[ ${COMMAND} == add ]]; then
3552
cp "${REFIND_ICON}" "${EFISTUB_DIR}/kernel-${KERNEL_VERSION}.png" || exit 1
3653
elif [[ ${COMMAND} == remove ]]; then

installkernel

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Copyright (C) 2009 Manoj Srivasta
88
# Copyright 2020-2024 Gentoo Authors
99
#
10-
# Install the kernel on a Gentoo Linux system.
10+
# Install the kernel on a Linux system.
1111
#
1212
# This script is called by the kernel's "make install" if it is installed as
1313
# /sbin/installkernel. It is also called by kernel-install.eclass.
@@ -138,13 +138,26 @@ export INSTALLKERNEL_LAYOUT
138138
export INSTALLKERNEL_INITRD_GENERATOR
139139
export INSTALLKERNEL_UKI_GENERATOR
140140

141+
if [ -f /etc/os-release ]; then
142+
# shellcheck source=/dev/null
143+
. /etc/os-release
144+
elif [ -f /usr/lib/os-release ]; then
145+
# shellcheck source=/dev/null
146+
. /usr/lib/os-release
147+
fi
148+
149+
# Set sane default if no or broken os-release
150+
export NAME="${NAME:=Linux}"
151+
export ID="${ID:=linux}"
152+
export PRETTY_NAME="${PRETTY_NAME:=Linux}"
153+
141154
suffix=
142155
if [ "${INSTALLKERNEL_LAYOUT}" = efistub ]; then
143156
if [ ${#} -le 3 ] || [ "${4}" = "/boot" ]; then
144157
# Relocate to ESP
145158
for candidate in /boot/EFI /boot/efi /boot /efi; do
146-
if [ -d ${candidate}/EFI/Gentoo ]; then
147-
dir=${candidate}/EFI/Gentoo
159+
if [ -d ${candidate}/EFI/${NAME} ]; then
160+
dir=${candidate}/EFI/${NAME}
148161
suffix=.efi
149162
else
150163
continue
@@ -198,7 +211,7 @@ if [ -f "${uki}" ] && [ "${INSTALLKERNEL_LAYOUT}" = uki ]; then
198211
for candidate in /boot/EFI /boot/efi /boot /efi; do
199212
if [ -d ${candidate}/EFI/Linux ]; then
200213
dir=${candidate}/EFI/Linux
201-
img_dest=gentoo
214+
img_dest=${ID}
202215
else
203216
continue
204217
fi

0 commit comments

Comments
 (0)