#!/bin/sh

# Copyright 2007 SMR Engineering & Development SA.  All rights reserved.
#
# Redistribution and use, with or without modification, are permitted
# provided that the following condition is met:
#
# Redistributions must retain the above copyright notice, this
# condition and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY SMR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL SMR BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

#
# Script to gather information about machine, username, etc.
#

# Print info about script and ask for confirmation.
echo
echo "*** SMR license info script"
echo
echo "This script will collect summary information about your machine, "
echo "comprising the type of machine, the operating system, the hostname, "
echo "the domainname, and the IP addresses of the machine's own network "
echo "interfaces."
echo
echo "The script will create a temporary file on this machine and write "
echo "the aforementioned information in human-readable form to that file. "
echo "You are kindly requested to send the contents of that file to SMR."
echo "SMR in turn may make use of this information to create a license file "
echo "for SMR software to be run on your machine."
echo 
printf "Proceed (y/n) ? "
read proceed
if test x$proceed != 'xy'; then
    echo "Script aborted."
    exit 1
fi
echo
echo "If confirmed by you, the script adds to the aforementioned "
echo "information also summary information about your account, comprising "
echo "the user name, the user id, the group names, and the group id's to "
echo "which the user is invited.  This information is only necessary in "
echo "cases where the machine is used also by other users that, according "
echo "to the license agreement, have no permission to use the software."
echo
printf "Include summary account information (y/n) ? "
read account
echo
if test x$account = 'xy'; then
    echo " *** Summary account information will be included."
else
    echo " *** Summary account information will not be included."
fi

# Create a temporary file.
TMPFILE='licenseinfo.txt'
if test $? -ne 0; then
	echo "$0: Can't create temp file, exiting..."
	exit 1
fi

# Run the diagnosis tools and redirect to the temporary file.
(echo "#----BEGIN INFO----"

echo "# Output of uname -a..."
uname -a
echo "# Output of uname -s..."
uname -s
echo "# Output of uname -n..."
uname -n
echo "# Output of uname -r..."
uname -r
echo "# Output of uname -v..."
uname -v
echo "# Output of uname -m..."
uname -m

echo "# Output of hostname..."
hostname
echo "# Output of hostname -f..."
hostname -f
echo "# Output of domainname..."
domainname

echo "# Output of ifconfig -a..."
if test -x /sbin/ifconfig; then
  /sbin/ifconfig -a
fi
if test -x /usr/sbin/ifconfig; then
  /usr/sbin/ifconfig -a
fi

if test x$account = 'xy'; then
    echo "# Output of id..."
    id
fi

echo "#----END INFO----")>$TMPFILE 2>&1

# Print the name of the temporary file and what to do with it.
echo
echo "Output of script has been written to $TMPFILE"
echo "Please send this file along with any remarks to support@smr.ch."



