summaryrefslogtreecommitdiffstats
path: root/nix-script-container.sh
blob: 14e624190cc0469e9decc4b6ece90eb68ac32dc3 (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
#!/usr/bin/env bash

# Level-2 wrapper to be able to
#
#   nix-script container <command>

source $(dirname ${BASH_SOURCE[0]})/nix-utils.sh

export VERBOSE

usage() {
    cat <<EOS >&2
    $(help_synopsis "${BASH_SOURCE[0]}" "[-h] [-l] <command>")

    -l  List all available commands
    -h  Show this help and exit

$(help_end "container")
EOS
}

while getopts "hl" OPTION
do
    case $OPTION in
        h)
            usage
            exit 0
            ;;

        l)
            caller_util_list_subcommands_for "nix-script-container"
            exit 0
            ;;
        *)
            ;;
    esac
done

[[ -z "$1" ]] && stderr "No command given" && usage && exit 1

SCRIPT=$(caller_util_get_script "nix-script-container" "$1")
[[ -z "$SCRIPT" ]] && exit 1
stdout "SCRIPT = $SCRIPT"

stdout "Parsing args for '$1'"
SCRIPT_ARGS=$(echo $* | sed -r "s/(.*)$1(.*)/\2/")

stdout "Calling: '$SCRIPT $SCRIPT_ARGS'"
RC_CONFIG=$RC_CONFIG RC_NIXPKGS=$RC_NIXPKGS exec bash $SCRIPT $SCRIPT_ARGS