pashage

Yet Another Opinionated Re-engineering of the Unix Password Store
git clone https://git.instinctive.eu/pashage.git
Log | Files | Refs | README | LICENSE

commit 09261cf1e2038eaaae69667a4af859d6e26a29ff
parent 301aaec064883a0757a021631ca8d71f1b9d3a0c
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Sat, 19 Oct 2024 11:19:57 +0000

Directories are created as needed before encryption
Diffstat:
Mspec/action_spec.sh | 35+++++++++++++++++++++++++++--------
Msrc/pashage.sh | 1+
2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/spec/action_spec.sh b/spec/action_spec.sh @@ -814,7 +814,10 @@ Describe 'Action Functions' unset PASSAGE_RECIPIENTS AGE=age PREFIX=/prefix + dirname() { @dirname "$@"; } + age() { mocklog age "$@"; } + mkdir() { mocklog mkdir "$@"; } setup() { %= data >"${SHELLSPEC_WORKDIR}/existing-file" @@ -827,9 +830,13 @@ Describe 'Action Functions' set_LOCAL_RECIPIENT_FILE() { LOCAL_RECIPIENT_FILE='' } + result() { + %text + #|$ mkdir -p /prefix/encrypted + #|$ age -e -i /path/to/identity -o /prefix/encrypted/file.age + } When run do_encrypt 'encrypted/file.age' - The error should equal \ - '$ age -e -i /path/to/identity -o /prefix/encrypted/file.age' + The error should equal "$(result)" End It 'overwrites existing file only once' @@ -840,9 +847,13 @@ Describe 'Action Functions' } preserve() { %preserve OVERWRITE; } AfterRun 'preserve' + result() { + %text:expand + #|$ mkdir -p ${PREFIX} + #|$ age -e -R /path/to/recipients -o ${PREFIX}/existing-file + } When run do_encrypt 'existing-file' - The error should equal \ - "$ age -e -R /path/to/recipients -o ${PREFIX}/existing-file" + The error should equal "$(result)" The variable OVERWRITE should equal no End @@ -854,9 +865,13 @@ Describe 'Action Functions' } preserve() { %preserve OVERWRITE; } AfterRun 'preserve' + result() { + %text:expand + #|$ mkdir -p ${PREFIX} + #|$ age -e -R /path/to/recipients -o ${PREFIX}/existing-file + } When run do_encrypt 'existing-file' - The error should equal \ - "$ age -e -R /path/to/recipients -o ${PREFIX}/existing-file" + The error should equal "$(result)" The variable OVERWRITE should equal yes End @@ -880,10 +895,14 @@ Describe 'Action Functions' LOCAL_RECIPIENT_FILE='/path/to/recipients/3' } OVERWRITE=yes + result() { + %text + #|$ mkdir -p /prefix/encrypted + #|$ age -e -R /path/to/recipients/1 -R /path/to/recipients/2 -r inline-recipient-1 -r inline-recipient-2 -r inline-recipient-3 -r inline-recipient-4 -R /path/to/recipients/3 -o /prefix/encrypted/file.age + } When call do_encrypt 'encrypted/file.age' - The error should equal \ - '$ age -e -R /path/to/recipients/1 -R /path/to/recipients/2 -r inline-recipient-1 -r inline-recipient-2 -r inline-recipient-3 -r inline-recipient-4 -R /path/to/recipients/3 -o /prefix/encrypted/file.age' + The error should equal "$(result)" End End diff --git a/src/pashage.sh b/src/pashage.sh @@ -631,6 +631,7 @@ do_encrypt() { die "Refusing to overwite ${TARGET}" fi fi + mkdir -p "$(dirname "${PREFIX}/${TARGET}")" "${AGE}" -e "$@" -o "${PREFIX}/${TARGET}" unset TARGET }