feat(zbm): Add networking/IP addressing setup to ZBM (#6)
This commit is contained in:
parent
be668b1bdc
commit
732cc47405
39
setup.sh
39
setup.sh
@ -770,6 +770,45 @@ function customize_dropbear_hooks () {
|
||||
fi
|
||||
}
|
||||
|
||||
function ensure_ip_in_kcl () {
|
||||
local zbm_config kcl_length kcl_string default_ip ip_addr_found new_kcl first_kcl_elem
|
||||
local -a kcl
|
||||
paru_install 'go-yq'
|
||||
|
||||
zbm_config='/etc/zfsbootmenu/config.yaml'
|
||||
kcl_length="$(yq '.Kernel.CommandLine | length' "${zbm_config}")"
|
||||
if [[ "${kcl_length}" -eq '0' ]]; then
|
||||
>&3 printf -- '%s\n' \
|
||||
'No .Kernel.CommandLine YAML element with content found in '"${zbm_config}"'. Exiting ...'
|
||||
exit 77
|
||||
else
|
||||
kcl_string="$(yq '.Kernel.CommandLine' "${zbm_config}")"
|
||||
fi
|
||||
|
||||
default_ip='ip='"${ARCHZBM_NET_CLIENT_IP}"':'"${ARCHZBM_NET_SERVER_IP}"':'"${ARCHZBM_NET_GATEWAY_IP}"':'"${ARCHZBM_NET_NETMASK}"':'"${ARCHZBM_NET_HOSTNAME}"':'"${ARCHZBM_NET_DEVICE}"':'"${ARCHZBM_NET_AUTOCONF}"
|
||||
mapfile -t kcl < <(<<<"${kcl_string}" tr ' ' '\n' | sed '/^$/d')
|
||||
for kcl_elem in "${!kcl[@]}"; do
|
||||
if grep -Piq -- 'ip=' <<<"${kcl[$kcl_elem]}"; then
|
||||
ip_addr_found='true'
|
||||
kcl["${kcl_elem}"]="${default_ip}"
|
||||
fi
|
||||
done
|
||||
if [[ ! "${ip_addr_found}" ]]; then
|
||||
kcl+=("${default_ip}")
|
||||
fi
|
||||
new_kcl=''
|
||||
first_kcl_elem='true'
|
||||
for kcl_elem in "${kcl[@]}"; do
|
||||
if [[ ! "${first_kcl_elem}" ]]; then
|
||||
new_kcl+=' '"${kcl_elem}"
|
||||
else
|
||||
new_kcl+="${kcl_elem}"
|
||||
unset -v first_kcl_elem
|
||||
fi
|
||||
done
|
||||
yq -i '.Kernel.CommandLine = "'"${new_kcl}"'"' "${zbm_config}"
|
||||
}
|
||||
|
||||
function we_want_ssh () {
|
||||
#2.10
|
||||
if [[ "${ARCHZBM_NET_CLIENT_IP}" ]] || \
|
||||
|
Loading…
x
Reference in New Issue
Block a user