#!/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 admin
# 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 xr_admin_env "$@"
else
    # We're in the XR network namespace. So just set the correct
    # PATH and LD_LIBRARY_PATH
    export PATH=/opt/cisco/calvados/sbin:/opt/cisco/calvados/bin:$PATH
    export LD_LIBRARY_PATH=/opt/cisco/calvados/usr/lib64
    if [ $# -eq 0 ]; then
        # No arguments supplied to spawn a shell in the right NS
        export PS1='ADMIN[\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

