diff --git a/bash/sources/16_keystore b/bash/sources/16_keystore index 15c9b76..17c26ff 100644 --- a/bash/sources/16_keystore +++ b/bash/sources/16_keystore @@ -33,9 +33,11 @@ function kstore { update) shift; _kstoreupdate "$@" ;; search) shift; _kstoresearch $@ ;; secret) shift; _kstoresecret $@ ;; + upload) shift; _kstoreupload $@ ;; *) __func_head "add [key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]" __func_help "update [key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]" + __func_help "upload [DIR]" __func_help "get [key] [prop, default: $_KSTORE_DEF_PROP]" __func_help "del [key] [prop, default: $_KSTORE_DEF_PROP]" __func_help "list" @@ -58,12 +60,15 @@ function _kstore { case "$SCOPE" in kstore) - COMPREPLY=( $(compgen -W "add del get list query update search secret" -- $CUR) ) + COMPREPLY=( $(compgen -W "add del get list query update upload search secret" -- $CUR) ) return ;; get|update) COMPREPLY=( $(compgen -W "$( _kstorequery "SELECT DISTINCT key FROM $_KSTORE_TABLE" )" -- $CUR) ) ;; + upload) + COMPREPLY=( $(compgen -f -- "$CUR") ) + ;; esac t=${COMP_WORDS[COMP_CWORD-2]} @@ -283,6 +288,42 @@ function _kstoresecret-change { _AUTH_SECRET=$_NEW_SECRET } +function _kstoreupload { + if [ -z "$1" ]; then + __func_head "[DIR]" + return 1 + fi + + _kstoreinit || return 1 + + which arch-upload-aws4 2>&1 > /dev/null + if [ $? -ne 0 ]; then + _kstoreinit-s3au + fi + + local _TARGET _FNAME _TEMP + + _TARGET="$1" + + if [ ! -r "$_TARGET" ]; then + echo "\"$_TARGET\" is not readable" + return 1 + fi + + _FNAME=$( basename "$_TARGET" ) + _TEMP="$( mktemp ).tar.gz" + + tar zcf "$_TEMP" "$_TARGET" + _kstoreenc "$_TEMP" > "${_TEMP}.enc" + + echo "Size: $(du -sh "${_TEMP}.enc")" + + arch-upload-aws4 "uploads/$_TARGET.enc" "${_TEMP}.enc" + + rm "${_TEMP}" + rm "${_TEMP}.enc" +} + function _kstoresecret-clear { unset _AUTH_SECRET _kstoresecret-auto del