#!/bin/bash -e
#
# pwansh - Private WAN shell
#

if [ -z $1 ] ; then
    echo "Usage: $0 <space>"
    echo "Available spaces:"
    echo "$(ip netns list)"
fi

export space=$1
shift


ip netns list | grep -q "^$space$\|^$space (" || {
    echo "Space $space is not running." >&2
    exit 1
}

export PS1="[$space] \u@\h:\w\$ "

function birdc() {
    /usr/sbin/birdc -s /var/run/bonding/pwan-bird-$space.sock $@
}
export -f birdc

if [ ! -z $1 ] ; then
    if [ "$1" = "birdc" ] ; then
        shift
        ip netns exec $space /usr/sbin/birdc -s /var/run/bonding/pwan-bird-$space.sock $@
    else
        ip netns exec $space $@
    fi
else
    ip netns exec $space bash --noprofile --norc
fi
