initial dual install try

This commit is contained in:
root 2020-04-28 23:44:56 +01:00
parent e66e2c6513
commit f379ca2e10
9 changed files with 95 additions and 79 deletions

View file

@ -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

View file

@ -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"

View file

@ -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
}

View file

@ -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!"

View file

@ -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

View file

@ -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!"

View file

@ -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(){

View file

@ -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!"

View file

@ -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!"