#!/bin/sh
# Copyright (c), NETGEAR, Inc.
# 350 East Plumeria, San Jose California, 95134, U.S.A.
# All rights reserved.
#
# This software is the confidential and proprietary information of
# NETGEAR, Inc. ("Confidential Information").  You shall not
# disclose such Confidential Information and shall use it only in
# accordance with the terms of the license agreement you entered into
# with NETGEAR.

function usage() {
    echo -e "Usage:  system <operation> <object>\n"
    echo "Arguments:"
    echo "<operation>"
    echo "    -g         to get some information."
    echo "<object>"
    echo "    serial_number       serial number."
    echo "    model_name          model name."
    exit
}

function get_opt() {
    value=""
    if [ -z "$1" ]; then
        echo "Please input object"
        return 1
    fi
    if [ "$1" = "model_name" ]; then
        value=`uci get sysProductInfo.model.modelName`
    elif [ "$1" = "serial_number" ]; then
        value=`setconfig -g 19`
    fi
    if [ -z "$value" ]; then
        echo "Can't get $1 from system"
        return 2
    fi
    echo $value
    return 0
}

ogargs=""
while getopts "g:h" opt; do
    case $opt in
    g ) ogargs=$OPTARG
        get_opt ${ogargs}
        [ "$?" -ne 0 ] && usage
        ;;
    h ) usage  >&2
        ;;
    \? ) usage  >&2
        ;;
    esac
done
