#!/bin/bash

# Description: Output blackcore server debug information
# V2.0:  Output data to separate files and compress to tar

#==============================================================================
#                    Constants
#==============================================================================
SUCCESS=0
FAILURE=1

TRUE=1
FALSE=0
SCRIPTNAME=`basename $0`
HOSTNAME=`hostname -s`

#==============================================================================
#                    Variables
#==============================================================================
SERIAL_NUMBER="UNKNOWN"

#==============================================================================
#                    Echo Text
#==============================================================================
echoText()
{
   echo -e "${1}" 
}
echoLine()
{
   echo "-------------------------------------------------------------------------------"
}

#==============================================================================
#   checkRoot: check if current user is root
#   params: n/a
#==============================================================================
checkRoot()
{
   if [ "$EUID" -ne 0 ]
   then
      return $FAILURE
   fi
   return $SUCCESS
}

#==============================================================================
#   echoUsage: print usage to screen
#   params: n/a
#==============================================================================
echoUsage()
{
   echoText "Usage: $SCRIPTNAME [OPTION]"
   echoText "OR     $SCRIPTNAME [OPTION] [NAME]\n"
   echoText "LONG OPTION         OPTION     MEANING"
   echoText "--help              -h         Print usage info "
   echoText "--directory <dir>   -d <dir>   Log output to directory dir (default /logs/)"
   echoText "--filename <fn>     -f <fn>    Log output to filename fn (default bc.<serial>.<datetime>)"
   echoText "--serial            -s         Print serial number then exit"
   echoText "--dont-compress     -!         Do not compress output to .tar.gz archive"
   echoText "                    -a         Do not output all info (used with below options)"
   echoText "--dmi                 r         Output DMI info"
   echoText "--network             n         Output network info"
   echoText "--os                  o         Output OS info"
   echoText "--dmesg               m         Output dmesg info"
   echoText "--ipmi                i         Output IPMI info"
   echoText "--pcie                p         Output PCIE info"
   echoText "--hardware            w         Output hardware info"
   echoText "--sfboot              b         Output sfboot info"
   echoText
	exit $SUCCESS
}

#==============================================================================
#   getParams - getCommandParams
#   params: $args
#==============================================================================
getCommandParams()
{
   XOR=$FALSE
   # turn long command line arguments into short ones
   for arg in "$@"; do
      shift
      case "$arg" in
         '--help')          set -- "$@" '-h'   ;;
         '--filename')      set -- "$@" '-f'   ;;
         '--directory')     set -- "$@" '-d'   ;;
         '--serial')        set -- "$@" '-s'   ;;
         '--dont-compress') set -- "$@" '-!'   ;;

         '--dmi')           set -- "$@" '-r'   ;;
         '--network')       set -- "$@" '-n'   ;;
         '--os')            set -- "$@" '-o'   ;;
         '--dmesg')         set -- "$@" '-m'   ;;
         '--ipmi')          set -- "$@" '-i'   ;;
         '--pcie')          set -- "$@" '-p'   ;;
         '--hardware')      set -- "$@" '-w'   ;;
         '--sfboot')        set -- "$@" '-b'   ;;
         *)                 set -- "$@" "$arg" ;;
      esac
   done

   # check the short ones
   while getopts ":f:d:?!hsarnomipwb" arg 2>/dev/null; do
      case $arg in
      f)
         LOG_FILE=$OPTARG
      ;;
      d)
         DIR_NAME=$OPTARG
      ;;
      h)
         echoUsage 
      ;;
      a)
         DMI_INFO=$FALSE
         NETWORK_INFO=$FALSE
         OS_INFO=$FALSE
         DMESG_INFO=$FALSE
         IPMI_INFO=$FALSE
         PCIE_INFO=$FALSE
         HARDWARE_INFO=$FALSE
         SFBOOT_INFO=$FALSE
      ;;
      r)
         DMI_INFO=$TRUE
      ;;
      n)
         NETWORK_INFO=$TRUE
      ;;
      o)
         OS_INFO=$TRUE
      ;;
      m)
         DMESG_INFO=$TRUE
      ;;
      i)
         IPMI_INFO=$TRUE
      ;;
      p)
         PCIE_INFO=$TRUE
      ;;
      w)
         HARDWARE_INFO=$TRUE
      ;;
      b)   
         SFBOOT_INFO=$TRUE
      ;;
      s)
         SERIAL_INFO=$TRUE   
      ;;
      !)
         ARCHIVE_LOGS=$FALSE
      ;;
      ?)
         echoUsage 
      ;;
      *)
         echoUsage 
      ;;
      esac
   done


}

#==============================================================================
#   getDmiInfo: get info from dmidecode
#   params: n/a
#==============================================================================
getDmiInfo()
{   
   which dmidecode> /dev/null 2>&1
   if [ $FAILURE = $? ]
   then
      echoText "<error> dmidecode: dmidecode not installed"
      return $FAILURE
   fi

   checkRoot
   if [ $? = $FAILURE ]
   then
      echoText "<error> dmidecode: requires root privileges"
      return
   fi

   SERIAL_NUMBER=`dmidecode -t system | grep "Serial Number:" | awk -F': ' '{print $2}'`
   MANUFACTURER=`dmidecode -t system | grep "Manufacturer:" | awk -F': ' '{print $2}'`
   PRODUCT=`dmidecode -t system | grep "Product Name:" | awk -F': ' '{print $2}'`
   UUID=`dmidecode -t system | grep "UUID:" | awk -F': ' '{print $2}'`
   CPU_MAN=`dmidecode -t processor| grep "Manufacturer:" | awk -F': ' '{print $2}'`
   CPU_FAM=`dmidecode -t processor| grep "Family:" | awk -F': ' '{print $2}'`
   CPU_VER=`dmidecode -t processor| grep "Version:" | awk -F': ' '{print $2}'`
   BOARD_MAN=`dmidecode -t baseboard | grep "Manufacturer:" | awk -F': ' '{print $2}'`
   BOARD_NAME=`dmidecode -t baseboard | grep "Product Name:" | awk -F': ' '{print $2}'`
   echoLine
   echoText " === dmidecode: pertinent info === \n"
   echoText "Serial Number             [$SERIAL_NUMBER]"
   echoText "Manufacturer              [$MANUFACTURER]"
   echoText "Product                   [$PRODUCT]"
   echoText "UUID                      [$UUID]"
   echoText "CPU Manufacturer          [$CPU_MAN]"
   echoText "CPU Family                [$CPU_FAM]"
   echoText "CPU Version               [$CPU_VER]"
   echoText "Motherboard Manufacturer  [$BOARD_MAN]"
   echoText "Motherboard Model         [$BOARD_NAME]\n"


   IFS=$'\n'
   OUTPUT=$(dmidecode)

   echoLine
   echoText " === dmidecode: full output === \n"
   
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done

}

#==============================================================================
#   getNetworkInfo: get info from ip 
#   params: n/a
#==============================================================================
getNetworkInfo()
{
   which ip > /dev/null 2>&1
   if [ $FAILURE = $? ]
   then
      echoText "<error> ip: ip not installed"
      return $FAILURE
   fi

   echoLine

   echoText " === ip a === \n"

   IFS=$'\n'
   OUTPUT=$(ip a)
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done

}

#==============================================================================
#   getOsInfo - OS info
#   params: n/a
#==============================================================================
getOsInfo()
{
   echoLine

   OS_PATHFILE="/etc/os-release"
   REDHAT_PATHFILE="/etc/redhat-release"

   if [ -f $REDHAT_PATHFILE ] 
   then
      OS_VARIANT="Redhat"
      OS_NAME="Redhat"	
      OS_RELEASE=`cat $REDHAT_PATHFILE`
   fi

   if [ -f $OS_PATHFILE ]
   then
      source $OS_PATHFILE
      OS_VARIANT="Generic"		 
      OS_NAME=$NAME
      OS_RELEASE=$VERSION_ID
      OS_PRETTY_NAME=$PRETTY_NAME
   fi   

   echoText " === Operating System Info === \n"


   if [ -z $OS_VARIANT ]
   then
      echoText "$PREFIX Operating System [Unknown]"
      exit $FAILURE
   else
      echoText "Operating System [$OS_NAME]"
      echoText "Release [$OS_RELEASE]"
      if [[ -n $OS_PRETTY_NAME ]]; then echoText "Name [${OS_PRETTY_NAME}]"; fi
   fi;

}

#==============================================================================
#   getKernelInfo: get info from inxi
#   params: n/a
#==============================================================================
getKernelInfo()
{
   echoText
   echoLine
   
   which uname > /dev/null 2>&1
   if [ $FAILURE = $? ]
   then
      echoText "<error> os: uname not installed"
      return $FAILURE
   fi

   echoText " === uname === \n"

   KERNEL_VERSION=`uname -r`
   BOOT_PARAMS=`cat /proc/cmdline`

   echoText "Kernel info"
   echoText "Version: [$KERNEL_VERSION]"
   echoText "Boot Parameters: [$BOOT_PARAMS]"
    
}

#==============================================================================
#   getCPUPowFreqInfo
#   params: n/a
#==============================================================================
getCPUPowFreqInfo()
{
   echoText
   echoLine

   which cpupower > /dev/null 2>&1
   if [ $FAILURE = $? ]
   then
      echoText "<error> os: cpupower not installed"
      return $FAILURE
   fi

   IFS=$'\n'
   OUTPUT=$(cpupower frequency-info)

   echoText " === cpupower frequency-info === \n"
   
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done

}

#==============================================================================
#   getTurbostatInfo
#   params: n/a
#==============================================================================
getTurbostatInfo()
{
   echoText
   echoLine

   which turbostat > /dev/null 2>&1
   if [ $FAILURE = $? ]
   then
      echoText "<error> os: turbostat not installed"
      return $FAILURE
   fi

   IFS=$'\n'
   OUTPUT=""
   touch "turbotemp.txt"
   TEMP_FILE="turbotemp.txt"

   turbostat --out $TEMP_FILE deliberate_error_throw_ignore_me 2>/dev/null
   # this command is janky, and i found the easiest way to make turbostat run for one pass was by doing this
   # if they patch this in the future it will need changing 
   
   OUTPUT=$(cat $TEMP_FILE)
   rm $TEMP_FILE
   
   echoText " === turbostat --out === \n"
   
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done

}

#==============================================================================
#   getDmesgInfo: get Dmesg info
#   params: n/a
#==============================================================================
getDmesgInfo()
{
   echoLine

   which dmesg > /dev/null 2>&1
   if [ $FAILURE = $? ]
   then
      echoText "<error> dmesg: dmesg not installed"
      return $FAILURE
   fi

   IFS=$'\n'
   OUTPUT=$(dmesg)

   echoText " === dmesg === \n"
   
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done
}

#==============================================================================
#   getIpmiInfo: get IPMI related info
#   params: n/a
#==============================================================================
getIpmiInfo()
{
   echoLine

   which ipmitool > /dev/null 2>&1
   if [ $FAILURE = $? ]
   then
      echoText "<error> ipmi: ipmitool not installed"
      return $FAILURE
   fi

   checkRoot
   if [ $? = $FAILURE ]
   then
      echoText "<error> ipmi: ipmitool requires root priveleges"
      return
   fi   

   echoText " === ipmitool lan print === \n"
   IFS=$'\n'
   OUTPUT=$(ipmitool lan print 2>/dev/null)
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done

   echoText
   echoLine
   echoText " === ipmitool lan print 8 === \n"
   IFS=$'\n'
   OUTPUT=$(ipmitool lan print 8 2>/dev/null)
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done

   echoText
   echoLine
   echoText " === ipmitool sdr list === \n"
   IFS=$'\n'
   OUTPUT=$(ipmitool sdr list 2>/dev/null)
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done

   echoText
   echoLine
   echoText " === ipmitool user list 2 === \n"
   IFS=$'\n'
   OUTPUT=$(ipmitool user list 2 2>/dev/null)
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done
}

#==============================================================================
#   getPcieInfo: get PCIE info
#   params: n/a
#==============================================================================
getPcieInfo()
{
   echoLine

   which lspci > /dev/null 2>&1
	if [ $FAILURE = $? ]
	then
	   echoText "<error> pcie: lspci not installed"
	   return
	fi 

   echoText " === lspci -vvvnn === \n"

	IFS=$'\n'
	OUTPUT=$(lspci -vvvnn)
	for LINE in $OUTPUT
	do
	   echoText "$LINE"
   done
       
}

#==============================================================================
#   getHardwareInfo: get hardware info
#   params: n/a
#==============================================================================
getHardwareInfo()
{
   which lscpu > /dev/null 2>&1
	if [ $FAILURE = $? ]
	then
	   echoText "<error> hardware: lscpu not installed"
	   return
	fi 

   echoLine
   echoText " === lscpu === \n"
	IFS=$'\n'
	OUTPUT=$(lscpu)
	for LINE in $OUTPUT
	do
	   echoText "$LINE"
   done
   

   which lsblk > /dev/null 2>&1
	if [ $FAILURE = $? ]
	then
	   echoText "<error> hardware: lsblk not installed"
	   return
	fi 

   echoText
   echoLine
   echoText " === lsblk === \n"
   IFS=$'\n'
   OUTPUT=$(lsblk 2>/dev/null)
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done
   

   which fdisk > /dev/null 2>&1
	if [ $FAILURE = $? ]
	then
	   echoText "<error> hardware: fdisk not installed"
	   return
	fi 

   echoText
   echoLine
   echoText " === fdisk -l === \n"
   IFS=$'\n'
   OUTPUT=$(fdisk -l 2>/dev/null)
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done


   which lshw > /dev/null 2>&1
	if [ $FAILURE = $? ]
	then
	   echoText "<error> hardware: lshw not installed"
	   return
	fi 

   echoText
   echoLine
   echoText " === lshw === \n"
   IFS=$'\n'
   OUTPUT=$(lshw 2>/dev/null)
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done
       
}

#==============================================================================
#   getSfBootInfo: get info from sfboot
#   params: n/a
#==============================================================================
getSfBootInfo()
{
   which sfboot > /dev/null 2>&1
   if [ $FAILURE = $? ]
   then
      echoText "<error> sfboot: sfboot not installed"
      return $FAILURE
   fi

   echoLine
   echoText " === sfboot === \n"   

   IFS=$'\n'
   OUTPUT=$(sfboot)
   for LINE in $OUTPUT
   do
      echoText "$LINE"
   done
    
}

#==============================================================================
#   getInxiInfo: get info from inxi
#   params: n/a
#==============================================================================
getInxiInfo()
{
   which inxi > /dev/null 2>&1
   if [ $FAILURE = $? ]
   then
      echoText "<error> inxi: inxi not installed"
      return $FAILURE
   fi

   if [[ $TRUE = $QUIET_MODE ]]
   then
      echoText "inxi info"
   fi

   IFS=$'\n'
   OUTPUT=$(inxi -F)
   for LINE in $OUTPUT
   do
      if [[ $FALSE = $QUIET_MODE ]]; then echoText "inxi: $LINE"; fi
   done
    
}

#==============================================================================
#   getScsiInfo: get info from scsi 
#   params: n/a
#==============================================================================
getScsiInfo()
{
   which lsscsi > /dev/null 2>&1
   if [ $FAILURE = $? ]
   then
      echoText "<error> lsscsi: lsscsi not installed"
      return $FAILURE
   fi
   
   if [[ $TRUE = $QUIET_MODE ]]
   then
      echoText "SCSI info"
   fi

   IFS=$'\n'
   OUTPUT=$(lsscsi)
   for LINE in $OUTPUT
   do
      if [[ $FALSE = $QUIET_MODE ]] 
      then 
         echoText "lsscsi: $LINE"
      else 
         TYPE=`echo $LINE | awk '{print $2}'`
         MANU=`echo $LINE | awk '{print $3}'`
         DEV=`echo $LINE | awk '{print $NF}'`
         echoText "Type [$TYPE]\tManufacturer [$MANU]\t Device [$DEV]"
      fi
   done
    
}



#==============================================================================
#                    CHECK FOR FILE ERROR
# If a script fails to pull info, flag in command line
#==============================================================================
checkForFileError()
{
   if [[ `cat $1 | grep "<error>"` ]]
   then
      echo "! Error getting $2 info"
   # else
   #    echo "* No error flagged getting $2 info"
   fi
}

#==============================================================================
#                    GET SERIAL NUMBER
#           Use dmidecode to get serial number
#==============================================================================
getSerial()
{
   which dmidecode> /dev/null 2>&1
   if [ $FAILURE = $? ]
   then
      echo "<error> serial: dmidecode not installed"
      return $FAILURE
   fi

   checkRoot
   if [ $? = $FAILURE ]
   then
      echo "<error> serial: requires root priveleges"
      return $FAILURE
   fi

   SERIAL_NUMBER=`dmidecode -t system | grep "Serial" | awk -F': ' '{print $2}'`
   echo "Serial number: $SERIAL_NUMBER"
}

printHeaderLine()
{
   echo -e "${1}\n\n$DATE | $HOSTNAME | $SERIAL_NUMBER\n" > ${1}
}

#==============================================================================
#                    CHECK OUTPUT FOLDER
# Check if output folder for storing results exists. If it doesn't, create it.
#==============================================================================

checkForDirAndLog()
{
   # defaults are DIR_NAME = "logs", LOG_FILE = "blackcore.<serial>.<datetime>"

   # if filename has not been defined
   if [ -z ${LOG_FILE+x} ]
   then
      LOG_FILE=$DEFAULT_FN
   fi

   # if directory name has not been defined
   if [ -z ${DIR_NAME+x} ]
   then
      DIR_NAME=$DEFAULT_DIR
   fi

   # if directory $TEMP_DIR does not exist
   if [ ! -d "$TEMP_DIR" ];
   then
      mkdir $TEMP_DIR
      if [ $FAILURE = $? ]
      then 
         rm -rf $TEMP_DIR
         mkdir $TEMP_DIR
      fi
   fi;
   
}
#==============================================================================
#                    MAIN
#==============================================================================

DMI_INFO=$TRUE
NETWORK_INFO=$TRUE
OS_INFO=$TRUE
DMESG_INFO=$TRUE
IPMI_INFO=$TRUE
PCIE_INFO=$TRUE
HARDWARE_INFO=$TRUE
SFBOOT_INFO=$TRUE

ARCHIVE_LOGS=$TRUE
SERIAL_INFO=$FALSE

echo -e "\n========================= BLACKCORE DEBUG INFO ================================"
echo -e  "To get usage, try './$SCRIPTNAME --help'"

DATE=`date`
DATE_TAG="`date +%Y%m%d_%H%M%S%Z`" 

getCommandParams ${@}
getSerial
if [ $TRUE = $SERIAL_INFO ]; then echo $SERIAL; exit $SUCCESS; fi

TEMP_DIR="temp"
DEFAULT_DIR="logs"
DEFAULT_FN="blackcore.$SERIAL_NUMBER.$DATE_TAG"

checkForDirAndLog 


   # if data is to be archived, save destination should be DIRECTORY/FILENAME.<datetime>.tar.gz
   # if data is not to be archived, save destination should be DIRECTORY/FILENAME<datetime>/ 
   # do all this nonesense at the end. whilst the program is running save everything to a dir called temp



# DMI_INFO
if [ $TRUE = $DMI_INFO ]
then
   echo "Creating DMI info"
   printHeaderLine $TEMP_DIR/dmi.log
   getDmiInfo >> $TEMP_DIR/dmi.log
   checkForFileError $TEMP_DIR/dmi.log dmi
fi

# NETWORK_INFO
if [ $TRUE = $NETWORK_INFO ]
then
   echo "Creating network info"
   printHeaderLine $TEMP_DIR/network.log
   getNetworkInfo >> $TEMP_DIR/network.log
   checkForFileError $TEMP_DIR/network.log network
fi

# OS_INFO
if [ $TRUE = $OS_INFO ]
then
   echo "Creating OS info"
   printHeaderLine $TEMP_DIR/os.log
   getOsInfo >> $TEMP_DIR/os.log
   getKernelInfo >> $TEMP_DIR/os.log
   getCPUPowFreqInfo >> $TEMP_DIR/os.log
   getTurbostatInfo >> $TEMP_DIR/os.log
   checkForFileError $TEMP_DIR/os.log os
fi

#DMESG_INFO
if [ $TRUE = $DMESG_INFO ]
then
   echo "Creating dmesg info"
   printHeaderLine $TEMP_DIR/dmesg.log
   getDmesgInfo >> $TEMP_DIR/dmesg.log
   checkForFileError $TEMP_DIR/dmesg.log dmesg
fi

# IPMI_INFO
if [ $TRUE = $IPMI_INFO ]
then
   echo "Creating IPMI info"
   printHeaderLine $TEMP_DIR/ipmi.log
   getIpmiInfo >> $TEMP_DIR/ipmi.log
   checkForFileError $TEMP_DIR/ipmi.log ipmi
fi

# PCIE_INFO
if [ $TRUE = $PCIE_INFO ]
then
   echo "Creating PCIE info"
   printHeaderLine $TEMP_DIR/pcie.log
   getPcieInfo >> $TEMP_DIR/pcie.log
   checkForFileError $TEMP_DIR/pcie.log pcie
fi

#HARDWARE_INFO
if [ $TRUE = $HARDWARE_INFO ]
then
   echo "Creating hardware info"
   printHeaderLine $TEMP_DIR/hardware.log
   getHardwareInfo >> $TEMP_DIR/hardware.log
   checkForFileError $TEMP_DIR/hardware.log hardware
fi

# SFBOOT_INFO
if [ $TRUE = $SFBOOT_INFO ]
then
   echo "Creating SFBoot info"
   printHeaderLine $TEMP_DIR/sfboot.log
   getSfBootInfo >> $TEMP_DIR/sfboot.log
   checkForFileError $TEMP_DIR/sfboot.log sfboot
fi

# check DIR_NAME != TEMP_DIR
if [ $DIR_NAME = $TEMP_DIR ]
then
   echo "Error: Directory name cannot be $TEMP_DIR."
   DIR_NAME="logs"
fi

# if directory DIR_NAME does not exist
if [ ! -d "$DIR_NAME" ];
then
   mkdir -p $DIR_NAME
   if [ $FAILURE = $? ]
   then 
      echo -e "mkdir for $DIR_NAME failed, reverting to default"
      DIR_NAME="logs"
      mkdir $DIR_NAME
   fi
fi;

# if not compressing files, save logs to logs. else, save to more specific dir
if [ $FALSE = $ARCHIVE_LOGS ]
then
   cp -a $TEMP_DIR $DIR_NAME
   rm -rf $TEMP_DIR
   if [ -d $DIR_NAME/$LOG_FILE ]
   then
      # directory exists, do you want to overwrite?
      echo "Directory $DIR_NAME/$LOG_FILE already exists, would you like to overwrite? y/n "
      read yn

      if [ "$yn" != "y" ];
      then
         echo "Exiting..."
         rm -rf $DIR_NAME/$TEMP_DIR
         break> /dev/null 2>&1
      else
      ## this bit still doesnt work for some reason
         # delete the old folder before renaming temp
         rm -rf $DIR_NAME/$LOG_FILE
         mv $DIR_NAME/$TEMP_DIR $DIR_NAME/$LOG_FILE
         echo -e "Logs saved to $DIR_NAME/$LOG_FILE"
      fi
   else
      mv $DIR_NAME/$TEMP_DIR $DIR_NAME/$LOG_FILE
      echo -e "Logs saved to $DIR_NAME/$LOG_FILE"
   fi

else
   if [ -f "$DIR_NAME/$LOG_FILE.tar.gz" ]
   then
      # file exists, do you want to overwrite?
      echo "File $LOG_FILE.tar.gz already exists, would you like to overwrite? y/n "
      read yn

      if [ "$yn" != "y" ];
      then
         echo "Exiting..."
         break> /dev/null 2>&1
      else 
         tar -cf $DIR_NAME/$LOG_FILE.tar.gz $TEMP_DIR
         echo -e "Logs saved to $DIR_NAME/$LOG_FILE.tar.gz"
      fi;
   else
      tar -cf $DIR_NAME/$LOG_FILE.tar.gz $TEMP_DIR
      echo -e "Logs saved to $DIR_NAME/$LOG_FILE.tar.gz"
   fi
   rm -rf $TEMP_DIR
fi
