aboutsummaryrefslogtreecommitdiff
path: root/lib/util.bash
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2023-03-10 10:44:48 +0100
committerPatrick Spek <p.spek@tyil.nl>2023-03-10 10:44:48 +0100
commit28c55aa1a8c82def2ffdb3e000812a5523371ac5 (patch)
tree35bf0c53822a6bc1d54d43e7948c5951f72d5d6d /lib/util.bash
parent7b4d5e80ab5bf5d29b38dc617317024373ae1fd0 (diff)
Add playbook_path()
Diffstat (limited to 'lib/util.bash')
-rw-r--r--lib/util.bash20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/util.bash b/lib/util.bash
index e5dbc3f..489ccf1 100644
--- a/lib/util.bash
+++ b/lib/util.bash
@@ -112,7 +112,7 @@ fetch_http_wget() {
# template, they are expected to be written as ${key}.
file_template()
{
- local file="$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK/share/$1" ; shift
+ local file="$(playbook_path "base")/share/$1" ; shift
local sedfile
sedfile="$(tmpfile)"
@@ -182,6 +182,24 @@ join_args() {
printf "%s" "$*"
}
+# Convenience function to easily get paths used by the playbook, or to use in
+# your playbook.
+playbook_path() {
+ if [[ -z "$BASHTARD_PLAYBOOK" ]]
+ then
+ crit "bashtard/playbook_path" "Called outside of a playbook"
+ return 1
+ fi
+
+ case "$1" in
+ base) printf "$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK" ;;
+ data) printf "$BASHTARD_ETCDIR/data.d/$BASHTARD_PLAYBOOK" ;;
+ *)
+ crit "bashtard/playbook_path" "Invalid path '$1'"
+ return 1
+ esac
+}
+
# Create a temporary directory. Similar to tempfile, but you'll get a directory
# instead.
tmpdir() {