Last active
October 5, 2015 13:09
-
-
Save mazgi/b4e6b08dac53c01ae344 to your computer and use it in GitHub Desktop.
Setup network configuration on Gentoo Linux
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 | |
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 |
Author
mazgi
commented
Oct 5, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment