diff --git a/auto_install/install.sh b/auto_install/install.sh index 0379e82..166b501 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -125,8 +125,8 @@ main(){ if [ -z "$UpdateCmd" ] || [ "$UpdateCmd" = "Reconfigure" ]; then : elif [ "$UpdateCmd" = "Update" ]; then - ### To do: test the update script and implement update for WireGuard as well - $SUDO /opt/pivpn/update.sh + $SUDO /opt/pivpn/update.sh "$@" + exit 0 elif [ "$UpdateCmd" = "Repair" ]; then source "$setupVars" runUnattended=true diff --git a/scripts/openvpn/update.sh b/scripts/update.sh similarity index 68% rename from scripts/openvpn/update.sh rename to scripts/update.sh index 5203b65..3f63c2a 100755 --- a/scripts/openvpn/update.sh +++ b/scripts/update.sh @@ -6,7 +6,14 @@ pivpnrepo="https://github.com/pivpn/pivpn.git" pivpnlocalpath="/etc/.pivpn" pivpnscripts="/opt/pivpn/" bashcompletiondir="/etc/bash_completion.d/" +setupVars="/etc/pivpn/setupVars.conf" +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +source "${setupVars}" ###Functions ##Updates scripts @@ -16,7 +23,7 @@ updatepivpnscripts(){ echo "going do update PiVPN Scripts" if [[ -d "$pivpnlocalpath" ]]; then if [[ -n "$pivpnlocalpath" ]]; then - sudo rm -rf "${pivpnlocalpath}/../.pivpn" + rm -rf "${pivpnlocalpath}/../.pivpn" cloneandupdate fi else @@ -32,7 +39,7 @@ updatefromtest(){ echo "PiVPN Scripts updating from test branch" if [[ -d "$pivpnlocalpath" ]]; then if [[ -n "$pivpnlocalpath" ]]; then - rm -rf "{$pivpnlocalpath}/../.pivpn" + rm -rf "${pivpnlocalpath}/../.pivpn" cloneupdttest fi else @@ -41,22 +48,23 @@ updatefromtest(){ echo "PiVPN Scripts updated have been updated from test branch" } -##Clone and copy pivpn scripts to /op/ +##Clone and copy pivpn scripts to /opt/pivpn cloneandupdate(){ - sudo git clone "$pivpnrepo" "$pivpnlocalpath" - sudo cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" - sudo cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir" + git clone "$pivpnrepo" "$pivpnlocalpath" + cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" + cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir" } ##same as cloneandupdate() but from test branch ##and falls back to master branch again after updating cloneupdttest(){ - sudo git clone "$pivpnrepo" "$pivpnlocalpath" - sudo git -C "$pivpnlocalpath" checkout test - sudo git -C "$pivpnlocalpath" pull origin test - sudo cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" - sudo cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir" - sudo git -C "$pivpnlocalpath" checkout master + git clone "$pivpnrepo" "$pivpnlocalpath" + git -C "$pivpnlocalpath" checkout test + git -C "$pivpnlocalpath" pull origin test + cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" + cp "${pivpnlocalpath}"/scripts/$VPN/*.sh "$pivpnscripts" + cp "${pivpnlocalpath}"/scripts/$VPN/bash-completion "$bashcompletiondir" + git -C "$pivpnlocalpath" checkout master } scriptusage(){ diff --git a/scripts/wireguard/bash-completion b/scripts/wireguard/bash-completion index 9eb591e..ff434c3 100644 --- a/scripts/wireguard/bash-completion +++ b/scripts/wireguard/bash-completion @@ -4,8 +4,8 @@ _pivpn() COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - dashopts="-a -c -d -l -qr -r -h -u" - opts="add clients debug list qrcode remove help uninstall" + dashopts="-a -c -d -l -qr -r -h -u -up" + opts="add clients debug list qrcode remove help uninstall update" if [ "${#COMP_WORDS[@]}" -eq 2 ] then if [[ ${cur} == -* ]] ; then diff --git a/scripts/wireguard/pivpn b/scripts/wireguard/pivpn index 3f96004..f3a14c9 100755 --- a/scripts/wireguard/pivpn +++ b/scripts/wireguard/pivpn @@ -48,6 +48,12 @@ uninstallServer(){ exit 0 } +updateScripts(){ + shift + $SUDO /opt/pivpn/update.sh "$@" + exit 0 +} + showHelp(){ echo "::: Control all PiVPN specific functions!" echo ":::" @@ -62,6 +68,7 @@ showHelp(){ echo "::: -r, remove Remove a client" echo "::: -h, help Show this help dialog" echo "::: -u, uninstall Uninstall pivpn from your system!" + echo "::: -up, update Updates PiVPN Scripts" exit 0 } @@ -79,5 +86,6 @@ case "$1" in "-r" | "remove" ) removeClient "$@";; "-h" | "help" ) showHelp;; "-u" | "uninstall" ) uninstallServer;; +"-up" | "update" ) updateScripts "$@" ;; * ) showHelp;; esac