aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2024-10-06 22:36:36 +0200
committerPatrick Spek <p.spek@tyil.nl>2024-10-06 22:36:36 +0200
commit9fc5ae560c1600b58aefcbe40cfe6e5b165cd773 (patch)
tree1562d35a68191052d3f43e4035e077ca24b8a943
parenta52a6c0debcf1d942da78eb60529cb702373385a (diff)
downloadbashtard-9fc5ae560c1600b58aefcbe40cfe6e5b165cd773.tar.gz
bashtard-9fc5ae560c1600b58aefcbe40cfe6e5b165cd773.tar.bz2
Add -g option for var
-rw-r--r--CHANGELOG.md3
-rw-r--r--lib/subcommands/var.bash14
2 files changed, 12 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index edea419..08f61f5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bashtard now bundles an example `.service` and example `.timer` file for use
with Systemd. They can be installed separetely with the `make` target
`install-svc-systemd`.
+- The `var` subcommand now support a `-g` option to write new/changed variables
+ to the `defaults` file, rather than the host-specific variable file in
+ `hosts.d`.
### Changed
diff --git a/lib/subcommands/var.bash b/lib/subcommands/var.bash
index 5cc1341..5080925 100644
--- a/lib/subcommands/var.bash
+++ b/lib/subcommands/var.bash
@@ -9,11 +9,15 @@ subcommand()
local key
local value
local secret
+ local file
+
+ file="$BASHTARD_ETCDIR/hosts.d/${BASHTARD_PLATFORM[fqdn]}"
# Handle opts
- while getopts ":p:s" opt
+ while getopts ":glp:s" opt
do
case "$opt" in
+ g) file="$BASHTARD_ETCDIR/defaults" ;;
p) export BASHTARD_PLAYBOOK="$OPTARG" ;;
s) secret=1 ;;
*) emerg "Unused opt '$opt'?" ;;
@@ -54,9 +58,9 @@ subcommand()
return 4
fi
- data="$(sq decrypt "$BASHTARD_ETCDIR/hosts.d/${BASHTARD_PLATFORM[fqdn]}.pgp" 2>/dev/null)"
+ data="$(sq decrypt "$file.pgp" 2>/dev/null)"
else
- data="$(<"$BASHTARD_ETCDIR/hosts.d/${BASHTARD_PLATFORM[fqdn]}")"
+ data="$(<"$file")"
fi
data="$(printf "%s\n%s=%s\n" "$(grep -v "^$key=" <<< "$data")" "$key" "$value" | sort)"
@@ -64,9 +68,9 @@ subcommand()
if [[ $secret ]]
then
sq encrypt --recipient-cert "$(config "bashtard.secrets.key.id")" - <<< "$data" >/dev/null \
- > "$BASHTARD_ETCDIR/hosts.d/${BASHTARD_PLATFORM[fqdn]}.pgp"
+ > "$file.pgp"
else
cat <<< "$data" \
- > "$BASHTARD_ETCDIR/hosts.d/${BASHTARD_PLATFORM[fqdn]}"
+ > "$file"
fi
}