Create a gist now

Instantly share code, notes, and snippets.

@mazgi /setup.sh
Last active Oct 5, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Show comment
Hide comment
@mazgi

mazgi Oct 5, 2015

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

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