#!/bin/bash
#
# Copyright (C) 2002-2003 by NCHC, Steven Shiau, K. L. Huang
# (steven _at_ nchc org tw, klhaung _at_ gmail com)
#
# 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; either version 2, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

# Load DRBL setting and functions
# Setting
# Source function library.
[ -f /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions

# Source DRBL setting
. /opt/drbl/conf/drbl.conf

# Source the drbl related functions
. $DRBL_SCRIPT_PATH/sbin/drbl-functions

# get the distribution name and type: OS_Version and OS_type
check_distribution_name

echo -n "Acquiring some info about the system."
#
echo -n .
case "$OS_Version" in
   RH*|FC*|CO*|MDK*|MDV*|SUSE*)
      drbl_ver="$(rpm -q drbl)"
      clonezilla_ver="$(rpm -q clonezilla)"
      ;;
   DBN*)
      drbl_ver="$(dpkg -l drbl | tail -n 1 | awk -F" " '{print $3}')"
      clonezilla_ver="$(dpkg -l clonezilla | tail -n 1 | awk -F" " '{print $3}')"
      ;;
   *)
      echo "This version in this distribution is NOT supported by DRBL, maybe you can try to use the drbl in testing or unstable repository. Program terminated!"
      exit 1 
esac

echo -n .
ARCH="$(uname -m)"
Kernel_VER="$(uname -r)"

echo -n .
if [ -f /tftpboot/nbi_img/kernel_version_in_initrd.txt ]; then
  client_kernel_ver="$(cat /tftpboot/nbi_img/kernel_version_in_initrd.txt)"
fi

if [ -f /tftpboot/nbi_img/client_kernel_arch.txt ]; then
  client_kernel_arch="$(cat /tftpboot/nbi_img/client_kernel_arch.txt)"
fi

# To strip the line feed, we use echo ``
echo -n .
private_NIC="$(/opt/drbl/bin/get-all-nic-ip  --private-ip-port)"
echo -n .
private_IP="$(/opt/drbl/bin/get-all-nic-ip --private-ip-address)"
echo -n .
client_IP="$(echo `/opt/drbl/bin/get-client-ip-list`)"


echo "done!"

# output the results:
echo "To report the bug, fill the following and send it to drbl@lists.nchc.org.tw (Chinses) or drbl-user@lists.sourceforge.net (English)"
echo "-------CUT BEGIN HERE--------------------------------------------"
echo "OS version: $FULL_OS_Version"
echo "DRBL version: $drbl_ver"
echo "Clonezilla version: $clonezilla_ver"
echo "Server arch: $ARCH"
echo "Server Kernel version: $Kernel_VER"
echo "Client kernel version: $client_kernel_ver"
echo "Client kernel arch: $client_kernel_arch"
echo "NICs with private IP address in server: $private_NIC"
echo "Private IP address in server: $private_IP"
echo "Client IP address: $client_IP"

echo
echo "Description of problem:"
echo "How reproducible:"
echo "Steps to Reproduce:"
echo "Actual results:"
echo "Expected results:"
echo "-------CUT END HERE----------------------------------------------"
