mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
76 lines
1.6 KiB
Bash
Executable file
76 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
###
|
|
### nux-runner is environment runner for nux-env enhanced bash scripts
|
|
### and provides out of the box support for task-style scripts
|
|
### (similar in usage such as apt, git).
|
|
###
|
|
|
|
readonly NUX_RUNNER=$0;
|
|
readonly NUX_RUNNER_BIN_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
|
|
source $NUX_RUNNER_BIN_DIR/../inc/nux-base.inc.sh
|
|
|
|
|
|
|
|
function is_function () {
|
|
declare -f "$1" &>/dev/null && return 0
|
|
return 1
|
|
}
|
|
|
|
runner.run() {
|
|
TASK=$1; shift; # Determines task
|
|
if is_function task.$TASK ; then
|
|
nux.log debug "Running task: $TASK";
|
|
task.$TASK "$@" # Runs task
|
|
else
|
|
nux.log debug "Including script: $NUX_SCRIPT"
|
|
source $NUX_SCRIPT; # Includes script
|
|
|
|
if is_function task.$TASK ; then
|
|
nux.log debug "Running task: $TASK";
|
|
task.$TASK "$@" # Runs task
|
|
else
|
|
echo "$NUX_SCRIPTNAME: Unrecognized task ''$TASK' not available."
|
|
echo "Try '$NUX_SCRIPTNAME help' for more information."
|
|
exit -1
|
|
fi
|
|
fi
|
|
}
|
|
##
|
|
## Tasks provided by 'nux-runner':
|
|
|
|
|
|
## debug - Runs specified task with debug messages enabled.
|
|
task.debug() {
|
|
N_LOG_debug=1
|
|
runner.run "$@"
|
|
}
|
|
|
|
## trace - Runs specified task with debug & trace enabled.
|
|
task.trace() {
|
|
N_LOG_debug=1;
|
|
N_LOG_trace=2;
|
|
runner.run "$@"
|
|
}
|
|
|
|
## help - Shows this help
|
|
task.help() {
|
|
echo Usage: $NUX_SCRIPTNAME [task] [options]
|
|
grep "^\#\#\# " $NUX_SCRIPT | cut -d\# -f4-
|
|
echo " Available Tasks: "
|
|
grep "^\#\# " $NUX_SCRIPT | cut -d\# -f3-
|
|
grep "^\#\# " $NUX_RUNNER | cut -d\# -f3-
|
|
echo
|
|
}
|
|
|
|
##
|
|
|
|
task.() {
|
|
task.help
|
|
}
|
|
|
|
readonly NUX_SCRIPT=$1;
|
|
shift; # Determines script
|
|
readonly NUX_SCRIPTNAME=$(basename $NUX_SCRIPT)
|
|
|
|
runner.run "$@"
|