#!/bin/sh
#
#  Licensed to the Apache Software Foundation (ASF) under one
#  or more contributor license agreements.  See the NOTICE file
#  distributed with this work for additional information
#  regarding copyright ownership.  The ASF licenses this file
#  to you under the Apache License, Version 2.0 (the
#  "License"); you may not use this file except in compliance
#  with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
PATH=/usr/bin:/bin:/sbin:/usr/sbin:/etc:/usr/ucb:/usr/bsd:/usr/etc:/usr/local/bin; export PATH

# Get system/environment
# Identify operating system environment 
ostype=`(uname -s) 2>/dev/null` || ostype=unknown
osrelease=`(uname -r) 2>/dev/null` || osrelease=unknown
uname_processor=`(uname -p) 2>/dev/null` || uname_processor=unknown  # Processor type
uname_machine=`(uname -m) 2>/dev/null` || uname_machine=unknown  # Machine class

#defaults for system commands/utilities
WHOAMI=whoami
AWK=awk
HEAD=head
LS=ls
LN=ln

InkHome="$ROOT"
[ -z "$InkHome" ] && InkHome="$INST_ROOT";
[ -z "$InkHome" ] && InkHome=`${HEAD} -1 /etc/traffic_server 2>/dev/null`
[ -z "$InkHome" ] && InkHome="/home/trafficserver"

ThisUser=`${WHOAMI} | ${AWK} '{print $1}'`
${LN} -s /usr/lib/libreadline.so ${InkHome}/bin/libreadline.so.3 2> /dev/null
${LN} -s /usr/lib/libncurses.so ${InkHome}/bin/libncurses.so.4 2> /dev/null
InktomiUser=`${LS} -l ${InkHome}/bin/traffic_server 2>/dev/null |${AWK} '{print $3}'`

argv=$@
if [ -z "$TCL_LIBRARY" ]; then
  TCL_LIBRARY="${InkHome}/bin/tshell_script"; export TCL_LIBRARY
else
  TCL_LIBRARY="${InkHome}/bin/tshell_script;$TCL_LIBRARY"; export TCL_LIBRARY
fi
MANPATH=${InkHome}/bin/tshell_script/man:$MANPATH
export MANPATH
LD_LIBRARY_PATH=${InkHome}/bin:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
exec ${InkHome}/bin/traffic_shell $argv
