|
@ -15,12 +15,41 @@ fi |
|
|
sudo apt install -y wireguard |
|
|
sudo apt install -y wireguard |
|
|
|
|
|
|
|
|
cd /etc/wireguard/ |
|
|
cd /etc/wireguard/ |
|
|
|
|
|
echo "Configuring wireguard ..." |
|
|
(umask 077 && printf "[Interface]\nPrivateKey = " | sudo tee wg0.conf > /dev/null) |
|
|
(umask 077 && printf "[Interface]\nPrivateKey = " | sudo tee wg0.conf > /dev/null) |
|
|
wg genkey | sudo tee -a wg0.conf | wg pubkey | sudo tee wg0.pubkey > /dev/null |
|
|
wg genkey | sudo tee -a wg0.conf | wg pubkey | sudo tee wg0.pubkey > /dev/null |
|
|
echo "ListenPort = ${wireguard_port:?} |
|
|
echo "ListenPort = ${wireguard_port:?} |
|
|
SaveConfig = true |
|
|
SaveConfig = true |
|
|
Address = ${wireguard_ip:?}/24" | sudo tee -a wg0.conf > /dev/null |
|
|
Address = ${wireguard_ip:?}/24" | sudo tee -a wg0.conf > /dev/null |
|
|
|
|
|
|
|
|
|
|
|
if [[ -e /etc/nftables.firewall ]]; then |
|
|
|
|
|
echo "detected firewall config: nftables.firewall" |
|
|
|
|
|
echo "opening port $wireguard_port on firewall ..." |
|
|
|
|
|
line="tcp dport 9271 accept" |
|
|
|
|
|
regex="$line" |
|
|
|
|
|
sed -E -e "/$regex/{s/.*/$line/;:a;n;ba;q}" -e "\$a $line" /etc/nftables.firewall | sudo tee nftables.firewall >/dev/null |
|
|
|
|
|
sudo /etc/nftables.conf |
|
|
|
|
|
else |
|
|
|
|
|
echo "No firewall detected." |
|
|
|
|
|
echo "If you are using a firewall, make sure port $wireguard_port is open." |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
echo "Starting wireguard ..." |
|
|
sudo systemctl start wg-quick@wg0 |
|
|
sudo systemctl start wg-quick@wg0 |
|
|
#sudo systemctl enable wg-quick@wg0 |
|
|
read -p "Enable wireguard to automatically start on boot? [Y/n] " tmp |
|
|
wg |
|
|
while true; do |
|
|
|
|
|
case tmp in |
|
|
|
|
|
''|y|Y|yes|Yes) |
|
|
|
|
|
sudo systemctl enable wg-quick@wg0 |
|
|
|
|
|
echo "Wireguard will now automatically start on boot." |
|
|
|
|
|
echo "To disable, run 'sudo systemctl disable wg-quick@wg0'" |
|
|
|
|
|
break |
|
|
|
|
|
;; |
|
|
|
|
|
n|N|no|No) |
|
|
|
|
|
echo "Wireguard will not start on boot." |
|
|
|
|
|
echo "To enable auto-start, run 'sudo systemctl enable wg-quick@wg0'" |
|
|
|
|
|
break |
|
|
|
|
|
;; |
|
|
|
|
|
*) echo "error: unrecognized input";; |
|
|
|
|
|
esac |
|
|
|
|
|
done |
|
|