mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-15 09:51:21 +00:00
networks: Make setup script idempotent
Only add a connection for a device if a connection with that name is not already associated with that device. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Signed-off-by: Joseph Nuthalpati <njoseph@thoughtworks.com>
This commit is contained in:
parent
6802e20a1d
commit
5e6e02184e
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user