6-add-ssh-to-bootloader #20
93
setup.sh
93
setup.sh
@ -832,43 +832,70 @@ function customize_dropbear_hooks () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function set_unique_ip_in_syslinux_kcl () {
|
||||||
|
local zbm_config default_ip
|
||||||
|
zbm_config="${1:?}"
|
||||||
|
default_ip="${2:?}"
|
||||||
|
|
||||||
|
# First -e expression removes first looks for lines that contain
|
||||||
|
# 'APPEND' plus a space character and only in those lines removes all
|
||||||
|
# occurrences of ' ip=' followed by as many non-space characters as
|
||||||
|
# possible. This removes whatever 'ip=' definition already was present.
|
||||||
|
#
|
||||||
|
# Second -e expression similarly looks for lines that contain 'APPEND'
|
||||||
|
# plus a space character then at their end inserts a space plus our
|
||||||
|
# desired new 'ip=' definition. This puts in place the 'ip=' we want.
|
||||||
|
sed -ri \
|
||||||
|
-e \\$'\x1''APPEND '$'\x1 s'$'\x1'' ip=([^[:space:]]*)'$'\x1'''$'\x1''gi' \
|
||||||
|
-e \\$'\x1''APPEND '$'\x1 s'$'\x1''$'$'\x1'' '"${default_ip}"''$'\x1''gi' \
|
||||||
|
"${zbm_config}"
|
||||||
|
}
|
||||||
|
|
||||||
function ensure_ip_in_kcl () {
|
function ensure_ip_in_kcl () {
|
||||||
local zbm_config kcl_length kcl_string default_ip ip_addr_found new_kcl first_kcl_elem
|
local default_ip
|
||||||
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}"
|
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 [[ "${part_schema}" = 'gpt' ]]; then
|
||||||
if grep -Piq -- 'ip=' <<<"${kcl[$kcl_elem]}"; then
|
local zbm_config kcl_length kcl_string ip_addr_found new_kcl first_kcl_elem
|
||||||
ip_addr_found='true'
|
local -a kcl
|
||||||
kcl["${kcl_elem}"]="${default_ip}"
|
paru_install 'go-yq'
|
||||||
fi
|
|
||||||
done
|
zbm_config='/etc/zfsbootmenu/config.yaml'
|
||||||
if [[ ! "${ip_addr_found}" ]]; then
|
kcl_length="$(yq '.Kernel.CommandLine | length' "${zbm_config}")"
|
||||||
kcl+=("${default_ip}")
|
if [[ "${kcl_length}" -eq '0' ]]; then
|
||||||
fi
|
>&3 printf -- '%s\n' \
|
||||||
new_kcl=''
|
'No .Kernel.CommandLine YAML element with content found in '"${zbm_config}"'. Exiting ...'
|
||||||
first_kcl_elem='true'
|
exit 77
|
||||||
for kcl_elem in "${kcl[@]}"; do
|
|
||||||
if [[ ! "${first_kcl_elem}" ]]; then
|
|
||||||
new_kcl+=' '"${kcl_elem}"
|
|
||||||
else
|
else
|
||||||
new_kcl+="${kcl_elem}"
|
kcl_string="$(yq '.Kernel.CommandLine' "${zbm_config}")"
|
||||||
unset -v first_kcl_elem
|
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
yq -i '.Kernel.CommandLine = "'"${new_kcl}"'"' "${zbm_config}"
|
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}"
|
||||||
|
else
|
||||||
|
local zbm_config
|
||||||
|
zbm_config='/boot/syslinux/syslinux.cfg'
|
||||||
|
set_unique_ip_in_syslinux_kcl "${zbm_config}" "${default_ip}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_pub_keys () {
|
function set_pub_keys () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user