-
-
Save sjpi/7097bab1711cff2ef88e55b9727e3e70 to your computer and use it in GitHub Desktop.
first boot shell script for vm guests
This file contains hidden or 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 | |
| # vim: set tabstop=2 noexpandtab: | |
| # Jesse Nelson <[email protected]> | |
| # | |
| # Custom setup script to init early networking after VM initialization | |
| # This script should be run before network init scripts as it preps the network | |
| # | |
| # The idea is to pass down ip config settings through boot params so that this | |
| # script can configure the network on first boot Anaconda will take care of this | |
| # on machines that are kickstarted, but this lets us just be 100% | |
| # | |
| # if no ipaddress is given then the box will setup as dhcp | |
| # | |
| # only eth0 will be setup further network setup should be dealt with by chef | |
| # higher up the stack | |
| # | |
| # Kernel Boot Paramaters: | |
| #------------------------------------------------------------------------------- | |
| # no_autoconfig: (nil) If set this scirpt will exit immediately | |
| # ip: (nil) Sets the boxes ip address in ifcfg-eth0 | |
| # netmask: (nil) same for netmask | |
| # gateway: (nil) same for gateway | |
| # hostname: (nil) Sets up the hostname in /etc/sysconfig/network | |
| # dnsdomain: (nil) Sets domain in /etc/sysconfig/network | |
| # run_list: (nil) Set the chef run_list | |
| # environemnt: (boot) Set the chef environment | |
| # ipv6 (No) enable/disable ipv6 | |
| # | |
| #------------------------------------------------------------------------------- | |
| # parse kernel boot args and eval them here | |
| for o in `cat /proc/cmdline` ; do | |
| case $o in | |
| no_autoconfig=*) no_autoconfig=${o#no_autoconfig=} ;; | |
| ip=*) ip=${o#ip=} ;; | |
| netmask=*) netmask=${o#netmask=} ;; | |
| gateway=*) gateway=${o#gateway=} ;; | |
| hostname=*) hostname=${o#hostname=} ;; | |
| dnsdomain=*) dnsdomain=${o#dnsdomain=} ;; | |
| run_list=*) run_list=${o#run_list=} ;; | |
| environment=*) environment=${o#environment} ;; | |
| ipv6=*) ipv6=${o#ipv6} ;; | |
| esac | |
| done | |
| # set defaults for some vars | |
| echo "Boot_setup Kernel params:" | |
| echo "ip: $ip" | |
| echo "netmask: $netmask" | |
| echo "gateway: $gateway" | |
| echo "hostname: $hostname" | |
| echo "domain: $dnsdomain" | |
| echo "ipv6: $ipv6" | |
| echo "run_list: $run_list" | |
| echo "envioronment: $environment" | |
| # bail if were asked not to touch the box | |
| # this handy when developing these scripts on images :D | |
| if [ -n "$no_autoconfig" ] ; then | |
| echo "Auto Configuration disabled by bootparam no_autoconfig" | |
| exit 1 | |
| fi | |
| function cleanup() { | |
| rm -f /etc/rc3.d/S01boot_setup | |
| } | |
| case $ipv6 in | |
| yes) ipv6="yes" ;; | |
| *) ipv6="no" ;; | |
| esac | |
| if [ -z $dnsdomain ] ; then | |
| $dnsdomain="unknown.local" | |
| fi | |
| # setup top level network things | |
| cat > /etc/sysconfig/network <<-EOF | |
| NETWORKING=yes | |
| NETWORKING_IPV6=$ipv6 | |
| HOSTNAME=$hostname | |
| DOMAINNAME=$dnsdomain | |
| EOF | |
| # if we are dhcp | |
| if [ -z $ip ] ; then | |
| cat >> /etc/sysconfig/network-scripts/ifcfg-eth0 <<-EOF | |
| DEVICE=eth0 | |
| BOOTPROTO=dhcp | |
| DHCP_HOSTNAME=$hostname | |
| EOF | |
| cleanup | |
| exit | |
| fi | |
| # hook up proper resolv.conf | |
| # chef should fix it as well. this is just enough to get running | |
| cat > /etc/resolv.conf <<-EOF | |
| domain $dnsdomain | |
| search $dnsdomain | |
| nameserver 8.8.8.8 | |
| nameserver 8.8.4.4 | |
| EOF | |
| domainname $dnsdomain | |
| cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<-EOF | |
| DEVICE=eth0 | |
| IPADDR=$ip | |
| NETMASK=$netmask | |
| GATEWAY=$gateway | |
| EOF | |
| cleanup | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment