From cd99963b743a38bed94ebae4ea11760a82148630 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 27 Oct 2023 16:49:03 +0200 Subject: [PATCH] Adding snippets/tpl.041.network-el9.sh --- snippets/tpl.041.network-el9.sh | 142 ++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 snippets/tpl.041.network-el9.sh diff --git a/snippets/tpl.041.network-el9.sh b/snippets/tpl.041.network-el9.sh new file mode 100644 index 0000000..e101b6c --- /dev/null +++ b/snippets/tpl.041.network-el9.sh @@ -0,0 +1,142 @@ +## !/bin/bash +#raw + +#----------------------------------------------------------- +create_networkconfig() { + + echo -e "\e[0Ksection_start:$( date +%s ):ks_create_networkconfig[collapsed=true]\r\e[0KGenerating network configuration ..." + echo + echo "${HASH_LINE}" + echo + log "Generating network configuration ..." + + local temp_dir=$( mktemp -p /tmp -d 'tmp.XXXXXXXXXX.cobbler' ) + local tmp_nw_cfg="${temp_dir}/network" + local tmp_nw_script_dir="${temp_dir}/network-scripts" + local nw_script_dir="/etc/sysconfig/network-scripts" + local nw_old_dir="${nw_script_dir}/.old" + local nm_cfg_dir='/etc/NetworkManager/system-connections' + local nm_old_dir="${nm_cfg_dir}/.old" + local ifcfg_file= + local if_uuid=$( uuidgen -r ) + + mkdir -pv "${tmp_nw_script_dir}" + mkdir -pv "${nw_old_dir}" + mkdir -pv "${nm_old_dir}" + + echo "Generating /etc/sysconfig/network ..." + + grep -v 'GATEWAY|HOSTNAME' /etc/sysconfig/network > "${tmp_nw_cfg}" + echo "GATEWAY=${gateway}" >> "${tmp_nw_cfg}" + echo "HOSTNAME=${hostname}" >> "${tmp_nw_cfg}" + mv -v /etc/sysconfig/network "/etc/sysconfig/network.orig.$( date -r /etc/sysconfig/network +'%Y-%m-%d_%H:%M:%S' )" + mv -v "${tmp_nw_cfg}" /etc/sysconfig/network + + echo "Generated /etc/sysconfig/network:" + cat /etc/sysconfig/network || true + echo + + # Also set the hostname now, some applications require it + echo "Generating '/etc/hostname' ..." + /bin/hostname "${base_hostname}" + echo "${base_hostname}" > '/etc/hostname' + + echo "Updating '/etc/hosts' ..." + echo >>'/etc/hosts' + echo "${ip_address_eth0} ${hostname} ${base_hostname}" >>'/etc/hosts' + echo "Generated /etc/hosts:" + cat '/etc/hosts' | true + echo + + for ifcfg_file in ${nw_script_dir}/ifcfg-* ; do + if [[ ! -f "${ifcfg_file}" ]] ; then + continue + fi + local bname=$(basename "${ifcfg_file}" ) + if [[ "${bname}" == "ifcfg-lo" ]] ; then + continue + fi + mv -v "${ifcfg_file}" "${nw_old_dir}" + done + + for ifcfg_file in ${nm_cfg_dir}/*.nmconnection ; do + if [[ ! -f "${ifcfg_file}" ]] ; then + continue + fi + local bname=$( basename "${ifcfg_file}" .nmconnection ) + if [[ "${bname}" == "lo" ]] ; then + continue + fi + mv -v "${ifcfg_file}" "${nm_old_dir}" + done + + local dev_basename="${DEVNAME_ETH0}.nmconnection" + local dev_file="${tmp_nw_script_dir}/${dev_basename}" + echo "Generating '${dev_file}' ..." + + cat <<-EOF >"${dev_file}" + [connection] + id=${DEVNAME_ETH0} + uuid=${if_uuid} + type=ethernet + interface-name=${DEVNAME_ETH0} + + [ethernet] + + [ipv4] + method=manual + address1=${IP_ADDRESS_ETH0}/${NETMASK_INT_ETH0},${gateway} + EOF + + local i=1 + local nameservers= + local searchdomains= + local ns= + local domain= + + if [[ "${#NAMESERVERS[*]}" -gt 0 ]] ; then + for ns in "${NAMESERVERS[@]}" ; do + nameservers+="${ns};" + done + echo "dns=${nameservers}" >>"${dev_file}" + fi + + if [[ "${#NS_SEARCH_DOMAINS[*]}" -gt 0 ]] ; then + for domain in "${NS_SEARCH_DOMAINS[@]}" ; do + searchdomains+="${domain};" + done + echo "dns-search=${searchdomains}" >>"${dev_file}" + fi + + cat <<-EOF >>"${dev_file}" + dns-options=timeout:1,attempts:2 + + [ipv6] + addr-gen-mode=eui64 + method=auto + + [proxy] + + EOF + + chmod -v 0600 "${dev_file}" + mv -v "${dev_file}" "${nm_cfg_dir}" + + rm -vrf "${temp_dir}" + + echo "Generated NM configfile '${nm_cfg_dir}/${dev_basename}'" + cat "${nm_cfg_dir}/${dev_basename}" || true + echo + + echo + echo "${HASH_LINE}" + echo "Content of ${nm_cfg_dir} ..." + ls -lA "${nm_cfg_dir}" + + echo -e "\e[0Ksection_end:$( date +%s ):ks_create_networkconfig\r\e[0K" +} + +create_networkconfig + +#end raw +## vim: ts=4 et list -- 2.39.5