#!/bin/sh
#################################################################
#								#
# Copyright (c) 2017 Fidelity National Information		#
# Services, Inc. and/or its subsidiaries. All rights reserved.	#
#								#
#	This source code contains the intellectual property	#
#	of its copyright holder(s), and is made available	#
#	under a license.  If you do not know the terms of	#
#	the license, please stop and do not read further.	#
#								#
#################################################################

# Check installing as root

uid=`id -u`

if [ "$uid" -ne 0 ]; then
	echo "$0 must be run as root"
	exit 1
fi

# Check valid package

package_dir=`dirname $0`
if [ "$package_dir" = "" ]; then
	package_dir="."
fi

if [ ! -f "${package_dir}/mumps.debug" ]; then
	echo "mumps.debug not found in package directory (${package_dir})"
	exit 1
fi

# Check valid $gtm_dist

if [ ! -d "$gtm_dist" ]; then
	echo "gtm_dist ($gtm_dist) is not a valid directory"
	exit 1
fi
if [ ! -x "$gtm_dist/mumps" ]; then
	echo "gtm_dist ($gtm_dist) is not a GT.M installation"
	exit 1
fi

# Confirm installation

echo ""
echo "Installing debug symbols to $gtm_dist"
echo ""
printf "Proceed? > "
read resp
response=$(echo "$resp" | tr '[a-z]' '[A-Z]')
if [ "Y" != "$response" -a "YES" != "$response" ] ; then
	exit 1
fi

# Do the copy

cp ${package_dir}/*.debug $gtm_dist/
ls -ald $gtm_dist/*.debug
echo ""
echo "Done. Please check the permissions on the listed files and change them as appropriate."
