Simplify rbashrc
This commit is contained in:
parent
6bd9a52adb
commit
e7c016e21b
@ -5,6 +5,8 @@ case $- in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
__SCRIPT=$BASH_SOURCE
|
__SCRIPT=$BASH_SOURCE
|
||||||
|
RBASH_HOME="$HOME/.rbash"
|
||||||
|
RBASH_SOURCES="$RBASH_HOME/sources"
|
||||||
|
|
||||||
# Source global definitions
|
# Source global definitions
|
||||||
if [ -f /etc/bashrc ]; then
|
if [ -f /etc/bashrc ]; then
|
||||||
@ -16,6 +18,8 @@ if [ -f ~/.rbashenv ]; then
|
|||||||
. ~/.rbashenv
|
. ~/.rbashenv
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$RBASH_SOURCES"
|
||||||
|
|
||||||
# don't put duplicate lines or lines starting with space in the history.
|
# don't put duplicate lines or lines starting with space in the history.
|
||||||
# See bash(1) for more options
|
# See bash(1) for more options
|
||||||
HISTCONTROL=ignoreboth
|
HISTCONTROL=ignoreboth
|
||||||
@ -88,58 +92,40 @@ if [ $? -eq 0 ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BASHL_UUID="<UUID>"
|
|
||||||
export BASH_SDIR=/tmp/$BASHL_UUID
|
|
||||||
[ ! -d "$BASH_SDIR" ] && mkdir "$BASH_SDIR"
|
|
||||||
|
|
||||||
|
|
||||||
function __cryptd {
|
|
||||||
echo "<PASSWD>" | gpg --batch -q --cipher-algo AES256 --passphrase-fd 0 -o "$2" -d "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
function __crypte {
|
|
||||||
echo "<PASSWD>" | gpg --batch -q --cipher-algo AES256 --passphrase-fd 0 -o "$1.enc" -c "$1"
|
|
||||||
mv "$1.enc" "$1"
|
|
||||||
}
|
|
||||||
__CFILE=""
|
|
||||||
function __cacheDownload {
|
|
||||||
MLINK=$( echo "$1" | md5sum | cut -d' ' -f1 )
|
|
||||||
|
|
||||||
__CFILE=$BASH_SDIR/$MLINK
|
|
||||||
|
|
||||||
if [ ! -f "$__CFILE" ]; then
|
|
||||||
__download "$1" > "$__CFILE"
|
|
||||||
__crypte "$__CFILE"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function __download {
|
function __download {
|
||||||
which curl 2>&1 > /dev/null
|
which curl 2>&1 > /dev/null
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
curl -s "$1"
|
curl -s "$1"
|
||||||
return;
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
which wget 2>&1 > /dev/null
|
which wget 2>&1 > /dev/null
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
wget -qO- "$1"
|
wget -qO- "$1"
|
||||||
return;
|
return
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __uuid {
|
function rbash_cache {
|
||||||
which uuidgen 2>&1 > /dev/null
|
local CACHE_FILE
|
||||||
if [ $? -eq 0 ]; then
|
MLINK=$( echo "$1" | md5sum | cut -d' ' -f1 )
|
||||||
uuidgen
|
|
||||||
else
|
CACHE_FILE="$RBASH_SOURCES/$MLINK"
|
||||||
head -n1 /proc/sys/kernel/random/uuid
|
|
||||||
|
if [ ! -f "$CACHE_FILE" ]; then
|
||||||
|
__download "$1" > "$CACHE_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
chmod 700 "$CACHE_FILE"
|
||||||
|
return "$CACHE_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
function rbash_upgrade {
|
function rbash_upgrade {
|
||||||
echo "Updating $__SCRIPT"
|
echo "Updating $__SCRIPT"
|
||||||
TMPID=`__uuid`
|
|
||||||
TMPFILE=/tmp/$TMPID
|
local TMPFILE
|
||||||
|
|
||||||
|
TMPFILE=$( mktemp )
|
||||||
__download "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/bash/bashrc/rbashrc" > $TMPFILE
|
__download "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/bash/bashrc/rbashrc" > $TMPFILE
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
@ -150,76 +136,61 @@ function rbash_upgrade {
|
|||||||
MCC_NAME=$2
|
MCC_NAME=$2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
UUID=`__uuid`
|
|
||||||
PASS=`__uuid`
|
|
||||||
PMC_NAME=$( echo "#_MACHINE_NAME_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
PMC_NAME=$( echo "#_MACHINE_NAME_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
||||||
PMCC_NAME=$( echo "#_MACHINE_COLORED_NAME_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
PMCC_NAME=$( echo "#_MACHINE_COLORED_NAME_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
||||||
UUID_TOK=$( echo "#_UUID_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
|
||||||
PASS_TOK=$( echo "#_PASSWD_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
|
||||||
COLOR_CODE_TOK=$( echo "#_COLOR_CODE_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
COLOR_CODE_TOK=$( echo "#_COLOR_CODE_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
||||||
COLOR_CODE=$(( $RANDOM * 6 / 32767 + 1 ))
|
COLOR_CODE=$(( $RANDOM * 6 / 32767 + 1 ))
|
||||||
|
|
||||||
sed -i \
|
sed -i \
|
||||||
-e "s/$PMC_NAME/$MC_NAME/g" \
|
-e "s/$PMC_NAME/$MC_NAME/g" \
|
||||||
-e "s/$PMCC_NAME/$MCC_NAME/g" \
|
-e "s/$PMCC_NAME/$MCC_NAME/g" \
|
||||||
-e "s/$UUID_TOK/$UUID/g" \
|
|
||||||
-e "s/$PASS_TOK/$PASS/g" \
|
|
||||||
-e "s/$COLOR_CODE_TOK/$COLOR_CODE/g" \
|
-e "s/$COLOR_CODE_TOK/$COLOR_CODE/g" \
|
||||||
$TMPFILE
|
$TMPFILE
|
||||||
|
|
||||||
mv $TMPFILE $__SCRIPT
|
mv $TMPFILE $__SCRIPT
|
||||||
|
|
||||||
# Clean up the old dir
|
# Clean up the old dir
|
||||||
if [ $? -eq 0 ] && [ -d "$BASH_SDIR" ]; then
|
if [ $? -eq 0 ] && [ -d "$RBASH_SOURCES" ]; then
|
||||||
rm -r "$BASH_SDIR"
|
rm -r "$RBASH_SOURCES"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. $__SCRIPT
|
source $__SCRIPT
|
||||||
}
|
}
|
||||||
|
|
||||||
function rbash_run {
|
function rbash_run {
|
||||||
|
local f
|
||||||
echo "Getting: $1"
|
echo "Getting: $1"
|
||||||
__cacheDownload "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/$1"
|
|
||||||
shift
|
|
||||||
TMPID=`__uuid`
|
|
||||||
TMPFILE=/tmp/$TMPID
|
|
||||||
__cryptd "$__CFILE" "$TMPFILE"
|
|
||||||
|
|
||||||
chmod 700 "$TMPFILE"
|
f=`rbash_cache "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/$1"`
|
||||||
"$TMPFILE" "$@"
|
shift
|
||||||
rm "$TMPFILE"
|
|
||||||
|
"$f" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '
|
export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '
|
||||||
export EDITOR=vim
|
export EDITOR=vim
|
||||||
|
|
||||||
# User specific aliases and functions
|
# User specific aliases and functions
|
||||||
echo "Source:"
|
function rbash_load {
|
||||||
function __ns {
|
local f path
|
||||||
if [ -z "$2" ]; then
|
|
||||||
FPATH="sources/$1"
|
|
||||||
else
|
|
||||||
FPATH=$1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo " $1"
|
echo " $1"
|
||||||
__cacheDownload "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/bash/bashrc/$FPATH"
|
path="sources/$1"
|
||||||
shift
|
f=rbash_cache "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/bash/bashrc/$path"
|
||||||
TMPID=`__uuid`
|
source "$f"
|
||||||
TMPFILE=/tmp/$TMPID
|
|
||||||
__cryptd "$__CFILE" "$TMPFILE"
|
|
||||||
. $TMPFILE
|
|
||||||
rm $TMPFILE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__ns "package.sh" 1
|
# Create default source config
|
||||||
__ns "10_aliases"
|
if [ ! -f "$RBASH_HOME/source.conf" ]; then
|
||||||
__ns "12_shortcuts"
|
cat <<___DEFAULT___ > "$RBASH_HOME/source.conf"
|
||||||
__ns "20_fast-greps"
|
echo "Source:"
|
||||||
__ns "40_go-command"
|
rbash_load "package.sh" 1
|
||||||
__ns "41_pivot-command"
|
rbash_load "10_aliases"
|
||||||
|
rbash_load "12_shortcuts"
|
||||||
# Source for additional rc
|
rbash_load "20_fast-greps"
|
||||||
if [ -f ~/.bashrc_local ]; then
|
rbash_load "40_go-command"
|
||||||
. ~/.bashrc_local
|
rbash_load "41_pivot-command"
|
||||||
|
___DEFAULT___
|
||||||
|
chmod 600 "$RBASH_HOME/source.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
source "$RBASH_HOME/source.conf"
|
||||||
|
Loading…
Reference in New Issue
Block a user