aboutsummaryrefslogtreecommitdiff
path: root/theory.sh.in
blob: 666bca4681d09fb3854c54d2a2e8a1254075d1d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh

# at a bare minimum, a directory is a theory package/library directory if it contains an action or a library.
is_theory_dir() {
    [ -d "${1}" ] || die 2 "'${1}' is not a directory"

    [ -r "${1}"/action ] && [ -s "${1}"/action ] && return 0
    [ -r "${1}"/libraries ] && [ -s "${1}"/libraries ] && return 0

    return 1
}

is_repo_dir() {
    [ -d "${1}" ] || die 2 "'${1}' is not a directory"

    [ -d "${1}"/packages ] && [ -d "${1}"/metadata ] &&
        [ -d "${1}"/libraries ] && [ -d "${1}"/metadata ] &&
        return 0

    return 1
}

is_pkg_dir() {
    [ -d "${1}" ] || die 2 "'${1}' is not a directory"

    match -E "^[A-Za-z][A-Za-z0-9_+-]*#[a-z0-9\._-]+$" "$(basename "${1}")" \
        && is_theory_dir "${1}" \
        && return 0

    return 1
}

is_lib_dir() {
    [ -d "${1}" ] || die 2 "'${1}' is not a directory"

    ! is_pkg_dir "${1}" && is_theory_dir "${1}" && return 0

    return 1
}