diff options
author | Patrick Spek <p.spek@tyil.nl> | 2024-04-02 09:32:25 +0200 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2024-04-02 09:32:25 +0200 |
commit | 5ae54c278477e9d975410892d9f6b0995f9a2dcc (patch) | |
tree | ed10140a9e6dfda7301a9a4764b677c921f4427a /lib/subcommands | |
parent | 87500911e02142fa7877f980818620042707ae5f (diff) |
Implement zap
Diffstat (limited to 'lib/subcommands')
-rw-r--r-- | lib/subcommands/zap.bash | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/subcommands/zap.bash b/lib/subcommands/zap.bash new file mode 100644 index 0000000..6864a33 --- /dev/null +++ b/lib/subcommands/zap.bash @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# SPDX-FileCopyrightText: 2023 Patrick Spek <p.spek@tyil.nl> +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +subcommand() +{ + local buffer + local playbook_base + local playbook_registry + + export BASHTARD_PLAYBOOK="$1" ; shift + + if [[ -z "$BASHTARD_PLAYBOOK" ]] + then + crit "bashtard/zap" "No playbook name specified" + return + fi + + playbook_base="$(playbook_path "base")" + playbook_registry="$BASHTARD_ETCDIR/registry.d/${BASHTARD_PLATFORM[fqdn]}" + + # Make sure we only run add if the playbook is not in the registry yet + if ! grep -Fqx "$BASHTARD_PLAYBOOK" "$playbook_registry" + then + crit "bashtard/zap" "'$BASHTARD_PLAYBOOK' is not registered for ${BASHTARD_PLATFORM[fqdn]}" + return 3 + fi + + notice "bashtard/zap" "Removing playbook '$BASHTARD_PLAYBOOK' from '${BASHTARD_PLATFORM[fqdn]}'" + + buffer="$(tmpfile)" + + # Remove the playbook from the registry + cp -- "$playbook_registry" "$buffer" + grep -Fvx "$BASHTARD_PLAYBOOK" "$buffer" \ + | sort > "$playbook_registry" +} |