install and uninstall

This commit is contained in:
shelleycat485 2020-05-02 00:06:09 +01:00
parent f379ca2e10
commit 3ed9ec5724
2 changed files with 65 additions and 30 deletions

View file

@ -11,11 +11,13 @@
# Make sure you have `curl` installed # Make sure you have `curl` installed
######## VARIABLES ######### ######## VARIABLES #########
pivpnGitUrl="https://github.com/pivpn/pivpn.git" #pivpnGitUrl="https://github.com/pivpn/pivpn.git"
pivpnGitUrl="/root/repos/pivpn"
setupVarsFile="setupVars.conf" setupVarsFile="setupVars.conf"
setupConfigDir="/etc/pivpn" # will be /etc/pivpn/${VPN}/setupVars.conf setupConfigDir="/etc/pivpn" # will be /etc/pivpn/${VPN}/setupVars.conf
tempsetupVarsFile="/tmp/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" piholeSetupVars="/etc/pihole/setupVars.conf"
dnsmasqConfig="/etc/dnsmasq.d/02-pivpn.conf" dnsmasqConfig="/etc/dnsmasq.d/02-pivpn.conf"
@ -142,7 +144,7 @@ main(){
if [ -z "$UpdateCmd" ] || [ "$UpdateCmd" = "Reconfigure" ]; then if [ -z "$UpdateCmd" ] || [ "$UpdateCmd" = "Reconfigure" ]; then
: :
elif [ "$UpdateCmd" = "Update" ]; then elif [ "$UpdateCmd" = "Update" ]; then
$SUDO /opt/pivpn/update.sh "$@" $SUDO ${pivpnScriptDir}/update.sh "$@"
exit 0 exit 0
elif [ "$UpdateCmd" = "Repair" ]; then elif [ "$UpdateCmd" = "Repair" ]; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
@ -213,7 +215,8 @@ main(){
# Save installation setting to the final location # Save installation setting to the final location
echo "INSTALLED_PACKAGES=(${INSTALLED_PACKAGES[*]})" >> ${tempsetupVarsFile} 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}" $SUDO cp ${tempsetupVarsFile} "${setupConfigDir}/${VPN}/${setupVarsFile}"
installScripts installScripts
@ -999,6 +1002,7 @@ getGitFiles(){
} }
cloneOrUpdateRepos(){ cloneOrUpdateRepos(){
pivpnFilesDir="${pivpnFilesDir}/${VPN}"
# Get Git files # Get Git files
getGitFiles ${pivpnFilesDir} ${pivpnGitUrl} || \ getGitFiles ${pivpnFilesDir} ${pivpnGitUrl} || \
{ echo "!!! Unable to clone ${pivpnGitUrl} into ${pivpnFilesDir}, unable to continue."; \ { echo "!!! Unable to clone ${pivpnGitUrl} into ${pivpnFilesDir}, unable to continue."; \
@ -2232,19 +2236,33 @@ confUnattendedUpgrades(){
installScripts(){ installScripts(){
# Install the scripts from /etc/.pivpn to their various locations # Install the scripts from /etc/.pivpn to their various locations
echo ":::" echo ":::"
echo -n -e "::: Installing scripts to /opt/pivpn...\n" echo "::: line ${LINENO}"
if [ ! -d /opt/pivpn ]; then echo -n -e "::: Installing scripts to ${pivpnScriptDir}...\n"
$SUDO mkdir -p /opt/pivpn echo "::: line ${LINENO}"
$SUDO chown root:root /opt/pivpn if [ ! -d "${pivpnScriptDir}/${VPN}" ]; then
$SUDO chmod 0755 /opt/pivpn $SUDO mkdir -p ${pivpnScriptDir}/${VPN}
$SUDO chown -R root:root ${pivpnScriptDir}
$SUDO chmod -R 0755 ${pivpnScriptDir}
fi fi
$SUDO install -m 755 "$pivpnFilesDir"/scripts/*.sh -t /opt/pivpn $SUDO install -m 755 "${pivpnFilesDir}"/scripts/*.sh -t ${pivpnScriptDir}
$SUDO install -m 755 "$pivpnFilesDir"/scripts/"$VPN"/*.sh -t /opt/pivpn/${VPN} $SUDO install -m 755 "${pivpnFilesDir}/scripts/${VPN}"/*.sh -t ${pivpnScriptDir}/${VPN}
$SUDO install -m 755 "$pivpnFilesDir"/scripts/"$VPN"/pivpn /usr/local/bin/pivpn/${VPN} echo "::: line ${LINENO}"
$SUDO install -m 644 "$pivpnFilesDir"/scripts/"$VPN"/bash-completion /etc/bash_completion.d/pivpn $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 # shellcheck disable=SC1091
echo "::: line ${LINENO}"
. /etc/bash_completion.d/pivpn . /etc/bash_completion.d/pivpn
echo "::: line ${LINENO}"
echo " done." echo " done."
} }

View file

@ -4,19 +4,6 @@
### 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.
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. # 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}')
@ -29,6 +16,31 @@ 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)
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 ### FIXME: introduce global lib
spinner(){ spinner(){
local pid=$1 local pid=$1
@ -152,11 +164,16 @@ removeAll(){
pihole restartdns pihole restartdns
fi fi
rm -rf /opt/pivpn rm -rf /opt/pivpn/${VPN}
rm -rf /etc/.pivpn # if dual installation, other installation will cause next line to fail
rm -rf /etc/pivpn 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 /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 rm -f /etc/bash_completion.d/pivpn
echo ":::" echo ":::"