2023-11-05 09:40:53 +00:00
|
|
|
#!/bin/bash
|
|
|
|
TEMP_CONF=$(mktemp)
|
2023-11-05 11:21:07 +00:00
|
|
|
SERVER_NAME="cs2"
|
|
|
|
SERVER_CONF_FILE="./server/${SERVER_NAME}.conf"
|
|
|
|
SERVER_KEYFILE="./server/private.key"
|
|
|
|
export ENDPOINT="wg.oliveratkinson.net:51820"
|
|
|
|
|
|
|
|
# Make server
|
|
|
|
if [[ ! -e "${SERVER_KEYFILE}" ]]; then
|
|
|
|
mkdir server 2> /dev/null
|
|
|
|
umask 077
|
|
|
|
wg genkey > $SERVER_KEYFILE
|
|
|
|
|
|
|
|
if [[ ! -e "${SERVER_CONF_FILE}" ]]; then
|
|
|
|
export SERVER_PRIVATE_KEY=$(cat $SERVER_KEYFILE)
|
|
|
|
envsubst < server.template > $SERVER_CONF_FILE
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
export SERVER_PUBLIC_KEY=$(wg pubkey < $SERVER_KEYFILE)
|
2023-11-05 09:40:53 +00:00
|
|
|
|
2023-11-05 11:21:07 +00:00
|
|
|
create_client() {
|
|
|
|
mkdir clients 2> /dev/null
|
|
|
|
umask 077
|
|
|
|
CPRK="/tmp/cprk"
|
|
|
|
CPUK="/tmp/cpuk"
|
|
|
|
wg genkey | tee $CPRK | wg pubkey > $CPUK
|
|
|
|
#export CLIENT_PRIVATE_KEY=$(cat $CLIENT_PK_FILE)
|
|
|
|
export CLIENT_PRIVATE_KEY=$(cat $CPRK)
|
|
|
|
export CLIENT_PUBLIC_KEY=$(cat $CPUK)
|
|
|
|
export IP_ADDR=$1
|
2023-11-05 09:40:53 +00:00
|
|
|
|
2023-11-05 11:21:07 +00:00
|
|
|
envsubst < client.template > clients/client${IP_ADDR}.$SERVER_NAME.conf
|
|
|
|
envsubst < peer.template >> $SERVER_CONF_FILE
|
|
|
|
rm $CPUK $CPRK
|
|
|
|
}
|
|
|
|
# create clients
|
|
|
|
for i in {2..5}; do
|
|
|
|
create_client $i
|
|
|
|
done
|
2023-11-05 09:40:53 +00:00
|
|
|
|