mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-18 19:00:15 +00:00
Moved command substitution to specific functions to avoid unnecessary execution
- Moved $availableInterfaces and $CurrentIPv4gw from the script header to their relevant function, considered that if the OS is not Raspbian a static IP is not set, so those variables are not used.
This commit is contained in:
parent
380dc0ab37
commit
379ab50f5f
1 changed files with 6 additions and 6 deletions
|
@ -59,12 +59,6 @@ c=$(( columns / 2 ))
|
|||
r=$(( r < 20 ? 20 : r ))
|
||||
c=$(( c < 70 ? 70 : c ))
|
||||
|
||||
# Find the gateway IP used to route to outside world
|
||||
CurrentIPv4gw="$(ip -o route get 192.0.2.1 | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk 'NR==2')"
|
||||
|
||||
# Find network interfaces whose state is UP, so as to skip virtual interfaces and the loopback interface
|
||||
availableInterfaces=$(ip -o link | awk '/state UP/ {print $2}' | cut -d':' -f1 | cut -d'@' -f1)
|
||||
|
||||
######## SCRIPT ############
|
||||
|
||||
main(){
|
||||
|
@ -529,6 +523,9 @@ local chooseInterfaceOptions
|
|||
# Loop sentinel variable
|
||||
local firstloop=1
|
||||
|
||||
# Find network interfaces whose state is UP, so as to skip virtual interfaces and the loopback interface
|
||||
availableInterfaces=$(ip -o link | awk '/state UP/ {print $2}' | cut -d':' -f1 | cut -d'@' -f1)
|
||||
|
||||
if [ -z "$availableInterfaces" ]; then
|
||||
echo "::: Could not find any active network interface, exiting"
|
||||
exit 1
|
||||
|
@ -630,6 +627,9 @@ validIPAndNetmask(){
|
|||
}
|
||||
|
||||
getStaticIPv4Settings() {
|
||||
# Find the gateway IP used to route to outside world
|
||||
CurrentIPv4gw="$(ip -o route get 192.0.2.1 | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk 'NR==2')"
|
||||
|
||||
# Find the IP address (and netmask) of the desidered interface
|
||||
CurrentIPv4addr="$(ip -o -f inet address show dev "${IPv4dev}" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}')"
|
||||
|
||||
|
|
Loading…
Reference in a new issue