Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package uki-tool for openSUSE:Factory checked in at 2025-05-26 18:35:15 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/uki-tool (Old) and /work/SRC/openSUSE:Factory/.uki-tool.new.2732 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "uki-tool" Mon May 26 18:35:15 2025 rev:7 rq:1279737 version:1.5.0+1.g563332e Changes: -------- --- /work/SRC/openSUSE:Factory/uki-tool/uki-tool.changes 2025-03-04 18:33:48.637004889 +0100 +++ /work/SRC/openSUSE:Factory/.uki-tool.new.2732/uki-tool.changes 2025-05-26 18:36:49.866688152 +0200 @@ -1,0 +2,23 @@ +Sat May 24 09:37:15 UTC 2025 - Valentin Lefebvre <valentin.lefeb...@suse.com> + +- Update to version 1.5.0+1.g563332e: + * fix SC2086 in common + * Release 1.5.0 + * sdboot: remove entry only for installed uki + * sdboot: do not break with old version + * bootloader: remove carefully installed uki. + * snapper: add uki ver in conf for sorting entries + * add quiet verb + * sdboot: apply sort-key and version id + * common: improve getting data from uki + * sdboot: fix conf filename + * snapper: Improve uki snapshots entries + * bootloaders: trust uki's uname for kerver + * bootloader menu-entries pretty_name + * snapper: improve the snapper plugin + * common: install/remove uki extra dir + * fix: grub2: grep menuentry id + * bootloader: take the uki path for removing entry + * Add version argument + +------------------------------------------------------------------- Old: ---- unified-kernel-image-tool-1.4.2+0.g1e31f3f.tar.xz New: ---- unified-kernel-image-tool-1.5.0+1.g563332e.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ uki-tool.spec ++++++ --- /var/tmp/diff_new_pack.yTdzJz/_old 2025-05-26 18:36:50.546716679 +0200 +++ /var/tmp/diff_new_pack.yTdzJz/_new 2025-05-26 18:36:50.550716847 +0200 @@ -20,7 +20,7 @@ %define bin_name uki-tool Name: uki-tool -Version: 1.4.2+0.g1e31f3f +Version: 1.5.0+1.g563332e Release: 0 Summary: Tool for the UKI and static-initrd project License: MIT ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.yTdzJz/_old 2025-05-26 18:36:50.602719028 +0200 +++ /var/tmp/diff_new_pack.yTdzJz/_new 2025-05-26 18:36:50.606719196 +0200 @@ -1,8 +1,6 @@ <servicedata> <service name="tar_scm"> - <param name="url">https://gitlab.suse.de/vlefebvre/unified-kernel-image-tool</param> - <param name="changesrevision">1de0ad2a87daccc937adc720d3560c7e23f2d39d</param></service><service name="tar_scm"> <param name="url">https://github.com/keentux/unified-kernel-image-tool</param> - <param name="changesrevision">1e31f3f6f89574eea2e452b97f3526bb077136ce</param></service></servicedata> + <param name="changesrevision">563332e8c2a1dbc282732b66812fe10949ea4f51</param></service></servicedata> (No newline at EOF) ++++++ unified-kernel-image-tool-1.4.2+0.g1e31f3f.tar.xz -> unified-kernel-image-tool-1.5.0+1.g563332e.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/CHANGELOG.md new/unified-kernel-image-tool-1.5.0+1.g563332e/CHANGELOG.md --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/CHANGELOG.md 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/CHANGELOG.md 2025-05-24 11:29:43.000000000 +0200 @@ -4,12 +4,49 @@ ## [1.x.x] - 2025-mm-dd +## Added + +## Changed + +## Fixed + +- SC2086 on common. + +## [1.5.0] - 2025-05-21 + ### Added +- version command to get the binary version at runtime. +- common: + - functions to get value from os-release in the system or uki. + - function to check if uki is installed in the efi dir. +- quiet argument to avoid any outputs. + ### Changed +- common: When adding/removing the uki, also take care of its extra directory. +- snapper plugin: + - get bootloader name + - sdboot: use the current uki + - install the addon in the esp partition + - Improve how snaphots are created +- bootloader: default title is the pretty_name. +- bootloader: Trust only the UKI's uname as kerver when managing UKIs. +- bootloader: Remove uki from efi dir only if not used anymore. +- sdboot: get version_id and id to fill the conf entry file correctly. +- sdboot: check if uki is installed before removing entries. +- grub2: refer to the uki_name_id when removing entry. +- common: improves function to get data from uki file (uname, pretty_name). + ### Fixed +- bootloaders: + - stop formating the UKI name when removing an entry for uki. + Trust only the filename from the given uki path. + - sdboot conf filename + - grub2: Add a space into the grep to not mix with other menuentry ID. +- common: Uses objdump instead of objcopy that can change the initial efi file. + ## [1.4.2] - 2025-02-27 ### Added diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/README.md new/unified-kernel-image-tool-1.5.0+1.g563332e/README.md --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/README.md 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/README.md 2025-05-24 11:29:43.000000000 +0200 @@ -2,9 +2,9 @@ > * **Author**: Valentin LEFEBVRE <valentin.lefeb...@suse.com> > * **Created at**: 2023-05-04 -> * **Updated at**: 2025-02-27 +> * **Updated at**: 2025-05-21 > * **Description**:Utilities to help with UKI and static initrd projects. -> * **version**: 1.4.2 +> * **version**: 1.5.0 > * **Topics** > * [I-Description](#i---description) > * [II-Installation](#ii---installation) @@ -52,6 +52,8 @@ OPTIONS: - help: Print this helper - verbose: Print debug information to the output + - quiet: Quiet mode. Not output information + - version: Print the binary version - COMMAND help: Print the helper of the command - COMMAND [OPTION]: Execute the command with additional options. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/TODO.md new/unified-kernel-image-tool-1.5.0+1.g563332e/TODO.md --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/TODO.md 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/TODO.md 2025-05-24 11:29:43.000000000 +0200 @@ -6,8 +6,6 @@ - [ ] sdboot: add more verifiaction about arch provided. IA32, x64, IA64, ARM, AA64, -- [ ] grub2: when searching if config exists, need to base on uki name id - instead of path - suite test: - [ ] Check versioning of uki-tool when verifying kernel size to take the correct value to compare. See @@ -18,6 +16,10 @@ boot and status of same services after booting the UKI - [ ] Made the test-suite executable for openQA server - [ ] Create missing TESTs +- [ ] snapper: Need to keep the uki from previous entries when creating new + new ones. Right now, all new entries created with snapshots, boot on the + current UKI booted. For sdboot, uki-(N).conf needs to be the copy of + uki-(N-1).conf. ### In Progress ⌛ @@ -35,3 +37,5 @@ - [x] Write a Man - [x] set default options for bootloader - [x] Write a suite test +- [x] grub2: when searching if config exists, need to base on uki name id + instead of path diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/build.sh new/unified-kernel-image-tool-1.5.0+1.g563332e/build.sh --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/build.sh 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/build.sh 2025-05-24 11:29:43.000000000 +0200 @@ -190,7 +190,6 @@ } ;; esac - # Checking scripts format printf "%s " "--- Checking ..." build_verify @@ -205,8 +204,20 @@ build_prepare printf "%s\n" "OK!" +# Get the binary version from the README +BIN_VERSION=$(\ + grep -i "version" ./README.md \ + | sed -E "s/.*\*\*version\*\*: ([^ ]+).*/\1/" \ + | head -n 1 \ +) +if [ "$BIN_VERSION" == "" ]; then + printf "%s\n" "Cannot get the version from the README.md" + build_clean + exit 1 +fi + # Put the needed global variables -printf "%s " "--- Building ..." +printf "%s " "--- Building version $BIN_VERSION ..." if ! list_all_cmds; then build_clean exit 1 @@ -215,6 +226,8 @@ echo "CMD=\"$CMD\"" echo "BIN=\"$SCRIPT\"" echo "VERBOSE=0" + echo "QUIET=0" + echo "BIN_VERSION=\"$BIN_VERSION\"" } >> "$SCRIPT_PATH" # Put the commands scripts functions diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/docs/man/uki-tool.1 new/unified-kernel-image-tool-1.5.0+1.g563332e/docs/man/uki-tool.1 --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/docs/man/uki-tool.1 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/docs/man/uki-tool.1 2025-05-24 11:29:43.000000000 +0200 @@ -1,10 +1,10 @@ -.\" Automatically generated by Pandoc 3.2 +.\" Automatically generated by Pandoc 3.6.4 .\" -.TH "UKI\-TOOL" "1" "September 09, 2024" "Version 1.4.0" "Manual of Unified Kernel Image Tool script" +.TH "UKI\-TOOL" "1" "May 21, 2025" "Version 1.5.0" "Manual of Unified Kernel Image Tool script" .SH NAME Unified Kernel Image Tool (UKIT) .SH SYNOPSIS -\f[B]uki\-tool\f[R] [help|verbose] COMMANDS [\f[I]OPTION\f[R]]... +\f[B]uki\-tool\f[R] [help|verbose|quiet] COMMANDS [\f[I]OPTION\f[R]]... .SH DESCRIPTION Tool that regroups useful command dealing with the Unified Kernel Image (UKI) and static initrd project. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/docs/man/uki-tool.1.md new/unified-kernel-image-tool-1.5.0+1.g563332e/docs/man/uki-tool.1.md --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/docs/man/uki-tool.1.md 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/docs/man/uki-tool.1.md 2025-05-24 11:29:43.000000000 +0200 @@ -2,8 +2,8 @@ title: UKI-TOOL section: 1 header: Manual of Unified Kernel Image Tool script -footer: Version 1.4.0 -date: September 09, 2024 +footer: Version 1.5.0 +date: May 21, 2025 commnent: Generate man with `pandoc name.1.md -s -t man --from=gfm -o name.1` --- @@ -13,7 +13,7 @@ # SYNOPSIS -**uki-tool** [help|verbose] COMMANDS [*OPTION*]... +**uki-tool** [help|verbose|quiet] COMMANDS [*OPTION*]... # DESCRIPTION diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/snapper/20-uki.snapper new/unified-kernel-image-tool-1.5.0+1.g563332e/snapper/20-uki.snapper --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/snapper/20-uki.snapper 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/snapper/20-uki.snapper 2025-05-24 11:29:43.000000000 +0200 @@ -3,6 +3,48 @@ shopt -s extglob nullglob set -e +function get_bootloader_name() { + if (command -v sdbootutil > /dev/null 2>&1); then + # Should return "grub2" or "systemd-boot" + sdbootutil bootloader + else + echo "grub2" + fi +} + +function get_uki_data_osrel() { + local uki_p="$1" + local data_key="$2" + local section="osrel" + objdump -h "$1" | grep -wq ".${section}" || echo "" + local data="$(objdump -s -j ".${section}" "${uki_p}" \ + | sed -n '/[0-9a-f]/s/^[^ ]* *\([^ ]* *\)\{5\}//p' \ + | tr -d '\n' \ + | tr -d '\0')" + [ "$data" = "" ] ||\ + printf %s "${data}" | sed -n "s/.*${data_key}=\"\([^\"]*\)\".*/\1/p" +} + +function get_uki_prettyname() { + get_uki_data_osrel "$1" "PRETTY_NAME" +} + +function get_uki_ver_id() { + get_uki_data_osrel "$1" "VERSION_ID" +} + +function get_uki_id() { + get_uki_data_osrel "$1" "ID" +} + +function get_snapshot_value() { + local num="$1" + local key="$2" + + grep "<${key}>" "/.snapshots/${num}/info.xml"\ + | sed -E "s|.*<${key}>(.*)</${key}>.*|\1|" +} + # Command functions # when creating a snapshot we create a sym links if not exists to all last # snapshots. And adda bootloader entry using addonrelated to the link @@ -12,26 +54,81 @@ num="$3" addonsNbr=$(find /usr/share/unified/addons/*.addon.efi | wc -l) idx=1 + grubconf_snapshot_path="/etc/grub.d/45_uki_snapshot" + grubconf_uki_path="/etc/grub.d/44_ukit_uki" + sdboot_entries="/boot/efi/loader/entries" + if [ "$(get_bootloader_name)" == "grub2" ]; then + # echo "#!/bin/sh" > "$grubconf_snapshot_path" + # echo "set -e" >> "$grubconf_snapshot_path" + # echo "cat << EOF" >> "$grubconf_snapshot_path" + # grub2 not ready for snapshots + return 0 + else + # If not currently booted with an UKI cancel + bootctl --print-stub-path > /dev/null 2>&1 || return 0 + fi [ "$fs" = btrfs ] || return 1 - for snapshot in $(find /.snapshots -mindepth 1 -maxdepth 1 -type d | sort -Vr); do - [ $idx -gt "$addonsNbr" ] && break + snapshots="$(find /.snapshots -mindepth 1 -maxdepth 1 -type d | sort -Vr)" + for snapshot in ${snapshots}; do + [ $idx -ge "$addonsNbr" ] && break + # Install the addon + if [ ! -f "/boot/efi/EFI/addons/uki$idx.addon.efi" ]; then + [ ! -d "/boot/efi/EFI/addons" ] &&\ + mkdir -p "/boot/efi/EFI/addons" + cp "/usr/share/unified/addons/uki$idx.addon.efi"\ + "/boot/efi/EFI/addons/uki$idx.addon.efi" + fi + # Create the snapshot entry [ -L /.snapshots/uki$idx ] && rm /.snapshots/uki$idx ln -f -r -s "$snapshot" /.snapshots/uki$idx - # TODO: Use sdbootutil (via uki-tool) to install entry - [ -f /boot/efi/loader/entries/uki-$idx.conf ] && rm /boot/efi/loader/entries/uki-$idx.conf - { - echo "title UKI snapshot $(basename "$snapshot")" - echo "efi /EFI/Linux/uki-0.1.0.efi" - echo "add-on /EFI/addons/uki$idx.addon.efi" - } &> /boot/efi/loader/entries/uki-$idx.conf + snapshot_num="$(basename $snapshot)" + date=$(get_snapshot_value "$snapshot_num" "date") + date=$(echo $date | sed 's/\(.*\) \(.*\):.*/\1T\2/') + style=$(get_snapshot_value "$snapshot_num" "style") + if [ "$(get_bootloader_name)" == "grub2" ]; then + # sed -n "/menuentry/,/}/p" $grubconf_uki_path \ + # | sed "s/menuentry.*/menuentry 'OpenSUSE Tumbleweed uki ($date) ($style)' {/" \ + # | sed "/chainloader/s/^/ add-on \/EFI\/addons\/uki$idx.addon.efi\n/"\ + # &>> "$grubconf_snapshot_path" + {} + else + # Create the uki-$idx.conf + curr_stub="$(bootctl --print-stub-path)" + pretty_name="$(get_uki_prettyname ${curr_stub})" + ver_id="$(get_uki_ver_id ${curr_stub})" + uki_id="$(get_uki_id ${curr_stub})" + uki_name=$(basename "${curr_stub}" .efi) + title="Snapper: ${pretty_name} ${ver_id} ($snapshot_num@$uki_name)" + esp_path="$(bootctl --print-esp-path)" + curr_efi="${curr_stub#${esp_path}}" + uki_name="$(basename ${curr_stub})" + uki_ver="$(basename ${curr_stub} .efi | sed -e 's|^uki-||')" + { + echo "title ${title}" + echo "sort-key ${uki_id}" + echo "version ${uki_ver}~${snapshot_num}" + echo "efi ${curr_efi}" + echo "add-on /EFI/addons/uki$idx.addon.efi" + } &> /boot/efi/loader/entries/uki-$idx.conf + fi ((idx++)) done + # if [ "$(get_bootloader_name)" == "grub2" ]; then + # echo "EOF" >> "$grubconf_snapshot_path" + # chmod +x "$grubconf_snapshot_path" + # grub2-mkconfig -o /boot/grub2/grub.cfg + # fi # Remove older link if not already deleted if [[ $idx -le $addonsNbr ]]; then for ((old=idx; old <= addonsNbr; old++)); do - rm "/boot/efi/loader/entries/uki-$old.conf" + [ -f "/.snapshots/uki$old" ] &&\ + rm "/.snapshots/uki$old" + [ -f "/boot/efi/EFI/addons/uki$old.addon.efi" ] &&\ + rm "/boot/efi/EFI/addons/uki$old.addon.efi" + [ -f "/boot/efi/loader/entries/uki-$old.conf" ] &&\ + rm "/boot/efi/loader/entries/uki-$old.conf" done fi } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/src/commands/extension.sh new/unified-kernel-image-tool-1.5.0+1.g563332e/src/commands/extension.sh --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/src/commands/extension.sh 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/src/commands/extension.sh 2025-05-24 11:29:43.000000000 +0200 @@ -323,7 +323,7 @@ objcopy --dump-section .initrd=initrd-tmp "$uki" EXTENSION_LSINITRD=$(lsinitrd ./initrd-tmp \ | grep "usr/" \ - | tr -s ' ' \ + | tr -d ' ' \ | cut -d ' ' -f9 \ | sed 's|^|/|') EXTENSION_INITRD_RELEASE=$(lsinitrd -f usr/lib/initrd-release ./initrd-tmp) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/src/commands/grub2.sh new/unified-kernel-image-tool-1.5.0+1.g563332e/src/commands/grub2.sh --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/src/commands/grub2.sh 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/src/commands/grub2.sh 2025-05-24 11:29:43.000000000 +0200 @@ -25,7 +25,8 @@ GRUB2_CMD_REMOVE=2 GRUB2_ARG_ALL="all" GRUB2_CONFIG_INITRD="43_ukit_initrd" -GRUB2_CONFIG_UKI="44_ukit_uki" +GRUB2_CONFIG_DIR="/etc/grub.d" +GRUB2_CONFIG_UKI="${GRUB2_CONFIG_DIR}/44_ukit_uki" GRUB2_CONFIG_FILE="/boot/grub2/grub.cfg" GRUB2_DEFAULT_FILE="/etc/default/grub" GRUB2_TRANSACTIONAL_UPDATE=0 @@ -52,7 +53,26 @@ } ### -# Remove a menuentry block from a config file +# Remove, if installed, and if not used anymore, the uki and its extra +# directory if the path point to an efi directory. +# ARGUMENTS +# 1 - uki path/name +# 2 - efi dir +# OUTPUTS: +# Debugging Status +# RETURN: +# None +### +_grub2_remove_uki_from_efi() { + efi_uki_path="$2/$(basename "$1")" + if ! grep -qR "${efi_uki_path}" "${GRUB2_CONFIG_DIR}"/*; then + common_remove_uki_from_efi "${COMMON_ESP_PATH}${efi_uki_path}" + echo_debug "UKI ${COMMON_ESP_PATH}${efi_uki_path} has been removed." + fi +} + +### +# Remove a menuentry block from a config file using its ID. # ARGUMENTS: # 1 - grub config path # 2 - menu entry ID @@ -65,14 +85,16 @@ grub_config_path="$1" entry_id="$2" if [ -f "$grub_config_path" ]; then - if grep -q "$entry_id" "$grub_config_path"; then + if grep -q "menuentry.*--id $entry_id " "$grub_config_path"; then echo_info "Removing menuentry for $entry_id ..." # Get the block to remove: - start_line=$(grep -n "menuentry.*--id $entry_id"\ + start_line=$(grep -n "menuentry.*--id $entry_id "\ "$grub_config_path" | cut -d':' -f1 | head -n 1) if [ "${start_line}" = "" ]; then echo_warning \ "Failed to find the menuentry id ${entry_id}" + echo_warning \ + "Abort ..." return fi start_line=$((start_line-1)) @@ -93,7 +115,8 @@ echo_debug "UKI ${uki_path} has been removed." _grub2_grub_cfg else - echo_warning "There isn't a menu entry for $entry_id" + echo_warning "There isn't a menu entry with ID $entry_id" + echo_warning "Can only removed entries created by this tool." return fi else @@ -193,7 +216,7 @@ exit 2 fi if [ "${title}" = "" ]; then - title="Linux ${kerver}, Static Initrd ${initrd_file}" + title="$(common_get_pretty_name) (Static Initrd)" fi if [ ! -f "/boot/$initrd_file" ]; then echo_info "$initrd_file isn't in boot partition, copy it to \ @@ -260,40 +283,40 @@ default="$4" title="$5" kerver="$6" - efi_dev="$(common_get_dev_name "${COMMON_ESP_PATH}")" - efi_uuid="$(common_get_dev_uuid "$efi_dev")" - grub_config_path="/etc/grub.d/$GRUB2_CONFIG_UKI" + if [ ! -f "${uki_path}" ]; then + echo_error "Unified Kernel Image not found at ${uki_path}." + exit 2 + fi uki_file=$(common_format_uki_name "${uki_path}" "${kerver}") - efi_uki_path="/${efi_d}/$uki_file" - uki_name_id=$(basename "${efi_uki_path}" .efi) + uki_name_id=$(basename "${uki_file}" .efi) eof="EOF" echo_debug "UUID boot partition: $efi_uuid" if [ "$cmd" -eq "$GRUB2_CMD_ADD" ]; then - if [ ! -f "${uki_path}" ]; then - echo_error "Unified Kernel Image not found at ${uki_path}." - exit 2 - fi + efi_dev="$(common_get_dev_name "${COMMON_ESP_PATH}")" + efi_uuid="$(common_get_dev_uuid "$efi_dev")" + efi_uki_path="/${efi_d}/$uki_file" + uki_ver=$(basename "${efi_uki_path}" .efi | sed -e 's|^uki-||') if [ "${title}" = "" ]; then - title="Unified Kernel Image $uki_file ($kerver)" + title="$(common_uki_get_pretty_name "${uki_path}")" fi common_install_uki_in_efi "${uki_path}" "${efi_d}" "${kerver}" - if [ -f "$grub_config_path" ]; then - if grep -q "${efi_uki_path}" "${grub_config_path}"; then + if [ -f "$GRUB2_CONFIG_UKI" ]; then + if grep -q "${efi_uki_path}" "$GRUB2_CONFIG_UKI"; then echo_warning "There's already a menu entry for ${efi_uki_path}" echo_warning "Remove it before adding it" return fi else - cat > $grub_config_path <<EOF + cat > $GRUB2_CONFIG_UKI <<EOF #!/bin/sh set -e EOF - chmod +x $grub_config_path + chmod +x $GRUB2_CONFIG_UKI fi echo_info "Add UKI menuentry for ${efi_uki_path}..." - cat >> $grub_config_path <<EOF + cat >> $GRUB2_CONFIG_UKI <<EOF cat << $eof -menuentry '${title}' --id ${uki_name_id} { +menuentry '${title} (uki-${uki_ver})' --id ${uki_name_id} { search --no-floppy --fs-uuid --set=root ${efi_uuid} echo "Loading unified kernel image ${uki_file} ..." chainloader ${efi_uki_path} @@ -305,7 +328,8 @@ fi _grub2_grub_cfg elif [ "$cmd" -eq "$GRUB2_CMD_REMOVE" ]; then - _grub2_remove_menuentry "${grub_config_path}" "${uki_name_id}" + _grub2_remove_menuentry "$GRUB2_CONFIG_UKI" "${uki_name_id}" + _grub2_remove_uki_from_efi "${uki_file}" "${efi_d}" fi } @@ -428,6 +452,13 @@ fi done else + if [ ! -f "${uki_path}" ]; then + uki_file=$(basename "${uki_path}") + uki_path="${COMMON_KERNEL_MODULESDIR}/${kerver}/${uki_file}" + else + uki_uname=$(common_uki_get_uname "${uki_path}") + [ "$uki_uname" = "" ] || kerver="${uki_uname}" + fi _grub2_uki "${cmd}" \ "${uki_path}" \ "${efi_d}" \ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/src/commands/sdboot.sh new/unified-kernel-image-tool-1.5.0+1.g563332e/src/commands/sdboot.sh --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/src/commands/sdboot.sh 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/src/commands/sdboot.sh 2025-05-24 11:29:43.000000000 +0200 @@ -140,10 +140,13 @@ title="$6" common_install_uki_in_efi "${uki}" "${efi_d}" "${kerver}" image=$(common_format_uki_name "${uki}" "${kerver}") + conf_name=$(basename "${image}" ".efi") uki_ver=$(basename "${image}" .efi | sed -e 's|^uki-||') - cat > "${SDBOOT_LOADER_ENTRIES_D}/${image}.conf" <<EOF -title ${title} -sort-key unified + id=$(common_uki_get_osrel_id "${uki}") + [ "$id" = "" ] && id="unified" + cat > "${SDBOOT_LOADER_ENTRIES_D}/${conf_name}.conf" <<EOF +title ${title} (uki-${uki_ver}) +sort-key ${id} version ${uki_ver} efi ${efi_d}/${image} architecture ${arch} @@ -201,10 +204,26 @@ } ### +# Remove, if installed, and if not used anymore, the uki and its extra +# directory if the path point to an efi directory. +# ARGUMENTS +# 1 - uki path/name +# OUTPUTS: +# Debugging Status +# RETURN: +# None +### +_sdboot_remove_uki_from_efi() { + if ! grep -qR "$1" "${SDBOOT_LOADER_ENTRIES_D}"/*; then + common_remove_uki_from_efi "$1" + echo_debug "UKI $1 has been removed." + fi +} + +### # Remove the entry conf file of uki # ARGUMENTS: # 1 - uki path -# 2 - kernel version # OUTPUTS: # Debug info # RETURN: @@ -212,18 +231,22 @@ ### _sdboot_uki_remove_entry() { uki="$1" - kerver="$2" - image=$(common_format_uki_name "${uki}" "${kerver}") - + # config file should be named by the uki filename and the uname + uki_uname=$(common_uki_get_uname "${uki}") + image=$(common_format_uki_name "${uki}" "${uki_uname}") conf_file="${SDBOOT_LOADER_ENTRIES_D}/${image}.conf" + # Old way to create conf was wihtout removing the "efi" extension. + if [ ! -f "${conf_file}" ]; then + conf_name=$(basename "${image}" ".efi") + conf_file="${SDBOOT_LOADER_ENTRIES_D}/${conf_name}.conf" + fi if [ -f "${conf_file}" ]; then uki_path=$(_sdboot_get_uki_from_conf "${conf_file}") - common_remove_uki_from_efi "${uki_path}" - echo_debug "UKI ${uki_path} has been removed." rm "${conf_file}" echo_debug "UKI sdboot entry has been removed..." + _sdboot_remove_uki_from_efi "${uki_path}" else - echo_debug "No ${conf_file} to remove." + echo_debug "No ${conf_file} found to remove." fi } @@ -248,7 +271,7 @@ echo_info "${initrd_path} has been removed" linux_path=$(_sdboot_get_linux_from_conf "${conf_file}") # Remove the installed linux if no initrd follows him. Means that the - # linux has been installed in the same time as the statis-initrd. + # linux has been installed in the same time as the static-initrd. linux_dir=$(dirname "$linux_path") num=$(find "$linux_dir" -maxdepth 1 -type f | wc -l) if [ "$num" = "1" ]; then @@ -326,12 +349,15 @@ kerver="$6" if [ "$cmd" = "$SDBOOT_CMD_ADD" ]; then if [ "${title}" = "" ]; then - title="Unified Kernel Image $(basename "${uki}" .efi) ($kerver)" + title="$(common_uki_get_pretty_name "${uki}")" + title="${title} $(common_uki_get_osrel_version "${uki}")" fi _sdboot_uki_add_entry \ "${uki}" "${efi_d}" "${arch}" "${kerver}" "${default}" "${title}" else - _sdboot_uki_remove_entry "${uki}" "${kerver}" + common_is_uki_installed_in_efi "${uki}" "${efi_d}" "${kerver}" && { + _sdboot_uki_remove_entry "${uki}" + } fi } @@ -345,7 +371,7 @@ _sdboot_initrd() { if [ "$cmd" = "$SDBOOT_CMD_ADD" ]; then if [ "${title}" = "" ]; then - title="Linux ${kerver}, Static Initrd $(basename "${initrd}")" + title="$(common_get_pretty_name) (Static Initrd)" fi _sdboot_initrd_add_entry \ "${initrd}" "${efi_d}" "${kerver}" "${default}" "${title}" \ @@ -480,6 +506,9 @@ if [ ! -f "${uki}" ]; then uki_file=$(basename "${uki}") uki="${COMMON_KERNEL_MODULESDIR}/${kerver}/${uki_file}" + else + uki_uname=$(common_uki_get_uname "${uki}") + [ "$uki_uname" = "" ] || kerver="${uki_uname}" fi _sdboot_uki "${cmd}" \ "${uki}" \ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/src/common.sh new/unified-kernel-image-tool-1.5.0+1.g563332e/src/common.sh --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/src/common.sh 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/src/common.sh 2025-05-24 11:29:43.000000000 +0200 @@ -23,6 +23,7 @@ export COMMON_ESP_PATH="/boot/efi" export COMMON_EFI_PATH="EFI/Linux" +export COMMON_OSREL_PATH="/etc/os-release" export COMMON_KERNEL_MODULESDIR="/usr/lib/modules" export COMMON_INITRD_DIR="/usr/share/initrd" export COMMON_INITRD_BASENAME="static-initrd-generic" @@ -98,6 +99,34 @@ } ### +# Get the value of the keyword from /etc/os-release +# ARGUMENTS +# 1 - keyword +# OUTPUTS: +# None +# RETURN: +# None +### +common_extract_from_osrel () { + grep "$2=" "${COMMON_OSREL_PATH}"\ + | cut -d "=" -f2\ + | tr -d '"' +} + +### +# Get the PRETTY_NAME from os-release +# ARGUMENTS +# None +# OUTPUTS: +# None +# RETURN: +# None +### +common_get_pretty_name() { + common_extract_from_osrel "PRETTY_NAME" +} + +### # Verify if the efi parititon has enough space left to install the file # ARGUMENTS # 1 - file path @@ -111,7 +140,7 @@ echo_warning "Verifying an unknow file ($1)" return 1 fi - efi_dev="$(common_get_dev_name ${COMMON_ESP_PATH})" + efi_dev="$(common_get_dev_name "${COMMON_ESP_PATH}")" file_size="$(du -m0 "$1" | cut -f 1)" efi_avail="$(common_get_dev_avail "$efi_dev")" echo_debug "${efi_avail}M available on efi partition" @@ -175,6 +204,28 @@ } ### +# Check if the uki in installed in the efi boot partition +# /boot/efi/EFI/<distro>/<ukiname>-<version>_k<kerver>.efi +# ARGUMENTS +# 1 - uki path +# 2 - efi dir +# 3 - kerver +# OUTPUTS: +# Debug +# RETURN: +# 0 if installed +### +common_is_uki_installed_in_efi() { + uki_path="$1" + efi_d="$2" + kerver="$3" + image=$(common_format_uki_name "${uki_path}" "${kerver}") + esp_efi_d="${COMMON_ESP_PATH}/${efi_d}" + [ -f "${esp_efi_d}/${image}" ] && return 0 + return 1 +} + +### # If not, install the uki in the efi boot partition # /boot/efi/EFI/<distro>/<ukiname>-<version>_k<kerver>.efi # ARGUMENTS @@ -187,31 +238,33 @@ # exit 2 in failure ### common_install_uki_in_efi() { + common_is_uki_installed_in_efi "$1" "$2" "$3" && return 0 uki_path="$1" efi_d="$2" kerver="$3" image=$(common_format_uki_name "$1" "${kerver}") + extra_d="${image}.extra.d" esp_efi_d="${COMMON_ESP_PATH}/${efi_d}" [ ! -d "${esp_efi_d}" ] && mkdir -p "${esp_efi_d}" - if [ ! -f "${esp_efi_d}/${image}" ]; then - if [ ! -f "${uki_path}" ]; then - echo_error "Unable to find the UKI file: ${uki_path}" - exit 2 - else - echo_debug "Install UKI in ${esp_efi_d}/${image}" - common_verify_efi_size "$uki_path" || exit 2 - common_install_file "$uki_path" "${esp_efi_d}/${image}" || { - echo_error "Error when installing ${esp_efi_d}/${image}" - exit 2 - } - fi + if [ ! -f "${uki_path}" ]; then + echo_error "Unable to find the UKI file: ${uki_path}" + exit 2 else - echo_debug "${esp_efi_d}/${image} already install" + echo_debug "Install UKI ${esp_efi_d}/${image}" + common_verify_efi_size "$uki_path" || exit 2 + common_install_file "$uki_path" "${esp_efi_d}/${image}" || { + echo_error "Error when installing ${esp_efi_d}/${image}" + exit 2 + } + echo_debug "Installing UKI extra dir ${esp_efi_d}/${extra_d}" + [ ! -d "${esp_efi_d}/${extra_d}" ] \ + && mkdir -p "${esp_efi_d}/${extra_d}" fi } ### -# Remove, if installed, the uki if the path point to efi directory +# Remove, if installed, the uki and its extra directory if the path point to +# an efi directory. # ARGUMENTS # 1 - uki path # OUTPUTS: @@ -221,15 +274,105 @@ ### common_remove_uki_from_efi() { uki_path="$1" - if echo "${uki_path}" | grep -q "^/boot/efi"; then + if echo "${uki_path}" | grep -q "^${COMMON_ESP_PATH}"; then [ -f "${uki_path}" ] && rm "${uki_path}" - + [ -d "${uki_path}.extra.d" ] && rm -r "${uki_path}.extra.d" else - echo_debug "No file at ${uki_path}" + echo_debug "${uki_path} isn't a path from ${COMMON_ESP_PATH}" fi } ### +# Get the data value from an efi's section. +# Use objdump and sed to get only lines containing hex (skipping headers) with +# sed -n `/[0-9a-f]/.../p`. Removes the addresse with `^[^ ]* *`, and removes +# the 5 8-characters hex columns and their spaces with `\([^ ]* *\)\{5\}`. +# ARGUMENTS +# 1 - uki path +# 2 - section name (ex "uname") +# OUTPUTS: +# section's data value +# RETURN: +# 1 if error. +### +common_uki_get_section_data() { + [ -f "$1" ] || return 1 + objdump -h "$1" | grep -wq ".$2" || return 1 + objdump -s -j ".$2" "$1" \ + | sed -n '/[0-9a-f]/s/^[^ ]* *\([^ ]* *\)\{5\}//p' \ + | tr -d '\n' \ + | tr -d '\0' +} + +### +# Get the value of the keyword from UKI's os-release +# ARGUMENTS +# 1 - uki path +# 2 - keyword +# OUTPUTS: +# None +# RETURN: +# None +### +common_uki_extract_osrel() { + data=$(common_uki_get_section_data "$1" "osrel") + [ "$data" = "" ] ||\ + printf %s "$data" | sed -n "s/.*$2=\"\([^\"]*\)\".*/\1/p" +} + +### +# Get the PRETTY_NAME from UKI's os-release +# ARGUMENTS +# 1 - uki path +# OUTPUTS: +# None +# RETURN: +# None +### +common_uki_get_pretty_name() { + common_uki_extract_osrel "$1" "PRETTY_NAME" +} + +### +# Get the ID from UKI's os-release +# ARGUMENTS +# 1 - uki path +# OUTPUTS: +# None +# RETURN: +# None +### +common_uki_get_osrel_id() { + common_uki_extract_osrel "$1" "ID" +} + +### +# Get the Version_id from UKI's os-release +# ARGUMENTS +# 1 - uki path +# OUTPUTS: +# None +# RETURN: +# None +### +common_uki_get_osrel_version() { + common_uki_extract_osrel "$1" "VERSION_ID" +} + +### +# Get the uname from UKI's sections +# ARGUMENTS +# 1 - uki path +# OUTPUTS: +# None +# RETURN: +# None +### +common_uki_get_uname() { + common_uki_get_section_data "$1" "uname" +} + +### # If not, install the static initrd with the kernel version into efi dir # following this pattern: /<boot>/<machineID>/<ker_ver>/{static-initrd, linux} # If linux file not present, install the linux wollowing the kernel version diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/src/main.sh new/unified-kernel-image-tool-1.5.0+1.g563332e/src/main.sh --- old/unified-kernel-image-tool-1.4.2+0.g1e31f3f/src/main.sh 2025-02-27 18:41:10.000000000 +0100 +++ new/unified-kernel-image-tool-1.5.0+1.g563332e/src/main.sh 2025-05-24 11:29:43.000000000 +0200 @@ -38,6 +38,7 @@ # warning message ### echo_warning() { + [ "$QUIET" -eq 1 ] && return color="\033[0;33m" color_light="\033[1;33m" color_none="\033[0m" @@ -53,6 +54,7 @@ # error message ### echo_error() { + [ "$QUIET" -eq 1 ] && return color="\033[0;31m" color_light="\033[1;31m" color_none="\033[0m" @@ -67,6 +69,7 @@ # info message ### echo_info() { + [ "$QUIET" -eq 1 ] && return color="\033[0;32m" color_light="\033[1;32m" color_none="\033[0m" @@ -92,19 +95,21 @@ # MAIN FUNCTIONS # ####################################################################### - ### # Print the usage help # OUTPUTS: # Write helper to stdout # RETURN: -# 2 +# None ### usage() { - usage_str="USAGE: $BIN [help] [verbose] COMMAND [help | COMMAND OPTION] + usage_str="USAGE: $BIN [help] [verbose] [quiet] [version] COMMAND \ +[help | COMMAND OPTION] OPTIONS: - help: Print this helper - verbose: Print debug information to the output + - quiet: Quiet mode. Not output information + - version: Print the binary version - COMMAND help: Print the helper of the command - COMMAND [OPTION]: Execute the command with additional options. @@ -130,6 +135,16 @@ exit 1 fi } +### +# Print the binary version +# OUTPUTS: +# Print the version to stdout +# RETURN: +# 0 +### +print_version() { + printf "%s\n" "$BIN_VERSION" +} ####################################################################### # ENTRY POINT # @@ -141,17 +156,12 @@ usage & exit 2 fi cmd_in="$1" -if [ "$cmd_in" = "help" ]\ - || [ "$cmd_in" = "--help" ]\ - || [ "$cmd_in" = "-h" ]; then - usage - exit 0 -elif [ "$cmd_in" = "verbose" ]\ - || [ "$cmd_in" = "-v" ]; then - VERBOSE=1 - cmd_in="$2" - shift 1 -fi +case "$cmd_in" in + help|--help|-h) usage ; exit 0 ;; + verbose|--verbose|-v) VERBOSE=1; cmd_in="$2"; shift 1 ;; + quiet|--quiet|-q) QUIET=1; cmd_in="$2"; shift 1 ;; + version|--version) print_version; exit 0 ;; +esac # Get the kernel name according the arch case $(uname -m) in