Fix update scripts from test branch

This commit is contained in:
Orazio 2019-12-30 11:44:33 +01:00
parent a6087f8bda
commit 41984e5f40
4 changed files with 32 additions and 16 deletions

View file

@ -125,8 +125,8 @@ main(){
if [ -z "$UpdateCmd" ] || [ "$UpdateCmd" = "Reconfigure" ]; then if [ -z "$UpdateCmd" ] || [ "$UpdateCmd" = "Reconfigure" ]; then
: :
elif [ "$UpdateCmd" = "Update" ]; 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 elif [ "$UpdateCmd" = "Repair" ]; then
source "$setupVars" source "$setupVars"
runUnattended=true runUnattended=true

View file

@ -6,7 +6,14 @@ pivpnrepo="https://github.com/pivpn/pivpn.git"
pivpnlocalpath="/etc/.pivpn" pivpnlocalpath="/etc/.pivpn"
pivpnscripts="/opt/pivpn/" pivpnscripts="/opt/pivpn/"
bashcompletiondir="/etc/bash_completion.d/" 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 ###Functions
##Updates scripts ##Updates scripts
@ -16,7 +23,7 @@ updatepivpnscripts(){
echo "going do update PiVPN Scripts" echo "going do update PiVPN Scripts"
if [[ -d "$pivpnlocalpath" ]]; then if [[ -d "$pivpnlocalpath" ]]; then
if [[ -n "$pivpnlocalpath" ]]; then if [[ -n "$pivpnlocalpath" ]]; then
sudo rm -rf "${pivpnlocalpath}/../.pivpn" rm -rf "${pivpnlocalpath}/../.pivpn"
cloneandupdate cloneandupdate
fi fi
else else
@ -32,7 +39,7 @@ updatefromtest(){
echo "PiVPN Scripts updating from test branch" echo "PiVPN Scripts updating from test branch"
if [[ -d "$pivpnlocalpath" ]]; then if [[ -d "$pivpnlocalpath" ]]; then
if [[ -n "$pivpnlocalpath" ]]; then if [[ -n "$pivpnlocalpath" ]]; then
rm -rf "{$pivpnlocalpath}/../.pivpn" rm -rf "${pivpnlocalpath}/../.pivpn"
cloneupdttest cloneupdttest
fi fi
else else
@ -41,22 +48,23 @@ updatefromtest(){
echo "PiVPN Scripts updated have been updated from test branch" 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(){ cloneandupdate(){
sudo git clone "$pivpnrepo" "$pivpnlocalpath" git clone "$pivpnrepo" "$pivpnlocalpath"
sudo cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts"
sudo cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir" cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir"
} }
##same as cloneandupdate() but from test branch ##same as cloneandupdate() but from test branch
##and falls back to master branch again after updating ##and falls back to master branch again after updating
cloneupdttest(){ cloneupdttest(){
sudo git clone "$pivpnrepo" "$pivpnlocalpath" git clone "$pivpnrepo" "$pivpnlocalpath"
sudo git -C "$pivpnlocalpath" checkout test git -C "$pivpnlocalpath" checkout test
sudo git -C "$pivpnlocalpath" pull origin test git -C "$pivpnlocalpath" pull origin test
sudo cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts"
sudo cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir" cp "${pivpnlocalpath}"/scripts/$VPN/*.sh "$pivpnscripts"
sudo git -C "$pivpnlocalpath" checkout master cp "${pivpnlocalpath}"/scripts/$VPN/bash-completion "$bashcompletiondir"
git -C "$pivpnlocalpath" checkout master
} }
scriptusage(){ scriptusage(){

View file

@ -4,8 +4,8 @@ _pivpn()
COMPREPLY=() COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
dashopts="-a -c -d -l -qr -r -h -u" dashopts="-a -c -d -l -qr -r -h -u -up"
opts="add clients debug list qrcode remove help uninstall" opts="add clients debug list qrcode remove help uninstall update"
if [ "${#COMP_WORDS[@]}" -eq 2 ] if [ "${#COMP_WORDS[@]}" -eq 2 ]
then then
if [[ ${cur} == -* ]] ; then if [[ ${cur} == -* ]] ; then

View file

@ -48,6 +48,12 @@ uninstallServer(){
exit 0 exit 0
} }
updateScripts(){
shift
$SUDO /opt/pivpn/update.sh "$@"
exit 0
}
showHelp(){ showHelp(){
echo "::: Control all PiVPN specific functions!" echo "::: Control all PiVPN specific functions!"
echo ":::" echo ":::"
@ -62,6 +68,7 @@ showHelp(){
echo "::: -r, remove Remove a client" echo "::: -r, remove Remove a client"
echo "::: -h, help Show this help dialog" echo "::: -h, help Show this help dialog"
echo "::: -u, uninstall Uninstall pivpn from your system!" echo "::: -u, uninstall Uninstall pivpn from your system!"
echo "::: -up, update Updates PiVPN Scripts"
exit 0 exit 0
} }
@ -79,5 +86,6 @@ case "$1" in
"-r" | "remove" ) removeClient "$@";; "-r" | "remove" ) removeClient "$@";;
"-h" | "help" ) showHelp;; "-h" | "help" ) showHelp;;
"-u" | "uninstall" ) uninstallServer;; "-u" | "uninstall" ) uninstallServer;;
"-up" | "update" ) updateScripts "$@" ;;
* ) showHelp;; * ) showHelp;;
esac esac