#!/usr/bin/env python
# Copyright (c) 2011 Arista Networks, Inc.  All rights reserved.
# Arista Networks, Inc. Confidential and Proprietary.
#
# This cli is strictly meant to be used as the default shell for
# internal login sessions on modular systems

import os, sys, Cell

# To prevent other users from running it on bash
if os.geteuid() != 90:
   sys.exit( "% Permission denied\n" )

args = [ '/usr/bin/FastCli', '--sysname', 'ar', '--disable-aaa',
         '--privilege', '15' ]

# Check if the user specified a command
if len( sys.argv ) > 1:
   # Only '-c' is supported
   if sys.argv[ 1 ] == '-c' or sys.argv[ 1 ] == '--command':
      args += [ sys.argv[ 1 ],
                '%s' % ( " ".join( sys.argv[ 2: ] ) ).strip( '\"\'' ) ]
   else:
      sys.exit( "% Invalid input: " + " ".join( sys.argv[ 1: ] ) )

try:
   # We can only be called on standby, so we know the peer is active.
   peerId = Cell.activeCell()
   os.environ[ 'CLI_PROMPT_PREFIX' ] = 's%d:' % peerId
   os.execv( args[ 0 ], args )
except Exception as e:
   sys.exit( e )
