skb-framework

The skb-framework is the main entry point to the framework. It realizes two things in one. First, it is an application itself. Second, it is a start script that can be used by other applications to start the framework.

At the start, it checks the setting __FW_LOADER_FLAVOR (line 1 in the source block below). If this variable is set, then another application wants to start the framework. Otherwise, the skb-framework is the application. In the later case, the script sets required variables for the loader (lines 3-5 below):

  • __FW_LOADER_FLAVOR - the flavor of the application, here SF

  • __FW_LOADER_SCRIPTNAME - the name of the script (application)

  • __FW_LOADER_APPNAME - the application name

The next step is to find the framework installation. The script tries the variable SF_HOME first, readlink first (lines 8-13), if that fails dirname (lines 15-19). If all attempts fail, the script terminates with an error (lines 20-24). Otherwise it set FW_HOME.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
if [[ -z ${__FW_LOADER_FLAVOR:-} ]]; then
    ## we should load the framework itself, so SF
    export __FW_LOADER_FLAVOR="SF"
    export __FW_LOADER_SCRIPTNAME="$0"
    export __FW_LOADER_APPNAME="SKB Framework"

    ## try readline to find where we are
    if [[ -z ${SF_HOME:-} ]]; then
        SF_HOME=$(readlink -f $0)
        SF_HOME=${SF_HOME%/*}
        SF_HOME=${SF_HOME%/*}
        export SF_HOME
    fi
    ## try dirname to find where we are
    if [[ -z ${SF_HOME:-} ]]; then
        SF_HOME=$(dirname $0)
        SF_HOME=$(cd $SF_HOME/..; pwd)
        export SF_HOME
    fi
    if [[ -z ${SF_HOME:-} ]]; then
        printf "  unable to set home \$SF_HOME (tried environment, readlink, and dirname \$0)\n"
        printf "  please set SF_HOME\n\n"
        exit 10
    fi
    export FW_HOME=$SF_HOME

If skb-framework is used by another application to start the framework, the script only tries to find the framework installation. The mechanism here is the same as explained above: try FW_HOME first, then readlink, then dirname. IF all fails, exit with an error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
else
    ## try readline to find where we are
    if [[ -z ${FW_HOME:-} ]]; then
        FW_HOME=$(readlink -f $0)
        FW_HOME=${FW_HOME%/*}
        FW_HOME=${FW_HOME%/*}
        export FW_HOME
    fi
    ## try dirname to find where we are
    if [[ -z ${FW_HOME:-} ]]; then
        FW_HOME=$(dirname $0)
        FW_HOME=$(cd $FW_HOME/..; pwd)
        export FW_HOME
    fi
    if [[ -z ${FW_HOME:-} ]]; then
        printf "  unable to set framework home \$FW_HOME (tried environment, readlink, and dirname \$0)\n"
        printf "  please set FW_HOME\n\n"
        exit 10
    fi

One the framework installation has been found, the script tests if the loader exists.

1
2
3
4
5
if [[ ! -x $FW_HOME/bin/loader/loader.sh ]]; then
    printf "  did find/set \$FW_HOME, but did not find loader\n"
    printf "  tried $FW_HOME/bin/loader/loader.sh\n\n"
    exit 11
fi

When all conditions are satisfied, the script executes the loader handing over all arguments unprocessed.

1
2
$FW_HOME/bin/loader/loader.sh $*
exit $?