From 13ac5ceeb04d95b026cfc200f46125a1dd6a4dd3 Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@4s3ti.net> Date: Sat, 4 Nov 2023 18:46:17 +0100 Subject: [PATCH] feat(Network): Add support for network manager fix #1774: Add support for network manager running on Raspberrypi OS bookworm --- auto_install/install.sh | 53 +++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 66c4e6a..b6ce710 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -576,7 +576,11 @@ preconfigurePackages() { # We set static IP only on Raspberry Pi OS if checkStaticIpSupported; then - BASE_DEPS+=(dhcpcd5) + if [[ "${OSCN}" != "bookworm" ]]; then + BASE_DEPS+=(dhcpcd5) + else + useNetworkManager=true + fi fi if [[ "${PKG_MANAGER}" == 'apt-get' ]]; then @@ -1351,22 +1355,11 @@ If you are not sure, please just keep the default." "${r}" "${c}" } setDHCPCD() { - # Append these lines to dhcpcd.conf to enable a static IP - { - echo "interface ${IPv4dev}" - echo "static ip_address=${IPv4addr}" - echo "static routers=${IPv4gw}" - echo "static domain_name_servers=${IPv4dns}" - } | ${SUDO} tee -a "${dhcpcdFile}" > /dev/null -} - -setStaticIPv4() { - # Tries to set the IPv4 address if [[ -f /etc/dhcpcd.conf ]]; then if grep -q "${IPv4addr}" "${dhcpcdFile}"; then echo "::: Static IP already configured." else - setDHCPCD + writeDHCPCDConf ${SUDO} ip addr replace dev "${IPv4dev}" "${IPv4addr}" echo ":::" echo -n "::: Setting IP to ${IPv4addr}. " @@ -1379,6 +1372,40 @@ setStaticIPv4() { fi } +writeDHCPCDConf() { + # Append these lines to dhcpcd.conf to enable a static IP + { + echo "interface ${IPv4dev}" + echo "static ip_address=${IPv4addr}" + echo "static routers=${IPv4gw}" + echo "static domain_name_servers=${IPv4dns}" + } | ${SUDO} tee -a "${dhcpcdFile}" > /dev/null + +} + +setNetworkManager() { + connectionUUID=$(nmcli -t con show --active \ + | awk -v ref="${IPv4dev}" -F: 'match($0, ref){print $2}') + + ${SUDO} nmcli con mod "${connectionUUID}" \ + ipv4.addresses "${IPv4addr}" \ + ipv4.gateway "${IPv4gw}" \ + ipv4.dns "${IPv4dns}" \ + ipv4.method "manual" +} + +setStaticIPv4() { + # Tries to set the IPv4 address + if [[ -v useNetworkManager ]]; then + echo "::: Using Network manager" + setNetworkManager + echo "useNetworkManager=${useNetworkManager}" >> "${tempsetupVarsFile}" + else + echo "::: Using DHCPCD" + setDHCPCD + fi +} + chooseUser() { # Choose the user for the ovpns if [[ "${runUnattended}" == 'true' ]]; then