1e4a06
#!/bin/bash
1e4a06
1e4a06
_scl_source_help="Usage: source scl_source <action> [<collection> ...]
1e4a06
1e4a06
Don't use this script outside of SCL scriptlets!
1e4a06
1e4a06
Options:
1e4a06
    -h, --help    display this help and exit"
1e4a06
1e4a06
if [ $# -eq 0 -o $1 = "-h" -o $1 = "--help" ]; then
1e4a06
    echo "$_scl_source_help"
1e4a06
    return 0
1e4a06
fi
1e4a06
1e4a06
1e4a06
if [ -z "$_recursion" ]; then
1e4a06
    _recursion="false"
1e4a06
fi
1e4a06
if [ -z "$_scl_scriptlet_name" ]; then
1e4a06
    # The only allowed action in the case of recursion is the same
1e4a06
    # as was the original
1e4a06
    _scl_scriptlet_name=$1
1e4a06
fi
1e4a06
shift 1
1e4a06
1e4a06
if [ -z "$_scl_dir" ]; then
1e4a06
    # No need to re-define the directory twice
1e4a06
    _scl_dir=/etc/scl/conf
1e4a06
    if [ ! -e $_scl_dir ]; then
1e4a06
        _scl_dir=/etc/scl/prefixes
1e4a06
    fi
1e4a06
fi
1e4a06
1e4a06
for arg in "$@"; do
1e4a06
    _scl_prefix_file=$_scl_dir/$arg
1e4a06
    _scl_prefix=`cat $_scl_prefix_file 2> /dev/null`
1e4a06
    if [ $? -ne 0 ]; then
1e4a06
        echo "Can't read $_scl_prefix_file, $arg is probably not installed."
1e4a06
        return 1
1e4a06
    fi
1e4a06
  
1e4a06
    # First check if the collection is already in the list
1e4a06
    # of collections to be enabled
1e4a06
    for scl in ${_scls[@]}; do
1e4a06
        if [ $arg == $scl ]; then
1e4a06
            continue 2
1e4a06
        fi
1e4a06
    done
1e4a06
1e4a06
    # Now check if the collection isn't already enabled
1e4a06
    /usr/bin/scl_enabled $arg > /dev/null 2> /dev/null
1e4a06
    if [ $? -ne 0 ]; then
1e4a06
        _scls+=($arg)
1e4a06
        _scl_prefixes+=($_scl_prefix)
1e4a06
    fi;
1e4a06
done
1e4a06
1e4a06
if [ $_recursion == "false" ]; then
1e4a06
    _i=0
1e4a06
    _recursion="true"
1e4a06
    while [ $_i -lt ${#_scls[@]} ]; do
1e4a06
        _scl_scriptlet_path="${_scl_prefixes[$_i]}/${_scls[$_i]}/${_scl_scriptlet_name}"
1e4a06
        source "$_scl_scriptlet_path"
1e4a06
        if [ $? -ne 0 ]; then
1e4a06
            echo "Can't source $_scl_scriptlet_name, skipping."
1e4a06
        else
1e4a06
            export X_SCLS="${_scls[$_i]} $X_SCLS"
1e4a06
        fi;
1e4a06
        _i=$(($_i+1))
1e4a06
    done
1e4a06
    _scls=()
1e4a06
    _scl_prefixes=()
1e4a06
    _scl_scriptlet_name=""
1e4a06
    _recursion="false"
1e4a06
fi