#!/bin/bash

full_version=0
if [ "x$1" = "xfull" ]; then
    full_version=1
fi

company_name=""
hardware_model=""

if [ -f /pica/etc/brand ]; then
    while read line; do
    	key="${line%%=*}"
    	key=`echo $key | grep -o "[^ ]\+\( \+[^ ]\+\)*"`
	
        value="${line##*=}"
        value=`echo $value | grep -o "[^ ]\+\( \+[^ ]\+\)*"`
	
        if [ "$key" = "COMPANY_NAME" ]; then
            company_name="$value"
        fi
        
        if [ "$key" = "HARDWARE_MODEL" ]; then
            hardware_model="$value"
        fi
    done < /pica/etc/brand
fi

if [ -z "$company_name" ]; then
    company_name="Pica8, Inc"
fi

if [ -z "$hardware_model" ]; then
    hardware_model="Unknown"
fi

rel_year=`grep CREATED_DATE /etc/lsb-release 2>/dev/null|awk -F/ '{print $NF}'`
[ "x${rel_year}" = "x" ] && rel_year=`date +%Y`

echo "Copyright (C) 2009-${rel_year} ${company_name}"

echo "==================================="
echo -n "Base ethernet MAC Address     : "

/pica/bin/system/pica_switch_mac
echo

echo "Hardware Model                : ${hardware_model}"

if [ -f /etc/lsb-release ]; then
    echo -n "Linux System Version/Revision : "
    echo -n `sed '/DISTRIB_RELEASE=/!d;s+DISTRIB_RELEASE=++' /etc/lsb-release`
    echo -n "/"
    echo `grep DISTRIB_REVISION /etc/lsb-release |awk -F= '{print $2}'`
    echo -n "Linux System Released Date    : "
    echo `grep CREATED_DATE /etc/lsb-release |awk -F= '{print $NF}'`
fi

if [ -f /pica/etc/lsb-release ]; then
    echo -n "L2/L3 Version/Revision        : "
    echo -n `sed '/DISTRIB_RELEASE=/!d;s+DISTRIB_RELEASE=++' /pica/etc/lsb-release`
    echo -n "/"
    echo `grep DISTRIB_REVISION /pica/etc/lsb-release |awk -F= '{print $2}'`
    echo -n "L2/L3 Released Date           : "
    echo `grep CREATED_DATE /etc/lsb-release |awk -F= '{print $NF}'`
    if [ $full_version -ne 0 ];then
        echo -n "L2/L3 GA Released Date        : "
        echo `grep GA_RELEASE_DATE /etc/lsb-release |awk -F= '{print $NF}'`
    fi
else
    res=`dpkg -s picos-switching >/dev/null 2>&1|grep Status|grep installed |wc -l`
    if [ $res -ne 0 ]; then
        echo -n "L2/L3 Version/Revision        : "
        echo -n `dpkg -s picos-switching|grep Version|awk '{print $NF}'|awk -F- '{print $1}'`
        echo -n "/"
        echo `dpkg -s picos-switching|grep Version|awk '{print $NF}'|awk -F- '{print $NF}'`
    fi
fi

echo

exit 0
