diff --git a/README.md b/README.md index c0e0f71..261857b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Server ```sh pkg_add wireguard-tools -pkg_add qrencode #optional +pkg_add libqrencode #optional sh wireguard_server.sh ``` ### For each client diff --git a/wireguard_client.sh b/wireguard_client.sh index 0a3eeea..e57c91e 100755 --- a/wireguard_client.sh +++ b/wireguard_client.sh @@ -14,11 +14,16 @@ client=$1 server_ip=$(curl ipinfo.io/ip) interface="wg0" config_file="/etc/wireguard/${interface}.conf" +interface_config_file="/etc/hostname.${interface}" clients_dir="/etc/wireguard/clients" server_port=$(grep "ListenPort" ${config_file} | awk '{print $3}') last_ip=$(tail -n 1 ${config_file} |\ grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}") +if ! [ -n "$last_ip" ]; then + # if it's the first peer, config file don't have any IP + last_ip=$(head -n 1 ${interface_config_file} | grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}" | head -n 1) +fi new_ip=$(echo "$last_ip" | awk -F. '{print $1"."$2"."$3"."$4+1}') client_ip="${new_ip}/32" diff --git a/wireguard_server.sh b/wireguard_server.sh old mode 100644 new mode 100755