]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Adding and using snippets/tpl.040.network.sh
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 18 Jun 2020 16:01:19 +0000 (18:01 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 18 Jun 2020 16:01:19 +0000 (18:01 +0200)
kickstart/template-centos8.ks
snippets/tpl.001.basics.sh
snippets/tpl.040.network.sh [new file with mode: 0644]
snippets/tpl.300.create-motd.sh

index 5bf9bf23c07ecf3c1bd27770f1f7bc14f83e8fdd..6e2fd562b7279965cb7f09dc50e213ca9c12c484 100644 (file)
@@ -147,18 +147,20 @@ rm -rf /var/var
 export hostname="$hostname"
 export system_name="$system_name"
 export gateway="$gateway"
+export mgmt_interface="eth0"
 export ip_address_eth0="$ip_address_eth0"
 export mac_address_eth0="$mac_address_eth0"
 export system_status="${SYSTEM_STATUS}"
 export ws_rel_filesdir="${WS_REL_FILESDIR}"
 
 echo
-echo "hostname:         '$hostname'"
-echo "system_name:      '$system_name'"
-echo "gateway:          '$gateway'"
-echo "ip_address_eth0:  '$ip_address_eth0'"
-echo "mac_address_eth0: '$mac_address_eth0'"
-echo "System status:    '${system_status}'"
+echo "hostname:             '$hostname'"
+echo "system_name:          '$system_name'"
+echo "gateway:              '$gateway'"
+echo "Management interface: '${mgmt_interface}'"
+echo "ip_address_eth0:      '$ip_address_eth0'"
+echo "mac_address_eth0:     '$mac_address_eth0'"
+echo "System status:        '${system_status}'"
 
 #set $basic_snippet = "per_status/" + $SYSTEM_STATUS + "/tpl.001.basics.sh"
 echo
@@ -170,6 +172,11 @@ echo
 echo "Using snippet $authkeys_snippet"
 $SNIPPET($authkeys_snippet)
 
+#set $network_snippet = "per_status/" + $SYSTEM_STATUS + "/tpl.040.network.sh"
+echo
+echo "Using snippet $network_snippet"
+$SNIPPET($network_snippet)
+
 #set $tweak_systemd_snippet = "per_status/" + $SYSTEM_STATUS + "/tpl.060.tweak_systemd.sh"
 echo
 echo "Using snippet $tweak_systemd_snippet"
index a3449676ea5c54f847626de3f8817f090e8908af..d1309d1277be8a852e6df630ed74e062635c6c6d 100644 (file)
@@ -49,6 +49,7 @@ echo "Some information:"
 echo "  \$hostname:             $hostname"
 echo "  \$system_name:          $system_name"
 echo "  \$gateway:              $gateway"
+echo "  \$management_interface: ${mgmt_interface}"
 echo "  \$mac_address_eth0:     $mac_address_eth0"
 echo "  \$ip_address_eth0:      $ip_address_eth0"
 echo "  \$IP_ADDRESS_ETH0:      $IP_ADDRESS_ETH0"
diff --git a/snippets/tpl.040.network.sh b/snippets/tpl.040.network.sh
new file mode 100644 (file)
index 0000000..34fe130
--- /dev/null
@@ -0,0 +1,76 @@
+## !/bin/bash
+#raw
+
+#-----------------------------------------------------------
+create_networkconfig() {
+
+    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 old_dir="${nw_script_dir}/.old"
+    local ifcfg_file=
+    local if_uuid=$( uuidgen -r )
+
+    mkdir -pv "${tmp_nw_script_dir}"
+    mkdir -pv "${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
+    /bin/hostname "${hostname}"
+
+    local dev_file="${tmp_nw_script_dir}/ifcfg-${mgmt_interface}"
+    echo "Generating '${dev_file}' ..."
+
+    cat <<-EOF >"${dev_file}"
+       NAME="${mgmt_interface}"
+       DEVICE="${mgmt_interface}"
+       ONBOOT=yes
+       NETBOOT=yes
+       UUID="${if_uuid}"
+       IPV6INIT=yes
+       BOOTPROTO=dhcp
+       TYPE=Ethernet
+       EOF
+
+    for ifcfg_file in ${nw_script_dir}/ifcfg-* ; do
+        local bname=$(basename "${ifcfg_file}" )
+        if [[ "${bname}" == "ifcfg-lo" ]] ; then
+            continue
+        fi
+        mv -v "${ifcfg_file}" "${old_dir}"
+    done
+    mv -v "${dev_file}" "${nw_script_dir}"
+    rm -vrf "${temp_dir}"
+
+    echo "Generated ${nw_script_dir}/ifcfg-${mgmt_interface}:"
+    cat "${nw_script_dir}/ifcfg-${mgmt_interface}" || true
+    echo
+
+    echo
+    echo "${HASH_LINE}"
+    echo "Inhalt von /etc/sysconfig/network-scripts ..."
+    ls -lA /etc/sysconfig/network-scripts
+
+}
+
+create_networkconfig
+
+#end raw
+## vim: ts=4 et list
index 77d60b9c51ad89a51d6bd825d122fc625f56ee5a..8a557c077c0e2274fda47655042b1ec4535eff44 100644 (file)
@@ -17,6 +17,8 @@ create_motd() {
     if wget -O "${mk_script}" --dns-timeout=2 --connect-timeout=3 --read-timeout=3 "${url}" ; then
         chmod 0755 "${mk_script}"
         "${mk_script}" > /etc/motd
+        mkdir -pv /root/bin
+        cp -pv "${mk_script}" /root/bin/create-motd.sh
     else
         echo "[$(date)]: Could not get 'mk_create_motd.ksh' from '${url}'." | tee -a "${ERROR_POINTER}"
     fi