#!/bin/bash
# ------------------------------------------------------------------
# Copyright (c) 2016-2017, 2019 by Cisco Systems, Inc.
# All rights reserved.
#
# Script to spawn a shell (or run a command) in an XR environment
# for developer use only
# ------------------------------------------------------------------

if [[ $(/sbin/ip netns identify $$) != "xrnns" ]]; then
    # We're not in the xrnns, so enter it now.
    exec /pkg/bin/nns_exec xrnns xrenv "$@"
else
    # We're in the XR network namespace
    source /opt/cisco/thinxr/set_env_vars
    if [ $# -eq 0 ]; then
        # No arguments supplied to spawn a shell in the right NS
        export PS1='XR[\h:\w]$ '
        # We want bash to inherit this envionment so don't source any rcs
        exec bash --norc --noprofile
    else
        # Assume the args are commands and just run it
        exec "$@"
    fi
fi
