#If no arguments are passed to this script, the sha1 cert will be displayed in default.
#Please do not modify the else statement, as it might disturb the backward compatibility.

#!/bin/sh
if [ $# -gt 0 ] && [ $1 == "sha2" ]; then
    cert_tool sha2_installed
    if [ $? -eq 0 ]; then
        cert_tool dump_sha2 2> /dev/null
        echo "----------------------------- Device Certificate -----------------------------"
        openssl x509 -inform der -in /tmp/.dev_cert_dump.der -noout -text
        echo "------------------------------------------------------------------------------"
    fi
elif [ $# -gt 0 ] && [ $1 == "lsc" ]; then
    lsc=`cat /storage/base_capwap_cfg_info | grep lsc_enabled | cut -d" " -f2`
    if [ "$lsc" == "true" ]; then
        echo "LSC: Enabled"
        echo "----------------------------- Device Certificate -----------------------------"
        openssl x509 -in /storage/lsc/device.cert -noout -text
        echo "------------------------------------------------------------------------------"
        echo "----------------------------- Root Certificate -------------------------------"
        openssl x509 -in /storage/lsc/ra.cert -noout -text
        echo "------------------------------------------------------------------------------"
        else
        echo "LSC: Not Enabled"
    fi
else
    cert_tool sha1_installed
    if [ $? -eq 0 ]; then
        cert_tool dump 2> /dev/null
        echo "----------------------------- Device Certificate -----------------------------"
        openssl x509 -inform der -in /tmp/.dev_cert_dump.der -noout -text
        echo "------------------------------------------------------------------------------"
    fi
fi
