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,6 +1309,11 @@ 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
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
@ -1344,6 +1349,7 @@ Enter a static local IP address for this system.\n\nIt will typically be ${IPv4_
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