summaryrefslogtreecommitdiffstats
path: root/builder/dnbd3-rootfs/hooks/cmdline/prepare-kernel-command-line-parameter.sh
blob: c038aecc7f61a077a096fcac54ad882045eab91c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
( # subshell for variable scoping
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"

echo -e \
    '-----------------------Kernel-Command-Line:--------------------------\n' \
    "${SLX_INITIAL_KERNEL_COMMAND_LINE}\n" \
    '----------------------------------------------------------------------'

for parameter in $(getargs BOOTIF=); do
    info "PXE given boot interface $parameter"
    dracut_interface_name="bootnet:$(echo $parameter | \
        sed --regexp-extended 's/.{2}[:\-]((.{2}[:\-]){5}.{2})/\1/' | \
        sed s/-/:/g)"
    info "Dracut interface name is: $dracut_interface_name"
    echo -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

    info "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"
    info "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
    warn 'No "ip" parameter found in the kernel command line.'
fi
if [ -z "$dracut_interface_name" ]; then
    warn 'No "BOOTIF" parameter found in the kernel command line.'
fi
mount --options bind "${writeable_proc_cmdline_path}cmdline" /proc/cmdline

if [ -z $(getargs "$SLX_SERVER") ]; then
    warn 'No "slxsrv" parameter found in the kernel command line.'
    exit 1
fi
if [ -z $(getargs "$SLX_SERVER_BASE") ]; then
    warn 'No "slxbase" parameter found in the kernel command line.'
    exit 1
fi

echo '-----------------------Dracut-Kernel-Command-Line:----------------------'
cat /proc/cmdline
echo '------------------------------------------------------------------------'
) || exit $?
# region vim modline

# vim: set tabstop=4 shiftwidth=4 expandtab:
# vim: foldmethod=marker foldmarker=region,endregion:

# endregion