pivpn/scripts/update.sh

101 lines
2.6 KiB
Bash
Raw Normal View History

2019-11-07 16:29:21 +00:00
#!/bin/bash
2019-10-14 10:27:28 +00:00
###Updates pivpn scripts (Not PiVPN)
###Main Vars
pivpnrepo="https://github.com/pivpn/pivpn.git"
pivpnlocalpath="/etc/.pivpn"
pivpnscripts="/opt/pivpn/"
bashcompletiondir="/etc/bash_completion.d/"
2019-12-30 10:44:33 +00:00
setupVars="/etc/pivpn/setupVars.conf"
2019-10-14 10:27:28 +00:00
2019-12-30 10:44:33 +00:00
if [ ! -f "${setupVars}" ]; then
echo "::: Missing setup vars file!"
exit 1
fi
source "${setupVars}"
2019-10-14 10:27:28 +00:00
###Functions
##Updates scripts
updatepivpnscripts(){
2019-11-07 16:29:21 +00:00
##We don't know what sort of changes users have made.
2019-10-14 10:27:28 +00:00
##Lets remove first /etc/.pivpn dir then clone it back again
echo "going do update PiVPN Scripts"
if [[ -d "$pivpnlocalpath" ]]; then
if [[ -n "$pivpnlocalpath" ]]; then
2019-12-30 10:44:33 +00:00
rm -rf "${pivpnlocalpath}/../.pivpn"
2019-10-14 10:27:28 +00:00
cloneandupdate
fi
2019-10-14 10:27:28 +00:00
else
cloneandupdate
2019-10-14 10:27:28 +00:00
fi
echo "PiVPN Scripts have been updated"
}
2019-11-07 16:29:21 +00:00
##Updates scripts using test branch
2019-10-14 10:27:28 +00:00
updatefromtest(){
2019-11-07 16:29:21 +00:00
##We don't know what sort of changes users have made.
2019-10-14 10:27:28 +00:00
##Lets remove first /etc/.pivpn dir then clone it back again
echo "PiVPN Scripts updating from test branch"
if [[ -d "$pivpnlocalpath" ]]; then
if [[ -n "$pivpnlocalpath" ]]; then
2019-12-30 10:44:33 +00:00
rm -rf "${pivpnlocalpath}/../.pivpn"
2019-10-14 10:27:28 +00:00
cloneupdttest
fi
2019-10-14 10:27:28 +00:00
else
cloneupdttest
2019-10-14 10:27:28 +00:00
fi
echo "PiVPN Scripts updated have been updated from test branch"
}
2019-12-30 10:44:33 +00:00
##Clone and copy pivpn scripts to /opt/pivpn
2019-10-14 10:27:28 +00:00
cloneandupdate(){
git clone "$pivpnrepo" "$pivpnlocalpath"
cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts"
cp "${pivpnlocalpath}"/scripts/$VPN/*.sh "$pivpnscripts"
cp "${pivpnlocalpath}"/scripts/$VPN/bash-completion "$bashcompletiondir"
2019-10-14 10:27:28 +00:00
}
##same as cloneandupdate() but from test branch
##and falls back to master branch again after updating
cloneupdttest(){
2019-12-30 10:44:33 +00:00
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
2019-10-14 10:27:28 +00:00
}
scriptusage(){
echo -e "Updates pivpn scripts,
2019-10-14 10:27:28 +00:00
Usage:
pivpn update | updates from master branch
pivpn update -t or --test | updates from test branch"
}
## SCRIPT
if [[ $# -eq 0 ]]; then
updatepivpnscripts
else
while true; do
case "$1" in
-t|--test|test)
2019-10-14 10:27:28 +00:00
updatefromtest
exit 0
;;
-h|--help|help)
2019-10-14 10:27:28 +00:00
scriptusage
exit 0
;;
2019-11-07 16:29:21 +00:00
* )
updatepivpnscripts
2019-10-14 10:27:28 +00:00
exit 0
;;
esac
done
fi