aboutsummaryrefslogtreecommitdiff
path: root/run.sh
blob: c06feed8ba307e35caf059ca25b65384437aa09d (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
echo DEV_ENV "$DEV_ENV"
[ ! -d "$DEV_ENV" ] && echo DEV_ENV DIRECTORY IS NOT FOUND && exit 1

run_runs_all=0
list_runs=0
while getopts "al" opt; do
    case "$opt" in
        a) run_runs_all=1
            ;;
        l) list_runs=1
            ;;
        *) echo invalid args
            exit
            ;;
    esac
done

shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift


script_dir="$( cd "$( dirname "$0" )" || exit > /dev/null && pwd )"

runs_dir="$(find "$script_dir/runs" -mindepth 1 -maxdepth 1 -type f -executable)"
runs_dir_all="$(find "$script_dir/runs-all" -mindepth 1 -maxdepth 1 -type f -executable)"

if [ $list_runs = 1 ]; then
    printf "  runs --------------\n"
    ls "$script_dir/runs"
    printf "\n  runs-all ----------\n"
    ls "$script_dir/runs-all"
    exit 0
fi

if [ "$1" != "" ]; then
    [ -e "$script_dir/runs/$1.sh" ] && . "$script_dir/runs/$1.sh"

    if [ $run_runs_all = 1 ]; then
        . "$script_dir/runs-all/$1.sh"
    fi
else
    for s in $runs_dir; do
        echo "running $s"
        . "$s"
    done

    if [ $run_runs_all = 1 ]; then
        for s in $runs_dir_all; do
            echo "running $s"
            . "$s"
        done
    fi
fi