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