From 44eeefea79bae3530932cd984ef8bad0ea087880 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Mon, 25 Jun 2018 11:07:41 +0200 Subject: [PATCH] Locate units using APPLY_ROOT env var --- Makefile | 4 ++++ apply | 6 +++++- push | 6 +++++- run | 10 +++++++--- 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0e9f912 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +all: + +lint: + find apply run push lib -type f -not -iname '*.*' | xargs shellcheck -s bash diff --git a/apply b/apply index 020eab3..60dfaee 100755 --- a/apply +++ b/apply @@ -11,7 +11,7 @@ function usage() { function host_targets() { local host="$*" - cat < "$host" | tr '\n' ' ' + cat < "${APPLY_ROOT}"/"$host" | tr '\n' ' ' } function push_each() { @@ -28,6 +28,10 @@ function push_each() { fi } +if [[ -z "${APPLY_ROOT:-}" ]]; then + APPLY_ROOT="." +fi + if [[ $# -lt 1 ]]; then usage fi diff --git a/push b/push index 47a3968..1ee3322 100755 --- a/push +++ b/push @@ -8,6 +8,10 @@ function usage() { exit 1 } +if [[ -z "${APPLY_ROOT:-}" ]]; then + APPLY_ROOT="." +fi + if [[ $# -lt 1 ]]; then usage fi @@ -33,7 +37,7 @@ remote="$1" tmp=$(ssh "$remote" 'mktemp -d') echo -e -n "\033[33m** pushing to\033[0m $remote:$tmp" -if scp -q -r groups units run lib "$remote":"$tmp"; then +if scp -q -r "${APPLY_ROOT}"/{groups,units,run,lib} "$remote":"$tmp"; then echo -e " \033[32mOK\033[0m" fi diff --git a/run b/run index c6a7f59..afe5fb6 100755 --- a/run +++ b/run @@ -9,7 +9,11 @@ function usage() { } function root_path() { - cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd + if [[ -z "${APPLY_ROOT:-}" ]]; then + cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd + else + echo "$APPLY_ROOT" + fi } function read_group() { @@ -19,7 +23,7 @@ function read_group() { if [[ ! "$item" == '#'* ]]; then echo "$item" fi - done < "$(root_path)/$target" + done < "$(root_path)/$target" } function run_group() { @@ -33,7 +37,7 @@ function run_group() { } function run_unit() { - /bin/bash -l -c "set -e; set -u; set -o pipefail; source lib; source '$*'" + /bin/bash -l -c "set -e; set -u; set -o pipefail; source lib; source '$(root_path)/$*'" } function log_file() {