Skip to content

Commit

Permalink
feat(Network): Add support for network manager
Browse files Browse the repository at this point in the history
fix #1774: Add support for network manager running on Raspberrypi OS bookworm
  • Loading branch information
coolapso committed Nov 4, 2023
1 parent f9ae966 commit 13ac5ce
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions auto_install/install.sh
Expand Up @@ -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
Expand Down Expand Up @@ -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}. "
Expand All @@ -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
Expand Down

0 comments on commit 13ac5ce

Please sign in to comment.