#!/bin/sh # 2020-06-13, Nico Schottelius # See https://ungleich.ch/u/products/vigir/ if [ $# -lt 2 ]; then echo "$0 vigir-ip-address vigir-id [wgprivkey]" echo " vigir-ip-address: where to find the vigir" echo " vigir-id: number in decimal format" echo " wgprivkey: if specified, use this private key" exit 1 fi set -x vigir_ip=$1; shift id=$1; shift hex_id=$(printf "%0.2x\n" "$id") vigir_hostname=vigir${id} prefix_base=2a0a:e5c1:5 my_prefix=${prefix_base}${hex_id} my_network=${my_prefix}::/48 my_wireguard_ip=${my_prefix}::42 my_lan_ip=${my_prefix}:cafe::42 my_wifi_ip=${my_prefix}:7ea::42 # wireguard if [ $# -eq 1 ]; then private_key=$1; shift else private_key=$(wg genkey) fi public_key=$(echo $private_key | wg pubkey) vpn_endpoint_host=vpn-2a0ae5c1500.ungleich.ch vpn_endpoint_pubkey=oaFiIVV1NjvDcfdtwJqR4F3k2XIC07npNgj0YjIEem4= i=0 found="" while [ $i -lt 30 ]; do echo "Trying to reach ${vigir_ip} ($i)" if ping -c1 ${vigir_ip} >/dev/null; then found="yes" break fi i=$((i+1)) done if [ -z "$found" ]; then echo "Unable to contact vigir. Exiting" exit 1 fi cat < ${vigir_hostname}.public_key # change to ipv6 vigir_ip=${my_lan_ip} sleep 15 while ! ping -c5 ${vigir_ip}; do echo "Waiting for vigir ${id}" sleep 2 done echo "Wireguard public key and id: ${id} ${public_key}"