#!/bin/bash
EPOCH=`date +%s`
MACHINE=`hostname -f`
if [ $? ]; then MACHINE=`cat /etc/hostname`; fi

REPORT=/tmp/$MACHINE~~~$EPOCH
touch $REPORT

echo '===IPADDRESSES_START===' >> $REPORT;
ip addr | grep 'inet' | grep -v 'scope host' | grep -v 'inet6 fe80' | cut -d ' ' -f 6 | tee -a $REPORT > /dev/null;
echo '===IPADDRESSES_END===' >> $REPORT;

echo '===OPERATINGSYSTEM_START===' >> $REPORT;
if [ -f /etc/redhat-release ]; then
  cat /etc/redhat-release >> $REPORT;
fi

if [ -f /etc/lsb-release ]; then
  cat /etc/lsb-release | grep 'DISTRIB_DESCRIPTION' | cut -d '=' -f 2 | sed -e 's/"//g' >> $REPORT;
fi
echo '===OPERATINGSYSTEM_END===' >> $REPORT;

echo '===KERNELVERSION_START===' >> $REPORT;
  uname -r >> $REPORT;
echo '===KERNELVERSION_END===' >> $REPORT;

if [ -x /usr/bin/yum ]; then
  yum list installed | sed -e 's/Installed Packages/===PACKAGELIST_START===/' | sed -e 's/\@.*$//' | sed -e 's/installed.*$//' | tee -a $REPORT > /dev/null;
  # maybe convert tabs to spaces
  echo '===PACKAGELIST_END===' >> $REPORT;
fi
if [ -x /usr/bin/apt ]; then
  echo '===PACKAGELIST_START===' >> $REPORT;
  apt list --installed 2>/dev/null | grep -v 'Listing...' | cut -d ' ' -f 1,2 | sed -e 's/\/.* / /' | tee -a $REPORT > /dev/null;
  echo '===PACKAGELIST_END===' >> $REPORT;
fi

curl -s -X POST -F "text/plain=@$REPORT" https://report.bit.nl/tx/

