Created
December 17, 2015 12:27
-
-
Save kapb14/06588e8e5228f484e39d to your computer and use it in GitHub Desktop.
Hostname/Network config script for Kickstart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# https://m.reddit.com/r/sysadmin/comments/1b1ezy/hostnamenetwork_config_script_for_kickstart/ | |
# | |
HWADDR=`ifconfig eth0 | grep HW | awk ' BEGIN { FS = " " } ; { print $5 } ; '` | |
hostn="" | |
mode="" | |
hostfile="/etc/sysconfig/network" | |
netfile="/etc/sysconfig/network-scripts/ifcfg-eth0" | |
hostname_result="" | |
while [[ -z $hostname_result ]] || [[ $hostname_result == "1" ]] ; do | |
hostn=$(whiptail --inputbox "Enter the Server's Hostname" 10 60 3>&1 1>&2 2>&3) | |
whiptail --title "Is the hostname correct?" --yesno "$hostn" 8 78 3>&1 1>&2 2>&3 | |
hostname_result=$? ; done | |
while [[ -z $mode ]] ; do | |
mode=$(whiptail --checklist "Static of DHCP Network configuration?" 10 60 5 Static "Static Network config" off DHCP "Dynamic Network config" off 3>&1 1>&2 2>&3) ; done | |
echo "DEVICE=\"eth0\"" > $netfile | |
echo "HWADDR=\"$HWADDR\"" >> $netfile | |
echo "ONBOOT=\"yes\"" >> $netfile | |
echo "NM_CONTROLLED=\"yes\"" >> $netfile | |
if [ $mode == '"DHCP"' ] | |
then | |
echo "BOOTPROTO=\"dhcp\"" >> $netfile | |
echo "NETWORKING=yes" > $hostfile | |
echo "HOSTNAME=$hostn" >> $hostfile | |
else | |
while [ -z $result ] || [ $result == "1" ] ; do | |
ipaddr=$(whiptail --inputbox "IP Address" 10 60 3>&1 1>&2 2>&3) | |
netmask=$(whiptail --inputbox "Network Mask" 10 60 "255.255.240.0" 3>&1 1>&2 2>&3) | |
gateway=$(whiptail --inputbox "Gateway" 10 60 3>&1 1>&2 2>&3) | |
dns1=$(whiptail --inputbox "DNS1" 10 60 3>&1 1>&2 2>&3) | |
dns2=$(whiptail --inputbox "DNS2" 10 60 3>&1 1>&2 2>&3) | |
domain=$(whiptail --inputbox "Domain" 10 60 "internal" 3>&1 1>&2 2>&3) | |
whiptail --title "Are the settings correct?" --yesno "\n IP Adress: $ipaddr \n Netmask: $netmask \n Gateway: $gateway \n DNS: $dns1,$dns2 \n Domain: $domain \n" 18 78 3>&1 1>&2 2>&3 | |
result=$? ; done | |
echo "BOOTPROTO=\"static\"" >> $netfile | |
echo "IPADDR=\"$ipaddr\"" >> $netfile | |
echo "NETMASK=\"$netmask\"" >> $netfile | |
echo "GATEWAY=\"$gateway\"" >> $netfile | |
echo "DNS1=\"$dns1\"" >> $netfile | |
echo "DNS2=\"$dns2\"" >> $netfile | |
echo "DOMAIN=\"$domain\"" >> $netfile | |
echo "NETWORKING=yes" > $hostfile | |
echo "HOSTNAME=$hostn.$domain" >> $hostfile | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment