small pixel drawing of a pufferfish pa

pa edit: add /tmp fallback if /dev/shm is missing
Jes Olson j3s@c3f.net
Sat, 31 Dec 2022 23:32:16 -0800
commit

c0a3973b0fea9b1241269ac24f36b805aabcaf84

parent

6cd0cdbb81fec9ef7e006176655328c2153899b9

1 files changed, 13 insertions(+), 12 deletions(-)

jump to
M papa

@@ -44,22 +44,26 @@

[ -f "$name.age" ] || die "Couldn't access $name" - # Use /dev/shm because it's an in-memory - # space that we can use to store private data - # & securely wipe it - [ -d /dev/shm ] || - die "Couldn't access /dev/shm" + # Prefer /dev/shm because it's an in-memory + # space that we can use to store data without + # having bits laying around in sectors. + tmpdir='/dev/shm' + # Fall back to /tmp - /dev/shm is Linux-only & /tmp + # and shared memory space on other operating systems + # have non-standard methods of setup/access. + [ -w "/dev/shm" ] || + tmpdir='/tmp' # Reimplement mktemp here, because # mktemp isn't defined in POSIX - tmpdir="/dev/shm/pa.$(rand_chars 8 '[:alnum:]')" + editdir="$tmpdir/pa.$(rand_chars 8 '[:alnum:]')" - tmpfile="$tmpdir/$name.age" + tmpfile="$editdir/$name.age" - mkdir "$tmpdir" || + mkdir "$editdir" || die "Couldn't create shared memory dir" - trap 'rm -rf $tmpdir' EXIT + trap 'rm -rf $editdir' EXIT # Handle nested items (/foo/bar.age) mkdir -p "$(dirname "$tmpfile")"

@@ -68,9 +72,6 @@ age --decrypt -i "$identities_file" -o "$tmpfile" "$name.age" ||

die "Couldn't decrypt $name.age" "${EDITOR:-vi}" "$tmpfile" - - [ -f "$tmpfile" ] || - die "New password not saved" age --encrypt -R "$recipients_file" -o "$name.age" "$tmpfile" || die "Couldn't encrypt $name.age"