#!/bin/sh # 2020-06-13, Nico Schottelius # See https://ungleich.ch/u/products/viwib-wifi-ipv6-box/ if [ $# -lt 2 ]; then echo "$0 viwib-ip-address viwib-id [wgprivkey]" echo " viwib-ip-address: where to find the viwib" echo " viwib-id: number in decimal format" echo " wgprivkey: if specified, use this private key" exit 1 fi set -x viwib_ip=$1; shift id=$1; shift hex_id=$(printf "%0.2x\n" "$id") viwib_hostname=viwib${id} prefix_base=2a0a:e5c1:6 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-2a0ae5c1600.ungleich.ch vpn_endpoint_pubkey=ygZQW3OSiMJl/RpKyaJVE0GSt6bjEDnoxdMJsNiloRE= i=0 found="" while [ $i -lt 30 ]; do echo "Trying to reach ${viwib_ip} ($i)" if ping -c1 ${viwib_ip} >/dev/null; then found="yes" break fi i=$((i+1)) done if [ -z "$found" ]; then echo "Unable to contact viwib. Exiting" exit 1 fi cat < ${viwib_hostname}.public_key # change to ipv6 viwib_ip=${my_lan_ip} sleep 15 while ! ping -c5 ${viwib_ip}; do echo "Waiting for viwib ${id}" sleep 2 done echo "Wireguard public key and id: ${id} ${public_key}"