kstore added upload / download db

This commit is contained in:
斟酌 鵬兄 2023-10-09 02:28:27 +08:00
parent 13dc0770b8
commit f6d744fda5

View File

@ -20,7 +20,7 @@ if [ -f "$RBASH_HOME/keystore.secret" ]; then
_AUTH_SECRET=$( cat "$RBASH_HOME/keystore.secret" )
fi
complete -W "add del get list query update search secret sync" kstore
complete -W "add del get list query update search secret" kstore
function kstore {
case $1 in
@ -32,7 +32,6 @@ function kstore {
update) shift; kstore-update "$@" ;;
search) shift; kstore-search $@ ;;
secret) shift; kstore-secret $@ ;;
sync) shift; kstore-sync $@ ;;
*)
__func_head "add [key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]"
__func_help "update [key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]"
@ -316,13 +315,72 @@ function kstore-dl-s3au {
fi
}
function kstore-sync {
function kstore-init-s3au {
kstore-dl-s3au "574d106cdced150fa6e04a9437d356d8688035cb2c63a045fa0d4ead8b3ec941" "arch_delete_aws4.sh" || return 1
kstore-dl-s3au "ce04b3f90b7d9a2578587c8ff841186810d977545943fb4a8234a6d6e9f7b568" "arch_delete_many_aws4.sh" || return 1
kstore-dl-s3au "31709a639fab27b5ba071dd4c843fd3e90d4cea07bbb055c08c9720d31a8d11d" "arch_download_aws4.sh" || return 1
kstore-dl-s3au "0bee6f925a41f496f66654062b49ea2a1cc55d877f4617d56bf91244aaf0be51" "arch_getacl_aws4.sh" || return 1
kstore-dl-s3au "dcb89894e78351af702fabb521cf1cf6ca512db9cd4cf3c70631bb1e51ab9340" "arch_list_aws4.sh" || return 1
kstore-dl-s3au "918cd96e5dd6f3a29f9ac90dc70b14eee595da31a8b6c74bdcd67d393b60ae3e" "arch_upload_aws4.sh" || return 1
kstore-dl-s3au "759ef3841525ce240d00e03578c39533c30bf246d61c12c2f3ba2ab37c5f814e" "arch_upload_aws4.sh" || return 1
}
function kstore-upload-db {
local _T _W
kstore-init || return 1
_T=$( date +%Y%m%d%H%M%S )
echo $_T > "$RBASH_HOME/keystore.latest"
which arch-upload-aws4 > /dav/null 2>&1
if [ $? -ne 0 ]; then
kstore-init-s3au
fi
kstore-enc $_AUTH_DB > "$RBASH_HOME/$_T.enc"
arch-upload-aws4 "keystore/$_T.enc" "$RBASH_HOME/$_T.enc"
arch-upload-aws4 "keystore/latest" "$RBASH_HOME/keystore.latest"
rm "$RBASH_HOME/$_T.enc"
rm "$RBASH_HOME/keystore.latest"
}
function kstore-download-db {
local _T _DOMAIN _URL _TMP _CONFIRM
kstore secret config || return 1
_DOMAIN="penguins-workspace.s3.ap-southeast-1.astropenguin.net"
_T=$( curl -s "https://$_DOMAIN/keystore/latest" )
if [ $? -ne 0 ]; then
return 1
fi
_TMP=$( mktemp )
curl -s "https://$_DOMAIN/keystore/$_T.enc" | kstore-dec > $_TMP
if [ $? -ne 0 ]; then
return 1
fi
_T=$( $_SQLITE "$_TMP" "SELECT COUNT( * ) FROM store" )
if [ $? -ne 0 ]; then
return 1
fi
if [ -f "$_AUTH_DB" ]; then
read -p "Replace existing db? (yes/no): " _CONFIRM
if [ "$_CONFIRM" == "yes" ]; then
_T="$_AUTH_DB.old.$( date +%Y%m%d%H%M%S )"
mv "$_AUTH_DB" "$_T"
mv $_TMP $_AUTH_DB
echo "Original copy: $_T"
else
echo "action canceled"
rm $_TMP
fi
else
mv $_TMP $_AUTH_DB
fi
}
function kstore-search {