mirror of
https://github.com/pia-foss/manual-connections.git
synced 2025-02-05 14:08:29 +00:00
Add WG_INTERFACE environment variable that defaults to "pia"
Allows overriding the default Wireguard interface "pia" with "wg0" for example. Useful when you want to match the Wireguard default `/etc/wireguard/wg0.conf` (see https://www.wireguard.com/quickstart/).
This commit is contained in:
parent
c7336e9e03
commit
71ff88e500
|
@ -80,6 +80,11 @@ if [[ -z $WG_SERVER_IP ||
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check if an Wireguard interface name has been specified (e.g. /etc/wireguard/INTERFACE.conf)
|
||||||
|
if [[ -z "$WG_INTERFACE" ]]; then
|
||||||
|
WG_INTERFACE=pia
|
||||||
|
fi
|
||||||
|
|
||||||
# Create ephemeral wireguard keys, that we don't need to save to disk.
|
# Create ephemeral wireguard keys, that we don't need to save to disk.
|
||||||
privKey=$(wg genkey)
|
privKey=$(wg genkey)
|
||||||
export privKey
|
export privKey
|
||||||
|
@ -112,7 +117,7 @@ fi
|
||||||
# these scripts. Feel free to fork the project and test it out.
|
# these scripts. Feel free to fork the project and test it out.
|
||||||
echo
|
echo
|
||||||
echo "Trying to disable a PIA WG connection in case it exists..."
|
echo "Trying to disable a PIA WG connection in case it exists..."
|
||||||
wg-quick down pia && echo -e "${green}\nPIA WG connection disabled!${nc}"
|
wg-quick down "$WG_INTERFACE" && echo -e "${green}\nPIA WG connection disabled!${nc}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# Create the WireGuard config based on the JSON received from the API
|
# Create the WireGuard config based on the JSON received from the API
|
||||||
|
@ -129,7 +134,7 @@ if [[ $PIA_DNS == "true" ]]; then
|
||||||
echo
|
echo
|
||||||
dnsSettingForVPN="DNS = $dnsServer"
|
dnsSettingForVPN="DNS = $dnsServer"
|
||||||
fi
|
fi
|
||||||
echo -n "Trying to write /etc/wireguard/pia.conf..."
|
echo -n "Trying to write /etc/wireguard/$WG_INTERFACE.conf..."
|
||||||
mkdir -p /etc/wireguard
|
mkdir -p /etc/wireguard
|
||||||
echo "
|
echo "
|
||||||
[Interface]
|
[Interface]
|
||||||
|
@ -141,7 +146,7 @@ PersistentKeepalive = 25
|
||||||
PublicKey = $(echo "$wireguard_json" | jq -r '.server_key')
|
PublicKey = $(echo "$wireguard_json" | jq -r '.server_key')
|
||||||
AllowedIPs = 0.0.0.0/0
|
AllowedIPs = 0.0.0.0/0
|
||||||
Endpoint = ${WG_SERVER_IP}:$(echo "$wireguard_json" | jq -r '.server_port')
|
Endpoint = ${WG_SERVER_IP}:$(echo "$wireguard_json" | jq -r '.server_port')
|
||||||
" > /etc/wireguard/pia.conf || exit 1
|
" > "/etc/wireguard/$WG_INTERFACE.conf" || exit 1
|
||||||
echo -e "${green}OK!${nc}"
|
echo -e "${green}OK!${nc}"
|
||||||
|
|
||||||
# Start the WireGuard interface.
|
# Start the WireGuard interface.
|
||||||
|
@ -149,8 +154,8 @@ echo -e "${green}OK!${nc}"
|
||||||
# If you get DNS errors because you miss some packages,
|
# If you get DNS errors because you miss some packages,
|
||||||
# just hardcode /etc/resolv.conf to "nameserver 10.0.0.242".
|
# just hardcode /etc/resolv.conf to "nameserver 10.0.0.242".
|
||||||
echo
|
echo
|
||||||
echo "Trying to create the wireguard interface..."
|
echo Trying to create the wireguard interface...
|
||||||
wg-quick up pia || exit 1
|
wg-quick up "$WG_INTERFACE" || exit 1
|
||||||
echo
|
echo
|
||||||
echo -e "${green}The WireGuard interface got created.${nc}
|
echo -e "${green}The WireGuard interface got created.${nc}
|
||||||
|
|
||||||
|
@ -158,7 +163,7 @@ At this point, internet should work via VPN.
|
||||||
|
|
||||||
To disconnect the VPN, run:
|
To disconnect the VPN, run:
|
||||||
|
|
||||||
--> ${green}wg-quick down pia${nc} <--
|
--> ${green}wg-quick down ${WG_INTERFACE}${nc} <--
|
||||||
"
|
"
|
||||||
|
|
||||||
# This section will stop the script if PIA_PF is not set to "true".
|
# This section will stop the script if PIA_PF is not set to "true".
|
||||||
|
|
Loading…
Reference in New Issue
Block a user