2021-01-25 15:37:53 -08:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2021-03-15 11:03:49 -07:00
|
|
|
# vpn-stack
|
2021-01-25 15:37:53 -08:00
|
|
|
# A set of bash scripts for installing and managing a WireGuard VPN server.
|
2021-03-15 11:03:49 -07:00
|
|
|
# https://git.stack-source.com/msb/vpn-stack
|
2022-07-14 12:32:41 -07:00
|
|
|
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2021-01-25 15:37:53 -08:00
|
|
|
|
2023-03-13 13:13:13 -07:00
|
|
|
# load include file
|
|
|
|
source $(dirname $0)/wg.sh
|
2021-01-25 15:37:53 -08:00
|
|
|
|
2023-03-13 13:13:13 -07:00
|
|
|
help()
|
|
|
|
{
|
|
|
|
thisfilename=$(basename -- "$0")
|
2024-07-24 14:00:18 -07:00
|
|
|
echo "Email client config."
|
2023-03-13 13:13:13 -07:00
|
|
|
echo ""
|
2024-07-24 14:00:18 -07:00
|
|
|
echo "usage: $thisfilename -c <client> -e <email> [-h]"
|
2023-03-13 13:13:13 -07:00
|
|
|
echo ""
|
|
|
|
echo " -h Print this help."
|
|
|
|
echo " -c <client> Name of the client configuration."
|
2024-07-24 14:00:18 -07:00
|
|
|
echo " -e <email> Email address to send config to."
|
2023-03-13 13:13:13 -07:00
|
|
|
}
|
2021-01-25 15:37:53 -08:00
|
|
|
|
2023-03-13 13:13:13 -07:00
|
|
|
wg::getoptions "$@"
|
|
|
|
|
|
|
|
# check for client config name
|
|
|
|
if [[ -z $client ]]; then
|
|
|
|
echo "client name is required"
|
|
|
|
exit
|
2021-01-25 15:37:53 -08:00
|
|
|
fi
|
|
|
|
|
2024-07-24 14:00:18 -07:00
|
|
|
# check for email address
|
|
|
|
if [[ -z $email ]]; then
|
|
|
|
echo "email address is required"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2023-03-13 13:13:13 -07:00
|
|
|
# set config file name
|
|
|
|
config=$client.conf
|
2021-01-25 15:37:53 -08:00
|
|
|
|
|
|
|
# check for existing config
|
|
|
|
if [ -f /etc/wireguard/clients/$config ]; then
|
|
|
|
|
2024-07-24 14:00:18 -07:00
|
|
|
# check for zip, create if it doesn't already exist
|
|
|
|
if [[ ! -f /var/lib/wireguard/$config.zip ]]; then
|
|
|
|
wg-client-zip-create.sh -c $client
|
2021-01-25 15:37:53 -08:00
|
|
|
fi
|
2024-07-24 14:00:18 -07:00
|
|
|
|
|
|
|
mail -s "WireGuard config for $client" --attach=/var/lib/wireguard/$config.zip $email <<< "Please find attached the WireGuard config for $client"
|
2021-01-25 15:37:53 -08:00
|
|
|
|
|
|
|
else
|
2024-07-24 14:00:18 -07:00
|
|
|
echo "config for $client $device does not exist"
|
2021-01-25 15:37:53 -08:00
|
|
|
fi
|