#!/bin/sh
#
# This script grabs logfiles from both the workstation and the 
# instrument controller and combines them into one file for
# sending to support.
#
#
DV_TAR=~/dv_logs.tar
DVIC_TAR=~/dvic.tar
HOST=`hostname`

# debugging flag
#VERBOSE=-v

#
# The controller, in development it could be a network controller.
#
DVIC=159.159.159.2
CONTROLLER=`grep ^DV_CONTROLLER_HOST $HOME/.softworx_${HOST}/user.swrc | awk '{print $2}'`
if [ "$CONTROLLER"X != "X" ]; then
	DVIC=$CONTROLLER
fi

DVICTYPE=`grep ^PC_Type: /usr/local/softWoRx/config/Resolve3D.SYS | awk '{print $2}'`

if [ "$DVICTYPE"X == "networkX" ]; then
#
# Grab the log, config and data directoies from the instrument controller
#
	echo "Grabbing files from IC"
	smbtar -s $DVIC -x c$ -u worx -p 4delta \
		$VERBOSE -t $DVIC_TAR \
  	ic540_dv/log ic540_dv/config ic540_dv/data ic540_dv/bin/pvcam.ini

else
	echo "DVIC is of type $DVICTYPE, no files needed"
fi

#
# Grab the latest softworx log
#
echo "Grabbing files from softWoRx workstation"
cd $HOME
rpm -qa > $HOME/softworx-logs/rpm.txt
tar cf $DV_TAR --exclude pixmaps --exclude desktop \
  -C $HOME ./softworx-logs/softworxlog*.txt ./softworx-logs/rpm.txt .softworx_${HOST}/user.swrc \
  -C /etc X11/xorg.conf \
  -C /usr/local/ softWoRx/config

#
# smbtar does not work nicely with tar on some machines. Combine the
# two archives this way.
#
if [ "$DVICTYPE"X == "networkX" ]; then
	tar --concatenate --file=$DV_TAR $DVIC_TAR
	rm -f $DVIC_TAR
fi


#
# Zip up the archive to make it a bit smaller
#
echo "Compressing logs"
gzip -f $DV_TAR


echo
echo "Done: $DV_TAR"
echo

echo -n "Press any key to continue: "
read ANS
