Use file as a global bool

This commit is contained in:
斟酌 鵬兄 2024-07-11 07:22:43 +08:00
parent ec489a9530
commit 9a9425b1e4

View File

@ -15,11 +15,13 @@ fi
_AUTH_DB=$RBASH_HOME/keystore.db _AUTH_DB=$RBASH_HOME/keystore.db
_AUTH_SECRET= _AUTH_SECRET=
_KSTORE_DEF_PROP=${_KSTORE_DEF_PROP:-val} _KSTORE_DEF_PROP=${_KSTORE_DEF_PROP:-val}
_KSTORE_DEC_FAILED="$RBASH_HOME/.decypt-failed"
if [ -f "$RBASH_HOME/keystore.secret" ]; then if [ -f "$RBASH_HOME/keystore.secret" ]; then
_AUTH_SECRET=$( cat "$RBASH_HOME/keystore.secret" ) _AUTH_SECRET=$( cat "$RBASH_HOME/keystore.secret" )
fi fi
function kstore { function kstore {
case $1 in case $1 in
add) shift; _kstoreadd "$@" ;; add) shift; _kstoreadd "$@" ;;
@ -130,7 +132,7 @@ function _kstoredec {
openssl enc -d -aes-256-cbc -pbkdf2 -k "$_AUTH_SECRET" -a -A openssl enc -d -aes-256-cbc -pbkdf2 -k "$_AUTH_SECRET" -a -A
_code=$? _code=$?
if [ $_code -ne 0 ]; then if [ $_code -ne 0 ]; then
_AUTH_SECRET= touch $_KSTORE_DEC_FAILED
return $_code return $_code
fi fi
} }
@ -199,6 +201,10 @@ function _kstoresecret-macos {
function _kstoresecret-config { function _kstoresecret-config {
local _CONFIRM local _CONFIRM
if [ -f "$_KSTORE_DEC_FAILED" ]; then
rm $_KSTORE_DEC_FAILED
_AUTH_SECRET=
fi
if [ -z "$_AUTH_SECRET" ]; then if [ -z "$_AUTH_SECRET" ]; then
_kstoresecret-auto get _kstoresecret-auto get