From d7d7521d837f3d1cd6e350cf1d7a70dc6fb9c0d5 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: Tue, 10 Mar 2015 12:00:40 +0800 Subject: [PATCH] Cache download --- bash/bashrc/rbashrc | 47 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/bash/bashrc/rbashrc b/bash/bashrc/rbashrc index de99777..a685431 100644 --- a/bash/bashrc/rbashrc +++ b/bash/bashrc/rbashrc @@ -61,6 +61,31 @@ if ! shopt -oq posix; then fi fi +BASHL_UUID="" +export BASH_SDIR=/tmp/$BASHL_UUID +[ ! -d "$BASH_SDIR" ] && mkdir "$BASH_SDIR" + + +function __cryptd { + echo "" | gpg --passphrase-fd 0 -o "$2" -d "$1" +} + +function __crypte { + echo "" | gpg --passphrase-fd 0 -o "$1.enc" -c "$1" + mv "$1.enc" "$1" +} +__CFILE="" +function __cacheDownload { + MLINK=$( echo "$1" | md5sum ) + + __CFILE=$BASH_SDIR/$MLINK + + if [ ! -f "$__CFILE" ]; then + curl -s "$1" > "$__CFILE" + __crypte "$__CFILE" + fi +} + function rbash_upgrade { echo "Updating the .bashrc" TMPFILE=/tmp/$( cat /proc/sys/kernel/random/uuid ) @@ -74,20 +99,32 @@ function rbash_upgrade { MCC_NAME=$2 fi + UUID=$( cat /proc/sys/kernel/random/uuid ) + PASS=$( cat /proc/sys/kernel/random/uuid ) PMC_NAME=$( echo "#_MACHINE_NAME_#" | sed -e "s/#_//g" ) PMCC_NAME=$( echo "#_MACHINE_COLORED_NAME_#" | sed -e "s/#_//g" ) - sed -i -e "s/$PMC_NAME/$MC_NAME/g" -e "s/$PMCC_NAME/$MCC_NAME/g" $TMPFILE + UUID_TOK=$( echo "#_UUID_#" | sed -e "s/#_//g" ) + PASS_TOK=$( echo "#_PASSWD_#" | sed -e "s/#_//g" ) + sed -i \ + -e "s/$PMC_NAME/$MC_NAME/g" \ + -e "s/$PMCC_NAME/$MCC_NAME/g" \ + -e "s/$UUID_TOK/$UUID/g" \ + -e "s/$PASS_TOK/$PASS/g" \ + $TMPFILE + mv $TMPFILE ~/.bashrc . ~/.bashrc } function rbash_run { echo "Getting: $1" - TMPFILE=/tmp/$( cat /proc/sys/kernel/random/uuid ) - curl -s "http://git.astropenguin.net/?p=utils.git;a=blob_plain;f=bash/$1;hb=HEAD" > $TMPFILE + __cacheDownload "http://git.astropenguin.net/?p=utils.git;a=blob_plain;f=bash/$1;hb=HEAD" shift - bash $TMPFILE $@ - rm $TMPFILE + TMPFILE=/tmp/$( cat /proc/sys/kernel/random/uuid ) + __cryptd "$__CFILE" "$TMPFILE" + + bash "$TMPFILE" $@ + rm "$TMPFILE"; } export PS1='This is \e[1;31m\e[0m: \w\n$ '