#!/bin/bash
#
# Copyright:: Copyright 2020, Cinc Project
# License:: Apache License, Version 2.0
#
# Licensed 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.
#
pcmd=`cat /proc/$PPID/comm`
pexe=`readlink /proc/$PPID/exe`
pcmdline=`tr '\000' ' ' < /proc/$PPID/cmdline`

echo "WARN: $0 was called by: $pexe [$pcmdline]" >&2

if [ ! -z "$CINC_DEPRECATED_LOG" ]; then
  echo "$0: called by: $pexe ($pcmd) cmdline=[$pcmdline] cwd=`pwd`" >> $CINC_DEPRECATED_LOG
fi

if [ "$(basename $0)" == "inspec" ] ; then
  name="cinc-auditor"
else
  name="$(basename ${0/chef/cinc})"
fi
echo "Redirecting to ${name}..." >&2

exec /opt/cinc-project/bin/${name} "$@"
