# 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

    find -L "$1" -mindepth 1 -maxdepth 1 -type f -name "$2*" | sed -n '/.*\/[0-9a-zA-Z_\-]\{1,\}$/p' | sort -n
}

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

# nc -q is default behavior on RHEL/Fedora, detect nc version
nc_output=`LANG=C nc -q 2>&1` ||:
case "$nc_output" in
   *"option requires an argument"*) nc_q_param="-q -1" ;;
   *"invalid option -- q "*) unset nc_q_param ;;
   *"invalid option -- 'q' "*) unset nc_q_param ;;
esac
unset nc_output
