Created
July 9, 2014 01:50
-
-
Save nbrew/3c4de28c3aa40e3fbbd0 to your computer and use it in GitHub Desktop.
Hackish sed scripts to change network interfaces from DHCP to Static IP on a CubieTruck
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 | |
# SETUP: | |
# * Replace '#iface eth0 inet<some-char>dhcp' with '# iface eth0 inet dhcp' | |
net="${1}" | |
function usage() { | |
echo "USAGE: ${0} (dhcp|static)" | |
echo | |
} | |
function to_static() { | |
sed -i'' \ | |
-e 's;^# \(iface eth0 inet static\);\1;' \ | |
-e 's;^# \(address 192\.168\.1\);\1;' \ | |
-e 's;^# \(netmask 255.255.255.0\);\1;' \ | |
-e 's;^# \(network 192.168.1.0\);\1;' \ | |
-e 's;^# \(broadcast 192.168.1.255\);\1;' \ | |
-e 's;^\(iface eth0 inet dhcp\);# \1;' /etc/network/interfaces | |
echo "Changed eth0 to static IP" | |
} | |
function to_dhcp() { | |
sed -i'' \ | |
-e 's;^\(iface eth0 inet static\);# \1;' \ | |
-e 's;^\(address 192\.168\.1\);# \1;' \ | |
-e 's;^\(netmask 255.255.255.0\);# \1;' \ | |
-e 's;^\(network 192.168.1.0\);# \1;' \ | |
-e 's;^\(broadcast 192.168.1.255\);# \1;' \ | |
-e 's;^# \(iface eth0 inet dhcp\);\1;' /etc/network/interfaces | |
echo "Changed eth0 to DHCP" | |
} | |
if [ "x" == "x${net}" ]; then | |
usage | |
exit 0 | |
fi | |
if [ "dhcp" == "${net}" ]; then | |
to_dhcp | |
else | |
to_static | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment