mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-21 04:10:20 +00:00
feat(Network): Add support for network manager
fix #1774: Add support for network manager running on Raspberrypi OS bookworm
This commit is contained in:
parent
f9ae9662ec
commit
13ac5ceeb0
1 changed files with 40 additions and 13 deletions
|
@ -576,7 +576,11 @@ preconfigurePackages() {
|
|||
|
||||
# We set static IP only on Raspberry Pi OS
|
||||
if checkStaticIpSupported; then
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue