How to set up/manage services on a computer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
630 B

#!/bin/bash
set -euo pipefail
if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "Usage: $(basename $0) IP [Port]"
exit 1
fi
wireguard_ip="$1"
if [[ -z $2 ]]; then
wireguard_port=9271
else
wireguard_port="$2"
fi
sudo apt install -y wireguard
cd /etc/wireguard/
(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
echo "ListenPort = ${wireguard_port:?}
SaveConfig = true
Address = ${wireguard_ip:?}/24" | sudo tee -a wg0.conf > /dev/null
sudo systemctl start wg-quick@wg0
#sudo systemctl enable wg-quick@wg0
wg