#!/usr/bin/env bash
#
# Append information into encrypted files.
#

# Load functions
LIB="`dirname $0`/../functions"
source "$LIB" readwrite $* || exit 1

# Get file
keyringer_get_file "$2"

# Only display directions if we're running append, not append-batch
if [ "$BASENAME" == "append" ]; then
  printf "Please write the content to be appended on %s, finnishing with Ctrl-D:\n" "$FILE"
fi

# Append content to an existing secret
( keyringer_exec decrypt "$BASEDIR" "$FILE" && cat ) | \
  keyringer_exec encrypt-batch "$BASEDIR" "$FILE"
