#!/bin/sh
#
# Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 3 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 3 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

# This file is a template, which is processed by gen-safe-forward-tools.R by replacing %%tool_name%%, %%var_name%% and %%config_file%%
# config_file is the name of the file where this tool is configured (used in the help message)
# var_name is the name of the variable inside that configuration file

# The purpose of this tool is to forward to the given tool, but before doing so
# it checks that tool exists and if not prints out some message suggesting what to do

if command -v %%tool_name%%>/dev/null; then
  exec %%tool_name%% "$@"
else
  >&2 echo "R package installation or similar process tried to execute tool '%%tool_name%%'."
  >&2 echo "The tool '%%tool_name%%' seems to be not available on your system."
  >&2 echo
  >&2 echo "****************************"
  >&2 echo "TROUBLESHOOTING"
  >&2 echo "If the tool '%%tool_name%%' is not installed, install it in order to proceed."
  >&2 echo "If the tool '%%tool_name%%' is installed, but under a non-standard path, or if you would like to use another tool that is compatible (e.g., gtar instead of tar), then the path to this tool can be configured in '%%config_file%%' (variable '%%var_name%%')."
  exit 1
fi