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