#!/bin/bash #---------------------------------------------------------------------------- # /usr/bin/mkinitrd - create initrd image # # Creation : 2021-06-19 dv # Last update: 2021-06-23 19:46:28 # # Copyright (c) 2019-2023 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 #----------------------------------------------------------------------------- # show help on command invokaction #----------------------------------------------------------------------------- show_help() { cat < add this module to the list of dracut modules. --without= remove this module from the list of dracut modules. --nocompress do not compress the generated initramfs. --force force dracut to overwrite an existing image. --image-version= set version of kernel image. EOF } #----------------------------------------------------------------------------- # main routine #----------------------------------------------------------------------------- main() { local initrd_image="/boot/initrd-$(uname -r).gz" local kernel_version="$(uname -r)" local add_modules local omit_modules local options local quiet=false while [ "${1:0:1}" = "-" ] do case "${1}" in --help) show_help exit 0 ;; -q|--quiet) shift options="${options} --quiet" quiet=true ;; -v|--verbose) shift options="${options} --verbose" ;; --image-version) shift if [ "${1}" != "" -a "${1:0:1}" != "-" ] then initrd_image="/boot/initrd-${1}.gz" kernel_version="${1}" shift else echo 'error: missing argument for --image-version!' >&2 show_help exit 1 fi ;; --image-version=*) initrd_image="/boot/initrd-${1:16}.gz" kernel_version="${1:16}" shift ;; --with) shift if [ "${1}" != "" -a "${1:0:1}" != "-" ] then add_modules="${add_modules} ${1}" shift else echo 'error: missing argument for --with!' >&2 show_help exit 1 fi ;; --with=*) add_modules="${add_modules} ${1:7}" shift ;; --without) shift if [ "${1}" != "" -a "${1:0:1}" != "-" ] then omit_modules="${omit_modules} ${1}" shift else echo 'error: missing argument for --without!' >&2 show_help exit 1 fi ;; --without=*) omit_modules="${omit_modules} ${1:7}" shift ;; --nocompress) shift options="${options} --no-compress" ;; -f|--force) shift options="${options} --force" ;; --version) shift echo "mkinitrd: dracut compatibility wrapper" exit 0 ;; *) echo "error: unknown option \"${1}\"!" >&2 echo "" show_help exit 1 ;; esac done if [ "$#" -ge 1 ] then initrd_image="${1}" shift fi if [ "$#" -ge 1 ] then kernel_version="${1}" shift fi if [ -n "${omit_modules}" ] then options="${options} --omit \"${omit_modules}\"" fi if [ -n "${add_modules}" ] then options="${options} --add \"${add_modules}\"" fi echo "Creating: ${initrd_image}|${kernel_version}" if dracut ${options} "${initrd_image}" "${kernel_version}" then echo "Creation of initrd succeeded!" exit 0 else echo "Creation of initrd failed!" exit 1 fi } #----------------------------------------------------------------------------- # call function main #----------------------------------------------------------------------------- main "${@}" #----------------------------------------------------------------------------- # end #-----------------------------------------------------------------------------