aboutsummaryrefslogtreecommitdiff
path: root/lib/util.bash
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2023-03-10 10:32:18 +0100
committerPatrick Spek <p.spek@tyil.nl>2023-03-10 10:32:18 +0100
commitcad506a3d8097d42d116400a26dbe4897d598b81 (patch)
tree7d93ef11598a212cfbcdb3e00156acf90edb2aa2 /lib/util.bash
parent20383605727e433f5b0daa6d98a0e6617b2ad416 (diff)
Move the file_template function and add a comment
Diffstat (limited to 'lib/util.bash')
-rw-r--r--lib/util.bash72
1 files changed, 38 insertions, 34 deletions
diff --git a/lib/util.bash b/lib/util.bash
index 1e6854a..e5dbc3f 100644
--- a/lib/util.bash
+++ b/lib/util.bash
@@ -106,40 +106,10 @@ fetch_http_wget() {
wget --quiet --output-document "$2" "$1"
}
-# Check if the first argument given appears in the list of all following
-# arguments.
-in_args() {
- local needle="$1"
- shift
-
- for arg in "$@"
- do
- [[ $needle == "$arg" ]] && return 0
- done
-
- return 1
-}
-
-# Join a list of arguments into a single string. By default, this will join
-# using a ",", but you can set a different character using -c. Note that this
-# only joins with a single character, not a string of characters.
-join_args() {
- local OPTIND
- local IFS=","
-
- while getopts ":c:" opt
- do
- case "$opt" in
- c) IFS="$OPTARG" ;;
- *) warn "bashtard/join_args" "Unused opt specified: $opt" ;;
- esac
- done
-
- shift $(( OPTIND - 1))
-
- printf "%s" "$*"
-}
-
+# A very simple means of templating a file, using sed and awk. The template
+# file is assumed to exist within the share directory of the current playbook.
+# Variables are passed as key=value pairs to this function. Inside the
+# template, they are expected to be written as ${key}.
file_template()
{
local file="$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK/share/$1" ; shift
@@ -178,6 +148,40 @@ file_template()
sed -f "$sedfile" "$file"
}
+# Check if the first argument given appears in the list of all following
+# arguments.
+in_args() {
+ local needle="$1"
+ shift
+
+ for arg in "$@"
+ do
+ [[ $needle == "$arg" ]] && return 0
+ done
+
+ return 1
+}
+
+# Join a list of arguments into a single string. By default, this will join
+# using a ",", but you can set a different character using -c. Note that this
+# only joins with a single character, not a string of characters.
+join_args() {
+ local OPTIND
+ local IFS=","
+
+ while getopts ":c:" opt
+ do
+ case "$opt" in
+ c) IFS="$OPTARG" ;;
+ *) warn "bashtard/join_args" "Unused opt specified: $opt" ;;
+ esac
+ done
+
+ shift $(( OPTIND - 1))
+
+ printf "%s" "$*"
+}
+
# Create a temporary directory. Similar to tempfile, but you'll get a directory
# instead.
tmpdir() {