#!/bin/bash
#
# A collector to prepare some info in XML format in the same fashion
# like it was done by dispatcher
#
# Copyright (c) 2020-2021 Virtuozzo International GmbH. All rights reserved.
#
# This file is part of vzreport. It's 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; either version 2 of the License,
# or (at your option) any later version.
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Our contact details: Virtuozzo International GmbH, Vordergasse 59, 8200
# Schaffhausen, Switzerland.
#

REPORT_DIR=$1
if [ -z "$REPORT_DIR" ]; then
    echo "Usage: $0 <REPORT_DIR>"
    exit 0
fi

echo '<ClientInfo id="-1" dyn_lists="">' > "$REPORT_DIR/ClientInfo.xml"
echo -n ' <Environment>' >> "$REPORT_DIR/ClientInfo.xml"
env | sed 's/&/$lt;/g' >> "$REPORT_DIR/ClientInfo.xml"
cat >> "$REPORT_DIR/ClientInfo.xml" <<EOF
</Environment>
 <HostInfo><![CDATA[]]></HostInfo>
 <NameInArchive></NameInArchive>
 <ClientSettings><![CDATA[]]></ClientSettings>
EOF
echo -n'<InstalledSoftware><![CDATA[' >> "$REPORT_DIR/ClientInfo.xml"
rpm -qa  >> "$REPORT_DIR/ClientInfo.xml"
cat >> "$REPORT_DIR/ClientInfo.xml" <<EOF
]]></InstalledSoftware>
 <CombinedReportId></CombinedReportId>
 <Rating>0</Rating>
</ClientInfo>
EOF
