mirror of
https://github.com/pia-foss/manual-connections.git
synced 2025-02-05 14:08:29 +00:00
Updates to be able to use a .env file and relative paths for the script
This commit is contained in:
parent
e956c57849
commit
5afbdf7b5c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.env
|
17
README.md
17
README.md
|
@ -87,6 +87,23 @@ The easiest way to trigger a fully automated connection is by running this oneli
|
||||||
sudo VPN_PROTOCOL=wireguard DISABLE_IPV6=yes DIP_TOKEN=no AUTOCONNECT=true PIA_PF=false PIA_DNS=true PIA_USER=p0123456 PIA_PASS=xxxxxxxx ./run_setup.sh
|
sudo VPN_PROTOCOL=wireguard DISABLE_IPV6=yes DIP_TOKEN=no AUTOCONNECT=true PIA_PF=false PIA_DNS=true PIA_USER=p0123456 PIA_PASS=xxxxxxxx ./run_setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The next easiest way to trigger a fully automated connection is to create a ".env" file inside the script directory that contains the settings on a line by line basis, e.g.:
|
||||||
|
```
|
||||||
|
VPN_PROTOCOL=wireguard
|
||||||
|
DISABLE_IPV6=yes
|
||||||
|
DIP_TOKEN=no
|
||||||
|
AUTOCONNECT=true
|
||||||
|
PIA_PF=false
|
||||||
|
PIA_DNS=true
|
||||||
|
PIA_USER=p0123456
|
||||||
|
PIA_PASS=xxxxxxxx
|
||||||
|
```
|
||||||
|
|
||||||
|
Then run:
|
||||||
|
```
|
||||||
|
sudo /path/to/script/run_setup.sh
|
||||||
|
```
|
||||||
|
|
||||||
Here is a list of scripts you could find useful:
|
Here is a list of scripts you could find useful:
|
||||||
* [Prompt based connection](run_setup.sh): This script allows connections with a one-line call, or will prompt for any missing or invalid variables. Variables available for one-line calls include:
|
* [Prompt based connection](run_setup.sh): This script allows connections with a one-line call, or will prompt for any missing or invalid variables. Variables available for one-line calls include:
|
||||||
* `PIA_USER` - your PIA username
|
* `PIA_USER` - your PIA username
|
||||||
|
|
26
run_setup.sh
26
run_setup.sh
|
@ -19,6 +19,14 @@
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
|
SCRIPT=$(realpath -s "$0")
|
||||||
|
SCRIPT_DIR=$(dirname "$SCRIPT")
|
||||||
|
if [[ -f "${SCRIPT_DIR}/.env" ]]; then
|
||||||
|
set -a
|
||||||
|
. ${SCRIPT_DIR}/.env
|
||||||
|
set +a
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if terminal allows output, if yes, define colors for output
|
# Check if terminal allows output, if yes, define colors for output
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
ncolors=$(tput colors)
|
ncolors=$(tput colors)
|
||||||
|
@ -98,7 +106,7 @@ while :; do
|
||||||
export PIA_PASS
|
export PIA_PASS
|
||||||
|
|
||||||
# Confirm credentials and generate token
|
# Confirm credentials and generate token
|
||||||
./get_token.sh
|
${SCRIPT_DIR}/get_token.sh
|
||||||
|
|
||||||
tokenLocation="/opt/piavpn-manual/token"
|
tokenLocation="/opt/piavpn-manual/token"
|
||||||
# If the script failed to generate an authentication token, the script will exit early.
|
# If the script failed to generate an authentication token, the script will exit early.
|
||||||
|
@ -159,7 +167,7 @@ if echo ${useDIP:0:1} | grep -iq y; then
|
||||||
done
|
done
|
||||||
export DIP_TOKEN
|
export DIP_TOKEN
|
||||||
# Confirm DIP_TOKEN and retrieve connection details
|
# Confirm DIP_TOKEN and retrieve connection details
|
||||||
./get_dip.sh
|
${SCRIPT_DIR}/get_dip.sh
|
||||||
dipDetails="/opt/piavpn-manual/dipAddress"
|
dipDetails="/opt/piavpn-manual/dipAddress"
|
||||||
# If the script failed to generate retrieve dedicated IP information, the script will exit early.
|
# If the script failed to generate retrieve dedicated IP information, the script will exit early.
|
||||||
if [ ! -f "$dipDetails" ]; then
|
if [ ! -f "$dipDetails" ]; then
|
||||||
|
@ -331,7 +339,7 @@ if [[ -z $DIP_TOKEN ]]; then
|
||||||
export PREFERRED_REGION
|
export PREFERRED_REGION
|
||||||
VPN_PROTOCOL="no"
|
VPN_PROTOCOL="no"
|
||||||
export VPN_PROTOCOL
|
export VPN_PROTOCOL
|
||||||
VPN_PROTOCOL=no ./get_region.sh
|
VPN_PROTOCOL=no ${SCRIPT_DIR}/get_region.sh
|
||||||
|
|
||||||
if [[ -s /opt/piavpn-manual/latencyList ]]; then
|
if [[ -s /opt/piavpn-manual/latencyList ]]; then
|
||||||
# Output the ordered list of servers that meet the latency specification $MAX_LATENCY
|
# Output the ordered list of servers that meet the latency specification $MAX_LATENCY
|
||||||
|
@ -387,7 +395,7 @@ if [[ -z $DIP_TOKEN ]]; then
|
||||||
# Validate in-line declaration of PREFERRED_REGION; if invalid remove input to initiate prompts
|
# Validate in-line declaration of PREFERRED_REGION; if invalid remove input to initiate prompts
|
||||||
echo "Region input is : $PREFERRED_REGION"
|
echo "Region input is : $PREFERRED_REGION"
|
||||||
export PREFERRED_REGION
|
export PREFERRED_REGION
|
||||||
VPN_PROTOCOL=no ./get_region.sh
|
VPN_PROTOCOL=no ${SCRIPT_DIR}/get_region.sh
|
||||||
if [[ $? != 1 ]]; then
|
if [[ $? != 1 ]]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
@ -472,7 +480,7 @@ CONNECTION_READY="true"
|
||||||
export CONNECTION_READY
|
export CONNECTION_READY
|
||||||
|
|
||||||
if [[ -z $DIP_TOKEN ]]; then
|
if [[ -z $DIP_TOKEN ]]; then
|
||||||
./get_region.sh
|
${SCRIPT_DIR}/get_region.sh
|
||||||
elif [[ $VPN_PROTOCOL == wireguard ]]; then
|
elif [[ $VPN_PROTOCOL == wireguard ]]; then
|
||||||
echo
|
echo
|
||||||
echo -e "You will be connecting with ${green}WG_SERVER_IP=$dipAddress${nc} using"
|
echo -e "You will be connecting with ${green}WG_SERVER_IP=$dipAddress${nc} using"
|
||||||
|
@ -481,11 +489,11 @@ elif [[ $VPN_PROTOCOL == wireguard ]]; then
|
||||||
echo -e "$ ${green}PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN" \\
|
echo -e "$ ${green}PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN" \\
|
||||||
echo "DIP_TOKEN=$DIP_TOKEN" \\
|
echo "DIP_TOKEN=$DIP_TOKEN" \\
|
||||||
echo "WG_SERVER_IP=$dipAddress WG_HOSTNAME=$dipHostname" \\
|
echo "WG_SERVER_IP=$dipAddress WG_HOSTNAME=$dipHostname" \\
|
||||||
echo -e "./connect_to_wireguard_with_token.sh${nc}"
|
echo -e "${SCRIPT_DIR}/connect_to_wireguard_with_token.sh${nc}"
|
||||||
echo
|
echo
|
||||||
PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN DIP_TOKEN=$DIP_TOKEN \
|
PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN DIP_TOKEN=$DIP_TOKEN \
|
||||||
WG_SERVER_IP=$dipAddress WG_HOSTNAME=$dipHostname \
|
WG_SERVER_IP=$dipAddress WG_HOSTNAME=$dipHostname \
|
||||||
./connect_to_wireguard_with_token.sh
|
${SCRIPT_DIR}/connect_to_wireguard_with_token.sh
|
||||||
rm -f /opt/piavpn-manual/latencyList
|
rm -f /opt/piavpn-manual/latencyList
|
||||||
exit 0
|
exit 0
|
||||||
elif [[ $VPN_PROTOCOL == openvpn* ]]; then
|
elif [[ $VPN_PROTOCOL == openvpn* ]]; then
|
||||||
|
@ -497,13 +505,13 @@ elif [[ $VPN_PROTOCOL == openvpn* ]]; then
|
||||||
echo "DIP_TOKEN=$DIP_TOKEN OVPN_SERVER_IP=$dipAddress" \\
|
echo "DIP_TOKEN=$DIP_TOKEN OVPN_SERVER_IP=$dipAddress" \\
|
||||||
echo "OVPN_HOSTNAME=$dipHostname" \\
|
echo "OVPN_HOSTNAME=$dipHostname" \\
|
||||||
echo "CONNECTION_SETTINGS=$VPN_PROTOCOL" \\
|
echo "CONNECTION_SETTINGS=$VPN_PROTOCOL" \\
|
||||||
echo -e "./connect_to_openvpn_with_token.sh${nc}"
|
echo -e "${SCRIPT_DIR}/connect_to_openvpn_with_token.sh${nc}"
|
||||||
echo
|
echo
|
||||||
PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN \
|
PIA_PF=$PIA_PF PIA_TOKEN=$PIA_TOKEN \
|
||||||
DIP_TOKEN=$DIP_TOKEN OVPN_SERVER_IP=$dipAddress \
|
DIP_TOKEN=$DIP_TOKEN OVPN_SERVER_IP=$dipAddress \
|
||||||
OVPN_HOSTNAME=$dipHostname \
|
OVPN_HOSTNAME=$dipHostname \
|
||||||
CONNECTION_SETTINGS=$VPN_PROTOCOL \
|
CONNECTION_SETTINGS=$VPN_PROTOCOL \
|
||||||
./connect_to_openvpn_with_token.sh
|
${SCRIPT_DIR}/connect_to_openvpn_with_token.sh
|
||||||
rm -f /opt/piavpn-manual/latencyList
|
rm -f /opt/piavpn-manual/latencyList
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user