~hokiegeek/bin

939801a857c79f0ef571ea7be898cd2a8cefd950 — HokieGeek 3 months ago 83cf299
[bwvpn] fixes several bugs and usability issues
1 files changed, 9 insertions(+), 7 deletions(-)

M bwvpn
M bwvpn => bwvpn +9 -7
@@ 1,14 1,16 @@
#!/bin/sh
vpncfg=$2
cmd=$1
item=$2
vpncfg=$3

if [[ "$1" == "stop" ]]; then
if [[ "$cmd" == "stop" ]]; then
    openvpn3 sessions-list | awk 'BEGIN{ FS=":" } $1 ~ /Path/ { p=$2 } $1 ~ /Config name/ && $2 = "'${vpncfg}'" { print p }' | while read p; do
        echo -n "$p\n\t"
        echo "[$p]"
        openvpn3 session-manage --disconnect --path $p
    done
elif [[ "$1" == "start" ]]; then
elif [[ "$cmd" == "start" ]]; then
    bwsession=$(bw unlock | awk -F= '$1 ~ /export BW_SESSION/ { gsub(/"/, "", $2); print $2 }')
    item=vpn.sonatype.dev
    [ -z "${bwsession}" ] && exit 1
    expect <<-EOF
    spawn openvpn3 session-start --config ${vpncfg}



@@ 24,8 26,8 @@ elif [[ "$1" == "start" ]]; then
    send -- "$(bw --session ${bwsession} get totp ${item})\r"

    expect eof

EOF
else
    echo "just start or stop, dude"
    echo "USAGE: bwvpn [start|stop] BWITEMNAME OVPNCONFIG"
    exit 1
fi