penguin/utils

my env utils

commit 1dce4b450cc505e4e25c41057c59859f254ff59e

author斟酌 鵬兄 <tgckpg@gmail.com>
date2022-08-15T14:32:16Z
subjectDownload arch utils
commit 1dce4b450cc505e4e25c41057c59859f254ff59e
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2022-08-15T14:32:16Z

    Download arch utils
---
 bash/rbashrc             |  8 +++++---
 bash/sources/16_keystore | 24 +++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/bash/rbashrc b/bash/rbashrc
index 5397b09..5052518 100644
--- a/bash/rbashrc
+++ b/bash/rbashrc
@@ -15,6 +15,7 @@ RBASH_REMOTE="https://git.k8s.astropenguin.net"
 RBASH_REPO="penguin/utils"
 RBASH_PATH="bash"
 RBASH_MERGED="$RBASH_SOURCES/merged"
+RBASH_BIN="$RBASH_HOME/bin"
 
 RHOSTNAME="<HOSTNAME>"
 RDOMAIN="<DOMAIN>"
@@ -90,13 +91,13 @@ function __download {
     which curl 2>&1 > /dev/null
     if [ $? -eq 0 ]; then
         curl -s "$1"
-        return
+        return $?
     fi
 
     which wget 2>&1 > /dev/null
     if [ $? -eq 0 ]; then
         wget -qO- "$1"
-        return
+        return $?
     fi
 }
 
@@ -115,7 +116,7 @@ function rbash_cache {
 }
 
 _RBASH_LOADED=
-mkdir -p "$RBASH_SOURCES"
+mkdir -p "$RBASH_SOURCES" "$RBASH_BIN"
 
 if [ ! -f "$RBASH_SOURCES/merged" ]; then
 	_RBASH_MERGE_START=1
@@ -291,6 +292,7 @@ function r2dissource {
 
 export PS1="This is ${RHOSTNAME}\e[1;3${RCOLOR}m${RDOMAIN}\e[0m: \w\n\$ "
 export EDITOR=vim
+export PATH="$RBASH_BIN:$PATH"
 
 # Source for custom bash env, allows overriding
 if [ -f "$RBASH_ENV" ]; then
diff --git a/bash/sources/16_keystore b/bash/sources/16_keystore
index 712a8aa..b208ec0 100644
--- a/bash/sources/16_keystore
+++ b/bash/sources/16_keystore
@@ -30,7 +30,7 @@ function kstore {
 		update) shift; kstore-update "$@" ;;
 		search) shift; kstore-search $@ ;;
 		secret) shift; kstore-secret $@ ;;
-		upload) shift; kstore-upload $@ ;;
+		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]"
@@ -289,6 +289,28 @@ function kstore-del {
 	fi
 }
 
+function kstore-dl-s3au {
+	local p tmp
+
+	p="https://git.k8s.astropenguin.net/penguin/s3-arch-utils/raw/branch/master"
+
+    which "$1" 2>&1 > /dev/null
+	if [ $? -ne 0 ]; then
+		tmp=$( mktemp )
+		__download "$p/$1" > $tmp
+		sha256sum $tmp | grep -q "$2"
+		if [ $? -eq 0 ]; then
+			mv $tmp "$RBASH_BIN/$1"
+			chmod +x "$RBASH_BIN/$1"
+		fi
+	fi
+}
+
+function kstore-sync {
+	kstore-dl-s3au "arch_download_aws4.sh" "f1c2e9c9de380d8e590f46a0cc0c320c711dcff3d7d34a1a86927e61030ae5b8" || return 1
+	kstore-dl-s3au "arch_upload_aws4.sh" "ca2229a5a7c98e8f5e692129a50b12457f8acbcb366a987cf3d8101cc4b38667" || return 1
+}
+
 function kstore-search {
 	local _termk _termp _cond
 	_termk=`kstore-quote "$1"`