diff --git a/actions/networks b/actions/networks index 1874c4c01..1501cc0b3 100755 --- a/actions/networks +++ b/actions/networks @@ -14,6 +14,21 @@ function get-interfaces { NO_OF_WIRELESS_IFACES=$(echo $WIRELESS_IFACES | wc -w) } +function add-connection { + local connection_name="$1" + shift + local interface="$1" + shift + local remaining_arguments="$@" + + already_exists=$(nmcli --terse --fields name,device con show | grep "$connection_name:$interface" || true) + if [ -n "$already_exists" ]; then + echo "Connection '$connection_name' already exists for device '$interface', not adding." + else + nmcli con add con-name "$connection_name" ifname "$interface" $remaining_arguments + fi +} + function activate-connection { connection_name="$1" nohup nmcli con up "$connection_name" &>/dev/null & @@ -25,7 +40,7 @@ function configure-regular-interface { local connection_name="FreedomBox WAN" # Create n-m connection for a regular interface - nmcli con add con-name "$connection_name" ifname "$interface" type ethernet + add-connection "$connection_name" "$interface" type ethernet nmcli con modify "$connection_name" connection.autoconnect TRUE nmcli con modify "$connection_name" connection.zone "$zone" activate-connection "$connection_name" @@ -38,7 +53,7 @@ function configure-shared-interface { local connection_name="FreedomBox LAN $interface" # Create n-m connection for eth1 - nmcli con add con-name "$connection_name" ifname "$interface" type ethernet + add-connection "$connection_name" "$interface" type ethernet nmcli con modify "$connection_name" connection.autoconnect TRUE nmcli con modify "$connection_name" connection.zone internal @@ -61,7 +76,7 @@ function configure-wireless-interface { local ssid="FreedomBox$interface" local secret="freedombox123" - nmcli con add con-name "$connection_name" ifname "$interface" type wifi ssid "$ssid" + add-connection "$connection_name" "$interface" type wifi ssid "$ssid" nmcli con modify "$connection_name" connection.autoconnect TRUE nmcli con modify "$connection_name" connection.zone internal nmcli con modify "$connection_name" ipv4.method shared