#!/bin/bash
# 
# ***** BEGIN LICENSE BLOCK *****
# Zimbra Collaboration Suite Server
# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013, 2014, 2016 Synacor, Inc.
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software Foundation,
# version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
# ***** END LICENSE BLOCK *****
# 
source /opt/zimbra/bin/zmshutil || exit 1
zmsetvars

while getopts "h" flag
do
  if [ x$flag == "xh" ]; then
    echo "Usage: $0 [-h]"
    echo "    Dumps various environment information"
    echo "    -h: This help information"
    exit 0
  fi
done

echo "----------------"
date +%Y%m%d%H%M%S
echo "----------------"
id
echo "----------------"
uname -a
echo "----------------"
hostname
echo "----------------"
H=`/opt/zimbra/bin/zmhostname`
echo $H
echo "----------------"
host $H 
echo "----------------"
P=`/opt/zimbra/libexec/get_plat_tag.sh`
echo $P
echo "----------------"
df -h
echo "----------------"
/sbin/ifconfig
echo "----------------"

if [[ x$P == "xMACOSX"* ]]; then
	ls -ld /Library/Receipts/zimbra-*
elif [[ "x$P" == "xUBUNTU"* || "x$P" == "DEBIAN"* ]]; then
	apt-cache show zimbra-core
else
	rpm -qi zimbra-core
fi
echo "----------------"
ls -l /opt/zimbra
echo "----------------"
uptime
echo "----------------"
memkb=$(zmsysmemkb)
echo $memkb KB
echo "----------------"
if [ x$P != "xMACOSX" -a x$P != "xMACOSXx86" ]; then
	echo "----------------"
	freemem=`free -m`
	echo FREE $freemem KB
	echo "----------------"
fi
echo "----------------"
cat /etc/hosts
echo "----------------"
cat /etc/resolv.conf
echo "----------------"
cat /etc/nsswitch.conf
echo "----------------"
if [ -x "/usr/sbin/selinux" ]; then
  /usr/sbin/selinux
fi
echo "----------------"
ls -ld /usr/lib/libstdc++*
if [ -d "/usr/lib64" ]; then
  ls -ld /usr/lib64/libstdc++*
fi
echo "----------------"
  

