commit 71724cda34eb835dfb79ff99ee9dde4cbe6b1084
parent 1d0d271068393c496f50738933fe6fe0debce0c1
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Fri, 15 Nov 2024 20:20:11 +0000
MULTILINE instead of OVERWRITE to communicate in-place generation
Diffstat:
4 files changed, 30 insertions(+), 29 deletions(-)
diff --git a/spec/action_spec.sh b/spec/action_spec.sh
@@ -1130,7 +1130,7 @@ Describe 'Action Functions'
End
It 'overwrites an existing file when forced'
- OVERWRITE=no
+ MULTILINE=no
DECISION=force
result(){
%text:expand
@@ -1150,7 +1150,7 @@ Describe 'Action Functions'
End
It 'overwrites an existing file after confirmation'
- OVERWRITE=no
+ MULTILINE=no
DECISION=default
yesno() {
mocklog yesno "$@";
@@ -1176,7 +1176,7 @@ Describe 'Action Functions'
End
It 'does not overwrite an existing file without confirmation'
- OVERWRITE=no
+ MULTILINE=no
DECISION=default
yesno() {
mocklog yesno "$@";
@@ -1195,7 +1195,7 @@ Describe 'Action Functions'
End
It 'updates the first line of an existing file'
- OVERWRITE=yes
+ MULTILINE=yes
mktemp() { %= "$1"; }
do_decrypt() {
mocklog do_decrypt "$@"
@@ -1227,7 +1227,7 @@ Describe 'Action Functions'
End
It 'updates the only line of an existing one-line file'
- OVERWRITE=yes
+ MULTILINE=yes
mktemp() { %= "$1"; }
do_decrypt() {
mocklog do_decrypt "$@"
diff --git a/spec/pashage_extra_spec.sh b/spec/pashage_extra_spec.sh
@@ -613,7 +613,7 @@ Describe 'Integrated Command Functions'
Describe 'cmd_generate'
DECISION=default
- OVERWRITE=no
+ MULTILINE=no
SHOW=text
It 'uses the character set given explicitly instead of environment'
@@ -1510,7 +1510,7 @@ Describe 'Integrated Command Functions'
Example 'generate'
DECISION=default
- OVERWRITE=no
+ MULTILINE=no
When run cmd_generate new-pass
The status should equal 1
The error should equal 'There are already pending changes.'
diff --git a/spec/usage_spec.sh b/spec/usage_spec.sh
@@ -97,7 +97,7 @@ Describe 'Command-Line Parsing'
mocklog do_generate "$@"
%text:expand >&2
#|DECISION=${DECISION}
- #|OVERWRITE=${OVERWRITE}
+ #|MULTILINE=${MULTILINE}
#|SELECTED_LINE=${SELECTED_LINE}
#|SHOW=${SHOW}
}
@@ -636,7 +636,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:punct:][:alnum:]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=text
}
@@ -652,7 +652,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 12 [:punct:][:alnum:]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=text
}
@@ -668,7 +668,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 12 [A-Z]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=text
}
@@ -684,7 +684,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path -f
#|$ do_generate -f 25 [:punct:][:alnum:]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=text
}
@@ -700,7 +700,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:punct:][:alnum:]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=clip
}
@@ -716,7 +716,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:punct:][:alnum:]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=clip
}
@@ -732,7 +732,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:punct:][:alnum:]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=qrcode
}
@@ -748,7 +748,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:punct:][:alnum:]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=qrcode
}
@@ -764,7 +764,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:alnum:]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=clip
}
@@ -780,7 +780,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:alnum:]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=clip
}
@@ -796,7 +796,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:alnum:]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=qrcode
}
@@ -812,7 +812,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:alnum:]
#|DECISION=default
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=qrcode
}
@@ -828,7 +828,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:punct:][:alnum:]
#|DECISION=default
- #|OVERWRITE=yes
+ #|MULTILINE=yes
#|SELECTED_LINE=1
#|SHOW=text
}
@@ -844,7 +844,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:punct:][:alnum:]
#|DECISION=default
- #|OVERWRITE=yes
+ #|MULTILINE=yes
#|SELECTED_LINE=1
#|SHOW=text
}
@@ -860,7 +860,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:punct:][:alnum:]
#|DECISION=force
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=text
}
@@ -876,7 +876,7 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path secret
#|$ do_generate secret 25 [:punct:][:alnum:]
#|DECISION=force
- #|OVERWRITE=no
+ #|MULTILINE=no
#|SELECTED_LINE=1
#|SHOW=text
}
diff --git a/src/pashage.sh b/src/pashage.sh
@@ -611,7 +611,7 @@ do_encrypt() {
# $2: new password length
# $3: new password charset
# DECISION: whether to ask before overwrite
-# OVERWRITE: whether to re-use existing secret data
+# MULTILINE: whether to re-use existing secret data
do_generate() {
NEW_PASS="$(random_chars "$2" "$3")"
NEW_PASS_LEN="$(strlen "${NEW_PASS}")"
@@ -628,12 +628,13 @@ do_generate() {
if [ -d "${PREFIX}/$1.age" ]; then
die "Cannot replace directory $1.age"
- elif [ -e "${PREFIX}/$1.age" ] && [ "${OVERWRITE}" = yes ]; then
+ elif [ -e "${PREFIX}/$1.age" ] && [ "${MULTILINE}" = yes ]; then
printf '%s\n' "Decrypting previous secret for $1"
OLD_SECRET_FULL="$(do_decrypt "${PREFIX}/$1.age")"
OLD_SECRET="${OLD_SECRET_FULL#*
}"
WIP_FILE="$(mktemp "${PREFIX}/$1-XXXXXXXXX.age")"
+ OVERWRITE=once
if [ "${OLD_SECRET}" = "${OLD_SECRET_FULL}" ]; then
do_encrypt "${WIP_FILE#"${PREFIX}"/}" <<-EOF
${NEW_PASS}
@@ -1201,7 +1202,7 @@ cmd_generate() {
SHOW=clip
shift ;;
-f|--force)
- if [ "${OVERWRITE}" = yes ]; then
+ if [ "${MULTILINE}" = yes ]; then
PARSE_ERROR=yes
break
fi
@@ -1212,7 +1213,7 @@ cmd_generate() {
PARSE_ERROR=yes
break
fi
- OVERWRITE=yes
+ MULTILINE=yes
shift ;;
-n|--no-symbols)
CHARSET="${CHARACTER_SET_NO_SYMBOLS}"
@@ -1244,7 +1245,7 @@ cmd_generate() {
done
if [ "${PARSE_ERROR}" = yes ] || [ $# -eq 0 ] || [ $# -gt 3 ] \
- || [ "${DECISION}-${OVERWRITE}" = force-yes ]
+ || [ "${DECISION}-${MULTILINE}" = force-yes ]
then
cmd_usage 'Usage: ' generate >&2
exit 1