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