From 1dce4b450cc505e4e25c41057c59859f254ff59e 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: Mon, 15 Aug 2022 22:32:16 +0800 Subject: [PATCH] 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="" RDOMAIN="" @@ -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"`