Static settings for wifi

This commit is contained in:
Bob Mottram 2016-10-22 21:25:42 +01:00
parent 6074a4bb37
commit 6ce080543d
2 changed files with 71 additions and 55 deletions

View File

@ -1309,41 +1309,47 @@ Enter a static local IP address for this system.\n\nIt will typically be ${IPv4_
ip_addresses_have_changed=1
fi
if [ $ip_addresses_have_changed ]; then
echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# The loopback network interface' >> /etc/network/interfaces
echo 'auto lo' >> /etc/network/interfaces
echo 'iface lo inet loopback' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# The primary network interface' >> /etc/network/interfaces
echo 'auto eth0' >> /etc/network/interfaces
echo 'iface eth0 inet static' >> /etc/network/interfaces
echo " address ${NEW_STATIC_IP}" >> /etc/network/interfaces
echo ' netmask 255.255.255.0' >> /etc/network/interfaces
echo " gateway ${NEW_STATIC_GATEWAY}" >> /etc/network/interfaces
echo " dns-nameservers 213.73.91.35 85.214.20.141" >> /etc/network/interfaces
echo '# Example to keep MAC address between reboots' >> /etc/network/interfaces
echo '#hwaddress ether DE:AD:BE:EF:CA:FE' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# The secondary network interface' >> /etc/network/interfaces
echo '#auto eth1' >> /etc/network/interfaces
echo '#iface eth1 inet dhcp' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# WiFi Example' >> /etc/network/interfaces
echo "#auto $WIFI_INTERFACE" >> /etc/network/interfaces
echo "#iface $WIFI_INTERFACE inet dhcp" >> /etc/network/interfaces
echo '# wpa-ssid "essid"' >> /etc/network/interfaces
echo '# wpa-psk "password"' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# Ethernet/RNDIS gadget (g_ether)' >> /etc/network/interfaces
echo '# ... or on host side, usbnet and random hwaddr' >> /etc/network/interfaces
echo '# Note on some boards, usb0 is automaticly setup with an init script' >> /etc/network/interfaces
echo '#iface usb0 inet static' >> /etc/network/interfaces
echo '# address 192.168.7.2' >> /etc/network/interfaces
echo '# netmask 255.255.255.0' >> /etc/network/interfaces
echo '# network 192.168.7.0' >> /etc/network/interfaces
echo '# gateway 192.168.7.1' >> /etc/network/interfaces
write_config_param "NETWORK_IS_STATIC" "1"
write_config_param "STATIC_IP_ADDRESS" "$NEW_STATIC_IP"
write_config_param "ROUTER_IP_ADDRESS" "$NEW_STATIC_GATEWAY"
if [[ $(config_param_exists "WIFI_INTERFACE") == "0" ]]; then
# wired network
echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# The loopback network interface' >> /etc/network/interfaces
echo 'auto lo' >> /etc/network/interfaces
echo 'iface lo inet loopback' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# The primary network interface' >> /etc/network/interfaces
echo 'auto eth0' >> /etc/network/interfaces
echo 'iface eth0 inet static' >> /etc/network/interfaces
echo " address ${NEW_STATIC_IP}" >> /etc/network/interfaces
echo ' netmask 255.255.255.0' >> /etc/network/interfaces
echo " gateway ${NEW_STATIC_GATEWAY}" >> /etc/network/interfaces
echo " dns-nameservers 213.73.91.35 85.214.20.141" >> /etc/network/interfaces
echo '# Example to keep MAC address between reboots' >> /etc/network/interfaces
echo '#hwaddress ether DE:AD:BE:EF:CA:FE' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# The secondary network interface' >> /etc/network/interfaces
echo '#auto eth1' >> /etc/network/interfaces
echo '#iface eth1 inet dhcp' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# WiFi Example' >> /etc/network/interfaces
echo "#auto $WIFI_INTERFACE" >> /etc/network/interfaces
echo "#iface $WIFI_INTERFACE inet dhcp" >> /etc/network/interfaces
echo '# wpa-ssid "essid"' >> /etc/network/interfaces
echo '# wpa-psk "password"' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# Ethernet/RNDIS gadget (g_ether)' >> /etc/network/interfaces
echo '# ... or on host side, usbnet and random hwaddr' >> /etc/network/interfaces
echo '# Note on some boards, usb0 is automaticly setup with an init script' >> /etc/network/interfaces
echo '#iface usb0 inet static' >> /etc/network/interfaces
echo '# address 192.168.7.2' >> /etc/network/interfaces
echo '# netmask 255.255.255.0' >> /etc/network/interfaces
echo '# network 192.168.7.0' >> /etc/network/interfaces
echo '# gateway 192.168.7.1' >> /etc/network/interfaces
fi
clear
echo ''

View File

@ -48,6 +48,23 @@ function wifi_is_running {
fi
}
function wifi_static_network_interface {
NETWORK_IS_STATIC=0
read_config_param "NETWORK_IS_STATIC"
if [ ${NETWORK_IS_STATIC} -eq 0 ]; then
echo '#this line must always be here' >> /etc/network/interfaces
echo 'iface default inet dhcp' >> /etc/network/interfaces
else
read_config_param "STATIC_IP_ADDRESS"
read_config_param "ROUTER_IP_ADDRESS"
echo '#static address' >> /etc/network/interfaces
echo 'iface default inet static' >> /etc/network/interfaces
echo " address ${STATIC_IP_ADDRESS}" >> /etc/network/interfaces
echo ' netmask 255.255.255.0' >> /etc/network/interfaces
echo " gateway ${ROUTER_IP_ADDRESS}" >> /etc/network/interfaces
fi
}
function setup_wifi_atheros {
if [[ $(running_as_root) == "0" ]]; then
return
@ -290,15 +307,19 @@ function hotspot_on {
systemctl restart hostapd
}
function wifi_wpa2_psk {
ssid=$1
passphrase=$2
function wifi_store_original_network_settings {
if [ ! -f /etc/network/interfaces_original ]; then
if ! grep -q "# wifi enabled" /etc/network/interfaces; then
cp /etc/network/interfaces /etc/network/interfaces_original
fi
fi
}
function wifi_wpa2_psk {
ssid=$1
passphrase=$2
wifi_store_original_network_settings
echo '# wifi enabled' > /etc/network/interfaces
echo 'auto lo' >> /etc/network/interfaces
@ -311,8 +332,7 @@ function wifi_wpa2_psk {
echo "iface ${WIFI_INTERFACE} inet manual" >> /etc/network/interfaces
echo " wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '#this line must always be here' >> /etc/network/interfaces
echo 'iface default inet dhcp' >> /etc/network/interfaces
wifi_static_network_interface
wpa_passphrase "$ssid" "$passphrase" > $WIFI_CONFIG
@ -323,11 +343,7 @@ function wifi_wpa2_psk {
function wifi_none {
ssid=$1
if [ ! -f /etc/network/interfaces_original ]; then
if ! grep -q "# wifi enabled" /etc/network/interfaces; then
cp /etc/network/interfaces /etc/network/interfaces_original
fi
fi
wifi_store_original_network_settings
echo '# wifi enabled' > /etc/network/interfaces
echo 'auto lo' >> /etc/network/interfaces
@ -340,8 +356,7 @@ function wifi_none {
echo "iface ${WIFI_INTERFACE} inet manual" >> /etc/network/interfaces
echo " wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '#this line must always be here' >> /etc/network/interfaces
echo 'iface default inet dhcp' >> /etc/network/interfaces
wifi_static_network_interface
echo 'update_config=1' > $WIFI_CONFIG
echo 'eapol_version=1' >> $WIFI_CONFIG
@ -368,11 +383,7 @@ function networks_from_file {
fi
read_config_param "WIFI_INTERFACE"
if [ ! -f /etc/network/interfaces_original ]; then
if ! grep -q "# wifi enabled" /etc/network/interfaces; then
cp /etc/network/interfaces /etc/network/interfaces_original
fi
fi
wifi_store_original_network_settings
echo '# wifi enabled' > /etc/network/interfaces
echo 'auto lo' >> /etc/network/interfaces
@ -385,8 +396,7 @@ function networks_from_file {
echo "iface ${WIFI_INTERFACE} inet manual" >> /etc/network/interfaces
echo " wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '#this line must always be here' >> /etc/network/interfaces
echo 'iface default inet dhcp' >> /etc/network/interfaces
wifi_static_network_interface
# remove wpa_supplicant.conf if it exists
if [ -f $WIFI_CONFIG ]; then