From 0957eda4430f343e845f2e18b3a8928426d7c541 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Sat, 10 Dec 2022 10:27:59 +0100 Subject: [PATCH] Remove interactive configuration --- README.md | 2 +- scripts/create-config.sh | 42 ++++++++++++++++++---------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index fc3aec6..2f2c07b 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Customize the file `docker-compose`. You can change the following environment va * `CLIENTS`: Number of clients for which configurations are to be created. Do not use more than 240 clients. * `DISABLE_FORWARD_ALL_TRAFFIC`: Use `true` or `yes` to not add iptables rules and do not forward all traffic. -If no environment variables are set, config creation script will ask you for settings. +If a required environment variable is not set, config creation script will end with an error. ### Create config files diff --git a/scripts/create-config.sh b/scripts/create-config.sh index d8e39ff..358af6b 100755 --- a/scripts/create-config.sh +++ b/scripts/create-config.sh @@ -6,39 +6,29 @@ rm *-client_*.png 2>/dev/null echo "Create configuration files" -while [[ -z $DEVICE ]]; do - echo -n "Device (eg tun0): " - read DEVICE -done +if [[ -z $DEVICE ]]; then + DEVICE="tun0" +fi echo " - Writing server config to file $DEVICE.conf" -while [[ -z $SERVER_HOST ]]; do - echo -n "Endpoint hostname: " - read SERVER_HOST -done +if [[ -z $SERVER_HOST ]]; then + echo " ERROR: No server hostname!" + exit 1 +fi echo " - Using endpoint hostname $SERVER_HOST" if [[ -z $SERVER_PORT ]]; then - echo -n "Endpoint port: " - read SERVER_PORT + echo " ERROR: No server port!" + exit 1 fi echo " - Using port $SERVER_PORT" if [[ -z $NETWORK ]]; then - echo -n "Network (/24): " - read NETWORK + NETWORK="192.168.42.0" +else + NETWORK=$(echo -n $NETWORK | sed -r "s/\.[0-9]+$//") fi -echo " - Using network $NETWORK/24" -NETWORK=$(echo -n $NETWORK | sed -r "s/\.[0-9]+$//") - -while [[ -z $CLIENTS ]]; do - echo -n "Number of clients: " - read CLIENTS -done -if (( $CLIENTS > 240 )); then - CLIENTS=240 -fi -echo " - Generating $CLIENTS client configs and client QR codes" +echo " - Using network $NETWORK.0/24" if [ "$DISABLE_FORWARD_ALL_TRAFFIC" != "true" ] && [ "$DISABLE_FORWARD_ALL_TRAFFIC" != "yes" ]; then echo " - Forward all traffic" @@ -46,6 +36,11 @@ else echo " - Do not forward all traffic" fi +if (( $CLIENTS > 240 )); then + CLIENTS=240 +fi +echo " - Generating $CLIENTS client configs and client QR codes" + SERVER_SEC_KEY=$(wg genkey) SERVER_PUB_KEY=$(echo $SERVER_SEC_KEY | wg pubkey) @@ -113,6 +108,7 @@ PublicKey = $SERVER_PUB_KEY AllowedIPs = 0.0.0.0/0, ::/0 Endpoint = $SERVER_HOST:$SERVER_PORT EOF + done # Create QR-codes for clients