#!/bin/sh

############
# CHANGELOG
#===========
# 2010/04/27    CRMS00221425    Thanh lam NGUYEN
#               Add reboot before entering a step if needed.
#
################
. /etc/init.d/rc.config
. $DEBUGBINPATH/.functions

# CRMS00221425
help()
{
    echo "Syntax: initstatus [all]"
    echo ""
    echo "Display the status of the current step or all the step until the current one if 'all' is given as parameter."
    echo ""
    exit 1
}
# CRMS00221425 END

RET=$OK

# CRMS00221425
: "${attr:=$esc[34m}Process command line${default:=$esc[0m}" # to restore vim syntax highlighting "]}]}"
all=0
while [[ $# -ne 0 ]]; do
    case "$1" in
        all) : "${attr}all${default}"
            all=1
        ;;
        *) : "${attr}unknown${default}"
            help
        ;;
    esac
    shift
done
# CRMS00221425 END

if [[ -e $stepStatusfile ]]; then
# CRMS00221425
    # read the status file
    if [[ $all -eq 1 ]]; then
        status="$(sed -e 's/^.*
//' $stepStatusFile)"
    else
        status="$(awk '/^STEP/{res="step "$2; next}/succeed/{res="step "$3" finished"; next}END{print res}' $stepStatusFile)"
    fi
# CRMS00221425 END
    echo "$status"
else
    RET=$NOK
fi

[[ $RET -eq $OK ]] && { EXITOK; } || { EXITNOK; }
