#! /bin/sh #---------------------------------------------------------------------------- # /var/install/bin/update-bootloader - update boot configuration # # Creation : 2021-04-23 hbfl # Last Update: $Id$ # # Copyright (c) 2001-@@YEAR@@ the eisfair team, team(at)eisfar(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- . /var/install/include/eislib do_debug="no" system="$(lsb_release -ds)" #----------------------------------------------------------------------------- # show help #----------------------------------------------------------------------------- show_help() { cat < UUID=${link}" done } #----------------------------------------------------------------------------- # find suitable initrd name for kernel image #----------------------------------------------------------------------------- lookup_initrd_name() { local kernel="${1}" if [ "${kernel}" == "kernel" ] then echo 'initrd.gz' return fi if [ "${kernel}" == "old-kernel" ] then echo 'old-initrd.gz' return fi local kernel_name=$(echo ${kernel} | cut -d'-' -f2-) echo "initrd-${kernel_name}.gz" } #----------------------------------------------------------------------------- # inspect /boot for kernel images in correct order #----------------------------------------------------------------------------- lookup_kernel_images() { local kernels='kernel' local kernel if [ -L '/boot/kernel' ] then # new configuration (prefer versioned kernels over old-kernel) local versioned_kernels="$(/usr/bin/ls /boot/kernel-* 2> /dev/null | /usr/bin/sed 's#/boot/##g' | /usr/bin/sort -r)" for kernel in ${versioned_kernels} do local initrd_name="$(lookup_initrd_name ${kernel})" if [ -f "/boot/${initrd_name}" ] then kernels="${kernels} ${kernel}" fi done if [ -f '/boot/old-kernel' ] then kernels="${kernels} old-kernel" fi else # old configuration (prefer old-kernel over versioned kernels) if [ -f "/boot/old-kernel" ] then kernels="${kernels} old-kernel" fi local versioned_kernels="$(/usr/bin/ls /boot/kernel-* 2> /dev/null | /usr/bin/sed 's#/boot/##g' | /usr/bin/sort -r)" # only add kernel images with valid initrd for kernel in ${versioned_kernels} do local initrd_name="$(lookup_initrd_name ${kernel})" if [ -f "/boot/${initrd_name}" ] then kernels="${kernels} ${kernel}" fi done fi echo "${kernels}" } #----------------------------------------------------------------------------- # lookup name of kernel for label entry (max length = 15 characters) #----------------------------------------------------------------------------- lookup_kernel_name() { local kernel="${1}" if [ "${kernel}" == "old-kernel" ] then echo 'oldeis' return fi if [ "${kernel}" == "kernel" ] then echo 'eis' return fi local kernel_name=$(echo ${kernel} | /usr/bin/cut -d'-' -f2-) echo "$(echo ${kernel_name} | /usr/bin/sed "s#${system}-##g")" } #----------------------------------------------------------------------------- # add default append arguments, if not present #----------------------------------------------------------------------------- extend_append_args() { local append="${@}" if [ -z "${append}" ] then # append-zeile existiert nicht, # setze consoleblank=600 (beim 5er Kernel ist default 0) append='consoleblank=600' else # zeile existiert if ! echo "${append}" | /usr/bin/grep -q 'consoleblank=600' then # setze consoleblank=600 (beim 5er Kernel ist default 0) append="${append} consoleblank=600" fi fi echo "${append}" } #----------------------------------------------------------------------------- # write kernel image to bootloader.conf #----------------------------------------------------------------------------- write_kernel_image() { local kernel="${1}" local root_uuid="${2}" local vga="${3}" local append_args="${4}" if [ -n "${vga}" ] then if ! echo "${append_args}" | /usr/bin/grep -q 'vga' then # setze vga append_args="${append_args} vga=${vga}" fi fi echo '' echo "LABEL $(lookup_kernel_name ${kernel})" echo " MENU LABEL $(lookup_kernel_name ${kernel})" echo " KERNEL ../${kernel}" echo " INITRD ../$(lookup_initrd_name ${kernel})" echo " APPEND root=${root_uuid} ${append_args}" } #----------------------------------------------------------------------------- # create config #----------------------------------------------------------------------------- create_config() { # read boot configuration local disk_byid='' local disk_dev='' local boot_byid='' local boot_dev='' local root_uuid='' local root_dev='' if "${lilo_conf}" then local vga="$(lookup_value_from_lilo_conf_with_filter 'vga' 'normal')" local append_args="$(lookup_value_from_lilo_conf 'append')" fi if [ -f "${boot_conf}" ] then local append_args="$(lookup_append_from_boot_conf 'APPEND')" fi # lookup root partition root_partition="$(lookup_device_from_path '/')" if [ -z "${root_partition}" ] then mecho --error "Failed to lookup block device for root partition" exit 1 fi root_uuid="$(lookup_volume_uuid_from_list ${root_partition})" if [ -z "${root_uuid}" ] then mecho --error "Cannot translate root disk partition ${root_partition} to /dev/disk/by-uuid/!" echo print_volume_uuids_from_list exit 1 fi # extra processing of values append_args="$(extend_append_args "${append_args}")" kernel_images="$(lookup_kernel_images)" if [ -z "${kernel_images}" ] then mecho --error "No kernel images found!" exit 1 fi # show values if [ "${do_debug}" = "yes" ] then echo -n "root_uuid = "; mecho --info "${root_uuid}" echo -n "append_args = "; mecho --info "${append_args}" echo -n "kernel_images = "; mecho --info "${kernel_images}" echo fi # write new config file { echo '#-------------------------------------------------------------------------' echo '# /boot/extlinux/extlinux.conf - bootloader configuration' echo "# created: ${EISDATE} ${EISTIME}" echo '#-------------------------------------------------------------------------' echo echo 'PATH com32' echo 'UI menu.c32' echo 'DEFAULT eis' echo 'PROMPT 0' echo 'MENU TITLE eisfair - EXTlinux - Bootmenu' echo 'TIMEOUT 30' for kernel in ${kernel_images} do write_kernel_image "${kernel}" \ "${root_uuid}" \ "${vga}" \ "${append_args}" done } > ${boot_conf} if [ ${?} -ne 0 ] then mecho --error "Failed to write to ${boot_conf}!" exit 1 fi if "${lilo_conf}" then /usr/bin/mv /etc/lilo.conf /etc/lilo.conf.OLD fi } #----------------------------------------------------------------------------- # main program #----------------------------------------------------------------------------- main() { boot_dir='/boot/extlinux' /usr/bin/mkdir -p ${boot_dir} boot_conf=${boot_dir}/extlinux.conf lilo_conf=false if [ -f '/etc/lilo.conf' ] then lilo_conf=true fi while [ "${1:0:2}" = "--" ] do case "${1}" in --help) shift show_help exit 0 ;; --generate-new) shift create_config exit 0 ;; --use-existing) shift # create_config # quiet=true exit 0 ;; *) echo "error: invalid switch \"${1}\"!" >&2 show_help exit 1 ;; esac done if [ -z "${@}" ] then create_config else show_help exit 0 fi exit 0 } #----------------------------------------------------------------------------- # call function main #----------------------------------------------------------------------------- main "${@}" #----------------------------------------------------------------------------- # end #-----------------------------------------------------------------------------