remove refs to /etc/pivpn/setupVars in selfcheck and debug scripts

tidy indenting
  on install, check if symlink already exists before making one to avoid error
  uninstall indicates which vpns are available for uninstall
  selfcheck checks both protocols if both present
  install - additional text in reconfigure saying 2nd protocol can be added
  change to use pivpn ovpn instaed of pivpn opv when dual protocols exist
This commit is contained in:
shelleycat485 2020-05-22 12:41:02 +01:00
parent e3363a7d98
commit b90077bd78
5 changed files with 86 additions and 37 deletions

View file

@ -16,7 +16,7 @@ echo -e "::::\t\t\e[4mLatest commit\e[0m\t\t ::::"
git --git-dir /etc/.pivpn/.git log -n 1 git --git-dir /etc/.pivpn/.git log -n 1
printf "=============================================\n" printf "=============================================\n"
echo -e "::::\t \e[4mInstallation settings\e[0m \t ::::" echo -e "::::\t \e[4mInstallation settings\e[0m \t ::::"
sed "s/$pivpnHOST/REDACTED/" < /etc/pivpn/setupVars.conf sed "s/$pivpnHOST/REDACTED/" < ${setupVars}
printf "=============================================\n" printf "=============================================\n"
echo -e ":::: \e[4mServer configuration shown below\e[0m ::::" echo -e ":::: \e[4mServer configuration shown below\e[0m ::::"
cat /etc/openvpn/server.conf cat /etc/openvpn/server.conf

View file

@ -3,11 +3,11 @@
# Must be root to use this tool # Must be root to use this tool
if [ $EUID -ne 0 ];then if [ $EUID -ne 0 ];then
if dpkg-query -s sudo &> /dev/null; then if dpkg-query -s sudo &> /dev/null; then
export SUDO="sudo" export SUDO="sudo"
else else
echo "::: Please install sudo or run this as root." echo "::: Please install sudo or run this as root."
exit 1 exit 1
fi fi
fi fi
scriptDir="/opt/pivpn" scriptDir="/opt/pivpn"
@ -17,7 +17,7 @@ showHelp(){
echo "::: To pass off to the pivpn command for each protocol" echo "::: To pass off to the pivpn command for each protocol"
echo ":::" echo ":::"
echo "::: Usage: pivpn wg <command> [option]" echo "::: Usage: pivpn wg <command> [option]"
echo "::: Usage: pivpn opv <command> [option]" echo "::: Usage: pivpn ovpn <command> [option]"
echo ":::" echo ":::"
echo "::: -h, help Show this help dialog" echo "::: -h, help Show this help dialog"
exit 0 exit 0
@ -30,7 +30,7 @@ fi
# Handle redirecting to specific functions based on arguments # Handle redirecting to specific functions based on arguments
case "$1" in case "$1" in
wg ) "${scriptDir}/wireguard/pivpn.sh" "${@:2}";; wg ) "${scriptDir}/wireguard/pivpn.sh" "${@:2}";;
opv ) "${scriptDir}/openvpn/pivpn.sh" "${@:2}";; ovpn ) "${scriptDir}/openvpn/pivpn.sh" "${@:2}";;
"-h" | "help" ) showHelp;; "-h" | "help" ) showHelp;;
* ) showHelp;; * ) showHelp;;
esac esac

View file

@ -1,13 +1,7 @@
#!/bin/bash #!/bin/bash
setupVars="/etc/pivpn/setupVars.conf" runselfcheck()
ERR=0 {
if [ ! -f "${setupVars}" ]; then
echo "::: Missing setup vars file!"
exit 1
fi
source "${setupVars}" source "${setupVars}"
if [ "$VPN" = "wireguard" ]; then if [ "$VPN" = "wireguard" ]; then
@ -162,3 +156,40 @@ fi
if [ "$ERR" -eq 1 ]; then if [ "$ERR" -eq 1 ]; then
echo -e "[INFO] Run \e[1mpivpn -d\e[0m again to see if we detect issues" echo -e "[INFO] Run \e[1mpivpn -d\e[0m again to see if we detect issues"
fi fi
} # end function
# now there are two places setupVars.conf can be, so check each one
dualprot='no'
setupVars="/etc/pivpn/wireguard/setupVars.conf"
ERR=0
if [ ! -f "${setupVars}" ]; then
echo "::: Missing ${setupVars}i, wireguard not installed"
else
echo "::: Selfcheck for wireguard, config from ${setupVars}"
runselfcheck
dualprot='yes'
fi
setupVars="/etc/pivpn/openvpn/setupVars.conf"
ERR=0
if [ ! -f "${setupVars}" ]; then
echo "::: Missing ${setupVars}, openvpn not installed"
else
echo "::: Selfcheck for openvpn, config from ${setupVars}"
runselfcheck
dualprot='yes'
fi
# add check for a mixed up installation
setupVars="/etc/pivpn/setupVars.conf"
if [ ${dualprot} == 'yes' && -f "${setupVars}" ]; then
echo "::: Older ${setupVars} exists, should not be there,
echo "::: two versions have been installed which are not compatible"
fi

View file

@ -4,6 +4,24 @@
### FIXME: global: config storage, refactor all scripts to adhere to the storage ### 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. ### FIXME: use variables where appropriate, reduce magic numbers by 99.9%, at least.
# what is already installed?
setupVars="/etc/pivpn/openvpn/setupVars.conf"
foundins=''
if [ -f "${setupVars}" ]; then
foundins="openvpn"
fi
setupVars="/etc/pivpn/wireguard/setupVars.conf"
if [ -f "${setupVars}" ]; then
foundins="${foundins} wireguard"
fi
if [ -z ${foundins} ]; then
foundins="nothing found"
fi
# Find the rows and columns. Will default to 80x24 if it can not be detected. # 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) screen_size=$(stty size 2>/dev/null || echo 24 80)
rows=$(echo "$screen_size" | awk '{print $1}') rows=$(echo "$screen_size" | awk '{print $1}')
@ -16,7 +34,7 @@ c=$(( columns / 2 ))
r=$(( r < 20 ? 20 : r )) r=$(( r < 20 ? 20 : r ))
c=$(( c < 70 ? 70 : c )) 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) 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 (${foundins}) to uninstall (press space to select):" "${r}" "${c}" 2)
VPNChooseOptions=(WireGuard "" on VPNChooseOptions=(WireGuard "" on
OpenVPN "" off) OpenVPN "" off)
@ -108,21 +126,21 @@ removeAll(){
vpnStillExists='no' vpnStillExists='no'
if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then
vpnStillExists='yes' vpnStillExists='yes'
$SUDO rm -f /usr/local/bin/pivpn $SUDO rm -f /usr/local/bin/pivpn
$SUDO ln -s -T /opt/pivpn/${othervpn}/pivpn.sh /usr/local/bin/pivpn $SUDO ln -s -T /opt/pivpn/${othervpn}/pivpn.sh /usr/local/bin/pivpn
echo ":::" echo ":::"
echo "::: Two VPN protocols exist, you should remove ${othervpn} too" echo "::: Two VPN protocols exist, you should remove ${othervpn} too"
echo ":::" echo ":::"
else else
rm -f /etc/bash_completion.d/pivpn rm -f /etc/bash_completion.d/pivpn
fi fi
# Disable IPv4 forwarding # Disable IPv4 forwarding
if [ ${vpnStillExists} == 'no' ]; then if [ ${vpnStillExists} == 'no' ]; then
sed -i '/net.ipv4.ip_forward=1/c\#net.ipv4.ip_forward=1' /etc/sysctl.conf sed -i '/net.ipv4.ip_forward=1/c\#net.ipv4.ip_forward=1' /etc/sysctl.conf
sysctl -p sysctl -p
fi fi
# Purge dependencies # Purge dependencies
@ -204,18 +222,18 @@ removeAll(){
fi fi
if [ ${vpnStillExists} == 'no' ]; then if [ ${vpnStillExists} == 'no' ]; then
echo ":::" echo ":::"
echo "::: Removing pivpn system files..." echo "::: Removing pivpn system files..."
rm -rf /etc/.pivpn rm -rf /etc/.pivpn
rm -rf /etc/pivpn rm -rf /etc/pivpn
rm -f /var/log/*pivpn* rm -f /var/log/*pivpn*
rm -rf /opt/pivpn rm -rf /opt/pivpn
rm -f /usr/local/bin/pivpn rm -f /usr/local/bin/pivpn
else else
echo ":::" echo ":::"
echo "::: Other protocol still present, so not" echo "::: Other protocol still present, so not"
echo "::: removing pivpn system files" echo "::: removing pivpn system files"
rm -f "${setupConfigDir}/${VPN}/${setupVarsFile}" rm -f "${setupConfigDir}/${VPN}/${setupVarsFile}"
fi fi
echo ":::" echo ":::"

View file

@ -16,7 +16,7 @@ echo -e "::::\t\t\e[4mLatest commit\e[0m\t\t ::::"
git --git-dir /etc/.pivpn/.git log -n 1 git --git-dir /etc/.pivpn/.git log -n 1
printf "=============================================\n" printf "=============================================\n"
echo -e "::::\t \e[4mInstallation settings\e[0m \t ::::" echo -e "::::\t \e[4mInstallation settings\e[0m \t ::::"
sed "s/$pivpnHOST/REDACTED/" < /etc/pivpn/setupVars.conf sed "s/$pivpnHOST/REDACTED/" < ${setupVars}
printf "=============================================\n" printf "=============================================\n"
echo -e ":::: \e[4mServer configuration shown below\e[0m ::::" echo -e ":::: \e[4mServer configuration shown below\e[0m ::::"
cd /etc/wireguard/keys cd /etc/wireguard/keys