mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-18 10:50:16 +00:00
Improved dual VPN uninstallation, remove duplicate code/script
- Allow using 'pivpn vpn -u' to directly uninstall VPN 'vpn' - Also allow using 'pivpn -u' with two VPNs (will present a dialog). - During uninstall, ask which VPN to remove only if there are two VPNs - PiVPN git repo will be downloaded to '/usr/local/src/pivpn'. All scripts in /opt/pivpn, the main pivpn script and the bash completion file, are now just symbolic links. Resolves issue #695. - Remove unused call to updateWireGuard().
This commit is contained in:
parent
1dc10e7d54
commit
823afa3fbb
8 changed files with 121 additions and 137 deletions
|
@ -18,7 +18,7 @@ pivpnGitUrl="https://github.com/pivpn/pivpn.git"
|
|||
setupVarsFile="setupVars.conf"
|
||||
setupConfigDir="/etc/pivpn"
|
||||
tempsetupVarsFile="/tmp/setupVars.conf"
|
||||
pivpnFilesDir="/etc/.pivpn"
|
||||
pivpnFilesDir="/usr/local/src/pivpn"
|
||||
pivpnScriptDir="/opt/pivpn"
|
||||
|
||||
piholeSetupVars="/etc/pihole/setupVars.conf"
|
||||
|
@ -950,11 +950,11 @@ updateRepo(){
|
|||
### FIXME: Never call rm -rf with a plain variable. Never again as SU!
|
||||
#$SUDO rm -rf "${1}"
|
||||
if test -n "$1"; then
|
||||
$SUDO rm -rf "$(dirname "$1")/.pivpn"
|
||||
$SUDO rm -rf "$(dirname "$1")/pivpn"
|
||||
fi
|
||||
# Go back to /etc otherwise git will complain when the current working
|
||||
# directory has just been deleted (/etc/.pivpn).
|
||||
cd /etc && \
|
||||
# Go back to /usr/local/src otherwise git will complain when the current working
|
||||
# directory has just been deleted (/usr/local/src/pivpn).
|
||||
cd /usr/local/src && \
|
||||
$SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $!
|
||||
cd "${1}" || exit 1
|
||||
if [ -z "${TESTING+x}" ]; then
|
||||
|
@ -972,11 +972,11 @@ makeRepo(){
|
|||
### FIXME: Never call rm -rf with a plain variable. Never again as SU!
|
||||
#$SUDO rm -rf "${1}"
|
||||
if test -n "$1"; then
|
||||
$SUDO rm -rf "$(dirname "$1")/.pivpn"
|
||||
$SUDO rm -rf "$(dirname "$1")/pivpn"
|
||||
fi
|
||||
# Go back to /etc otherwhise git will complain when the current working
|
||||
# directory has just been deleted (/etc/.pivpn).
|
||||
cd /etc && \
|
||||
# Go back to /usr/local/src otherwhise git will complain when the current working
|
||||
# directory has just been deleted (/usr/local/src/pivpn).
|
||||
cd /usr/local/src && \
|
||||
$SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $!
|
||||
cd "${1}" || exit 1
|
||||
if [ -z "${TESTING+x}" ]; then
|
||||
|
@ -2224,43 +2224,34 @@ confUnattendedUpgrades(){
|
|||
}
|
||||
|
||||
installScripts(){
|
||||
# Install the scripts from /etc/.pivpn to their various locations
|
||||
echo -n -e "::: Installing scripts to ${pivpnScriptDir}...\n"
|
||||
if [ ! -d "${pivpnScriptDir}/${VPN}" ]; then
|
||||
$SUDO install -m 0755 -o root -d ${pivpnScriptDir}/${VPN}
|
||||
fi
|
||||
$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
|
||||
# may already exist if installing the second protocol
|
||||
if [ ! -e "/usr/local/bin/pivpn" ]; then
|
||||
$SUDO ln -s -T ${pivpnScriptDir}/${VPN}/pivpn.sh /usr/local/bin/pivpn
|
||||
fi
|
||||
# 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
|
||||
# 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
|
||||
|
||||
if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then
|
||||
# both are installed, no bash completion, delete if already there
|
||||
$SUDO rm -f /etc/bash_completion.d/pivpn
|
||||
if [[ ${VPN} == 'wireguard' ]]; then
|
||||
othervpn='openvpn'
|
||||
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
|
||||
othervpn='wireguard'
|
||||
fi
|
||||
|
||||
# Symlink scripts from /usr/local/src/pivpn to their various locations
|
||||
echo -n -e "::: Installing scripts to ${pivpnScriptDir}...\n"
|
||||
|
||||
# if the other protocol file exists it has been installed
|
||||
if [ -r "${setupConfigDir}/${othervpn}/${setupVarsFile}" ]; then
|
||||
# Both are installed, no bash completion, unlink if already there
|
||||
$SUDO unlink /etc/bash_completion.d/pivpn
|
||||
|
||||
# Unlink the protocol specific pivpn script and symlink the common
|
||||
# script to the location instead
|
||||
$SUDO unlink /usr/local/bin/pivpn
|
||||
$SUDO ln -s -T "${pivpnFilesDir}/scripts/pivpn" /usr/local/bin/pivpn
|
||||
else
|
||||
# Only one protocol is installed, symlink bash completion, the pivpn script
|
||||
# and the script directory
|
||||
$SUDO ln -s -T "${pivpnFilesDir}/scripts/${VPN}/bash-completion" /etc/bash_completion.d/pivpn
|
||||
$SUDO ln -s -T "${pivpnFilesDir}/scripts/${VPN}/pivpn.sh" /usr/local/bin/pivpn
|
||||
$SUDO ln -s "${pivpnFilesDir}/scripts/" "${pivpnScriptDir}"
|
||||
# shellcheck disable=SC1091
|
||||
. /etc/bash_completion.d/pivpn
|
||||
fi
|
||||
|
||||
echo " done."
|
||||
}
|
||||
|
||||
|
|
|
@ -47,30 +47,19 @@ function removeOVPNFunc {
|
|||
}
|
||||
|
||||
function uninstallFunc {
|
||||
$SUDO ${scriptDir}/uninstall.sh
|
||||
$SUDO ${scriptDir}/uninstall.sh "${vpn}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
function versionFunc {
|
||||
printf "\e[1mVersion 1.9\e[0m\n"
|
||||
}
|
||||
|
||||
function update {
|
||||
|
||||
shift
|
||||
# $SUDO ${scriptDir}/update.sh "$@"
|
||||
echo "::: The updating functionality for PiVPN scripts is temporarily disabled"
|
||||
echo "::: To keep the VPN (and the system) up to date, use 'apt update' and 'apt upgrade'"
|
||||
$SUDO ${scriptDir}/update.sh "$@"
|
||||
exit 0
|
||||
|
||||
|
||||
}
|
||||
|
||||
function backup {
|
||||
|
||||
$SUDO ${scriptDir}/backup.sh
|
||||
exit 0
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,7 +94,6 @@ case "$1" in
|
|||
"-r" | "revoke" ) removeOVPNFunc "$@";;
|
||||
"-h" | "help" ) helpFunc;;
|
||||
"-u" | "uninstall" ) uninstallFunc;;
|
||||
"-v" ) versionFunc;;
|
||||
"-up"| "update" ) update "$@" ;;
|
||||
"-bk"| "backup" ) backup;;
|
||||
* ) helpFunc;;
|
||||
|
|
|
@ -13,7 +13,7 @@ source "${setupVars}"
|
|||
echo -e "::::\t\t\e[4mPiVPN debug\e[0m\t\t ::::"
|
||||
printf "=============================================\n"
|
||||
echo -e "::::\t\t\e[4mLatest commit\e[0m\t\t ::::"
|
||||
git --git-dir /etc/.pivpn/.git log -n 1
|
||||
git --git-dir /usr/local/src/pivpn/.git log -n 1
|
||||
printf "=============================================\n"
|
||||
echo -e "::::\t \e[4mInstallation settings\e[0m \t ::::"
|
||||
sed "s/$pivpnHOST/REDACTED/" < ${setupVars}
|
||||
|
|
|
@ -11,7 +11,11 @@ if [ $EUID -ne 0 ];then
|
|||
fi
|
||||
|
||||
scriptDir="/opt/pivpn"
|
||||
vpn="wireguard"
|
||||
|
||||
uninstallServer(){
|
||||
$SUDO ${scriptDir}/uninstall.sh
|
||||
exit 0
|
||||
}
|
||||
|
||||
showHelp(){
|
||||
echo "::: To pass off to the pivpn command for each protocol"
|
||||
|
@ -20,6 +24,7 @@ showHelp(){
|
|||
echo "::: Usage: pivpn ovpn <command> [option]"
|
||||
echo ":::"
|
||||
echo "::: -h, help Show this help dialog"
|
||||
echo "::: -u, uninstall Uninstall pivpn from your system!"
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
@ -32,5 +37,6 @@ case "$1" in
|
|||
wg ) "${scriptDir}/wireguard/pivpn.sh" "${@:2}";;
|
||||
ovpn ) "${scriptDir}/openvpn/pivpn.sh" "${@:2}";;
|
||||
"-h" | "help" ) showHelp;;
|
||||
"-u" | "uninstall" ) uninstallServer;;
|
||||
* ) showHelp;;
|
||||
esac
|
||||
|
|
|
@ -4,24 +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.
|
||||
|
||||
# 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.
|
||||
screen_size=$(stty size 2>/dev/null || echo 24 80)
|
||||
rows=$(echo "$screen_size" | awk '{print $1}')
|
||||
|
@ -34,24 +16,46 @@ 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 (${foundins}) 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"
|
||||
setupConfigDir="/etc/pivpn"
|
||||
setupVarsFile="setupVars.conf"
|
||||
setupVars="${setupConfigDir}/${VPN}/${setupVarsFile}"
|
||||
setupConfigDir="/etc/pivpn"
|
||||
pivpnFilesDir="/usr/local/src/pivpn"
|
||||
pivpnScriptDir="/opt/pivpn"
|
||||
|
||||
if [ -r "${setupConfigDir}/wireguard/${setupVarsFile}" ] && [ -r "${setupConfigDir}/openvpn/${setupVarsFile}" ]; then
|
||||
vpnStillExists=1
|
||||
|
||||
# Two protocols have been installed, check if the script has passed
|
||||
# an argument, otherwise ask the user which one he wants to remove
|
||||
if [ $# -ge 1 ]; then
|
||||
VPN="$1"
|
||||
echo "::: Uninstalling VPN: $VPN"
|
||||
else
|
||||
chooseVPNCmd=(whiptail --backtitle "Setup PiVPN" --title "Uninstall" --separate-output --radiolist "Both OpenVPN and WireGuard are installed, choose 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 "::: Uninstalling VPN: $VPN"
|
||||
VPN="${VPN,,}"
|
||||
else
|
||||
echo "::: Cancel selected, exiting...."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
setupVars="${setupConfigDir}/${VPN}/${setupVarsFile}"
|
||||
else
|
||||
vpnStillExists=0
|
||||
|
||||
if [ -r "${setupConfigDir}/wireguard/${setupVarsFile}" ]; then
|
||||
setupVars="${setupConfigDir}/wireguard/${setupVarsFile}"
|
||||
elif [ -r "${setupConfigDir}/openvpn/${setupVarsFile}" ]; then
|
||||
setupVars="${setupConfigDir}/openvpn/${setupVarsFile}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f "${setupVars}" ]; then
|
||||
echo "::: Missing setup vars file!"
|
||||
|
@ -61,12 +65,6 @@ fi
|
|||
# shellcheck disable=SC1090
|
||||
source "${setupVars}"
|
||||
|
||||
if [[ ${VPN} == 'wireguard' ]]; then
|
||||
othervpn='openvpn'
|
||||
else
|
||||
othervpn='wireguard'
|
||||
fi
|
||||
|
||||
### FIXME: introduce global lib
|
||||
spinner(){
|
||||
local pid=$1
|
||||
|
@ -123,25 +121,11 @@ removeAll(){
|
|||
|
||||
fi
|
||||
|
||||
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 ${othervpn} too"
|
||||
echo ":::"
|
||||
|
||||
else
|
||||
rm -f /etc/bash_completion.d/pivpn
|
||||
fi
|
||||
|
||||
# Disable IPv4 forwarding
|
||||
if [ ${vpnStillExists} == 'no' ]; then
|
||||
sed -i '/net.ipv4.ip_forward=1/c\#net.ipv4.ip_forward=1' /etc/sysctl.conf
|
||||
sysctl -p
|
||||
fi
|
||||
if [ "${vpnStillExists}" -eq 0 ]; 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..."
|
||||
|
@ -221,20 +205,34 @@ 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
|
||||
if [ "${vpnStillExists}" -eq 0 ]; then
|
||||
echo ":::"
|
||||
echo "::: Removing pivpn system files..."
|
||||
rm -rf "${setupConfigDir}"
|
||||
rm -rf "${pivpnFilesDir}"
|
||||
rm -f /var/log/*pivpn*
|
||||
rm -f /etc/bash_completion.d/pivpn
|
||||
unlink "${pivpnScriptDir}"
|
||||
unlink /usr/local/bin/pivpn
|
||||
else
|
||||
if [[ ${VPN} == 'wireguard' ]]; then
|
||||
othervpn='openvpn'
|
||||
else
|
||||
othervpn='wireguard'
|
||||
fi
|
||||
|
||||
echo ":::"
|
||||
echo "::: Other VPN ${othervpn} still present, so not"
|
||||
echo "::: removing pivpn system files"
|
||||
rm -f "${setupConfigDir}/${VPN}/${setupVarsFile}"
|
||||
|
||||
# Restore single pivpn script and bash completion for the remaining VPN
|
||||
$SUDO unlink /usr/local/bin/pivpn
|
||||
$SUDO ln -s -T "${pivpnFilesDir}/scripts/${othervpn}/pivpn.sh" /usr/local/bin/pivpn
|
||||
$SUDO ln -s -T "${pivpnFilesDir}/scripts/${othervpn}/bash-completion" /etc/bash_completion.d/pivpn
|
||||
# shellcheck disable=SC1091
|
||||
. /etc/bash_completion.d/pivpn
|
||||
fi
|
||||
|
||||
echo ":::"
|
||||
printf "::: Finished removing PiVPN from your system.\\n"
|
||||
|
|
|
@ -19,6 +19,10 @@ c=$(( columns / 2 ))
|
|||
r=$(( r < 20 ? 20 : r ))
|
||||
c=$(( c < 70 ? 70 : c ))
|
||||
|
||||
echo "::: The updating functionality for PiVPN scripts is temporarily disabled"
|
||||
echo "::: To keep the VPN (and the system) up to date, use 'apt update' and 'apt upgrade'"
|
||||
exit 0
|
||||
|
||||
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)
|
||||
|
|
|
@ -48,15 +48,13 @@ removeClient(){
|
|||
}
|
||||
|
||||
uninstallServer(){
|
||||
$SUDO ${scriptdir}/uninstall.sh
|
||||
$SUDO ${scriptdir}/uninstall.sh "${vpn}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
updateScripts(){
|
||||
shift
|
||||
# $SUDO ${scriptdir}/update.sh "$@"
|
||||
echo "::: The updating functionality for PiVPN scripts is temporarily disabled"
|
||||
echo "::: To keep the VPN (and the system) up to date, use 'apt update' and 'apt upgrade'"
|
||||
$SUDO ${scriptdir}/update.sh "$@"
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
@ -98,7 +96,6 @@ case "$1" in
|
|||
"-h" | "help" ) showHelp;;
|
||||
"-u" | "uninstall" ) uninstallServer;;
|
||||
"-up" | "update" ) updateScripts "$@" ;;
|
||||
"-wg" | "wgupdate" ) updateWireGuard ;;
|
||||
"-bk" | "backup" ) backup ;;
|
||||
* ) showHelp;;
|
||||
esac
|
||||
|
|
|
@ -13,7 +13,7 @@ source "${setupVars}"
|
|||
echo -e "::::\t\t\e[4mPiVPN debug\e[0m\t\t ::::"
|
||||
printf "=============================================\n"
|
||||
echo -e "::::\t\t\e[4mLatest commit\e[0m\t\t ::::"
|
||||
git --git-dir /etc/.pivpn/.git log -n 1
|
||||
git --git-dir /usr/local/src/pivpn/.git log -n 1
|
||||
printf "=============================================\n"
|
||||
echo -e "::::\t \e[4mInstallation settings\e[0m \t ::::"
|
||||
sed "s/$pivpnHOST/REDACTED/" < ${setupVars}
|
||||
|
|
Loading…
Reference in a new issue