#!/usr/bin/env bash # -*- coding: utf-8 -*- # region imports source '/usr/lib/rebash/core.sh' core.import exceptions core.import logging # endregion ( logging.set_commands_level debug logging.set_level debug [[ "$SLX_LOG_FILE_PATH" == "" ]] && SLX_LOG_FILE_PATH=/var/log/openslx logging.set_log_file "$SLX_LOG_FILE_PATH" SLX_INITIAL_KERNEL_COMMAND_LINE="$(cat /proc/cmdline | tr --delete '\n')" # This location will be used to have a writable kernel command line file # location. writeable_proc_cmdline_path='/writable_proc_cmdline/' mkdir --parents "$writeable_proc_cmdline_path" # NOTE: The fake writeable overlay have to be a temporary filesystem for the # hack to work. mount --types tmpfs tmpfs "$writeable_proc_cmdline_path" echo -n "$SLX_INITIAL_KERNEL_COMMAND_LINE" > \ "${writeable_proc_cmdline_path}/cmdline" logging.debug \ '-----------------------Kernel-Command-Line:------------------------------' logging.debug "${SLX_INITIAL_KERNEL_COMMAND_LINE}" logging.debug \ '-------------------------------------------------------------------------' for parameter in $(getargs BOOTIF=); do logging.debug "PXE given boot interface $parameter" dracut_interface_name="bootnet:$(echo $parameter | \ sed --regexp-extended 's/.{2}[:\-]((.{2}[:\-]){5}.{2})/\1/' | \ sed s/-/:/g)" logging.debug "Dracut interface name is: $dracut_interface_name" logging.plain -n " ifname=$dracut_interface_name" >> \ "${writeable_proc_cmdline_path}cmdline" done for parameter in $(getargs ip=); do temp="$parameter:" set -- while [ -n "$temp" ]; do set -- "$@" "${temp%%:*}" temp=${temp#*:} done [ -n "$1" ] && ip=$1 [ -n "$2" ] && server_ip=$2 [ -n "$3" ] && gateway_ip=$3 [ -n "$4" ] && net_mask=$4 logging.debug "PXE given net configuration: ip: $ip server_ip: $server_ip gateway_ip: $gateway_ip net_mask: $net_mask" dracut_ip_configuration="$ip::$gateway_ip:$net_mask::bootnet:off" logging.debug "Dracut ip configuration is: $dracut_ip_configuration" sed --regexp-extended "s/ip=[^ ]*/ip=$dracut_ip_configuration/g" \ --in-place "${writeable_proc_cmdline_path}cmdline" done if [ -z "$dracut_ip_configuration" ]; then logging.warn 'No "ip" parameter found in the kernel command line.' fi if [ -z "$dracut_interface_name" ]; then logging.warn 'No "BOOTIF" parameter found in the kernel command line.' fi mount --options bind "${writeable_proc_cmdline_path}cmdline" /proc/cmdline if [ -z "$(getargs slxsrv=)" ]; then logging.warn 'No "slxsrv" parameter found in the kernel command line.' exit 1 fi if [ -z "$(getargs slxbase=)" ]; then logging.warn 'No "slxbase" parameter found in the kernel command line.' exit 1 fi logging.debug \ '-----------------------Dracut-Kernel-Command-Line:-----------------------' logging.debug "$(logging.cat /proc/cmdline)" logging.debug \ '-------------------------------------------------------------------------' ) # region vim modline # vim: set tabstop=4 shiftwidth=4 expandtab: # vim: foldmethod=marker foldmarker=region,endregion: # endregion