pivpn/ciscripts/startup.sh
4s3ti 5d0cc9e072 feat(ossupport): Jammy Support & CI Updates
Add support for Ubuntu Jammy (22.04)
Add CI tests for Ubuntu Jammy
Remove CI tests for Ubuntu Xenial
Rename CI tests stages
Add new CI Scripts to get pipeline code more "DRY"
Update CI Scripts to exit on error with /bin/bash -e
Add semantic-release settings
Add CI Release step for PiVPN automated versioning
2022-08-17 22:11:48 +02:00

62 lines
1.2 KiB
Bash

#!/bin/bash -e
interface=$(ip -o link \
| awk '{print $2}' \
| cut -d ':' -f 1 \
| cut -d '@' -f 1 \
| grep -v -w 'lo' \
| head -1)
ipaddress=$(ip addr show "${interface}" \
| grep -o -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}/[0-9]{2}")
gateway=$(ip route show | awk '/default/ {print $3}')
hostname="pivpn.test"
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}
common() {
sed -i "s/INTERFACE/${interface}/g" "${vpnconfig}"
sed -i "s|IPADDRESS|${ipaddress}|g" "${vpnconfig}"
sed -i "s/GATEWAY/${gateway}/g" "${vpnconfig}"
}
openvpn() {
vpnconfig="ciscripts/ci_openvpn.conf"
twofour=1
common
sed -i "s/2POINT4/${twofour}/g" "${vpnconfig}"
cat "${vpnconfig}"
exit 0
}
wireguard() {
vpnconfig="ciscripts/ci_wireguard.conf"
common
cat "${vpnconfig}"
exit 0
}
if [[ "$#" -lt 1 ]]; then
err "specifiy a VPN protocol to prepare"
exit 1
else
chmod +x auto_install/install.sh
sudo hostnamectl set-hostname "${hostname}"
cat /etc/os-release
while true; do
case "${1}" in
-o | --openvpn)
openvpn
;;
-w | --wireguard)
wireguard
;;
*)
err "unknown vpn protocol"
exit 1
;;
esac
done
fi