mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-19 19:30:16 +00:00
install and uninstall
This commit is contained in:
parent
f379ca2e10
commit
3ed9ec5724
2 changed files with 65 additions and 30 deletions
|
@ -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."
|
||||
}
|
||||
|
||||
|
|
|
@ -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 ":::"
|
||||
|
|
Loading…
Reference in a new issue