#!/usr/bin/env bash ## (c) 2023 th(at)bogus.net ## ## extremely hacky way to convert a pivpn wg client config file to ifconfig-syntax ## used by openbsd (e.g. put this into /etc/hostname.wg0) ## while getopts "h?" opt do case "$opt" in h|\?) echo "usage: $0 [-h] " echo "or: cat | $0" echo " -h : this" exit 0 ;; esac done while read line do if [[ $line =~ ^PrivateKey\ =\ (.+)$ ]] then WGKEY=${BASH_REMATCH[1]} fi if [[ $line =~ ^Address\ =\ ([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\/[[:digit:]]+)$ ]] then IFADDR=${BASH_REMATCH[1]} fi if [[ $line =~ ^PublicKey\ =\ (.+)$ ]] then WGPEER=${BASH_REMATCH[1]} fi if [[ $line =~ ^PresharedKey\ =\ (.+)$ ]] then WGPSK=${BASH_REMATCH[1]} fi if [[ $line =~ ^Endpoint\ =\ ([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)\:([[:digit:]]+)$ ]] then WGENDPOINTADDR=${BASH_REMATCH[1]} WGENDPOINTPORT=${BASH_REMATCH[2]} fi if [[ $line =~ ^AllowedIPs\ =\ (.*)$ ]] then ALLOWEDIPS=${BASH_REMATCH[1]} fi done < "${1:-/dev/stdin}" echo -n wgkey $WGKEY wgpeer $WGPEER wgpsk $WGPSK wgendpoint $WGENDPOINTADDR $WGENDPOINTPORT for n in ${ALLOWEDIPS//,/ } do echo -n \ wgaip $n done echo echo inet $IFADDR echo up