mirror of
https://github.com/ryantm/agenix.git
synced 2024-11-22 09:40:47 +03:00
Merge pull request #161 from n8henrie/warnings-to-stderr
Output user-facing warnings to stderr instead of stdout
This commit is contained in:
commit
0c50bbe60e
1 changed files with 14 additions and 7 deletions
|
@ -33,6 +33,15 @@ function show_help () {
|
||||||
echo "age version: $(@ageBin@ --version)"
|
echo "age version: $(@ageBin@ --version)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function warn() {
|
||||||
|
printf '%s\n' "$*" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
function err() {
|
||||||
|
warn "$*"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
test $# -eq 0 && (show_help && exit 1)
|
test $# -eq 0 && (show_help && exit 1)
|
||||||
|
|
||||||
REKEY=0
|
REKEY=0
|
||||||
|
@ -99,8 +108,7 @@ function edit {
|
||||||
|
|
||||||
if [ -z "$KEYS" ]
|
if [ -z "$KEYS" ]
|
||||||
then
|
then
|
||||||
>&2 echo "There is no rule for $FILE in $RULES."
|
err "There is no rule for $FILE in $RULES."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CLEARTEXT_DIR=$(@mktempBin@ -d)
|
CLEARTEXT_DIR=$(@mktempBin@ -d)
|
||||||
|
@ -118,8 +126,7 @@ function edit {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ "${DECRYPT[*]}" != *"--identity"* ]]; then
|
if [[ "${DECRYPT[*]}" != *"--identity"* ]]; then
|
||||||
echo "No identity found to decrypt $FILE. Try adding an SSH key at $HOME/.ssh/id_rsa or $HOME/.ssh/id_ed25519 or using the --identity flag to specify a file."
|
err "No identity found to decrypt $FILE. Try adding an SSH key at $HOME/.ssh/id_rsa or $HOME/.ssh/id_ed25519 or using the --identity flag to specify a file."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
DECRYPT+=(-o "$CLEARTEXT_FILE" "$FILE")
|
DECRYPT+=(-o "$CLEARTEXT_FILE" "$FILE")
|
||||||
@ageBin@ "${DECRYPT[@]}" || exit 1
|
@ageBin@ "${DECRYPT[@]}" || exit 1
|
||||||
|
@ -132,10 +139,10 @@ function edit {
|
||||||
|
|
||||||
if [ ! -f "$CLEARTEXT_FILE" ]
|
if [ ! -f "$CLEARTEXT_FILE" ]
|
||||||
then
|
then
|
||||||
echo "$FILE wasn't created."
|
warn "$FILE wasn't created."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
[ -f "$FILE" ] && [ "$EDITOR" != ":" ] && @diffBin@ "$CLEARTEXT_FILE.before" "$CLEARTEXT_FILE" 1>/dev/null && echo "$FILE wasn't changed, skipping re-encryption." && return
|
[ -f "$FILE" ] && [ "$EDITOR" != ":" ] && @diffBin@ -q "$CLEARTEXT_FILE.before" "$CLEARTEXT_FILE" && warn "$FILE wasn't changed, skipping re-encryption." && return
|
||||||
|
|
||||||
ENCRYPT=()
|
ENCRYPT=()
|
||||||
while IFS= read -r key
|
while IFS= read -r key
|
||||||
|
@ -158,7 +165,7 @@ function rekey {
|
||||||
|
|
||||||
for FILE in $FILES
|
for FILE in $FILES
|
||||||
do
|
do
|
||||||
echo "rekeying $FILE..."
|
warn "rekeying $FILE..."
|
||||||
EDITOR=: edit "$FILE"
|
EDITOR=: edit "$FILE"
|
||||||
cleanup
|
cleanup
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue