dotfiles/bin/setupWireguard

20 lines
707 B
Plaintext
Raw Normal View History

2020-08-12 13:34:09 +00:00
#!/bin/bash
2020-10-14 08:52:24 +00:00
set -aeou pipefail
2020-08-15 12:15:37 +00:00
keepassdb="$HOME/Nextcloud/passwords/Passwords.kdbx"
2020-08-12 13:34:09 +00:00
type wg >/dev/null 2>&1 || { printf "wireguard is not installed\n" >&2; exit 1; }
type keepassxc-cli >/dev/null 2>&1 || { printf "KeepassXC is not installed\n" >&2; exit 1; }
2020-10-13 07:13:20 +00:00
printf "Enter password for %s: " "$keepassdb":
read -s -r password
2020-08-12 13:34:09 +00:00
printf "\n"
2020-10-13 07:13:20 +00:00
networks=$(echo "$password" | keepassxc-cli ls "$keepassdb" /Wireguard/"$HOSTNAME")
2020-08-12 13:34:09 +00:00
umask 077
for network in $networks;do
echo "configuring /etc/wireguard/${network}.conf"
2020-10-13 07:13:20 +00:00
echo "$password" | keepassxc-cli show -q --attributes Notes "$keepassdb" /Wireguard/"$HOSTNAME"/"$network" | sudo tee /etc/wireguard/"${network}".conf > /dev/null
2020-08-12 13:34:09 +00:00
done
unset password