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