# Common functions shared by LTSP scripts

boolean_is_true(){
    case $1 in
       # match all cases of true|y|yes
       [Tt][Rr][Uu][Ee]|[Yy]|[Yy][Ee][Ss]) return 0 ;;
       *) return 1 ;;
    esac
}

# list files in a directory consisting only of alphanumerics, hyphens and
# underscores
# $1 - directory to list
# $2 - optional prefix to limit which files are selected
run_parts_list() {
    if [ $# -lt 1 ]; then
        echo "ERROR: Usage: run_parts_list <dir>" > /dev/stderr
        exit 1
    fi
    if [ ! -d "$1" ]; then
        echo "ERROR: Not a directory: $1" > /dev/stderr
        exit 1
    fi

    if [ -d "$1" ]; then
        if [ -n "$2" ]; then
            find_opts="-name $2*"
        fi
        for file in $(find -L $1 -mindepth 1 -maxdepth 1 -type f $find_opts | sort -n) ; do
            basefile=$(basename $file)
            if [ -n "$(echo "$basefile" | egrep ^[0-9a-zA-Z_\-]*$)" ]; then
                echo $file
            fi
        done
    fi
}

if [ -f /usr/share/ltsp/ltsp-vendor-functions ]; then
    . /usr/share/ltsp/ltsp-vendor-functions
fi
