#!/bin/sh
# Utility functions for all init scripts
# --------------------------------------
# Return the number of init scripts.
numScripts()
{
    DIR=/etc/init.d
    CWD=`pwd`
    cd $DIR
    cnt=0
    for file in `ls -1 S??*`
    do
        val=`echo $file | cut -c2-3`
        if [ $val -lt 90 ]
        then
            cnt=`expr $cnt + 1`
        fi
    done
    cd $CWD
    echo $cnt
}

# Return the value for a specified kernel
# command line argument. If not found, return
# an empty string.
getArgValue()
{
    ARG=$1
    VALUE=
    for i in $(cat /proc/cmdline)
    do
        echo $i | grep "$ARG" > /dev/null
        if [ $? = 0 ]; then
            VALUE=`echo $i | cut -f2 -d"="`
            break
        fi
    done
    echo $VALUE
}

# Load functions from add on packages
# Some of the functions may depend on these functions
# so load them after these functions.
if [ -d /etc/init.d/functions.d ]
then
    numFiles=`ls -1 /etc/init.d/functions.d/* | wc -l`
    if [ $numFiles -gt 0 ]
    then
        for file in `ls -1 /etc/init.d/functions.d/*`
        do
            . $file
        done
    fi
fi

