#!/bin/bash # Enable static IP or DHCP for Raspbian # # Copyleft 2017 by Ignacio Nunez Hernanz # GPL licensed (see end of file) * Use at your own risk! # # Usage: # # ./installer.sh nc-static-IP.sh () # # See installer.sh instructions for details # More at: https://ownyourbits.com # ACTIVE_=no IP_=192.168.1.130 DESCRIPTION="Set up a static IP address (on), or DHCP (off)" configure() { # delete NCP config grep -q "^# NextCloudPi autogenerated" /etc/dhcpcd.conf && \ sed -i '/^# NextCloudPi autogenerated/,+6d' /etc/dhcpcd.conf [[ $ACTIVE_ != "yes" ]] && { systemctl restart dhcpcd echo "DHCP enabled" return } local GW="$( ip r | grep "default via" | awk '{ print $3 }' )" local DNS="$( grep nameserver /etc/resolv.conf | head -1 | awk '{ print $2 }' )" [[ "$DNS" == "" ]] && DNS="$GW" cat >> /etc/dhcpcd.conf <