Repository URL to install this package:
|
Version:
0.1.0 ▾
|
#!/usr/bin/env bash
# ------------------------------------------------------------
# Bash script template for the freckles shell script connector
#
# If run outside freckles, those environment variables can be adjusted:
#
# ECHO_TASK_START=false
# ECHO_TASK_FINISH=false
#
# Copyright 2018 by Markus Binsteiner
# licensed under the BSD-2-Clause Plus Patent License
# ------------------------------------------------------------
# GLOBAL VARS
# return value codes
SUCCESS=0
NO_CHANGE=100
SKIPPED=101
# ----------------------------------------------------
# freckly init stuff
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then source "$HOME/.nix-profile/etc/profile.d/nix.sh"; fi
# additional bin paths
{% for path in extra_paths %}
if [ -d "{{ path }}" ]; then
export PATH="{{ path }}:$PATH"
fi
{% endfor %}
if [ -f "$THIS_DIR/exodus-binaries/bundle.sh" ]; then
$THIS_DIR/exodus-binaries/bundle.sh $THIS_DIR/exodus-binaries
export PATH="$THIS_DIR/exodus-binaries/bin:$PATH"
fi
export PATH="$THIS_DIR/executables:$PATH"
cd "${THIS_DIR}/working_dir"
# ----------------------------------------------------
# helper functions
function start_task
{
if [ "$ECHO_TASK_START" = true ]; then
echo "STARTING_TASK[${1}]: ${2}"
fi
}
function task_finished
{
if [ "$ECHO_TASK_FINISHED" = true ]; then
echo "FINISHED_TASK[${1}]: ${2}"
fi
}
{% include "init_vars.j2" %}
init_vars --debug true
#echo "DEBUG: $DEBUG"
#echo "RUN USER: $RUN_USER"
#echo "ROOT PERMISSIONS: $ROOT_PERMISSIONS"
{% if functions %}
# ----------------------------------------------------
# functions
{% for func_name, func in functions.items() %}
# {{ func_name }}: {{ func.doc.get_short_help(use_help=True) }}
#
{% include "function.j2" %}
{% endfor %}
# ----------------------------------------------------
{% endif %}
# start script
# ----------------------------------------------------
{% for command in commands %}
# {{ command['desc'] }}
start_task "{{ command['task_id'] }}" "{{ command['task_desc'] }}"
{{ command['command'] }}{% for arg_name, value in command['args'].items() %} --{{ arg_name }} "{{ value }}"{% endfor %}
task_finished "{{ command['task_id'] }}" "$?"
{% endfor %}