mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-18 19:00:15 +00:00
* Changed pivpn command exit codes from 1 to 0
- exit code 1 means general error hence should not be used for exiting successfully * added backup script to backup openvpn and pivpn generated certificates * added update script to update /opt/pivpn scripts, -t | --test | test update from test branch * Fixed hostname length issue #831 - the script now checks for hostname length right at the beginning and prompts for a new one. - HOST_NAME to host_name, as best practice variables with capitals, should be used by system variables only. * fixed ubuntu 18.04 being detected as not supported OS, now fully supported and tested. * changed how scripts are copied to /opt/pivpn, it hat a lot of long repetitive lines, now it copies all *.sh files making it easier to manage when adding new scripts/features * Changed how supported OS are presented when maybeOS_Support() is called.
This commit is contained in:
parent
9525784b7f
commit
d5215e2747
2 changed files with 130 additions and 0 deletions
31
scripts/backup.sh
Executable file
31
scripts/backup.sh
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/bash
|
||||||
|
install_user=$(</etc/pivpn/INSTALL_USER)
|
||||||
|
install_home=$(grep -m1 "^${install_user}:" /etc/passwd | cut -d: -f6)
|
||||||
|
install_home=${install_home%/} # remove possible trailing slash
|
||||||
|
backupdir=pivpnbackup
|
||||||
|
openvpndir=/etc/openvpn
|
||||||
|
ovpnsdir=${install_home}/ovpns
|
||||||
|
date=$(date +%Y-%m-%d-%H%M%S)
|
||||||
|
|
||||||
|
backup_openvpn(){
|
||||||
|
if [[ ! -d $install_home/$backupdir ]]; then
|
||||||
|
mkdir $install_home/$backupdir
|
||||||
|
fi
|
||||||
|
cp -r $openvpndir $ovpnsdir $backupdir 2&>1
|
||||||
|
backupzip=$date-pivpnbackup.tgz
|
||||||
|
tar -czf $backupzip -C ${install_home} $backupdir 2&>1
|
||||||
|
echo -e "Backup crated to $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if [[ ! $EUID -eq 0 ]];then
|
||||||
|
if [[ $(dpkg-query -s sudo) ]];then
|
||||||
|
export SUDO="sudo"
|
||||||
|
else
|
||||||
|
echo "::: Please install sudo or run this as root."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
backup_openvpn
|
||||||
|
|
99
scripts/update.sh
Executable file
99
scripts/update.sh
Executable file
|
@ -0,0 +1,99 @@
|
||||||
|
#/bin/bash
|
||||||
|
|
||||||
|
###Updates pivpn scripts (Not PiVPN)
|
||||||
|
###Main Vars
|
||||||
|
pivpnrepo="https://github.com/pivpn/pivpn.git"
|
||||||
|
pivpnlocalpath="/etc/.pivpn"
|
||||||
|
pivpnscripts="/opt/pivpn/scripts"
|
||||||
|
bashcompletiondir="/etc/bash_completion.d/pivpn"
|
||||||
|
|
||||||
|
|
||||||
|
###Functions
|
||||||
|
##Updates scripts
|
||||||
|
updatepivpnscripts(){
|
||||||
|
##We don't know what sort of changes users have made.
|
||||||
|
##Lets remove first /etc/.pivpn dir then clone it back again
|
||||||
|
echo "going do update PiVPN Scripts"
|
||||||
|
if [[ -d $pivpnlocalpath ]]; then
|
||||||
|
|
||||||
|
sudo rm -rf $pivpnlocalpath
|
||||||
|
cloneandupdate
|
||||||
|
|
||||||
|
else
|
||||||
|
cloneandupdate
|
||||||
|
fi
|
||||||
|
echo "PiVPN Scripts have been updated"
|
||||||
|
}
|
||||||
|
|
||||||
|
##Updates scripts using test branch
|
||||||
|
updatefromtest(){
|
||||||
|
##We don't know what sort of changes users have made.
|
||||||
|
##Lets remove first /etc/.pivpn dir then clone it back again
|
||||||
|
echo "PiVPN Scripts updating from test branch"
|
||||||
|
if [[ -d /etc/.pivpn ]]; then
|
||||||
|
|
||||||
|
rm -rf /etc/.pivpn
|
||||||
|
cloneupdttest
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
cloneupdttest
|
||||||
|
|
||||||
|
fi
|
||||||
|
echo "PiVPN Scripts updated have been updated from test branch"
|
||||||
|
}
|
||||||
|
|
||||||
|
##Clone and copy pivpn scripts to /op/
|
||||||
|
cloneandupdate(){
|
||||||
|
|
||||||
|
sudo git clone $pivpnrepo $pivpnlocalpath
|
||||||
|
sudo cp -r $pivpnlocalpath/scripts $pivpnscripts
|
||||||
|
sudo 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 -r $pivpnlocalpath/scripts $pivpnscripts
|
||||||
|
sudo cp $pivpnlocalpath/scripts/bash-completion $bashcompletiondir
|
||||||
|
sudo git -C $pivpnlocalpath checkout master
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
scriptusage(){
|
||||||
|
echo -e "Updates pivpn scripts,\n
|
||||||
|
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 )
|
||||||
|
updatefromtest
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-h | --help | help )
|
||||||
|
scriptusage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
updatepivpnscripts
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in a new issue