2022-08-17 19:47:50 +00:00
|
|
|
#!/bin/bash -e
|
2021-01-26 15:39:30 +00:00
|
|
|
|
2022-08-05 21:11:22 +00:00
|
|
|
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}")
|
2021-01-26 15:39:30 +00:00
|
|
|
gateway=$(ip route show | awk '/default/ {print $3}')
|
|
|
|
hostname="pivpn.test"
|
|
|
|
|
2022-07-27 12:53:36 +00:00
|
|
|
err() {
|
|
|
|
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
2021-01-26 15:39:30 +00:00
|
|
|
}
|
2022-07-26 13:20:35 +00:00
|
|
|
|
2022-07-27 12:53:36 +00:00
|
|
|
common() {
|
|
|
|
sed -i "s/INTERFACE/${interface}/g" "${vpnconfig}"
|
|
|
|
sed -i "s|IPADDRESS|${ipaddress}|g" "${vpnconfig}"
|
|
|
|
sed -i "s/GATEWAY/${gateway}/g" "${vpnconfig}"
|
2021-01-26 15:39:30 +00:00
|
|
|
}
|
|
|
|
|
2022-07-27 12:53:36 +00:00
|
|
|
openvpn() {
|
|
|
|
vpnconfig="ciscripts/ci_openvpn.conf"
|
|
|
|
twofour=1
|
|
|
|
common
|
|
|
|
sed -i "s/2POINT4/${twofour}/g" "${vpnconfig}"
|
|
|
|
cat "${vpnconfig}"
|
|
|
|
exit 0
|
2021-01-26 15:39:30 +00:00
|
|
|
}
|
|
|
|
|
2022-07-27 12:53:36 +00:00
|
|
|
wireguard() {
|
|
|
|
vpnconfig="ciscripts/ci_wireguard.conf"
|
|
|
|
common
|
|
|
|
cat "${vpnconfig}"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ "$#" -lt 1 ]]; then
|
|
|
|
err "specifiy a VPN protocol to prepare"
|
|
|
|
exit 1
|
2021-01-26 15:39:30 +00:00
|
|
|
else
|
2022-07-27 12:53:36 +00:00
|
|
|
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
|
2021-01-26 15:39:30 +00:00
|
|
|
fi
|