mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-18 19:00:15 +00:00
Cleanup (#111)
* Tab completion for nopass, no further completion after one argument * Cleaned up install.sh
This commit is contained in:
parent
516b93ee43
commit
1cdd5d1494
2 changed files with 63 additions and 64 deletions
|
@ -12,9 +12,6 @@
|
||||||
|
|
||||||
######## VARIABLES #########
|
######## VARIABLES #########
|
||||||
|
|
||||||
tmpLog=/tmp/pivpn-install.log
|
|
||||||
instalLogLoc=/etc/pivpn/install.log
|
|
||||||
|
|
||||||
pivpnGitUrl="https://github.com/pivpn/pivpn.git"
|
pivpnGitUrl="https://github.com/pivpn/pivpn.git"
|
||||||
pivpnFilesDir="/etc/.pivpn"
|
pivpnFilesDir="/etc/.pivpn"
|
||||||
|
|
||||||
|
@ -89,8 +86,8 @@ if hash lsb_release 2>/dev/null; then
|
||||||
noOS_Support
|
noOS_Support
|
||||||
fi
|
fi
|
||||||
# else get info from os-release
|
# else get info from os-release
|
||||||
elif [[ "$(cat /etc/os-release | grep raspbian)" ]]; then
|
elif grep -q debian /etc/os-release; then
|
||||||
if [[ "$(cat /etc/os-release | grep jessie)" ]]; then
|
if grep -q jessie /etc/os-release; then
|
||||||
PLAT="Raspbian"
|
PLAT="Raspbian"
|
||||||
OSCN="jessie"
|
OSCN="jessie"
|
||||||
else
|
else
|
||||||
|
@ -111,7 +108,8 @@ spinner()
|
||||||
local pid=$1
|
local pid=$1
|
||||||
local delay=0.50
|
local delay=0.50
|
||||||
local spinstr='/-\|'
|
local spinstr='/-\|'
|
||||||
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
|
while ps a | awk '{print $1}' | grep -q "$pid"
|
||||||
|
do
|
||||||
local temp=${spinstr#?}
|
local temp=${spinstr#?}
|
||||||
printf " [%c] " "$spinstr"
|
printf " [%c] " "$spinstr"
|
||||||
local spinstr=$temp${spinstr%"$temp"}
|
local spinstr=$temp${spinstr%"$temp"}
|
||||||
|
@ -151,8 +149,8 @@ chooseUser() {
|
||||||
# Find out how many users are available to choose from
|
# Find out how many users are available to choose from
|
||||||
userCount=$(echo "$availableUsers" | wc -l)
|
userCount=$(echo "$availableUsers" | wc -l)
|
||||||
chooseUserCmd=(whiptail --title "Choose A User" --separate-output --radiolist "Choose:" $r $c $userCount)
|
chooseUserCmd=(whiptail --title "Choose A User" --separate-output --radiolist "Choose:" $r $c $userCount)
|
||||||
chooseUserOptions=$("${chooseUserCmd[@]}" "${userArray[@]}" 2>&1 >/dev/tty)
|
if chooseUserOptions=$("${chooseUserCmd[@]}" "${userArray[@]}" 2>&1 >/dev/tty)
|
||||||
if [[ $? = 0 ]]; then
|
then
|
||||||
for desiredUser in $chooseUserOptions
|
for desiredUser in $chooseUserOptions
|
||||||
do
|
do
|
||||||
pivpnUser=$desiredUser
|
pivpnUser=$desiredUser
|
||||||
|
@ -202,8 +200,8 @@ chooseInterface() {
|
||||||
# Find out how many interfaces are available to choose from
|
# Find out how many interfaces are available to choose from
|
||||||
interfaceCount=$(echo "$availableInterfaces" | wc -l)
|
interfaceCount=$(echo "$availableInterfaces" | wc -l)
|
||||||
chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface" $r $c $interfaceCount)
|
chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface" $r $c $interfaceCount)
|
||||||
chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty)
|
if chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty)
|
||||||
if [[ $? = 0 ]]; then
|
then
|
||||||
for desiredInterface in $chooseInterfaceOptions
|
for desiredInterface in $chooseInterfaceOptions
|
||||||
do
|
do
|
||||||
pivpnInterface=$desiredInterface
|
pivpnInterface=$desiredInterface
|
||||||
|
@ -239,12 +237,12 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
|
||||||
until [[ $ipSettingsCorrect = True ]]
|
until [[ $ipSettingsCorrect = True ]]
|
||||||
do
|
do
|
||||||
# Ask for the IPv4 address
|
# Ask for the IPv4 address
|
||||||
IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" $r $c "$IPv4addr" 3>&1 1>&2 2>&3)
|
if IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" $r $c "$IPv4addr" 3>&1 1>&2 2>&3)
|
||||||
if [[ $? = 0 ]];then
|
then
|
||||||
echo "::: Your static IPv4 address: $IPv4addr"
|
echo "::: Your static IPv4 address: $IPv4addr"
|
||||||
# Ask for the gateway
|
# Ask for the gateway
|
||||||
IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" $r $c "$IPv4gw" 3>&1 1>&2 2>&3)
|
if IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" $r $c "$IPv4gw" 3>&1 1>&2 2>&3)
|
||||||
if [[ $? = 0 ]];then
|
then
|
||||||
echo "::: Your static IPv4 gateway: $IPv4gw"
|
echo "::: Your static IPv4 gateway: $IPv4gw"
|
||||||
# Give the user a chance to review their settings before moving on
|
# Give the user a chance to review their settings before moving on
|
||||||
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct?
|
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct?
|
||||||
|
@ -454,10 +452,10 @@ make_repo() {
|
||||||
echo -n "::: Cloning $2 into $1..."
|
echo -n "::: Cloning $2 into $1..."
|
||||||
$SUDO rm -rf "$1"
|
$SUDO rm -rf "$1"
|
||||||
$SUDO git clone -q "$2" "$1" > /dev/null & spinner $!
|
$SUDO git clone -q "$2" "$1" > /dev/null & spinner $!
|
||||||
if [ -z ${TESTING+x} ]; then
|
if [ -z "${TESTING+x}" ]; then
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
$SUDO git -C $1 checkout test
|
$SUDO git -C "$1" checkout test
|
||||||
fi
|
fi
|
||||||
echo " done!"
|
echo " done!"
|
||||||
}
|
}
|
||||||
|
@ -467,7 +465,7 @@ update_repo() {
|
||||||
echo -n "::: Updating repo in $1..."
|
echo -n "::: Updating repo in $1..."
|
||||||
cd "$1" || exit
|
cd "$1" || exit
|
||||||
$SUDO git pull -q > /dev/null & spinner $!
|
$SUDO git pull -q > /dev/null & spinner $!
|
||||||
if [ -z ${TESTING+x} ]; then
|
if [ -z "${TESTING+x}" ]; then
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
${SUDOE} git checkout test
|
${SUDOE} git checkout test
|
||||||
|
@ -477,11 +475,11 @@ update_repo() {
|
||||||
|
|
||||||
setCustomProto() {
|
setCustomProto() {
|
||||||
# Set the available protocols into an array so it can be used with a whiptail dialog
|
# Set the available protocols into an array so it can be used with a whiptail dialog
|
||||||
protocol=$(whiptail --title "Protocol" --radiolist \
|
if protocol=$(whiptail --title "Protocol" --radiolist \
|
||||||
"Choose a protocol. Please only choose TCP if you know why you need TCP." $r $c 2 \
|
"Choose a protocol. Please only choose TCP if you know why you need TCP." $r $c 2 \
|
||||||
"UDP" "" ON \
|
"UDP" "" ON \
|
||||||
"TCP" "" OFF 3>&1 1>&2 2>&3)
|
"TCP" "" OFF 3>&1 1>&2 2>&3)
|
||||||
if [ $? -eq 0 ]; then
|
then
|
||||||
# Convert option into lowercase (UDP->udp)
|
# Convert option into lowercase (UDP->udp)
|
||||||
pivpnProto="${protocol,,}"
|
pivpnProto="${protocol,,}"
|
||||||
echo "::: Using protocol: $pivpnProto"
|
echo "::: Using protocol: $pivpnProto"
|
||||||
|
@ -501,16 +499,15 @@ setCustomPort() {
|
||||||
do
|
do
|
||||||
portInvalid="Invalid"
|
portInvalid="Invalid"
|
||||||
|
|
||||||
PROTO=`cat /etc/pivpn/INSTALL_PROTO`
|
PROTO=$(cat /etc/pivpn/INSTALL_PROTO)
|
||||||
if [ "$PROTO" = "udp" ]; then
|
if [ "$PROTO" = "udp" ]; then
|
||||||
DEFAULT_PORT=1194
|
DEFAULT_PORT=1194
|
||||||
else
|
else
|
||||||
DEFAULT_PORT=443
|
DEFAULT_PORT=443
|
||||||
fi
|
fi
|
||||||
|
if PORT=$(whiptail --title "Default OpenVPN Port" --inputbox "You can modify the default OpenVPN port. \nEnter a new value or hit 'Enter' to retain the default" $r $c $DEFAULT_PORT 3>&1 1>&2 2>&3)
|
||||||
PORT=$(whiptail --title "Default OpenVPN Port" --inputbox "You can modify the default OpenVPN port. \nEnter a new value or hit 'Enter' to retain the default" $r $c $DEFAULT_PORT 3>&1 1>&2 2>&3)
|
then
|
||||||
if [[ $? = 0 ]]; then
|
if [[ "$PORT" =~ ^[0-9]+$ ]] && [ "$PORT" -ge 1 ] && [ "$PORT" -le 65535 ]; then
|
||||||
if [[ "$PORT" =~ ^[0-9]+$ ]] && [ "$PORT" -ge 1 -a "$PORT" -le 65535 ]; then
|
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
PORT=$portInvalid
|
PORT=$portInvalid
|
||||||
|
@ -544,8 +541,9 @@ setClientDNS() {
|
||||||
Level3 "" off
|
Level3 "" off
|
||||||
Norton "" off
|
Norton "" off
|
||||||
Custom "" off)
|
Custom "" off)
|
||||||
DNSchoices=$("${DNSChoseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty)
|
|
||||||
if [[ $? = 0 ]];then
|
if DNSchoices=$("${DNSChoseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty)
|
||||||
|
then
|
||||||
case $DNSchoices in
|
case $DNSchoices in
|
||||||
Google)
|
Google)
|
||||||
echo "::: Using Google DNS servers."
|
echo "::: Using Google DNS servers."
|
||||||
|
@ -578,8 +576,9 @@ setClientDNS() {
|
||||||
until [[ $DNSSettingsCorrect = True ]]
|
until [[ $DNSSettingsCorrect = True ]]
|
||||||
do
|
do
|
||||||
strInvalid="Invalid"
|
strInvalid="Invalid"
|
||||||
OVPNDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" $r $c "" 3>&1 1>&2 2>&3)
|
|
||||||
if [[ $? = 0 ]];then
|
if OVPNDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" $r $c "" 3>&1 1>&2 2>&3)
|
||||||
|
then
|
||||||
OVPNDNS1=$(echo "$OVPNDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
|
OVPNDNS1=$(echo "$OVPNDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
|
||||||
OVPNDNS2=$(echo "$OVPNDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}')
|
OVPNDNS2=$(echo "$OVPNDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}')
|
||||||
if ! valid_ip "$OVPNDNS1" || [ ! "$OVPNDNS1" ]; then
|
if ! valid_ip "$OVPNDNS1" || [ ! "$OVPNDNS1" ]; then
|
||||||
|
@ -642,7 +641,7 @@ confOpenVPN() {
|
||||||
|
|
||||||
# Edit the EASY_RSA variable in the vars file to point to the new easy-rsa directory,
|
# Edit the EASY_RSA variable in the vars file to point to the new easy-rsa directory,
|
||||||
# And set the chosen key size
|
# And set the chosen key size
|
||||||
cd /etc/openvpn/easy-rsa
|
cd /etc/openvpn/easy-rsa || exit
|
||||||
$SUDO sed -i 's:"`pwd`":"/etc/openvpn/easy-rsa":' vars
|
$SUDO sed -i 's:"`pwd`":"/etc/openvpn/easy-rsa":' vars
|
||||||
$SUDO sed -i "s/\(KEY_SIZE=\).*/\1${ENCRYPT}/" vars
|
$SUDO sed -i "s/\(KEY_SIZE=\).*/\1${ENCRYPT}/" vars
|
||||||
|
|
||||||
|
@ -676,39 +675,39 @@ confOpenVPN() {
|
||||||
|
|
||||||
for i in $CERTVAL
|
for i in $CERTVAL
|
||||||
do
|
do
|
||||||
if [ $i == '"COUNTRY"' ]; then
|
if [ "$i" == '"COUNTRY"' ]; then
|
||||||
COUNTRY=$(whiptail --title "Certificate Country" --inputbox \
|
COUNTRY=$(whiptail --title "Certificate Country" --inputbox \
|
||||||
"Enter a 2 letter abbreviation for Country" $r $c US 3>&1 1>&2 2>&3)
|
"Enter a 2 letter abbreviation for Country" $r $c US 3>&1 1>&2 2>&3)
|
||||||
$SUDO sed -i "s/\(KEY_COUNTRY=\"\).*/\1${COUNTRY}\"/" vars
|
$SUDO sed -i "s/\(KEY_COUNTRY=\"\).*/\1${COUNTRY}\"/" vars
|
||||||
fi
|
fi
|
||||||
if [ $i == '"STATE"' ]; then
|
if [ "$i" == '"STATE"' ]; then
|
||||||
STATE=$(whiptail --title "Certificate State" --inputbox \
|
STATE=$(whiptail --title "Certificate State" --inputbox \
|
||||||
"Enter a 2 letter abbreviated State or Province" $r $c CA 3>&1 1>&2 2>&3)
|
"Enter a 2 letter abbreviated State or Province" $r $c CA 3>&1 1>&2 2>&3)
|
||||||
$SUDO sed -i "s/\(KEY_PROVINCE=\"\).*/\1${STATE}\"/" vars
|
$SUDO sed -i "s/\(KEY_PROVINCE=\"\).*/\1${STATE}\"/" vars
|
||||||
fi
|
fi
|
||||||
if [ $i == '"CITY"' ]; then
|
if [ "$i" == '"CITY"' ]; then
|
||||||
CITY=$(whiptail --title "Certificate City" --inputbox \
|
CITY=$(whiptail --title "Certificate City" --inputbox \
|
||||||
"Enter a City name" $r $c SanFrancisco 3>&1 1>&2 2>&3)
|
"Enter a City name" $r $c SanFrancisco 3>&1 1>&2 2>&3)
|
||||||
$SUDO sed -i "s/\(KEY_CITY=\"\).*/\1${CITY}\"/" vars
|
$SUDO sed -i "s/\(KEY_CITY=\"\).*/\1${CITY}\"/" vars
|
||||||
fi
|
fi
|
||||||
if [ $i == '"ORG"' ]; then
|
if [ "$i" == '"ORG"' ]; then
|
||||||
ORG=$(whiptail --title "Certificate Org" --inputbox \
|
ORG=$(whiptail --title "Certificate Org" --inputbox \
|
||||||
"Enter an Organization name" $r $c Fort-Funston 3>&1 1>&2 2>&3)
|
"Enter an Organization name" $r $c Fort-Funston 3>&1 1>&2 2>&3)
|
||||||
$SUDO sed -i "s/\(KEY_ORG=\"\).*/\1${ORG}\"/" vars
|
$SUDO sed -i "s/\(KEY_ORG=\"\).*/\1${ORG}\"/" vars
|
||||||
fi
|
fi
|
||||||
if [ $i == '"EMAIL"' ]; then
|
if [ "$i" == '"EMAIL"' ]; then
|
||||||
EMAIL=$(whiptail --title "Certificate Email" --inputbox \
|
EMAIL=$(whiptail --title "Certificate Email" --inputbox \
|
||||||
"Enter an Email Address" $r $c "me@myhost.mydomain" 3>&1 1>&2 2>&3)
|
"Enter an Email Address" $r $c "me@myhost.mydomain" 3>&1 1>&2 2>&3)
|
||||||
$SUDO sed -i "s/\(KEY_EMAIL=\"\).*/\1${EMAIL}\"/" vars
|
$SUDO sed -i "s/\(KEY_EMAIL=\"\).*/\1${EMAIL}\"/" vars
|
||||||
fi
|
fi
|
||||||
if [ $i == '"SERVER_NAME"' ]; then
|
if [ "$i" == '"SERVER_NAME"' ]; then
|
||||||
SERVER_NAME=$(whiptail --title "Server Name" --inputbox \
|
SERVER_NAME=$(whiptail --title "Server Name" --inputbox \
|
||||||
"Enter a Server Name" $r $c "pivpn" 3>&1 1>&2 2>&3)
|
"Enter a Server Name" $r $c "pivpn" 3>&1 1>&2 2>&3)
|
||||||
# This began a rabbit hole of errors. Nope.
|
# This began a rabbit hole of errors. Nope.
|
||||||
#sed -i '/export KEY_CN/s/^#//g' vars
|
#sed -i '/export KEY_CN/s/^#//g' vars
|
||||||
#sed -i "s/\(KEY_CN=\"\).*/\1${SERVER_NAME}\"/" vars
|
#sed -i "s/\(KEY_CN=\"\).*/\1${SERVER_NAME}\"/" vars
|
||||||
fi
|
fi
|
||||||
if [ $i == '"KEY_NAME"' ]; then
|
if [ "$i" == '"KEY_NAME"' ]; then
|
||||||
KEY_NAME=$(whiptail --title "Key Name" --inputbox \
|
KEY_NAME=$(whiptail --title "Key Name" --inputbox \
|
||||||
"Enter a Key Name" $r $c "EasyRSA" 3>&1 1>&2 2>&3)
|
"Enter a Key Name" $r $c "EasyRSA" 3>&1 1>&2 2>&3)
|
||||||
$SUDO sed -i "s/\(KEY_NAME=\"\).*/\1${KEY_NAME}\"/" vars
|
$SUDO sed -i "s/\(KEY_NAME=\"\).*/\1${KEY_NAME}\"/" vars
|
||||||
|
@ -741,7 +740,7 @@ confOpenVPN() {
|
||||||
whiptail --msgbox --backtitle "Setup OpenVPN" --title "Server Information" "The server key, Diffie-Hellman key, and HMAC key will now be generated." $r $c
|
whiptail --msgbox --backtitle "Setup OpenVPN" --title "Server Information" "The server key, Diffie-Hellman key, and HMAC key will now be generated." $r $c
|
||||||
|
|
||||||
# Build the server
|
# Build the server
|
||||||
${SUDOE} ./build-key-server --batch $SERVER_NAME
|
${SUDOE} ./build-key-server --batch "$SERVER_NAME"
|
||||||
|
|
||||||
if ([ "$ENCRYPT" -ge "4096" ] && whiptail --backtitle "Setup OpenVPN" --title "Download Diffie-Hellman Parameters" --yesno --defaultno "Download Diffie-Hellman parameters from a public DH parameter generation service?\n\nGenerating DH parameters for a $ENCRYPT-bit key can take many hours on a Raspberry Pi. You can instead download DH parameters from \"2 Ton Digital\" that are generated at regular intervals as part of a public service. Downloaded DH parameters will be randomly selected from a pool of the last 128 generated.\nMore information about this service can be found here: https://2ton.com.au/dhtool/\n\nIf you're paranoid, choose 'No' and Diffie-Hellman parameters will be generated on your device." $r $c)
|
if ([ "$ENCRYPT" -ge "4096" ] && whiptail --backtitle "Setup OpenVPN" --title "Download Diffie-Hellman Parameters" --yesno --defaultno "Download Diffie-Hellman parameters from a public DH parameter generation service?\n\nGenerating DH parameters for a $ENCRYPT-bit key can take many hours on a Raspberry Pi. You can instead download DH parameters from \"2 Ton Digital\" that are generated at regular intervals as part of a public service. Downloaded DH parameters will be randomly selected from a pool of the last 128 generated.\nMore information about this service can be found here: https://2ton.com.au/dhtool/\n\nIf you're paranoid, choose 'No' and Diffie-Hellman parameters will be generated on your device." $r $c)
|
||||||
then
|
then
|
||||||
|
@ -757,7 +756,7 @@ fi
|
||||||
${SUDOE} openvpn --genkey --secret keys/ta.key
|
${SUDOE} openvpn --genkey --secret keys/ta.key
|
||||||
|
|
||||||
# Write config file for server using the template .txt file
|
# Write config file for server using the template .txt file
|
||||||
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]*')
|
||||||
$SUDO cp /etc/.pivpn/server_config.txt /etc/openvpn/server.conf
|
$SUDO cp /etc/.pivpn/server_config.txt /etc/openvpn/server.conf
|
||||||
|
|
||||||
$SUDO sed -i "s/LOCALIP/${LOCALIP}/g" /etc/openvpn/server.conf
|
$SUDO sed -i "s/LOCALIP/${LOCALIP}/g" /etc/openvpn/server.conf
|
||||||
|
@ -771,7 +770,7 @@ fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if they modified protocol put value in server.conf
|
# if they modified protocol put value in server.conf
|
||||||
if [ $PROTO != "udp" ]; then
|
if [ "$PROTO" != "udp" ]; then
|
||||||
$SUDO sed -i "s/proto udp/proto tcp/g" /etc/openvpn/server.conf
|
$SUDO sed -i "s/proto udp/proto tcp/g" /etc/openvpn/server.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -813,17 +812,17 @@ confNetwork() {
|
||||||
|
|
||||||
# if ufw enabled, configure that
|
# if ufw enabled, configure that
|
||||||
if hash ufw 2>/dev/null; then
|
if hash ufw 2>/dev/null; then
|
||||||
$SUDO ufw status | grep inactive &>/dev/null
|
if $SUDO ufw status | grep -q inactive
|
||||||
if [[ $? -eq 0 ]]; then
|
then
|
||||||
noUFW=1
|
noUFW=1
|
||||||
else
|
else
|
||||||
echo "::: Detected UFW is enabled."
|
echo "::: Detected UFW is enabled."
|
||||||
echo "::: Adding UFW rules..."
|
echo "::: Adding UFW rules..."
|
||||||
$SUDO cp /etc/.pivpn/ufw_add.txt /tmp/ufw_add.txt
|
$SUDO cp /etc/.pivpn/ufw_add.txt /tmp/ufw_add.txt
|
||||||
$SUDO sed -i 's/IPv4dev/'$IPv4dev'/' /tmp/ufw_add.txt
|
$SUDO sed -i 's/IPv4dev/'"$IPv4dev"'/' /tmp/ufw_add.txt
|
||||||
$SUDO sed -i "s/\(DEFAULT_FORWARD_POLICY=\).*/\1\"ACCEPT\"/" /etc/default/ufw
|
$SUDO sed -i "s/\(DEFAULT_FORWARD_POLICY=\).*/\1\"ACCEPT\"/" /etc/default/ufw
|
||||||
$SUDO sed -i -e '/delete these required/r /tmp/ufw_add.txt' -e//N /etc/ufw/before.rules
|
$SUDO sed -i -e '/delete these required/r /tmp/ufw_add.txt' -e//N /etc/ufw/before.rules
|
||||||
$SUDO ufw allow ${PORT}/${PROTO}
|
$SUDO ufw allow "${PORT}/${PROTO}"
|
||||||
$SUDO ufw allow from 10.8.0.0/24
|
$SUDO ufw allow from 10.8.0.0/24
|
||||||
$SUDO ufw reload
|
$SUDO ufw reload
|
||||||
echo "::: UFW configuration completed."
|
echo "::: UFW configuration completed."
|
||||||
|
@ -834,7 +833,7 @@ confNetwork() {
|
||||||
# else configure iptables
|
# else configure iptables
|
||||||
if [[ $noUFW -eq 1 ]]; then
|
if [[ $noUFW -eq 1 ]]; then
|
||||||
echo 1 > /tmp/noUFW
|
echo 1 > /tmp/noUFW
|
||||||
$SUDO iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o $IPv4dev -j MASQUERADE
|
$SUDO iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o "$IPv4dev" -j MASQUERADE
|
||||||
if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then
|
if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then
|
||||||
$SUDO iptables-save | $SUDO tee /etc/iptables/rules.v4 > /dev/null
|
$SUDO iptables-save | $SUDO tee /etc/iptables/rules.v4 > /dev/null
|
||||||
else
|
else
|
||||||
|
@ -848,12 +847,10 @@ confNetwork() {
|
||||||
}
|
}
|
||||||
|
|
||||||
confOVPN() {
|
confOVPN() {
|
||||||
IPv4pub=$(dig +short myip.opendns.com @resolver1.opendns.com)
|
if ! IPv4pub=$(dig +short myip.opendns.com @resolver1.opendns.com)
|
||||||
if [ $? -ne 0 ]
|
|
||||||
then
|
then
|
||||||
echo "dig failed, now trying to curl eth0.me"
|
echo "dig failed, now trying to curl eth0.me"
|
||||||
IPv4pub=$(curl eth0.me)
|
if ! IPv4pub=$(curl eth0.me)
|
||||||
if [ $? -ne 0 ]
|
|
||||||
then
|
then
|
||||||
echo "eth0.me failed, please check your internet connection/DNS"
|
echo "eth0.me failed, please check your internet connection/DNS"
|
||||||
exit $?
|
exit $?
|
||||||
|
@ -879,7 +876,7 @@ confOVPN() {
|
||||||
$SUDO cp /etc/.pivpn/Default.txt /etc/openvpn/easy-rsa/keys/Default.txt
|
$SUDO cp /etc/.pivpn/Default.txt /etc/openvpn/easy-rsa/keys/Default.txt
|
||||||
|
|
||||||
if [ "$METH" == "$IPv4pub" ]; then
|
if [ "$METH" == "$IPv4pub" ]; then
|
||||||
$SUDO sed -i 's/IPv4pub/'$IPv4pub'/' /etc/openvpn/easy-rsa/keys/Default.txt
|
$SUDO sed -i 's/IPv4pub/'"$IPv4pub"'/' /etc/openvpn/easy-rsa/keys/Default.txt
|
||||||
else
|
else
|
||||||
until [[ $publicDNSCorrect = True ]]
|
until [[ $publicDNSCorrect = True ]]
|
||||||
do
|
do
|
||||||
|
@ -891,7 +888,7 @@ confOVPN() {
|
||||||
fi
|
fi
|
||||||
if (whiptail --backtitle "Confirm DNS Name" --title "Confirm DNS Name" --yesno "Is this correct?\n\n Public DNS Name: $PUBLICDNS" $r $c) then
|
if (whiptail --backtitle "Confirm DNS Name" --title "Confirm DNS Name" --yesno "Is this correct?\n\n Public DNS Name: $PUBLICDNS" $r $c) then
|
||||||
publicDNSCorrect=True
|
publicDNSCorrect=True
|
||||||
$SUDO sed -i 's/IPv4pub/'$PUBLICDNS'/' /etc/openvpn/easy-rsa/keys/Default.txt
|
$SUDO sed -i 's/IPv4pub/'"$PUBLICDNS"'/' /etc/openvpn/easy-rsa/keys/Default.txt
|
||||||
else
|
else
|
||||||
publicDNSCorrect=False
|
publicDNSCorrect=False
|
||||||
|
|
||||||
|
@ -905,15 +902,15 @@ confOVPN() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if they modified protocol put value in Default.txt for clients to use
|
# if they modified protocol put value in Default.txt for clients to use
|
||||||
if [ $PROTO != "udp" ]; then
|
if [ "$PROTO" != "udp" ]; then
|
||||||
$SUDO sed -i -e "s/proto udp/proto tcp/g" /etc/openvpn/easy-rsa/keys/Default.txt
|
$SUDO sed -i -e "s/proto udp/proto tcp/g" /etc/openvpn/easy-rsa/keys/Default.txt
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# verify server name to strengthen security
|
# verify server name to strengthen security
|
||||||
$SUDO sed -i "s/SRVRNAME/${SERVER_NAME}/" /etc/openvpn/easy-rsa/keys/Default.txt
|
$SUDO sed -i "s/SRVRNAME/${SERVER_NAME}/" /etc/openvpn/easy-rsa/keys/Default.txt
|
||||||
|
|
||||||
$SUDO mkdir /home/$pivpnUser/ovpns
|
$SUDO mkdir "/home/$pivpnUser/ovpns"
|
||||||
$SUDO chmod 0777 -R /home/$pivpnUser/ovpns
|
$SUDO chmod 0777 -R "/home/$pivpnUser/ovpns"
|
||||||
}
|
}
|
||||||
|
|
||||||
installPiVPN() {
|
installPiVPN() {
|
||||||
|
@ -975,11 +972,9 @@ chooseUser
|
||||||
# Ask if unattended-upgrades will be enabled
|
# Ask if unattended-upgrades will be enabled
|
||||||
unattendedUpgrades
|
unattendedUpgrades
|
||||||
|
|
||||||
# Install and log everything to a file
|
# Install
|
||||||
installPiVPN
|
installPiVPN
|
||||||
|
|
||||||
# Move the log file into /etc/pivpn for storage
|
|
||||||
#$SUDO mv $tmpLog $installLogLoc
|
|
||||||
|
|
||||||
displayFinalMessage
|
displayFinalMessage
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,19 @@ _pivpn()
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
dashopts="-a -d -l -r -h -u"
|
||||||
opts="debug add list revoke uninstall help"
|
opts="debug add list revoke uninstall help"
|
||||||
|
if [ "${#COMP_WORDS[@]}" -eq 2 ]
|
||||||
|
then
|
||||||
if [[ ${cur} == -* ]] ; then
|
if [[ ${cur} == -* ]] ; then
|
||||||
opts="-a -d -l -r -h -u"
|
COMPREPLY=( $(compgen -W "${dashopts}" -- "${cur}") )
|
||||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
else
|
||||||
return 0
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||||
|
fi
|
||||||
|
elif [[ ( "$prev" == "add" || "$prev" == "-a" ) && "${#COMP_WORDS[@]}" -eq 3 ]]
|
||||||
|
then
|
||||||
|
COMPREPLY=( $(compgen -W "nopass" -- "${cur}") )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
complete -F _pivpn pivpn
|
complete -F _pivpn pivpn
|
||||||
|
|
Loading…
Reference in a new issue