Use long format options

This commit is contained in:
gardouille 2023-07-20 15:26:25 +02:00
parent 65537f8fe6
commit e67344fdd3
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 17 additions and 17 deletions

View File

@ -7,9 +7,9 @@ EFI_MOUNT_PATH="/boot/efi"
temp_efi_list_file="/tmp/efibootmgr.label.entry.temp"
# OS related vars
ROOT_UUID=$(findmnt -kno UUID /)
ROOT_FSTYPE=$(findmnt -kno FSTYPE /)
CRYPT_PART_UUID=$(blkid | sed -n 's;/dev/.*_crypt.*UUID="\(.*\)".*TYPE=.*;\1;p')
ROOT_UUID=$(findmnt --kernel --noheadings --output UUID -- /)
ROOT_FSTYPE=$(findmnt --kernel --noheadings --output FSTYPE -- /)
CRYPT_PART_UUID=$(blkid | sed --silent 's;/dev/.*_crypt.*UUID="\(.*\)".*TYPE=.*;\1;p')
temp_kernel_list_file="/tmp/kernel.list.temp"
temp_kernel_command_file="/tmp/kernel.command.temp"
@ -18,11 +18,11 @@ temp_kernel_command_file="/tmp/kernel.command.temp"
# Clean old entries {{{
## Install efibootmgr tool if not available
command -v efibootmgr > /dev/null || aptitude install -y efibootmgr
command -v efibootmgr > /dev/null || aptitude install --assume-yes -- efibootmgr
## Get all old entries list with base label
rm -f -- "${temp_efi_list_file}" ; touch "${temp_efi_list_file}"
efibootmgr | grep -E ".*${EFI_BASE_LABEL}.*" | cut -c 5-8 > "${temp_efi_list_file}"
rm --force -- "${temp_efi_list_file}" ; touch "${temp_efi_list_file}"
efibootmgr | grep --extended-regexp -- ".*${EFI_BASE_LABEL}.*" | cut --characters=5-8 > "${temp_efi_list_file}"
## Remove all matching entries
while IFS= read -r OLD_EFI_ENTRY; do
@ -44,16 +44,16 @@ find "${EFI_MOUNT_PATH}/EFI/debian" -type f -iname "linux.debian.*.efi" -delete
# Create unified kernels blob and efiboot entries {{{
## Install objcopy tool if not available
command -v objcopy > /dev/null || aptitude install -y binutils
command -v objcopy > /dev/null || aptitude install --assume-yes -- binutils
## Put Kernel command line in temp file
rm -f -- "${temp_kernel_command_file}" ; touch "${temp_kernel_command_file}"
rm --force -- "${temp_kernel_command_file}" ; touch "${temp_kernel_command_file}"
printf "%s" "root=UUID=${ROOT_UUID} rootfstype=${ROOT_FSTYPE} add_efi_memmap \
ro cryptdevice=UUID=${CRYPT_PART_UUID}:lvm" >> "${temp_kernel_command_file}"
## Get all kernel versions starting with the oldest
rm -f -- "${temp_kernel_list_file}" ; touch "${temp_kernel_list_file}"
ls -1tr /boot/vmlinuz-* >> "${temp_kernel_list_file}"
rm --force -- "${temp_kernel_list_file}" ; touch "${temp_kernel_list_file}"
ls -1tr -- /boot/vmlinuz-* >> "${temp_kernel_list_file}"
## For each version of the kernel {{{
while IFS= read -r KERNEL; do
@ -61,19 +61,19 @@ while IFS= read -r KERNEL; do
KERNEL_VERSION=$(printf "%s" "${KERNEL}" | sed 's;.*vmlinuz-\(.*\);\1;')
### Ensure EFI device is mounted (excluding systemd-automount line)
if ! mount | grep -v "autofs" | grep --quiet "${EFI_MOUNT_PATH}"; then
if ! mount | grep --invert-match -- "autofs" | grep --quiet -- "${EFI_MOUNT_PATH}"; then
mount "${EFI_MOUNT_PATH}" || exit 2
fi
ESP=$(findmnt -kno SOURCE "${EFI_MOUNT_PATH}" | grep -v systemd | sed s-/dev/--)
ESP=$(findmnt -kno SOURCE "${EFI_MOUNT_PATH}" | grep --invert-match -- systemd | sed s-/dev/--)
ESP_DISK=$(lsblk /dev/"${ESP}" -no pkname)
ESP_PART=$(cat /sys/class/block/"${ESP}"/partition)
### Calculate address values to use for each section
osrel_offs=$(objdump -h "/usr/lib/systemd/boot/efi/linuxx64.efi.stub" | awk 'NF==7 {size=strtonum("0x"$3); offset=strtonum("0x"$4)} END {print size + offset}')
cmdline_offs=$((osrel_offs + $(stat -Lc%s "/usr/lib/os-release")))
linux_offs=$((cmdline_offs + $(stat -Lc%s "${temp_kernel_command_file}")))
initrd_offs=$((linux_offs + $(stat -Lc%s "/boot/vmlinuz-6.3.0-1-amd64")))
osrel_offs=$(objdump --section-headers -- "/usr/lib/systemd/boot/efi/linuxx64.efi.stub" | awk 'NF==7 {size=strtonum("0x"$3); offset=strtonum("0x"$4)} END {print size + offset}')
cmdline_offs=$((osrel_offs + $(stat --dereference --format=%s -- "/usr/lib/os-release")))
linux_offs=$((cmdline_offs + $(stat --dereference --format=%s -- "${temp_kernel_command_file}")))
initrd_offs=$((linux_offs + $(stat --dereference --format=%s -- "/boot/vmlinuz-${KERNEL_VERSION}")))
### Create a unified kernel
@ -111,6 +111,6 @@ efibootmgr --disk /dev/"${ESP_DISK}" --part "${ESP_PART}" --create --label "${EF
# }}}
## Remove temp files
rm -f -- "${temp_efi_list_file}" "${temp_kernel_list_file}" "${temp_kernel_command_file}"
rm --force -- "${temp_efi_list_file}" "${temp_kernel_list_file}" "${temp_kernel_command_file}"
exit 0