feat(Network): Add support for network manager

fix #1774: Add support for network manager running on Raspberrypi OS bookworm
This commit is contained in:
4s3ti 2023-11-04 18:46:17 +01:00
parent f9ae9662ec
commit 13ac5ceeb0
No known key found for this signature in database
GPG key ID: AC2D3B898F96BC51

View file

@ -576,7 +576,11 @@ preconfigurePackages() {
# We set static IP only on Raspberry Pi OS # We set static IP only on Raspberry Pi OS
if checkStaticIpSupported; then if checkStaticIpSupported; then
BASE_DEPS+=(dhcpcd5) if [[ "${OSCN}" != "bookworm" ]]; then
BASE_DEPS+=(dhcpcd5)
else
useNetworkManager=true
fi
fi fi
if [[ "${PKG_MANAGER}" == 'apt-get' ]]; then if [[ "${PKG_MANAGER}" == 'apt-get' ]]; then
@ -1351,22 +1355,11 @@ If you are not sure, please just keep the default." "${r}" "${c}"
} }
setDHCPCD() { 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 [[ -f /etc/dhcpcd.conf ]]; then
if grep -q "${IPv4addr}" "${dhcpcdFile}"; then if grep -q "${IPv4addr}" "${dhcpcdFile}"; then
echo "::: Static IP already configured." echo "::: Static IP already configured."
else else
setDHCPCD writeDHCPCDConf
${SUDO} ip addr replace dev "${IPv4dev}" "${IPv4addr}" ${SUDO} ip addr replace dev "${IPv4dev}" "${IPv4addr}"
echo ":::" echo ":::"
echo -n "::: Setting IP to ${IPv4addr}. " echo -n "::: Setting IP to ${IPv4addr}. "
@ -1379,6 +1372,40 @@ setStaticIPv4() {
fi 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() { chooseUser() {
# Choose the user for the ovpns # Choose the user for the ovpns
if [[ "${runUnattended}" == 'true' ]]; then if [[ "${runUnattended}" == 'true' ]]; then