]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Avoid bash arrays on append action (closes #26)
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 26 Nov 2013 00:04:56 +0000 (22:04 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 26 Nov 2013 00:04:56 +0000 (22:04 -0200)
lib/keyringer/actions/append

index e945bff32dbed9d717fdac0148dd576db9720c17..e307056529c0eef5d60e21bb45d76b1249506cbc 100755 (executable)
@@ -10,29 +10,11 @@ source "$LIB" || exit 1
 # Get file
 keyringer_get_file "$2"
 
-OLDIFS="$IFS"
-IFS=$'\n'
-
-CONTENT=($(keyringer_exec decrypt "$BASEDIR" "$FILE"))
-
+# Only display directions if we're running append, not append-batch
 if [ "$BASENAME" == "append" ]; then
-  # only display directions if we're running append, not append-batch
-  printf "\n%s currently has %d lines\n\n" "$FILE" "${#CONTENT[@]}"
-  printf "Now please write the content to be appended on %s, finnishing with Ctrl-D:\n" "$FILE"
-fi
-
-APPEND=($(cat -))
-
-NEW=( ${CONTENT[@]} ${APPEND[@]} )
-
-for element in $(seq 0 $((${#NEW[@]} - 1))); do
-  echo ${NEW[$element]}
-done | keyringer_exec encrypt-batch $BASEDIR $FILE
-
-err="$?"
-
-if [ "$err" != "0" ]; then
-  exit "$err"
+  printf "Please write the content to be appended on %s, finnishing with Ctrl-D:\n" "$FILE"
 fi
 
-IFS="$OLDIFS"
+# Append content to an existing secret
+( keyringer_exec decrypt "$BASEDIR" "$FILE" && cat ) | \
+  keyringer_exec encrypt-batch $BASEDIR $FILE