mirror of
https://github.com/pivpn/pivpn.git
synced 2025-01-19 19:09:46 +00:00
Update to setStaticIPv4 function
This commit is contained in:
parent
d844f874a3
commit
cf9f052445
1 changed files with 15 additions and 10 deletions
|
@ -326,22 +326,27 @@ setDHCPCD() {
|
||||||
|
|
||||||
setStaticIPv4() {
|
setStaticIPv4() {
|
||||||
# Tries to set the IPv4 address
|
# Tries to set the IPv4 address
|
||||||
if grep -q "$IPv4addr" $dhcpcdFile; then
|
if [[ -f /etc/dhcpcd.conf ]]; then
|
||||||
# address already set, noop
|
if grep -q "${IPv4addr}" ${dhcpcdFile}; then
|
||||||
|
echo "::: Static IP already configured."
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
setDHCPCD
|
setDHCPCD
|
||||||
$SUDO ip addr replace dev "$pivpnInterface" "$IPv4addr"
|
$SUDO ip addr replace dev "${pivpnInterface}" "${IPv4addr}"
|
||||||
echo ":::"
|
echo ":::"
|
||||||
echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete."
|
echo "::: Setting IP to ${IPv4addr}. You may need to restart after the install is complete."
|
||||||
echo ":::"
|
echo ":::"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo "::: Critical: Unable to locate configuration file to set static IPv4 address!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
setNetwork() {
|
setNetwork() {
|
||||||
# Sets the Network IP and Mask correctly
|
# Sets the Network IP and Mask correctly
|
||||||
LOCALMASK=$(ifconfig "$pivpnInterface" | awk '/Mask:/{ print $4;} ' | cut -c6-)
|
LOCALMASK=$(ifconfig "${pivpnInterface}" | awk '/Mask:/{ print $4;} ' | cut -c6-)
|
||||||
LOCALIP=$(ifconfig "$pivpnInterface" | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*')
|
LOCALIP=$(ifconfig "${pivpnInterface}" | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*')
|
||||||
IFS=. read -r i1 i2 i3 i4 <<< "$LOCALIP"
|
IFS=. read -r i1 i2 i3 i4 <<< "$LOCALIP"
|
||||||
IFS=. read -r m1 m2 m3 m4 <<< "$LOCALMASK"
|
IFS=. read -r m1 m2 m3 m4 <<< "$LOCALMASK"
|
||||||
LOCALNET=$(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))")
|
LOCALNET=$(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))")
|
||||||
|
|
Loading…
Add table
Reference in a new issue