Skip to content

Instantly share code, notes, and snippets.

@Hayao0819
Last active August 14, 2022 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hayao0819/d0bc7d890fe220c92c34f651356c2cae to your computer and use it in GitHub Desktop.
Save Hayao0819/d0bc7d890fe220c92c34f651356c2cae to your computer and use it in GitHub Desktop.
dracutをインストールされている全てのカーネルで実行するスクリプト
#!/usr/bin/env bash
set -euo pipefail
Force=false
# shellcheck source=/dev/null
#source <(curl -sL https://raw.githubusercontent.com/Hayao0819/FasBashLib/build-0.2.x/fasbashlib.sh)
PrintArray(){ printf '%s\n' "${@}"; }
Bool(){ [[ "${1,,}" = true ]]; }
Array.Includes(){ eval "PrintArray \"\${${1}[@]}\"" | grep -qx "${2}"; }
GetKernelListFromBoot(){
find "/boot" -mindepth 1 -maxdepth 1 -name "vmlinuz-*" -printf "%f\n" | sed 's/vmlinuz-//' | sort -r
}
GetKernelListFromModuleDir(){
find "/lib/modules/" -mindepth 1 -maxdepth 1 -type d -printf "%f\n" | sort -r
}
GetMakableKernelList(){
local kernel module=()
# shellcheck disable=SC2034
readarray -t module < <(GetKernelListFromModuleDir)
while read -r kernel; do
if Array.Includes module "$kernel"; then
echo "$kernel"
fi
done < <(GetKernelListFromBoot)
}
Main(){
local kernel initramfs
while read -r kernel; do
initramfs="/boot/initramfs-${kernel}.img"
if [[ -f "$initramfs" ]] && ! Bool "$Force"; then
echo "initramfs-${kernel}.img already exists" >&2
continue
fi
dracut "$@" "$initramfs" "$kernel"
done < <(GetMakableKernelList)
}
if PrintArray "$@" | grep -qx -e "-f" -e "--force"; then
Force=true
fi
Main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment