aboutsummaryrefslogtreecommitdiff
path: root/src/cpt
blob: cdaff4295d2d2563c53766ebdb51dadaa1e3765d (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh -ef

bi() {
    # Build and install function for cpt.
    parser_definition() {
        setup REST help:usage -- "usage: ${0##*/} bi [-dfSty] [--root ROOT] [pkg...]"
        msg -- '' 'Options:'
        flag CPT_TEST    -t --test    export:1 init:@export -- "Run tests (if they exist)"
        flag CPT_DEBUG   -d --debug   export:1 init:@export -- "Keep the build directories after operation"
        flag CPT_NOSTRIP -S --nostrip export:1 init:@export -- "Don't strip debug information from the binaries" \
                                                               "(might want to add '-g' to your '\$CFLAGS')"
        global_options
    }

    eval "$(getoptions parser_definition parse "$0")"
    parse "$@"
    eval set -- "$REST"
    cpt-build "$@"

    # When building multiple packages, cpt will already ask to install
    # the packages, so no need for this here.
    [ "$2" ] || cpt-install "$@"
}

cbi() {
    # Checksum, build and install.
    parser_definition() {
        setup REST help:usage -- "usage: ${0##*/} cbi [-dfSsty] [--root ROOT] [pkg...]"
        msg -- '' 'Options:'
        flag CPT_TEST    -t --test    export:1 init:@export -- "Run tests (if they exist)"
        flag CPT_DEBUG   -d --debug   export:1 init:@export -- "Keep the build directories after operation"
        flag CPT_NOSTRIP -S --nostrip export:1 init:@export -- "Don't strip debug information from the binaries" \
                                                               "(might want to add '-g' to your '\$CFLAGS')"
        flag sha -s --    "Generate checksums using the depracated sha256 algorithm"
        global_options
    }

    eval "$(getoptions parser_definition parse "$0")"
    parse "$@"
    eval set -- "$REST"

    cpt-checksum "$@"; cpt-build "$@"
    [ "$2" ] || cpt-install "$@"
}

if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi

# If none of the tools below are specified, we will reenable glob
unset glob

[ "$1" ] && { arg=$1; shift; }
case "$arg" in
    --help|-h|'')
        log "Carbs Packaging Tool"
        set --
        for path in $(SEARCH_PATH=$PATH pkg_find cpt-* all -x); do
            set -- "${path##*/cpt-}" "$@"
            max=$((${#1} > max ? ${#1} : max))
        done

        for path; do
            printf "%b->%b %-${max}s  " "$colorb" "$colre" "${path#*/cpt-}"
            awk 'NR==2{if(/^# /){sub(/^# */,"");print}else print "";exit}' \
                "$(command -v "cpt-$path")"
        done | sort -uk1 >&2
        exit
        ;;

    --version|-v|version) version ;;

    # Reserve these arguments for the following tools.
    a|alternatives) arg=alternatives ;;
    b|build)        arg=build ;;
    c|checksum)     arg=checksum ;;
    d|download)     arg=download ;;
    i|install)      arg=install ;;
    l|list)         arg=list ;;
    r|remove)       arg=remove ;;
    s|search)       arg=search ;;
    u|update)       arg=update ;;
    bi|cbi)         "$arg" "$@"; exit "$?" ;;
    *) glob=1 ;;
esac

util=$(SEARCH_PATH=$PATH pkg_find "cpt-$arg${glob:+*}" "" -x 2>/dev/null) ||
    die "'cpt $arg' is not a valid command"

"$util" "$@"