Skip to content

Instantly share code, notes, and snippets.

@mazgi
Last active October 5, 2015 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mazgi/b4e6b08dac53c01ae344 to your computer and use it in GitHub Desktop.
Save mazgi/b4e6b08dac53c01ae344 to your computer and use it in GitHub Desktop.
Setup network configuration on Gentoo Linux
#!/bin/bash
set -e
DO_SETUP=false
function read_yes_or_no(){
echo -n "${1} [y/N] "
read YES_OR_NO
case ${YES_OR_NO^^} in
YES|Y )
DO_SETUP=true
;;
""|NO|N )
# do nothing
;;
* )
read_yes_or_no "${1}"
;;
esac
}
function suicide(){
SELF="$(readlink -f ${0})"
sed -i "\!${SELF}!d" /etc/inittab
rm -f "${SELF}" || true
}
if [ 'localhost' != "$(hostname)" ]; then
suicide
exit 0
fi
read_yes_or_no "Do you want initialize and setting up network configurations?"
if ${DO_SETUP}; then
echo -n "Please input hostname > "
read host_name
echo -n "Please input eth1 IP Addr and Subnet mask (e.g. \"0.0.0.0/24\") > "
read eth1_ipaddr
echo -n "Please input eth1 Default Gateway > "
read eth1_route
cat<<EOI>/etc/conf.d/hostname
hostname="${host_name}"
EOI
cat<<EOI>/etc/conf.d/net.eth1
config_eth1="${eth1_ipaddr}"
routes_eth1="default via ${eth1_route}"
dns_servers_eth1="172.16.0.1 172.16.0.2"
EOI
test -x /etc/init.d/net.eth1 && /etc/init.d/net.eth1 restart || true
suicide
fi
exit 0
@mazgi
Copy link
Author

mazgi commented Oct 5, 2015

[root@localhost] # tail -1 /etc/inittab
cfnw::bootwait:/etc/setup.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment