40 lines
990 B
Bash
Executable File
40 lines
990 B
Bash
Executable File
#!/bin/bash
|
|
TEMP_CONF=$(mktemp)
|
|
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)
|
|
|
|
create_client() {
|
|
mkdir clients 2> /dev/null
|
|
umask 077
|
|
CPRK="/tmp/cprk" # client private key
|
|
CPUK="/tmp/cpuk" # client public key
|
|
wg genkey | tee $CPRK | wg pubkey > $CPUK
|
|
export CLIENT_PRIVATE_KEY=$(cat $CPRK)
|
|
export CLIENT_PUBLIC_KEY=$(cat $CPUK)
|
|
export IP_ADDR=$1
|
|
|
|
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
|
|
|