From 9a9425b1e4280bbe6ec8f4de66c3cb67356787ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Thu, 11 Jul 2024 07:22:43 +0800 Subject: [PATCH] Use file as a global bool --- bash/sources/16_keystore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bash/sources/16_keystore b/bash/sources/16_keystore index f8bb249..3d3c223 100644 --- a/bash/sources/16_keystore +++ b/bash/sources/16_keystore @@ -15,11 +15,13 @@ fi _AUTH_DB=$RBASH_HOME/keystore.db _AUTH_SECRET= _KSTORE_DEF_PROP=${_KSTORE_DEF_PROP:-val} +_KSTORE_DEC_FAILED="$RBASH_HOME/.decypt-failed" if [ -f "$RBASH_HOME/keystore.secret" ]; then _AUTH_SECRET=$( cat "$RBASH_HOME/keystore.secret" ) fi + function kstore { case $1 in add) shift; _kstoreadd "$@" ;; @@ -130,7 +132,7 @@ function _kstoredec { openssl enc -d -aes-256-cbc -pbkdf2 -k "$_AUTH_SECRET" -a -A _code=$? if [ $_code -ne 0 ]; then - _AUTH_SECRET= + touch $_KSTORE_DEC_FAILED return $_code fi } @@ -199,6 +201,10 @@ function _kstoresecret-macos { function _kstoresecret-config { local _CONFIRM + if [ -f "$_KSTORE_DEC_FAILED" ]; then + rm $_KSTORE_DEC_FAILED + _AUTH_SECRET= + fi if [ -z "$_AUTH_SECRET" ]; then _kstoresecret-auto get