diff options
| author | Patrick Spek <p.spek@tyil.nl> | 2024-10-06 21:37:43 +0200 |
|---|---|---|
| committer | Patrick Spek <p.spek@tyil.nl> | 2024-10-06 21:37:43 +0200 |
| commit | a52a6c0debcf1d942da78eb60529cb702373385a (patch) | |
| tree | 31c7d85765dc0e60d8b74a0b98e9c87482be02db | |
| parent | 8c077b23dc0d7bb96096a9943fce50527882fbd6 (diff) | |
| download | bashtard-a52a6c0debcf1d942da78eb60529cb702373385a.tar.gz bashtard-a52a6c0debcf1d942da78eb60529cb702373385a.tar.bz2 | |
Add checks for sq availability
| -rw-r--r-- | lib/subcommands/var.bash | 6 | ||||
| -rw-r--r-- | lib/util/config.bash | 24 |
2 files changed, 26 insertions, 4 deletions
diff --git a/lib/subcommands/var.bash b/lib/subcommands/var.bash index b492a51..5cc1341 100644 --- a/lib/subcommands/var.bash +++ b/lib/subcommands/var.bash @@ -41,6 +41,12 @@ subcommand() # Set the var for this specific host if [[ $secret ]] then + if ! command -v sq > /dev/null + then + emerg "$BASHTARD_NAME/var" "You must have sq available in your \$PATH for secret variable functionality" + return 5 + fi + # Check if Key ID is configured, or bail out immediately if [[ "$(config "bashtard.secrets.key.id")" == "" ]] then diff --git a/lib/util/config.bash b/lib/util/config.bash index 5dff25c..cac75e7 100644 --- a/lib/util/config.bash +++ b/lib/util/config.bash @@ -59,8 +59,16 @@ config_for() { # Decrypt the file if needed, otherwise just get the file # contents as-is. case "$file" in - *.pgp) data="$(sq decrypt - < "$file" 2>/dev/null)" ;; - *) data="$(<"$file")" + *.pgp) + if ! command -v sq > /dev/null + then + emerg "$BASHTARD_NAME/var" "You must have sq available in your \$PATH for secret variable functionality" + fi + + data="$(sq decrypt - < "$file" 2>/dev/null)" + ;; + *) + data="$(<"$file")" esac # Check if the lookup is a reference variable, defined by using @@ -149,8 +157,16 @@ config_subkeys_for() { # Decrypt the file if needed, otherwise just get the file # contents as-is. case "$file" in - *.pgp) data="$(sq decrypt - < "$file" 2>/dev/null)" ;; - *) data="$(<"$file")" + *.pgp) + if ! command -v sq > /dev/null + then + emerg "$BASHTARD_NAME/var" "You must have sq available in your \$PATH for secret variable functionality" + fi + + data="$(sq decrypt - < "$file" 2>/dev/null)" + ;; + *) + data="$(<"$file")" esac while read -r result |
