From f379ca2e10d4b49e641f1a1cdddfbcf9d96c0644 Mon Sep 17 00:00:00 2001 From: root <63857845+shelleycat485@users.noreply.github.com> Date: Tue, 28 Apr 2020 23:44:56 +0100 Subject: [PATCH 01/21] initial dual install try --- auto_install/install.sh | 122 +++++++++++++++++--------------- scripts/openvpn/makeOVPN.sh | 2 +- scripts/openvpn/pivpn | 19 ++--- scripts/openvpn/pivpnDebug.sh | 2 +- scripts/openvpn/removeOVPN.sh | 2 +- scripts/wireguard/makeCONF.sh | 2 +- scripts/wireguard/pivpn | 21 +++--- scripts/wireguard/pivpnDEBUG.sh | 2 +- scripts/wireguard/removeCONF.sh | 2 +- 9 files changed, 95 insertions(+), 79 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 8630a9e..d0e8cdb 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -12,7 +12,9 @@ ######## VARIABLES ######### pivpnGitUrl="https://github.com/pivpn/pivpn.git" -setupVars="/etc/pivpn/setupVars.conf" +setupVarsFile="setupVars.conf" +setupConfigDir="/etc/pivpn" # will be /etc/pivpn/${VPN}/setupVars.conf +tempsetupVarsFile="/tmp/setupVars.conf" pivpnFilesDir="/etc/.pivpn" piholeSetupVars="/etc/pihole/setupVars.conf" @@ -118,7 +120,14 @@ main(){ fi fi - if [ -r "$setupVars" ]; then + # see which setup already exists + if [ -r "${setupVarsDir}/wireguard/${setupVarsFile}" ]; then + setupVars="${setupVarsDir}/wireguard/${setupVarsFile}" + elif [ -f "${setupVarsDir}/openvpn/${setupVarsFile}" ]; then + setupVars="${setupVarsDir}/openvpn/${setupVarsFile}" + fi + + if [ -r "$setupVars" ]; then #qqq if [[ "${reconfigure}" == true ]]; then echo "::: --reconfigure passed to install script, will reinstall PiVPN overwriting existing settings" UpdateCmd="Reconfigure" @@ -137,7 +146,7 @@ main(){ exit 0 elif [ "$UpdateCmd" = "Repair" ]; then # shellcheck disable=SC1090 - source "$setupVars" + source "$setupVars" #qqq runUnattended=true fi @@ -203,8 +212,9 @@ main(){ fi # Save installation setting to the final location - echo "INSTALLED_PACKAGES=(${INSTALLED_PACKAGES[*]})" >> /tmp/setupVars.conf - $SUDO cp /tmp/setupVars.conf "$setupVars" + echo "INSTALLED_PACKAGES=(${INSTALLED_PACKAGES[*]})" >> ${tempsetupVarsFile} + echo "::: Setupfiles copied to ${setupConfigDir}/{$VPN}/${setupVarsFile}" + $SUDO cp ${tempsetupVarsFile} "${setupConfigDir}/${VPN}/${setupVarsFile}" installScripts @@ -287,8 +297,8 @@ distroCheck(){ BASE_DEPS+=(dhcpcd5) fi - echo "PLAT=${PLAT}" > /tmp/setupVars.conf - echo "OSCN=${OSCN}" >> /tmp/setupVars.conf + echo "PLAT=${PLAT}" > ${tempsetupVarsFile} + echo "OSCN=${OSCN}" >> ${tempsetupVarsFile} } noOSSupport(){ @@ -470,7 +480,7 @@ preconfigurePackages(){ echo iptables-persistent iptables-persistent/autosave_v6 boolean false | $SUDO debconf-set-selections fi - echo "USING_UFW=${USING_UFW}" >> /tmp/setupVars.conf + echo "USING_UFW=${USING_UFW}" >> ${tempsetupVarsFile} } installDependentPackages(){ @@ -581,12 +591,12 @@ if [ "${runUnattended}" = 'true' ]; then exit 1 fi fi - echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf + echo "IPv4dev=${IPv4dev}" >> ${tempsetupVarsFile} return else if [ "$interfaceCount" -eq 1 ]; then IPv4dev="${availableInterfaces}" - echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf + echo "IPv4dev=${IPv4dev}" >> ${tempsetupVarsFile} return fi fi @@ -596,7 +606,7 @@ if chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2 for desiredInterface in ${chooseInterfaceOptions}; do IPv4dev=${desiredInterface} echo "::: Using interface: $IPv4dev" - echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf + echo "IPv4dev=${IPv4dev}" >> ${tempsetupVarsFile} done else echo "::: Cancel selected, exiting...." @@ -711,9 +721,9 @@ getStaticIPv4Settings() { echo "::: Skipping setting static IP address" fi - echo "dhcpReserv=${dhcpReserv}" >> /tmp/setupVars.conf - echo "IPv4addr=${IPv4addr}" >> /tmp/setupVars.conf - echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf + echo "dhcpReserv=${dhcpReserv}" >> ${tempsetupVarsFile} + echo "IPv4addr=${IPv4addr}" >> ${tempsetupVarsFile} + echo "IPv4gw=${IPv4gw}" >> ${tempsetupVarsFile} return fi @@ -735,10 +745,10 @@ No: Setup static IP address Don't know what DHCP Reservation is? Answer No." ${r} ${c}); then dhcpReserv=1 # shellcheck disable=SC2129 - echo "dhcpReserv=${dhcpReserv}" >> /tmp/setupVars.conf + echo "dhcpReserv=${dhcpReserv}" >> ${tempsetupVarsFile} # We don't really need to save them as we won't set a static IP but they might be useful for debugging - echo "IPv4addr=${CurrentIPv4addr}" >> /tmp/setupVars.conf - echo "IPv4gw=${CurrentIPv4gw}" >> /tmp/setupVars.conf + echo "IPv4addr=${CurrentIPv4addr}" >> ${tempsetupVarsFile} + echo "IPv4gw=${CurrentIPv4gw}" >> ${tempsetupVarsFile} else # Ask if the user wants to use DHCP settings as their static IP if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address? @@ -747,8 +757,8 @@ Don't know what DHCP Reservation is? Answer No." ${r} ${c}); then Gateway: ${CurrentIPv4gw}" ${r} ${c}); then IPv4addr=${CurrentIPv4addr} IPv4gw=${CurrentIPv4gw} - echo "IPv4addr=${IPv4addr}" >> /tmp/setupVars.conf - echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf + echo "IPv4addr=${IPv4addr}" >> ${tempsetupVarsFile} + echo "IPv4gw=${IPv4gw}" >> ${tempsetupVarsFile} # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that. @@ -803,8 +813,8 @@ It is also possible to use a DHCP reservation, but if you are going to do that, IP address: ${IPv4addr} Gateway: ${IPv4gw}" ${r} ${c}); then # If the settings are correct, then we need to set the pivpnIP - echo "IPv4addr=${IPv4addr}" >> /tmp/setupVars.conf - echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf + echo "IPv4addr=${IPv4addr}" >> ${tempsetupVarsFile} + echo "IPv4gw=${IPv4gw}" >> ${tempsetupVarsFile} # After that's done, the loop ends and we move on ipSettingsCorrect=True else @@ -867,8 +877,8 @@ chooseUser(){ fi install_home=$(grep -m1 "^${install_user}:" /etc/passwd | cut -d: -f6) install_home=${install_home%/} - echo "install_user=${install_user}" >> /tmp/setupVars.conf - echo "install_home=${install_home}" >> /tmp/setupVars.conf + echo "install_user=${install_user}" >> ${tempsetupVarsFile} + echo "install_home=${install_home}" >> ${tempsetupVarsFile} return fi @@ -915,8 +925,8 @@ chooseUser(){ echo "::: Using User: $install_user" install_home=$(grep -m1 "^${install_user}:" /etc/passwd | cut -d: -f6) install_home=${install_home%/} # remove possible trailing slash - echo "install_user=${install_user}" >> /tmp/setupVars.conf - echo "install_home=${install_home}" >> /tmp/setupVars.conf + echo "install_user=${install_user}" >> ${tempsetupVarsFile} + echo "install_home=${install_home}" >> ${tempsetupVarsFile} done else echo "::: Cancel selected, exiting...." @@ -1034,13 +1044,13 @@ installPiVPN(){ confWireGuard confNetwork - echo "pivpnPROTO=${pivpnPROTO}" >> /tmp/setupVars.conf + echo "pivpnPROTO=${pivpnPROTO}" >> ${tempsetupVarsFile} fi - echo "pivpnDEV=${pivpnDEV}" >> /tmp/setupVars.conf - echo "pivpnNET=${pivpnNET}" >> /tmp/setupVars.conf - echo "subnetClass=${subnetClass}" >> /tmp/setupVars.conf + echo "pivpnDEV=${pivpnDEV}" >> ${tempsetupVarsFile} + echo "pivpnNET=${pivpnNET}" >> ${tempsetupVarsFile} + echo "subnetClass=${subnetClass}" >> ${tempsetupVarsFile} } askWhichVPN(){ @@ -1093,7 +1103,7 @@ askWhichVPN(){ fi fi - echo "VPN=${VPN}" >> /tmp/setupVars.conf + echo "VPN=${VPN}" >> ${tempsetupVarsFile} } downloadVerifyKey(){ @@ -1295,7 +1305,7 @@ askCustomProto(){ exit 1 fi fi - echo "pivpnPROTO=${pivpnPROTO}" >> /tmp/setupVars.conf + echo "pivpnPROTO=${pivpnPROTO}" >> ${tempsetupVarsFile} return fi @@ -1308,7 +1318,7 @@ askCustomProto(){ # Convert option into lowercase (UDP->udp) pivpnPROTO="${pivpnPROTO,,}" echo "::: Using protocol: $pivpnPROTO" - echo "pivpnPROTO=${pivpnPROTO}" >> /tmp/setupVars.conf + echo "pivpnPROTO=${pivpnPROTO}" >> ${tempsetupVarsFile} else echo "::: Cancel selected, exiting...." exit 1 @@ -1338,7 +1348,7 @@ askCustomPort(){ exit 1 fi fi - echo "pivpnPORT=${pivpnPORT}" >> /tmp/setupVars.conf + echo "pivpnPORT=${pivpnPORT}" >> ${tempsetupVarsFile} return fi @@ -1381,7 +1391,7 @@ askCustomPort(){ fi done # write out the port - echo "pivpnPORT=${pivpnPORT}" >> /tmp/setupVars.conf + echo "pivpnPORT=${pivpnPORT}" >> ${tempsetupVarsFile} } askClientDNS(){ @@ -1414,8 +1424,8 @@ askClientDNS(){ exit 1 fi - echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf - echo "pivpnDNS2=${pivpnDNS2}" >> /tmp/setupVars.conf + echo "pivpnDNS1=${pivpnDNS1}" >> ${tempsetupVarsFile} + echo "pivpnDNS2=${pivpnDNS2}" >> ${tempsetupVarsFile} return fi @@ -1450,8 +1460,8 @@ askClientDNS(){ # Use the Raspberry Pi VPN IP as DNS server. pivpnDNS1="$vpnGw" - echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf - echo "pivpnDNS2=${pivpnDNS2}" >> /tmp/setupVars.conf + echo "pivpnDNS1=${pivpnDNS1}" >> ${tempsetupVarsFile} + echo "pivpnDNS2=${pivpnDNS2}" >> ${tempsetupVarsFile} return fi fi @@ -1536,8 +1546,8 @@ askClientDNS(){ exit 1 fi - echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf - echo "pivpnDNS2=${pivpnDNS2}" >> /tmp/setupVars.conf + echo "pivpnDNS1=${pivpnDNS1}" >> ${tempsetupVarsFile} + echo "pivpnDNS2=${pivpnDNS2}" >> ${tempsetupVarsFile} } #Call this function to use a regex to check user input for a valid custom domain @@ -1564,7 +1574,7 @@ askCustomDomain(){ else echo "::: Skipping custom domain" fi - echo "pivpnSEARCHDOMAIN=${pivpnSEARCHDOMAIN}" >> /tmp/setupVars.conf + echo "pivpnSEARCHDOMAIN=${pivpnSEARCHDOMAIN}" >> ${tempsetupVarsFile} return fi @@ -1593,7 +1603,7 @@ askCustomDomain(){ done fi - echo "pivpnSEARCHDOMAIN=${pivpnSEARCHDOMAIN}" >> /tmp/setupVars.conf + echo "pivpnSEARCHDOMAIN=${pivpnSEARCHDOMAIN}" >> ${tempsetupVarsFile} } askPublicIPOrDNS(){ @@ -1619,7 +1629,7 @@ askPublicIPOrDNS(){ exit 1 fi fi - echo "pivpnHOST=${pivpnHOST}" >> /tmp/setupVars.conf + echo "pivpnHOST=${pivpnHOST}" >> ${tempsetupVarsFile} return fi @@ -1663,7 +1673,7 @@ askPublicIPOrDNS(){ exit 1 fi - echo "pivpnHOST=${pivpnHOST}" >> /tmp/setupVars.conf + echo "pivpnHOST=${pivpnHOST}" >> ${tempsetupVarsFile} } askEncryption(){ @@ -1712,9 +1722,9 @@ askEncryption(){ fi fi - echo "TWO_POINT_FOUR=${TWO_POINT_FOUR}" >> /tmp/setupVars.conf - echo "pivpnENCRYPT=${pivpnENCRYPT}" >> /tmp/setupVars.conf - echo "USE_PREDEFINED_DH_PARAM=${USE_PREDEFINED_DH_PARAM}" >> /tmp/setupVars.conf + echo "TWO_POINT_FOUR=${TWO_POINT_FOUR}" >> ${tempsetupVarsFile} + echo "pivpnENCRYPT=${pivpnENCRYPT}" >> ${tempsetupVarsFile} + echo "USE_PREDEFINED_DH_PARAM=${USE_PREDEFINED_DH_PARAM}" >> ${tempsetupVarsFile} return fi @@ -1746,9 +1756,9 @@ askEncryption(){ USE_PREDEFINED_DH_PARAM=0 fi - echo "TWO_POINT_FOUR=${TWO_POINT_FOUR}" >> /tmp/setupVars.conf - echo "pivpnENCRYPT=${pivpnENCRYPT}" >> /tmp/setupVars.conf - echo "USE_PREDEFINED_DH_PARAM=${USE_PREDEFINED_DH_PARAM}" >> /tmp/setupVars.conf + echo "TWO_POINT_FOUR=${TWO_POINT_FOUR}" >> ${tempsetupVarsFile} + echo "pivpnENCRYPT=${pivpnENCRYPT}" >> ${tempsetupVarsFile} + echo "USE_PREDEFINED_DH_PARAM=${USE_PREDEFINED_DH_PARAM}" >> ${tempsetupVarsFile} } cidrToMask(){ @@ -2092,8 +2102,8 @@ confNetwork(){ ;; esac - echo "INPUT_CHAIN_EDITED=${INPUT_CHAIN_EDITED}" >> /tmp/setupVars.conf - echo "FORWARD_CHAIN_EDITED=${FORWARD_CHAIN_EDITED}" >> /tmp/setupVars.conf + echo "INPUT_CHAIN_EDITED=${INPUT_CHAIN_EDITED}" >> ${tempsetupVarsFile} + echo "FORWARD_CHAIN_EDITED=${FORWARD_CHAIN_EDITED}" >> ${tempsetupVarsFile} fi } @@ -2156,7 +2166,7 @@ askUnattendedUpgrades(){ echo "::: Skipping unattended upgrades" fi fi - echo "UNATTUPG=${UNATTUPG}" >> /tmp/setupVars.conf + echo "UNATTUPG=${UNATTUPG}" >> ${tempsetupVarsFile} return fi @@ -2168,7 +2178,7 @@ askUnattendedUpgrades(){ UNATTUPG=0 fi - echo "UNATTUPG=${UNATTUPG}" >> /tmp/setupVars.conf + echo "UNATTUPG=${UNATTUPG}" >> ${tempsetupVarsFile} } confUnattendedUpgrades(){ @@ -2230,8 +2240,8 @@ installScripts(){ fi $SUDO install -m 755 "$pivpnFilesDir"/scripts/*.sh -t /opt/pivpn - $SUDO install -m 755 "$pivpnFilesDir"/scripts/"$VPN"/*.sh -t /opt/pivpn - $SUDO install -m 755 "$pivpnFilesDir"/scripts/"$VPN"/pivpn /usr/local/bin/pivpn + $SUDO install -m 755 "$pivpnFilesDir"/scripts/"$VPN"/*.sh -t /opt/pivpn/${VPN} + $SUDO install -m 755 "$pivpnFilesDir"/scripts/"$VPN"/pivpn /usr/local/bin/pivpn/${VPN} $SUDO install -m 644 "$pivpnFilesDir"/scripts/"$VPN"/bash-completion /etc/bash_completion.d/pivpn # shellcheck disable=SC1091 . /etc/bash_completion.d/pivpn diff --git a/scripts/openvpn/makeOVPN.sh b/scripts/openvpn/makeOVPN.sh index c645c55..719e670 100755 --- a/scripts/openvpn/makeOVPN.sh +++ b/scripts/openvpn/makeOVPN.sh @@ -1,7 +1,7 @@ #!/bin/bash # Create OVPN Client # Default Variable Declarations -setupVars="/etc/pivpn/setupVars.conf" +setupVars="/etc/pivpn/openvpn/setupVars.conf" DEFAULT="Default.txt" FILEEXT=".ovpn" CRT=".crt" diff --git a/scripts/openvpn/pivpn b/scripts/openvpn/pivpn index 27d2d98..f461d7a 100755 --- a/scripts/openvpn/pivpn +++ b/scripts/openvpn/pivpn @@ -10,26 +10,29 @@ if [[ ! $EUID -eq 0 ]];then fi fi +scriptdir="/opt/pivpn" +vpn="openvpn" + function makeOVPNFunc { shift - $SUDO /opt/pivpn/makeOVPN.sh "$@" + $SUDO ${scripdir}/${vpn}/makeOVPN.sh "$@" exit 0 } function listClientsFunc { shift - $SUDO /opt/pivpn/clientStat.sh "$@" + $SUDO ${scripdir}/${vpn}/clientStat.sh "$@" exit 0 } function listOVPNFunc { - $SUDO /opt/pivpn/listOVPN.sh + $SUDO ${scripdir}/${vpn}/listOVPN.sh exit 0 } function debugFunc { echo "::: Generating Debug Output" - $SUDO /opt/pivpn/pivpnDebug.sh | tee /tmp/debug.txt + $SUDO ${scripdir}/${vpn}/pivpnDebug.sh | tee /tmp/debug.txt echo "::: " echo "::: Debug output completed above." echo "::: Copy saved to /tmp/debug.txt" @@ -39,12 +42,12 @@ function debugFunc { function removeOVPNFunc { shift - $SUDO /opt/pivpn/removeOVPN.sh "$@" + $SUDO ${scripdir}/${vpn}/removeOVPN.sh "$@" exit 0 } function uninstallFunc { - $SUDO /opt/pivpn/uninstall.sh + $SUDO ${scripdir}/uninstall.sh exit 0 } @@ -55,7 +58,7 @@ function versionFunc { function update { shift - $SUDO /opt/pivpn/update.sh "$@" + $SUDO ${scripdir}/update.sh "$@" exit 0 @@ -63,7 +66,7 @@ function update { function backup { - $SUDO /opt/pivpn/backup.sh + $SUDO ${scripdir}/backup.sh exit 0 } diff --git a/scripts/openvpn/pivpnDebug.sh b/scripts/openvpn/pivpnDebug.sh index 8299fa3..644933e 100755 --- a/scripts/openvpn/pivpnDebug.sh +++ b/scripts/openvpn/pivpnDebug.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # This scripts runs as root -setupVars="/etc/pivpn/setupVars.conf" +setupVars="/etc/pivpn/openvpn/setupVars.conf" if [ ! -f "${setupVars}" ]; then echo "::: Missing setup vars file!" diff --git a/scripts/openvpn/removeOVPN.sh b/scripts/openvpn/removeOVPN.sh index 50666f0..4f79385 100755 --- a/scripts/openvpn/removeOVPN.sh +++ b/scripts/openvpn/removeOVPN.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # PiVPN: revoke client script -setupVars="/etc/pivpn/setupVars.conf" +setupVars="/etc/pivpn/openvpn/setupVars.conf" INDEX="/etc/openvpn/easy-rsa/pki/index.txt" if [ ! -f "${setupVars}" ]; then diff --git a/scripts/wireguard/makeCONF.sh b/scripts/wireguard/makeCONF.sh index 745db08..db68c97 100755 --- a/scripts/wireguard/makeCONF.sh +++ b/scripts/wireguard/makeCONF.sh @@ -1,6 +1,6 @@ #!/bin/bash -setupVars="/etc/pivpn/setupVars.conf" +setupVars="/etc/pivpn/wireguard/setupVars.conf" if [ ! -f "${setupVars}" ]; then echo "::: Missing setup vars file!" diff --git a/scripts/wireguard/pivpn b/scripts/wireguard/pivpn index fd1ed17..73bcf88 100755 --- a/scripts/wireguard/pivpn +++ b/scripts/wireguard/pivpn @@ -10,53 +10,56 @@ if [ $EUID -ne 0 ];then fi fi +scriptdir="/opt/pivpn" +vpn="wireguard" + makeConf(){ shift - $SUDO /opt/pivpn/makeCONF.sh "$@" + $SUDO ${scriptdir}/${vpn}/makeCONF.sh "$@" exit 0 } listConnected(){ shift - $SUDO /opt/pivpn/clientSTAT.sh "$@" + $SUDO ${scriptdir}/${vpn}/clientSTAT.sh "$@" exit 0 } debug(){ - $SUDO /opt/pivpn/pivpnDEBUG.sh + $SUDO ${scriptdir}/${vpn}/pivpnDEBUG.sh exit 0 } listClients(){ - $SUDO /opt/pivpn/listCONF.sh + $SUDO ${scriptdir}/${vpn}/listCONF.sh exit 0 } showQrcode(){ shift - $SUDO /opt/pivpn/qrcodeCONF.sh "$@" + $SUDO ${scriptdir}/${vpn}/qrcodeCONF.sh "$@" exit 0 } removeClient(){ shift - $SUDO /opt/pivpn/removeCONF.sh "$@" + $SUDO ${scriptdir}/${vpn}/removeCONF.sh "$@" exit 0 } uninstallServer(){ - $SUDO /opt/pivpn/uninstall.sh + $SUDO ${scriptdir}/uninstall.sh exit 0 } updateScripts(){ shift - $SUDO /opt/pivpn/update.sh "$@" + $SUDO ${scriptdir}/update.sh "$@" exit 0 } backup(){ - $SUDO /opt/pivpn/backup.sh + $SUDO ${scriptdir}/backup.sh } showHelp(){ diff --git a/scripts/wireguard/pivpnDEBUG.sh b/scripts/wireguard/pivpnDEBUG.sh index 8c0d9ef..a78e9a3 100755 --- a/scripts/wireguard/pivpnDEBUG.sh +++ b/scripts/wireguard/pivpnDEBUG.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # This scripts runs as root -setupVars="/etc/pivpn/setupVars.conf" +setupVars="/etc/pivpn/wireguard/setupVars.conf" if [ ! -f "${setupVars}" ]; then echo "::: Missing setup vars file!" diff --git a/scripts/wireguard/removeCONF.sh b/scripts/wireguard/removeCONF.sh index 414b492..8eff9cc 100755 --- a/scripts/wireguard/removeCONF.sh +++ b/scripts/wireguard/removeCONF.sh @@ -1,6 +1,6 @@ #!/bin/bash -setupVars="/etc/pivpn/setupVars.conf" +setupVars="/etc/pivpn/wireguard/setupVars.conf" if [ ! -f "${setupVars}" ]; then echo "::: Missing setup vars file!" From 3ed9ec5724911cd67771c80ca12799f89a33267c Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Sat, 2 May 2020 00:06:09 +0100 Subject: [PATCH 02/21] install and uninstall --- auto_install/install.sh | 44 ++++++++++++++++++++++++----------- scripts/uninstall.sh | 51 +++++++++++++++++++++++++++-------------- 2 files changed, 65 insertions(+), 30 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index d0e8cdb..45c2744 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -11,11 +11,13 @@ # Make sure you have `curl` installed ######## VARIABLES ######### -pivpnGitUrl="https://github.com/pivpn/pivpn.git" +#pivpnGitUrl="https://github.com/pivpn/pivpn.git" +pivpnGitUrl="/root/repos/pivpn" setupVarsFile="setupVars.conf" setupConfigDir="/etc/pivpn" # will be /etc/pivpn/${VPN}/setupVars.conf tempsetupVarsFile="/tmp/setupVars.conf" -pivpnFilesDir="/etc/.pivpn" +pivpnFilesDir="/etc/.pivpn" # will be updated when $VPN known +pivpnScriptDir="/opt/pivpn" piholeSetupVars="/etc/pihole/setupVars.conf" dnsmasqConfig="/etc/dnsmasq.d/02-pivpn.conf" @@ -142,7 +144,7 @@ main(){ if [ -z "$UpdateCmd" ] || [ "$UpdateCmd" = "Reconfigure" ]; then : elif [ "$UpdateCmd" = "Update" ]; then - $SUDO /opt/pivpn/update.sh "$@" + $SUDO ${pivpnScriptDir}/update.sh "$@" exit 0 elif [ "$UpdateCmd" = "Repair" ]; then # shellcheck disable=SC1090 @@ -213,7 +215,8 @@ main(){ # Save installation setting to the final location echo "INSTALLED_PACKAGES=(${INSTALLED_PACKAGES[*]})" >> ${tempsetupVarsFile} - echo "::: Setupfiles copied to ${setupConfigDir}/{$VPN}/${setupVarsFile}" + echo "::: Setupfiles copied to ${setupConfigDir}/${VPN}/${setupVarsFile}" + $SUDO mkdir "${setupConfigDir}/${VPN}/" $SUDO cp ${tempsetupVarsFile} "${setupConfigDir}/${VPN}/${setupVarsFile}" installScripts @@ -999,6 +1002,7 @@ getGitFiles(){ } cloneOrUpdateRepos(){ + pivpnFilesDir="${pivpnFilesDir}/${VPN}" # Get Git files getGitFiles ${pivpnFilesDir} ${pivpnGitUrl} || \ { echo "!!! Unable to clone ${pivpnGitUrl} into ${pivpnFilesDir}, unable to continue."; \ @@ -2232,19 +2236,33 @@ confUnattendedUpgrades(){ installScripts(){ # Install the scripts from /etc/.pivpn to their various locations echo ":::" - echo -n -e "::: Installing scripts to /opt/pivpn...\n" - if [ ! -d /opt/pivpn ]; then - $SUDO mkdir -p /opt/pivpn - $SUDO chown root:root /opt/pivpn - $SUDO chmod 0755 /opt/pivpn + echo "::: line ${LINENO}" + echo -n -e "::: Installing scripts to ${pivpnScriptDir}...\n" + echo "::: line ${LINENO}" + if [ ! -d "${pivpnScriptDir}/${VPN}" ]; then + $SUDO mkdir -p ${pivpnScriptDir}/${VPN} + $SUDO chown -R root:root ${pivpnScriptDir} + $SUDO chmod -R 0755 ${pivpnScriptDir} fi - $SUDO install -m 755 "$pivpnFilesDir"/scripts/*.sh -t /opt/pivpn - $SUDO install -m 755 "$pivpnFilesDir"/scripts/"$VPN"/*.sh -t /opt/pivpn/${VPN} - $SUDO install -m 755 "$pivpnFilesDir"/scripts/"$VPN"/pivpn /usr/local/bin/pivpn/${VPN} - $SUDO install -m 644 "$pivpnFilesDir"/scripts/"$VPN"/bash-completion /etc/bash_completion.d/pivpn + $SUDO install -m 755 "${pivpnFilesDir}"/scripts/*.sh -t ${pivpnScriptDir} + $SUDO install -m 755 "${pivpnFilesDir}/scripts/${VPN}"/*.sh -t ${pivpnScriptDir}/${VPN} + echo "::: line ${LINENO}" + $SUDO mkdir -p /usr/local/bin/pivpn/${VPN} + echo "::: line ${LINENO}" + $SUDO install -v -m 755 "${pivpnFilesDir}/scripts/${VPN}"/pivpn -t /usr/local/bin/pivpn/${VPN} + echo "::: line ${LINENO}" + ls -l ${pivpnFilesDir}/scripts/${VPN}/bash-completion + echo "::: line ${LINENO}" + $SUDO -E 'bash cat "${pivpnFilesDir}/scripts/${VPN}/bash-completion" >> /etc/bash_completion.d/pivpn' + echo "::: line ${LINENO}" + $SUDO chown root:root /etc/bash_completion.d/pivpn + echo "::: line ${LINENO}" + $SUDO chmod 755 /etc/bash_completion.d/pivpn # shellcheck disable=SC1091 + echo "::: line ${LINENO}" . /etc/bash_completion.d/pivpn + echo "::: line ${LINENO}" echo " done." } diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index d40afbe..3bf8dca 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -4,19 +4,6 @@ ### FIXME: global: config storage, refactor all scripts to adhere to the storage ### FIXME: use variables where appropriate, reduce magic numbers by 99.9%, at least. -PKG_MANAGER="apt-get" -UPDATE_PKG_CACHE="${PKG_MANAGER} update" -dnsmasqConfig="/etc/dnsmasq.d/02-pivpn.conf" -setupVars="/etc/pivpn/setupVars.conf" - -if [ ! -f "${setupVars}" ]; then - echo "::: Missing setup vars file!" - exit 1 -fi - -# shellcheck disable=SC1090 -source "${setupVars}" - # Find the rows and columns. Will default to 80x24 if it can not be detected. screen_size=$(stty size 2>/dev/null || echo 24 80) rows=$(echo "$screen_size" | awk '{print $1}') @@ -29,6 +16,31 @@ c=$(( columns / 2 )) r=$(( r < 20 ? 20 : r )) c=$(( c < 70 ? 70 : c )) + chooseVPNCmd=(whiptail --backtitle "Setup PiVPN" --title "Installation mode" --separate-output --radiolist "WireGuard is a new kind of VPN that provides near-instantaneous connection speed, high performance, and modern cryptography.\\n\\nIt's the recommended choice especially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\\n\\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol or if you need features like TCP and custom search domain.\\n\\nChoose a VPN to uninstall (press space to select):" "${r}" "${c}" 2) + VPNChooseOptions=(WireGuard "" on + OpenVPN "" off) + + if VPN=$("${chooseVPNCmd[@]}" "${VPNChooseOptions[@]}" 2>&1 >/dev/tty) ; then + echo "::: Using VPN: $VPN" + VPN="${VPN,,}" + else + echo "::: Cancel selected, exiting...." + exit 1 + fi + +PKG_MANAGER="apt-get" +UPDATE_PKG_CACHE="${PKG_MANAGER} update" +dnsmasqConfig="/etc/dnsmasq.d/02-pivpn.conf" +setupVars="/etc/pivpn/${VPN}/setupVars.conf" + +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +# shellcheck disable=SC1090 +source "${setupVars}" + ### FIXME: introduce global lib spinner(){ local pid=$1 @@ -152,11 +164,16 @@ removeAll(){ pihole restartdns fi - rm -rf /opt/pivpn - rm -rf /etc/.pivpn - rm -rf /etc/pivpn + rm -rf /opt/pivpn/${VPN} + # if dual installation, other installation will cause next line to fail + rmdir /opt/pivpn + rm -rf /etc/.pivpn/${VPN} + rmdir /etc/.pivpn + rm -rf /etc/pivpn/${VPN} + rmdir /etc/pivpn rm -f /var/log/*pivpn* - rm -f /usr/local/bin/pivpn + rm -f /usr/local/bin/pivpn/${VPN} + # TODO fix bash_completion removal rm -f /etc/bash_completion.d/pivpn echo ":::" From 5330454f2b48a7a75f0d670f95afe609a19c67d0 Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Sun, 3 May 2020 17:55:48 +0100 Subject: [PATCH 03/21] added generic pivpn for 2 protocols --- scripts/pivpn | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 scripts/pivpn diff --git a/scripts/pivpn b/scripts/pivpn new file mode 100755 index 0000000..216b2cb --- /dev/null +++ b/scripts/pivpn @@ -0,0 +1,36 @@ +#!/bin/bash + +# Must be root to use this tool +if [ $EUID -ne 0 ];then + if dpkg-query -s sudo &> /dev/null; then + export SUDO="sudo" + else + echo "::: Please install sudo or run this as root." + exit 1 + fi +fi + +scriptdir="/opt/pivpn" +vpn="wireguard" + +showHelp(){ + echo "::: To pass off to the pivpn command for each protocol" + echo ":::" + echo "::: Usage: pivpn wg [option]" + echo "::: Usage: pivpn opv [option]" + echo ":::" + echo "::: -h, help Show this help dialog" + exit 0 +} + +if [ $# = 0 ]; then + showHelp +fi + +# Handle redirecting to specific functions based on arguments +case "$1" in + wg ) "${scriptDir}/wireguard/pivpn" "${@:2}";; + opv ) "${scriptDir}/openvpn/pivpn" "${@:2}";; +"-h" | "help" ) showHelp;; +* ) showHelp;; +esac From 6a8e508951cecc8cd27718e18930cd13eb64ad2b Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Mon, 4 May 2020 09:54:07 +0100 Subject: [PATCH 04/21] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 157822a..503abf6 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ About ----- +Branch test is a modification that allows installing both openvpn and wireguard on the same machine. To do this, run the installer twice locally, makeing sure you are going to pull branch test. + + Visit the [PiVPN](https://pivpn.io) site for more information. This is a set of shell scripts initially developed by **@0-kaladin** that serve to easily turn your Raspberry Pi (TM) into a VPN server using two free, open-source protocols: From 4e3a58702f58108586987241b9007676b070a33b Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Tue, 5 May 2020 00:05:10 +0100 Subject: [PATCH 05/21] more dual --- auto_install/install.sh | 34 +++++++++------------------ scripts/openvpn/{pivpn => pivpn.sh} | 0 scripts/pivpn | 4 ++-- scripts/wireguard/{pivpn => pivpn.sh} | 0 4 files changed, 13 insertions(+), 25 deletions(-) rename scripts/openvpn/{pivpn => pivpn.sh} (100%) rename scripts/wireguard/{pivpn => pivpn.sh} (100%) diff --git a/auto_install/install.sh b/auto_install/install.sh index 45c2744..c423c18 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -16,7 +16,7 @@ pivpnGitUrl="/root/repos/pivpn" setupVarsFile="setupVars.conf" setupConfigDir="/etc/pivpn" # will be /etc/pivpn/${VPN}/setupVars.conf tempsetupVarsFile="/tmp/setupVars.conf" -pivpnFilesDir="/etc/.pivpn" # will be updated when $VPN known +pivpnFilesDir="/etc/.pivpn" pivpnScriptDir="/opt/pivpn" piholeSetupVars="/etc/pihole/setupVars.conf" @@ -1002,7 +1002,6 @@ getGitFiles(){ } cloneOrUpdateRepos(){ - pivpnFilesDir="${pivpnFilesDir}/${VPN}" # Get Git files getGitFiles ${pivpnFilesDir} ${pivpnGitUrl} || \ { echo "!!! Unable to clone ${pivpnGitUrl} into ${pivpnFilesDir}, unable to continue."; \ @@ -2235,32 +2234,21 @@ confUnattendedUpgrades(){ installScripts(){ # Install the scripts from /etc/.pivpn to their various locations - echo ":::" - echo "::: line ${LINENO}" echo -n -e "::: Installing scripts to ${pivpnScriptDir}...\n" echo "::: line ${LINENO}" if [ ! -d "${pivpnScriptDir}/${VPN}" ]; then - $SUDO mkdir -p ${pivpnScriptDir}/${VPN} - $SUDO chown -R root:root ${pivpnScriptDir} - $SUDO chmod -R 0755 ${pivpnScriptDir} + $SUDO install -m 0755 -o root -d ${pivpnScriptDir}/${VPN} +# $SUDO mkdir -p ${pivpnScriptDir}/${VPN} +# $SUDO chown -R root:root ${pivpnScriptDir} +# $SUDO chmod -R 0755 ${pivpnScriptDir} fi - - $SUDO install -m 755 "${pivpnFilesDir}"/scripts/*.sh -t ${pivpnScriptDir} - $SUDO install -m 755 "${pivpnFilesDir}/scripts/${VPN}"/*.sh -t ${pivpnScriptDir}/${VPN} - echo "::: line ${LINENO}" - $SUDO mkdir -p /usr/local/bin/pivpn/${VPN} - echo "::: line ${LINENO}" - $SUDO install -v -m 755 "${pivpnFilesDir}/scripts/${VPN}"/pivpn -t /usr/local/bin/pivpn/${VPN} - echo "::: line ${LINENO}" - ls -l ${pivpnFilesDir}/scripts/${VPN}/bash-completion - echo "::: line ${LINENO}" - $SUDO -E 'bash cat "${pivpnFilesDir}/scripts/${VPN}/bash-completion" >> /etc/bash_completion.d/pivpn' - echo "::: line ${LINENO}" + $SUDO install -v -m 755 -t ${pivpnScriptDir} ${pivpnFilesDir}/scripts/*.sh + $SUDO install -v -m 755 -t ${pivpnScriptDir}/${VPN} ${pivpnFilesDir}/scripts/${VPN}/*.sh + $SUDO install -v -m 755 -t /usr/local/bin /${pivpnFilesDir}/scripts/pivpn + $SUDO cp "${pivpnFilesDir}/scripts/${VPN}/bash-completion" /etc/bash_completion.d/pivpn $SUDO chown root:root /etc/bash_completion.d/pivpn - echo "::: line ${LINENO}" $SUDO chmod 755 /etc/bash_completion.d/pivpn # shellcheck disable=SC1091 - echo "::: line ${LINENO}" . /etc/bash_completion.d/pivpn echo "::: line ${LINENO}" echo " done." @@ -2269,7 +2257,7 @@ installScripts(){ displayFinalMessage(){ if [ "${runUnattended}" = 'true' ]; then echo "::: Installation Complete!" - echo "::: Now run 'pivpn add' to create the ovpn profiles." + echo "::: Now run 'pivpn add' to create the client profiles." echo "::: Run 'pivpn help' to see what else you can do!" echo echo "::: If you run into any issue, please read all our documentation carefully." @@ -2281,7 +2269,7 @@ displayFinalMessage(){ fi # Final completion message to user - whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Now run 'pivpn add' to create the ovpn profiles. + whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Now run 'pivpn add' to create the client profiles. Run 'pivpn help' to see what else you can do!\\n\\nIf you run into any issue, please read all our documentation carefully. All incomplete posts or bug reports will be ignored or deleted.\\n\\nThank you for using PiVPN." ${r} ${c} if (whiptail --title "Reboot" --yesno --defaultno "It is strongly recommended you reboot after installation. Would you like to reboot now?" ${r} ${c}); then diff --git a/scripts/openvpn/pivpn b/scripts/openvpn/pivpn.sh similarity index 100% rename from scripts/openvpn/pivpn rename to scripts/openvpn/pivpn.sh diff --git a/scripts/pivpn b/scripts/pivpn index 216b2cb..e330552 100755 --- a/scripts/pivpn +++ b/scripts/pivpn @@ -29,8 +29,8 @@ fi # Handle redirecting to specific functions based on arguments case "$1" in - wg ) "${scriptDir}/wireguard/pivpn" "${@:2}";; - opv ) "${scriptDir}/openvpn/pivpn" "${@:2}";; + wg ) "${scriptDir}/wireguard/pivpn.sh" "${@:2}";; + opv ) "${scriptDir}/openvpn/pivpn.sh" "${@:2}";; "-h" | "help" ) showHelp;; * ) showHelp;; esac diff --git a/scripts/wireguard/pivpn b/scripts/wireguard/pivpn.sh similarity index 100% rename from scripts/wireguard/pivpn rename to scripts/wireguard/pivpn.sh From 9351016db568f33a6d5a237d7d9ba0a9c38de771 Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Tue, 5 May 2020 09:24:20 +0100 Subject: [PATCH 06/21] extra D in scriptdir --- scripts/pivpn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pivpn b/scripts/pivpn index e330552..029f211 100755 --- a/scripts/pivpn +++ b/scripts/pivpn @@ -10,7 +10,7 @@ if [ $EUID -ne 0 ];then fi fi -scriptdir="/opt/pivpn" +scriptDir="/opt/pivpn" vpn="wireguard" showHelp(){ From 21d954167c97c6257b837012882f3c78551185d9 Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Tue, 5 May 2020 21:43:20 +0100 Subject: [PATCH 07/21] typo in openvpn --- scripts/openvpn/pivpn.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/openvpn/pivpn.sh b/scripts/openvpn/pivpn.sh index f461d7a..66ab5cc 100755 --- a/scripts/openvpn/pivpn.sh +++ b/scripts/openvpn/pivpn.sh @@ -10,29 +10,29 @@ if [[ ! $EUID -eq 0 ]];then fi fi -scriptdir="/opt/pivpn" +scriptDir="/opt/pivpn" vpn="openvpn" function makeOVPNFunc { shift - $SUDO ${scripdir}/${vpn}/makeOVPN.sh "$@" + $SUDO ${scriptDir}/${vpn}/makeOVPN.sh "$@" exit 0 } function listClientsFunc { shift - $SUDO ${scripdir}/${vpn}/clientStat.sh "$@" + $SUDO ${scriptDir}/${vpn}/clientStat.sh "$@" exit 0 } function listOVPNFunc { - $SUDO ${scripdir}/${vpn}/listOVPN.sh + $SUDO ${scriptDir}/${vpn}/listOVPN.sh exit 0 } function debugFunc { echo "::: Generating Debug Output" - $SUDO ${scripdir}/${vpn}/pivpnDebug.sh | tee /tmp/debug.txt + $SUDO ${scriptDir}/${vpn}/pivpnDebug.sh | tee /tmp/debug.txt echo "::: " echo "::: Debug output completed above." echo "::: Copy saved to /tmp/debug.txt" @@ -42,12 +42,12 @@ function debugFunc { function removeOVPNFunc { shift - $SUDO ${scripdir}/${vpn}/removeOVPN.sh "$@" + $SUDO ${scriptDir}/${vpn}/removeOVPN.sh "$@" exit 0 } function uninstallFunc { - $SUDO ${scripdir}/uninstall.sh + $SUDO ${scriptDir}/uninstall.sh exit 0 } @@ -58,7 +58,7 @@ function versionFunc { function update { shift - $SUDO ${scripdir}/update.sh "$@" + $SUDO ${scriptDir}/update.sh "$@" exit 0 @@ -66,7 +66,7 @@ function update { function backup { - $SUDO ${scripdir}/backup.sh + $SUDO ${scriptDir}/backup.sh exit 0 } From 081bf912c2910de1476c9a485f0e6f3ed4d72d95 Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Tue, 5 May 2020 23:12:32 +0100 Subject: [PATCH 08/21] still debugging dual --- auto_install/install.sh | 17 ++++++++++++++--- scripts/backup.sh | 27 ++++++++++++++++++++++++++- scripts/update.sh | 27 ++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index c423c18..f34230c 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -2243,9 +2243,20 @@ installScripts(){ # $SUDO chmod -R 0755 ${pivpnScriptDir} fi $SUDO install -v -m 755 -t ${pivpnScriptDir} ${pivpnFilesDir}/scripts/*.sh - $SUDO install -v -m 755 -t ${pivpnScriptDir}/${VPN} ${pivpnFilesDir}/scripts/${VPN}/*.sh - $SUDO install -v -m 755 -t /usr/local/bin /${pivpnFilesDir}/scripts/pivpn - $SUDO cp "${pivpnFilesDir}/scripts/${VPN}/bash-completion" /etc/bash_completion.d/pivpn + $SUDO install -v -m 755 -t ${pivpnScriptDir}/${VPN} ${pivpnFilesDir}/scripts/${VPN}/*.sh + # line for the single command being installed + $SUDO ln -s -T ${pivpnFilesDir}/scripts/${VPN}/pivpn pivpn + # if the other protocol file exists + if [ ${VPN} -eq 'wireguard' ]; then + othervpn='openvpn' + else + othervpn='wireguard' + fi + if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile} ] then; + # dont need a link, copy the common script to the location instead + $SUDO install -v -m 755 -t /usr/local/bin /${pivpnFilesDir}/scripts/pivpn + fi + $SUDO cp "${pivpnFilesDir}/scripts/${VPN}/bash-completion" /etc/bash_completion.d/pivpn $SUDO chown root:root /etc/bash_completion.d/pivpn $SUDO chmod 755 /etc/bash_completion.d/pivpn # shellcheck disable=SC1091 diff --git a/scripts/backup.sh b/scripts/backup.sh index 8711c96..adf5b43 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -2,7 +2,32 @@ backupdir=pivpnbackup date=$(date +%Y%m%d-%H%M%S) -setupVars="/etc/pivpn/setupVars.conf" + +# Find the rows and columns. Will default to 80x24 if it can not be detected. +screen_size=$(stty size 2>/dev/null || echo 24 80) +rows=$(echo "$screen_size" | awk '{print $1}') +columns=$(echo "$screen_size" | awk '{print $2}') + +# Divide by two so the dialogs take up half of the screen, which looks nice. +r=$(( rows / 2 )) +c=$(( columns / 2 )) +# Unless the screen is tiny +r=$(( r < 20 ? 20 : r )) +c=$(( c < 70 ? 70 : c )) + + chooseVPNCmd=(whiptail --backtitle "Setup PiVPN" --title "Installation mode" --separate-output --radiolist "Choose a VPN to update (press space to select):" "${r}" "${c}" 2) + VPNChooseOptions=(WireGuard "" on + OpenVPN "" off) + + if VPN=$("${chooseVPNCmd[@]}" "${VPNChooseOptions[@]}" 2>&1 >/dev/tty) ; then + echo "::: Using VPN: $VPN" + VPN="${VPN,,}" + else + echo "::: Cancel selected, exiting...." + exit 1 + fi + +setupVars="/etc/pivpn/${VPN}/setupVars.conf" if [ ! -f "${setupVars}" ]; then echo "::: Missing setup vars file!" diff --git a/scripts/update.sh b/scripts/update.sh index 609c273..eed1ce8 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -6,7 +6,32 @@ pivpnrepo="https://github.com/pivpn/pivpn.git" pivpnlocalpath="/etc/.pivpn" pivpnscripts="/opt/pivpn/" bashcompletiondir="/etc/bash_completion.d/" -setupVars="/etc/pivpn/setupVars.conf" + +# Find the rows and columns. Will default to 80x24 if it can not be detected. +screen_size=$(stty size 2>/dev/null || echo 24 80) +rows=$(echo "$screen_size" | awk '{print $1}') +columns=$(echo "$screen_size" | awk '{print $2}') + +# Divide by two so the dialogs take up half of the screen, which looks nice. +r=$(( rows / 2 )) +c=$(( columns / 2 )) +# Unless the screen is tiny +r=$(( r < 20 ? 20 : r )) +c=$(( c < 70 ? 70 : c )) + + chooseVPNCmd=(whiptail --backtitle "Setup PiVPN" --title "Installation mode" --separate-output --radiolist "Choose a VPN to update (press space to select):" "${r}" "${c}" 2) + VPNChooseOptions=(WireGuard "" on + OpenVPN "" off) + + if VPN=$("${chooseVPNCmd[@]}" "${VPNChooseOptions[@]}" 2>&1 >/dev/tty) ; then + echo "::: Using VPN: $VPN" + VPN="${VPN,,}" + else + echo "::: Cancel selected, exiting...." + exit 1 + fi + +setupVars="/etc/pivpn/${VPN}/setupVars.conf" if [ ! -f "${setupVars}" ]; then echo "::: Missing setup vars file!" From e09bbda1e9aba16319e31979be74460ae338ba3c Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Tue, 5 May 2020 23:13:59 +0100 Subject: [PATCH 09/21] update to backup --- scripts/backup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index adf5b43..a632a81 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -15,7 +15,7 @@ c=$(( columns / 2 )) r=$(( r < 20 ? 20 : r )) c=$(( c < 70 ? 70 : c )) - chooseVPNCmd=(whiptail --backtitle "Setup PiVPN" --title "Installation mode" --separate-output --radiolist "Choose a VPN to update (press space to select):" "${r}" "${c}" 2) + chooseVPNCmd=(whiptail --backtitle "Setup PiVPN" --title "Installation mode" --separate-output --radiolist "Choose a VPN configuration to backup (press space to select):" "${r}" "${c}" 2) VPNChooseOptions=(WireGuard "" on OpenVPN "" off) From 052376a133ce27052206c9e31c86d6512923f1b3 Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Wed, 6 May 2020 22:03:38 +0100 Subject: [PATCH 10/21] install.sh path correct --- auto_install/install.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index f34230c..d133e6c 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -2244,16 +2244,17 @@ installScripts(){ fi $SUDO install -v -m 755 -t ${pivpnScriptDir} ${pivpnFilesDir}/scripts/*.sh $SUDO install -v -m 755 -t ${pivpnScriptDir}/${VPN} ${pivpnFilesDir}/scripts/${VPN}/*.sh - # line for the single command being installed - $SUDO ln -s -T ${pivpnFilesDir}/scripts/${VPN}/pivpn pivpn - # if the other protocol file exists - if [ ${VPN} -eq 'wireguard' ]; then + # make a link for a single command being installed + $SUDO ln -s -T ${pivpnScriptDir}/${VPN}/pivpn.sh /usr/local/bin/pivpn + # if the other protocol file exists it has been installed + if [[ ${VPN} == 'wireguard' ]]; then othervpn='openvpn' else othervpn='wireguard' fi - if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile} ] then; + if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then # dont need a link, copy the common script to the location instead + $SUDO rm -f /usr/local/bin/pivpn $SUDO install -v -m 755 -t /usr/local/bin /${pivpnFilesDir}/scripts/pivpn fi $SUDO cp "${pivpnFilesDir}/scripts/${VPN}/bash-completion" /etc/bash_completion.d/pivpn From f6463b88491664833666fb0acfd5aee161da7f24 Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Wed, 6 May 2020 23:00:13 +0100 Subject: [PATCH 11/21] uninstall to detect one prot remaining, wg_update removed --- scripts/wireguard/bash-completion | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/wireguard/bash-completion b/scripts/wireguard/bash-completion index 412072a..a971696 100644 --- a/scripts/wireguard/bash-completion +++ b/scripts/wireguard/bash-completion @@ -4,8 +4,8 @@ _pivpn() COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - dashopts="-a -c -d -l -qr -r -h -u -up -wg -bk" - opts="add clients debug list qrcode remove help uninstall update wgupdate backup" + dashopts="-a -c -d -l -qr -r -h -u -up -bk" + opts="add clients debug list qrcode remove help uninstall update backup" if [ "${#COMP_WORDS[@]}" -eq 2 ] then if [[ ${cur} == -* ]] ; then From 9b04391629badfe97afdadde7b2a0c4e5d645414 Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Wed, 6 May 2020 23:29:04 +0100 Subject: [PATCH 12/21] uninstall change --- scripts/uninstall.sh | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 3bf8dca..7d53659 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -37,10 +37,26 @@ if [ ! -f "${setupVars}" ]; then echo "::: Missing setup vars file!" exit 1 fi - + # shellcheck disable=SC1090 source "${setupVars}" +# if the other protocol file exists it has been installed +if [[ ${VPN} == 'wireguard' ]]; then + othervpn='openvpn' +else + othervpn='wireguard' +fi +vpnStillExists=no +if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then + $SUDO rm -f /usr/local/bin/pivpn + $SUDO ln -s -T ${pivpnScriptDir}/${othervpn}/pivpn.sh /usr/local/bin/pivpn + vpnStillExists=yes + echo ":::" + echo "::: Two VPN protocols exist, you should remove the other one too" + echo ":::" +fi + ### FIXME: introduce global lib spinner(){ local pid=$1 @@ -98,8 +114,10 @@ removeAll(){ fi # Disable IPv4 forwarding - sed -i '/net.ipv4.ip_forward=1/c\#net.ipv4.ip_forward=1' /etc/sysctl.conf - sysctl -p + if [ ${vpnStillExists} != 'yes' ]; then + sed -i '/net.ipv4.ip_forward=1/c\#net.ipv4.ip_forward=1' /etc/sysctl.conf + sysctl -p + fi # Purge dependencies echo "::: Purge dependencies..." @@ -172,9 +190,10 @@ removeAll(){ rm -rf /etc/pivpn/${VPN} rmdir /etc/pivpn rm -f /var/log/*pivpn* - rm -f /usr/local/bin/pivpn/${VPN} - # TODO fix bash_completion removal - rm -f /etc/bash_completion.d/pivpn + rm -rf /usr/local/bin/pivpn/${VPN} + if [ ${vpnStillExists} != 'yes' ]; then + rm -f /etc/bash_completion.d/pivpn + fi echo ":::" echo "::: Removing VPN configuration files..." From 501b9919a820aed718a20f2ad6b8fabdb719c65b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 10 May 2020 16:37:30 +0000 Subject: [PATCH 13/21] after ubuntu testing --- auto_install/install.sh | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index d133e6c..09d4a29 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -12,9 +12,9 @@ ######## VARIABLES ######### #pivpnGitUrl="https://github.com/pivpn/pivpn.git" -pivpnGitUrl="/root/repos/pivpn" +pivpnGitUrl="/home/ubuntu/repos/pivpn" setupVarsFile="setupVars.conf" -setupConfigDir="/etc/pivpn" # will be /etc/pivpn/${VPN}/setupVars.conf +setupConfigDir="/etc/pivpn" tempsetupVarsFile="/tmp/setupVars.conf" pivpnFilesDir="/etc/.pivpn" pivpnScriptDir="/opt/pivpn" @@ -123,13 +123,13 @@ main(){ fi # see which setup already exists - if [ -r "${setupVarsDir}/wireguard/${setupVarsFile}" ]; then - setupVars="${setupVarsDir}/wireguard/${setupVarsFile}" - elif [ -f "${setupVarsDir}/openvpn/${setupVarsFile}" ]; then - setupVars="${setupVarsDir}/openvpn/${setupVarsFile}" + if [ -r "${setupConfigDir}/wireguard/${setupVarsFile}" ]; then + setupVars="${setupConfigDir}/wireguard/${setupVarsFile}" + elif [ -r "${setupConfigDir}/openvpn/${setupVarsFile}" ]; then + setupVars="${setupConfigDir}/openvpn/${setupVarsFile}" fi - if [ -r "$setupVars" ]; then #qqq + if [ -r "$setupVars" ]; then if [[ "${reconfigure}" == true ]]; then echo "::: --reconfigure passed to install script, will reinstall PiVPN overwriting existing settings" UpdateCmd="Reconfigure" @@ -137,7 +137,7 @@ main(){ ### What should the script do when passing --unattended to an existing installation? UpdateCmd="Reconfigure" else - askAboutExistingInstall + askAboutExistingInstall ${setupVars} fi fi @@ -148,7 +148,7 @@ main(){ exit 0 elif [ "$UpdateCmd" = "Repair" ]; then # shellcheck disable=SC1090 - source "$setupVars" #qqq + source "$setupVars" runUnattended=true fi @@ -242,7 +242,7 @@ askAboutExistingInstall(){ opt3a="Reconfigure" opt3b="Reinstall PiVPN with new settings" - UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\nWe have detected an existing install.\n\nPlease choose from the following options:" ${r} ${c} 3 \ + UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\nWe have detected an existing install.\n$1\n\nPlease choose from the following options:" ${r} ${c} 3 \ "${opt1a}" "${opt1b}" \ "${opt2a}" "${opt2b}" \ "${opt3a}" "${opt3b}" 3>&2 2>&1 1>&3) || \ @@ -2235,15 +2235,11 @@ confUnattendedUpgrades(){ installScripts(){ # Install the scripts from /etc/.pivpn to their various locations echo -n -e "::: Installing scripts to ${pivpnScriptDir}...\n" - echo "::: line ${LINENO}" if [ ! -d "${pivpnScriptDir}/${VPN}" ]; then $SUDO install -m 0755 -o root -d ${pivpnScriptDir}/${VPN} -# $SUDO mkdir -p ${pivpnScriptDir}/${VPN} -# $SUDO chown -R root:root ${pivpnScriptDir} -# $SUDO chmod -R 0755 ${pivpnScriptDir} fi - $SUDO install -v -m 755 -t ${pivpnScriptDir} ${pivpnFilesDir}/scripts/*.sh - $SUDO install -v -m 755 -t ${pivpnScriptDir}/${VPN} ${pivpnFilesDir}/scripts/${VPN}/*.sh + $SUDO install -m 755 -t ${pivpnScriptDir} ${pivpnFilesDir}/scripts/*.sh + $SUDO install -m 755 -t ${pivpnScriptDir}/${VPN} ${pivpnFilesDir}/scripts/${VPN}/*.sh # make a link for a single command being installed $SUDO ln -s -T ${pivpnScriptDir}/${VPN}/pivpn.sh /usr/local/bin/pivpn # if the other protocol file exists it has been installed @@ -2255,14 +2251,13 @@ installScripts(){ if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then # dont need a link, copy the common script to the location instead $SUDO rm -f /usr/local/bin/pivpn - $SUDO install -v -m 755 -t /usr/local/bin /${pivpnFilesDir}/scripts/pivpn + $SUDO install -m 755 -t /usr/local/bin /${pivpnFilesDir}/scripts/pivpn fi $SUDO cp "${pivpnFilesDir}/scripts/${VPN}/bash-completion" /etc/bash_completion.d/pivpn $SUDO chown root:root /etc/bash_completion.d/pivpn $SUDO chmod 755 /etc/bash_completion.d/pivpn # shellcheck disable=SC1091 . /etc/bash_completion.d/pivpn - echo "::: line ${LINENO}" echo " done." } From 969cff784831d7eb40f49d14379f7ed4d22d588c Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 10 May 2020 16:42:23 +0000 Subject: [PATCH 14/21] Readme to say dual install --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 503abf6..64d2ae6 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ About ----- -Branch test is a modification that allows installing both openvpn and wireguard on the same machine. To do this, run the installer twice locally, makeing sure you are going to pull branch test. +Modification that allows installing both openvpn and wireguard on the same machine. To do this, run the installer twice locally, makeing sure you are going to pull branch test. Visit the [PiVPN](https://pivpn.io) site for more information. From b230bade61db2ddee7fabc4388f142d3e014aaf6 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 10 May 2020 21:13:03 +0000 Subject: [PATCH 15/21] uninstall fixes --- scripts/uninstall.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 7d53659..12a2675 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -31,7 +31,9 @@ c=$(( c < 70 ? 70 : c )) PKG_MANAGER="apt-get" UPDATE_PKG_CACHE="${PKG_MANAGER} update" dnsmasqConfig="/etc/dnsmasq.d/02-pivpn.conf" -setupVars="/etc/pivpn/${VPN}/setupVars.conf" +setupConfigDir="/etc/pivpn" +setupVarsFile="setupVars.conf" +setupVars="${setupConfigDir}/${VPN}/${setupVarsFile}" if [ ! -f "${setupVars}" ]; then echo "::: Missing setup vars file!" @@ -41,21 +43,11 @@ fi # shellcheck disable=SC1090 source "${setupVars}" -# if the other protocol file exists it has been installed if [[ ${VPN} == 'wireguard' ]]; then othervpn='openvpn' else othervpn='wireguard' fi -vpnStillExists=no -if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then - $SUDO rm -f /usr/local/bin/pivpn - $SUDO ln -s -T ${pivpnScriptDir}/${othervpn}/pivpn.sh /usr/local/bin/pivpn - vpnStillExists=yes - echo ":::" - echo "::: Two VPN protocols exist, you should remove the other one too" - echo ":::" -fi ### FIXME: introduce global lib spinner(){ @@ -190,8 +182,18 @@ removeAll(){ rm -rf /etc/pivpn/${VPN} rmdir /etc/pivpn rm -f /var/log/*pivpn* - rm -rf /usr/local/bin/pivpn/${VPN} - if [ ${vpnStillExists} != 'yes' ]; then + + vpnStillExists='no' + + if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then + $SUDO rm -f /usr/local/bin/pivpn + $SUDO ln -s -T ${pivpnScriptDir}/${othervpn}/pivpn.sh /usr/local/bin/pivpn + vpnStillExists='yes' + echo ":::" + echo "::: Two VPN protocols exist, you should remove the other one too" + echo ":::" + + else rm -f /etc/bash_completion.d/pivpn fi From ff77077d56ca572f270b702ae1fd95bbd70d382e Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 10 May 2020 21:46:54 +0000 Subject: [PATCH 16/21] more uninstall --- scripts/uninstall.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 12a2675..86df98d 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -105,8 +105,22 @@ removeAll(){ fi + vpnStillExists='no' + + if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then + vpnStillExists='yes' + $SUDO rm -f /usr/local/bin/pivpn + $SUDO ln -s -T ${pivpnScriptDir}/${othervpn}/pivpn.sh /usr/local/bin/pivpn + echo ":::" + echo "::: Two VPN protocols exist, you should remove the other one too" + echo ":::" + + else + rm -f /etc/bash_completion.d/pivpn + fi + # Disable IPv4 forwarding - if [ ${vpnStillExists} != 'yes' ]; then + if [ ${vpnStillExists} == 'no' ]; then sed -i '/net.ipv4.ip_forward=1/c\#net.ipv4.ip_forward=1' /etc/sysctl.conf sysctl -p fi @@ -183,20 +197,6 @@ removeAll(){ rmdir /etc/pivpn rm -f /var/log/*pivpn* - vpnStillExists='no' - - if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then - $SUDO rm -f /usr/local/bin/pivpn - $SUDO ln -s -T ${pivpnScriptDir}/${othervpn}/pivpn.sh /usr/local/bin/pivpn - vpnStillExists='yes' - echo ":::" - echo "::: Two VPN protocols exist, you should remove the other one too" - echo ":::" - - else - rm -f /etc/bash_completion.d/pivpn - fi - echo ":::" echo "::: Removing VPN configuration files..." From 56adbca52eeec5bd416e6b388ac661280106f605 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 10 May 2020 21:48:38 +0000 Subject: [PATCH 17/21] more uninstall --- scripts/uninstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 86df98d..8d04cea 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -110,7 +110,7 @@ removeAll(){ if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then vpnStillExists='yes' $SUDO rm -f /usr/local/bin/pivpn - $SUDO ln -s -T ${pivpnScriptDir}/${othervpn}/pivpn.sh /usr/local/bin/pivpn + $SUDO ln -s -T /opt/pivpn/${othervpn}/pivpn.sh /usr/local/bin/pivpn echo ":::" echo "::: Two VPN protocols exist, you should remove the other one too" echo ":::" From be3ee135861140d3d24c8239a073c11f0b5e5cfd Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Mon, 11 May 2020 16:49:10 +0100 Subject: [PATCH 18/21] Update install.sh --- auto_install/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/auto_install/install.sh b/auto_install/install.sh index 09d4a29..0bd80ba 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -9,6 +9,7 @@ # # curl -L https://install.pivpn.io | bash # Make sure you have `curl` installed +# timestamp 2020/5/11 16:48BST ######## VARIABLES ######### #pivpnGitUrl="https://github.com/pivpn/pivpn.git" From 4e3a57b9aa5e6d6b1dc86f6c5b117efe8d0778cf Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Wed, 13 May 2020 00:51:45 +0100 Subject: [PATCH 19/21] better uninstall.sh --- auto_install/install.sh | 4 ++-- scripts/uninstall.sh | 39 +++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 0bd80ba..f92e6a6 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -9,11 +9,11 @@ # # curl -L https://install.pivpn.io | bash # Make sure you have `curl` installed -# timestamp 2020/5/11 16:48BST +# timestamp 2020/5/13 00:51BST ######## VARIABLES ######### #pivpnGitUrl="https://github.com/pivpn/pivpn.git" -pivpnGitUrl="/home/ubuntu/repos/pivpn" +pivpnGitUrl="/home/pi/repos/pivpn" setupVarsFile="setupVars.conf" setupConfigDir="/etc/pivpn" tempsetupVarsFile="/tmp/setupVars.conf" diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 8d04cea..ccdcb56 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -108,12 +108,12 @@ removeAll(){ vpnStillExists='no' if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then - vpnStillExists='yes' - $SUDO rm -f /usr/local/bin/pivpn - $SUDO ln -s -T /opt/pivpn/${othervpn}/pivpn.sh /usr/local/bin/pivpn - echo ":::" - echo "::: Two VPN protocols exist, you should remove the other one too" - echo ":::" + vpnStillExists='yes' + $SUDO rm -f /usr/local/bin/pivpn + $SUDO ln -s -T /opt/pivpn/${othervpn}/pivpn.sh /usr/local/bin/pivpn + echo ":::" + echo "::: Two VPN protocols exist, you should remove ${othervpn} too" + echo ":::" else rm -f /etc/bash_completion.d/pivpn @@ -179,24 +179,12 @@ removeAll(){ printf "::: Auto cleaning remaining dependencies..." $PKG_MANAGER -y autoclean &> /dev/null & spinner $!; printf "done!\\n"; - echo ":::" - # Removing pivpn files - echo "::: Removing pivpn system files..." if [ -f "$dnsmasqConfig" ]; then rm -f "$dnsmasqConfig" pihole restartdns fi - rm -rf /opt/pivpn/${VPN} - # if dual installation, other installation will cause next line to fail - rmdir /opt/pivpn - rm -rf /etc/.pivpn/${VPN} - rmdir /etc/.pivpn - rm -rf /etc/pivpn/${VPN} - rmdir /etc/pivpn - rm -f /var/log/*pivpn* - echo ":::" echo "::: Removing VPN configuration files..." @@ -215,6 +203,21 @@ removeAll(){ rm -rf "$install_home/ovpns" fi + if [ ${vpnStillExists} == 'no' ]; then + echo ":::" + echo "::: Removing pivpn system files..." + rm -rf /etc/.pivpn + rm -rf /etc/pivpn + rm -f /var/log/*pivpn* + rm -rf /opt/pivpn + rm -f /usr/local/bin/pivpn + else + echo ":::" + echo "::: Other protocol still present, so not" + echo "::: removing pivpn system files" + rm -f "${setupConfigDir}/${VPN}/${setupVarsFile}" + fi + echo ":::" printf "::: Finished removing PiVPN from your system.\\n" printf "::: Reinstall by simpling running\\n:::\\n:::\\tcurl -L https://install.pivpn.io | bash\\n:::\\n::: at any time!\\n:::\\n" From e700cf1c8f0a1e2b779fdb3b025324f3a7ce1d62 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 13 May 2020 19:49:48 +0000 Subject: [PATCH 20/21] bash_completion not used in dual --- auto_install/install.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index f92e6a6..e0482fe 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -13,7 +13,7 @@ ######## VARIABLES ######### #pivpnGitUrl="https://github.com/pivpn/pivpn.git" -pivpnGitUrl="/home/pi/repos/pivpn" +pivpnGitUrl="/home/ubuntu/repos/pivpn" setupVarsFile="setupVars.conf" setupConfigDir="/etc/pivpn" tempsetupVarsFile="/tmp/setupVars.conf" @@ -2249,16 +2249,25 @@ installScripts(){ else othervpn='wireguard' fi + if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then + # both are installed # dont need a link, copy the common script to the location instead $SUDO rm -f /usr/local/bin/pivpn $SUDO install -m 755 -t /usr/local/bin /${pivpnFilesDir}/scripts/pivpn fi - $SUDO cp "${pivpnFilesDir}/scripts/${VPN}/bash-completion" /etc/bash_completion.d/pivpn - $SUDO chown root:root /etc/bash_completion.d/pivpn - $SUDO chmod 755 /etc/bash_completion.d/pivpn - # shellcheck disable=SC1091 - . /etc/bash_completion.d/pivpn + + if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then + # both are installed, no bash completion, delete if already there + $SUDO rm -f /etc/bash_completion.d/pivpn + else + # only one protocol is installed, put bash completion in place + $SUDO cp "${pivpnFilesDir}/scripts/${VPN}/bash-completion" /etc/bash_completion.d/pivpn + $SUDO chown root:root /etc/bash_completion.d/pivpn + $SUDO chmod 755 /etc/bash_completion.d/pivpn + # shellcheck disable=SC1091 + . /etc/bash_completion.d/pivpn + fi echo " done." } From d4b3c9ee897a8c8d3608e73ff1b616f0488a8110 Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Thu, 14 May 2020 15:32:19 +0100 Subject: [PATCH 21/21] both wg and openvpn can be installed --- auto_install/install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index e0482fe..200fa76 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -9,11 +9,12 @@ # # curl -L https://install.pivpn.io | bash # Make sure you have `curl` installed -# timestamp 2020/5/13 00:51BST + +# timestamp 2020/5/14 15:29BST ######## VARIABLES ######### -#pivpnGitUrl="https://github.com/pivpn/pivpn.git" -pivpnGitUrl="/home/ubuntu/repos/pivpn" +pivpnGitUrl="https://github.com/pivpn/pivpn.git" +#pivpnGitUrl="/home/ubuntu/repos/pivpn" setupVarsFile="setupVars.conf" setupConfigDir="/etc/pivpn" tempsetupVarsFile="/tmp/setupVars.conf"