#!/bin/sh
##
#  linux-explorer-wrapper and repack
#  to unpack this file on Solaris you must use gtar
#  Tested Ubuntu 9.10 16.04 16.10 LTS
#  Tested Fedora release 24 (Twenty Four)
#  Tested CentOS Linux 7
#  Tested Orace Linux Server reease 6.0
#  Tested Red Hat Enterprise Linux Server release 6.5
#  Tested Fedora release 24
#  Tested
#  Tested
#  Tested
#  Ver 0.89
# 
#. ./linux-explorer.sh
OK=2
OUT=out
HOST=`hostname`
#echo $OUT $HOST
if [ -d $OUT/linux ]
then
	cd  $OUT/linux/
	TARG=`ls -d *${HOST}-*|grep -v tar.gz`
	TARGCNT=`echo $TARG|wc -c`
	TARGCNT=`expr $TARGCNT - 1`
	Start=`expr $TARGCNT - 18` 
	STAMP=`echo $TARG |cut -c ${Start}-$TARGCNT`
	echo TARG is $TARG
else
	echo no out dir $OUT/linux/
	exit 1
fi
##
# New style ip addr
if [ -f ${TARG}/network/ip_add.out ]
then
  MAC=`cat ${TARG}/network/ip_add.out |grep  'link/ether'  |head -1|awk  '{print $2}'|sed -e 's/://g'`
    echo "ip add MAC=$MAC"
else
	# Old style ifconfig -a 
	if [ -f ${TARG}/network/ifconfig_-a.out ]
	then
	  MAC=`cat ${TARG}/network/ifconfig_-a.out|grep HWaddr  |head -1|awk  '{print $5}'|sed -e 's/://g'`
	  echo "ifcon MAC=$MAC"
	
	fi
fi
if [ "$MAC" = "" ]
then
	echo "No network found ip addr or ifconfig "
	exit 2
fi
#
SHOSTID=`echo $MAC|sed -e 's/://g'|cut -c 5-12`
echo "rename $TARG explorer.$SHOSTID.$HOST-$STAMP"

	mv $TARG explorer.$SHOSTID.$HOST-$STAMP
	OK=$?

if [ "$OK" -eq 0 ]
then
	rm explorer.*.tar.gz
	tar -cf explorer.$SHOSTID.$HOST-$STAMP.tar explorer.$SHOSTID.$HOST-$STAMP
	gzip explorer.$SHOSTID.$HOST-$STAMP.tar
fi


