aboutsummaryrefslogtreecommitdiff
path: root/bin/ak
blob: d18012a45844de937193cc17d3099d21155ac410 (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
55
#!/bin/bash

PROGRAM=$(basename $0)
source $AK_LIBDIR/_ak_logit
source $AK_LIBDIR/_ak_script_exit

if [ $# -eq 0 ]
then
    logit "WARNING" "No command given"
    (
        find $AK_BINDIR | grep 'ak-' | while read available
        do
            #subcmd="$(basename $available | cut -d '-' -f 2)"
            subcmd="$(basename $available)"
            args="-h"
            if [ -n "$subcmd" ]
            then
                echo $subcmd | cut -d '-' -f 2 | sort | uniq | sed -e 's/^/ak /g'
                # $(echo $subcmd) $args
            fi
        done
    ) | sort | uniq
    exit 1
fi

subcmd="$(echo $* | sed -e 's/ /-/g')"
if [ -f "$AK_BINDIR/ak-$subcmd" ]
then
    $(echo ak-$subcmd)
    exit_program $? "ak-$subcmd command finished";
else
    argc=$#
    argv="$*"
    counter=1
    while [ $counter -lt $argc ]
    do
        subcmd="$(echo $argv | cut -d ' ' -f -$counter | sed -e 's/ /\-/g')"
        args="$(echo "$argv"| cut -d ' ' -f $(($counter + 1))-)"
        if [ -n "$subcmd" ] && [ -f "$AK_BINDIR/ak-$subcmd" ]
        then
            logit "INFO" "Running: ak-$subcmd with args: $args"
            $(echo ak-$subcmd) $args
            exit_program $? "ak-$subcmd command finished";
        fi
        counter=$(($counter + 1))
    done
    find $AK_BINDIR | while read available
    do
        echo $(basename $available) |\
            grep ak-$(echo $argv | cut -d ' ' -f 1) |\
            sed -e 's/-/ /g'
    done
    logit "ERROR" "Unknown subcommand: $*"
    exit 1
fi