Locate units using APPLY_ROOT env var

This commit is contained in:
Loic Nageleisen 2018-06-25 11:07:41 +02:00
parent 8a178cdc2b
commit 44eeefea79
4 changed files with 21 additions and 5 deletions

4
Makefile Normal file
View file

@ -0,0 +1,4 @@
all:
lint:
find apply run push lib -type f -not -iname '*.*' | xargs shellcheck -s bash

6
apply
View file

@ -11,7 +11,7 @@ function usage() {
function host_targets() { function host_targets() {
local host="$*" local host="$*"
cat < "$host" | tr '\n' ' ' cat < "${APPLY_ROOT}"/"$host" | tr '\n' ' '
} }
function push_each() { function push_each() {
@ -28,6 +28,10 @@ function push_each() {
fi fi
} }
if [[ -z "${APPLY_ROOT:-}" ]]; then
APPLY_ROOT="."
fi
if [[ $# -lt 1 ]]; then if [[ $# -lt 1 ]]; then
usage usage
fi fi

6
push
View file

@ -8,6 +8,10 @@ function usage() {
exit 1 exit 1
} }
if [[ -z "${APPLY_ROOT:-}" ]]; then
APPLY_ROOT="."
fi
if [[ $# -lt 1 ]]; then if [[ $# -lt 1 ]]; then
usage usage
fi fi
@ -33,7 +37,7 @@ remote="$1"
tmp=$(ssh "$remote" 'mktemp -d') tmp=$(ssh "$remote" 'mktemp -d')
echo -e -n "\033[33m** pushing to\033[0m $remote:$tmp" 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" echo -e " \033[32mOK\033[0m"
fi fi

10
run
View file

@ -9,7 +9,11 @@ function usage() {
} }
function root_path() { 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() { function read_group() {
@ -19,7 +23,7 @@ function read_group() {
if [[ ! "$item" == '#'* ]]; then if [[ ! "$item" == '#'* ]]; then
echo "$item" echo "$item"
fi fi
done < "$(root_path)/$target" done < "$(root_path)/$target"
} }
function run_group() { function run_group() {
@ -33,7 +37,7 @@ function run_group() {
} }
function run_unit() { 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() { function log_file() {