#!/bin/bash
# -----------------------------------------------------------------------------
# xr_cli
#
# Script to run XR commands
#
# Copyright (c) 2017, 2019 by Cisco Systems, Inc.
# All rights reserved.
# -----------------------------------------------------------------------------

# This script exists to use on ThinXR in place of the xr_cli used on Full XR.
# xr_cli is needed as it is called by the ZTP function xrcmd in
# /pkg/bin/ztp_helper.sh.  On Full XR, xr_cli is a symlink to
# /pkg/bin/showtech_helper.  We cannot use this on ThinXR because it would run
# in the wrong namespace.

if [[ $(/sbin/ip netns identify $$) != "xrnns" ]]; then
    # We're not in the xrnns, so enter it now.
    exec xrenv /pkg/bin/xr_cli "$@"
else
    # We're in the XR network namespace.  Launch showtech_helper, but run it 
    # with the name xr_cli in order to get the correct behaviour.
    exec -a xr_cli /pkg/bin/showtech_helper "$@"
fi

