2015-03-04 04:43:33 +00:00
|
|
|
# If not running interactively, don't do anything
|
|
|
|
case $- in
|
|
|
|
*i*) ;;
|
|
|
|
*) return;;
|
|
|
|
esac
|
|
|
|
|
2016-04-29 07:34:32 +00:00
|
|
|
__SCRIPT=$BASH_SOURCE
|
2016-04-28 01:45:44 +00:00
|
|
|
|
2015-03-04 04:43:33 +00:00
|
|
|
# Source global definitions
|
|
|
|
if [ -f /etc/bashrc ]; then
|
|
|
|
. /etc/bashrc
|
|
|
|
fi
|
|
|
|
|
2015-05-21 02:52:44 +00:00
|
|
|
# Source for Custom bash ENV
|
|
|
|
if [ -f ~/.rbashenv ]; then
|
|
|
|
. ~/.rbashenv
|
|
|
|
fi
|
|
|
|
|
2015-03-04 04:43:33 +00:00
|
|
|
# don't put duplicate lines or lines starting with space in the history.
|
|
|
|
# See bash(1) for more options
|
|
|
|
HISTCONTROL=ignoreboth
|
|
|
|
|
|
|
|
# append to the history file, don't overwrite it
|
|
|
|
shopt -s histappend
|
|
|
|
|
|
|
|
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
|
|
|
|
HISTSIZE=1000
|
|
|
|
HISTFILESIZE=2000
|
|
|
|
|
|
|
|
# check the window size after each command and, if necessary,
|
|
|
|
# update the values of LINES and COLUMNS.
|
|
|
|
shopt -s checkwinsize
|
|
|
|
|
|
|
|
# If set, the pattern "**" used in a pathname expansion context will
|
|
|
|
# match all files and zero or more directories and subdirectories.
|
|
|
|
#shopt -s globstar
|
|
|
|
|
|
|
|
# make less more friendly for non-text input files, see lesspipe(1)
|
|
|
|
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
|
|
|
|
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set a fancy prompt (non-color, unless we know we "want" color)
|
|
|
|
case "$TERM" in
|
|
|
|
xterm-color) color_prompt=yes;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Alias definitions.
|
|
|
|
# You may want to put all your additions into a separate file like
|
|
|
|
# ~/.bash_aliases, instead of adding them here directly.
|
|
|
|
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
|
|
|
|
|
|
|
|
if [ -f ~/.bash_aliases ]; then
|
|
|
|
. ~/.bash_aliases
|
|
|
|
fi
|
|
|
|
|
|
|
|
# enable programmable completion features (you don't need to enable
|
|
|
|
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
|
|
|
|
# sources /etc/bash.bashrc).
|
|
|
|
if ! shopt -oq posix; then
|
|
|
|
if [ -f /usr/share/bash-completion/bash_completion ]; then
|
|
|
|
. /usr/share/bash-completion/bash_completion
|
|
|
|
elif [ -f /etc/bash_completion ]; then
|
|
|
|
. /etc/bash_completion
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-03-10 05:59:33 +00:00
|
|
|
if [ -x "/usr/bin/gpg-agent" ]; then
|
|
|
|
GPG_ENV="$HOME/.gnupg/environment"
|
|
|
|
|
|
|
|
function __start_agent {
|
|
|
|
gpg-agent --daemon > "${GPG_ENV}"
|
|
|
|
chmod 600 "${GPG_ENV}"
|
|
|
|
. "${GPG_ENV}" > /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -f "${GPG_ENV}" ]; then
|
|
|
|
. "${GPG_ENV}" > /dev/null
|
|
|
|
|
|
|
|
gpg-agent > /dev/null 2>&1
|
|
|
|
[ "$?" -ne 0 ] && { __start_agent; }
|
|
|
|
else
|
|
|
|
__start_agent;
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-03-10 04:00:40 +00:00
|
|
|
BASHL_UUID="<UUID>"
|
|
|
|
export BASH_SDIR=/tmp/$BASHL_UUID
|
|
|
|
[ ! -d "$BASH_SDIR" ] && mkdir "$BASH_SDIR"
|
|
|
|
|
|
|
|
|
|
|
|
function __cryptd {
|
2015-03-10 04:55:54 +00:00
|
|
|
echo "<PASSWD>" | gpg --batch -q --cipher-algo AES256 --passphrase-fd 0 -o "$2" -d "$1"
|
2015-03-10 04:00:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function __crypte {
|
2015-03-10 04:55:54 +00:00
|
|
|
echo "<PASSWD>" | gpg --batch -q --cipher-algo AES256 --passphrase-fd 0 -o "$1.enc" -c "$1"
|
2015-03-10 04:00:40 +00:00
|
|
|
mv "$1.enc" "$1"
|
|
|
|
}
|
|
|
|
__CFILE=""
|
|
|
|
function __cacheDownload {
|
2022-08-10 05:16:11 +00:00
|
|
|
MLINK=$( echo "$1" | md5sum | cut -d' ' -f1 )
|
2015-03-10 04:00:40 +00:00
|
|
|
|
|
|
|
__CFILE=$BASH_SDIR/$MLINK
|
|
|
|
|
|
|
|
if [ ! -f "$__CFILE" ]; then
|
2016-02-22 00:31:54 +00:00
|
|
|
__download "$1" > "$__CFILE"
|
2015-03-10 04:00:40 +00:00
|
|
|
__crypte "$__CFILE"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-02-22 00:31:54 +00:00
|
|
|
function __download {
|
|
|
|
which curl 2>&1 > /dev/null
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
curl -s "$1"
|
|
|
|
return;
|
|
|
|
fi
|
|
|
|
|
|
|
|
which wget 2>&1 > /dev/null
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
wget -qO- "$1"
|
|
|
|
return;
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-11-24 07:56:43 +00:00
|
|
|
function __uuid {
|
2016-02-21 17:42:48 +00:00
|
|
|
which uuidgen 2>&1 > /dev/null
|
2015-11-24 08:01:14 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
2022-08-07 14:23:15 +00:00
|
|
|
uuidgen
|
2015-11-24 07:56:43 +00:00
|
|
|
else
|
2022-08-07 14:23:15 +00:00
|
|
|
head -n1 /proc/sys/kernel/random/uuid
|
2015-11-24 07:56:43 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-03-06 03:24:05 +00:00
|
|
|
function rbash_upgrade {
|
2016-04-28 01:45:44 +00:00
|
|
|
echo "Updating $__SCRIPT"
|
2022-08-07 14:23:15 +00:00
|
|
|
TMPID=`__uuid`
|
2016-02-21 12:00:52 +00:00
|
|
|
TMPFILE=/tmp/$TMPID
|
2022-08-07 14:14:45 +00:00
|
|
|
__download "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/bash/bashrc/rbashrc" > $TMPFILE
|
2015-03-04 04:43:33 +00:00
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
MC_NAME="<MACHINE_NAME>"
|
|
|
|
MCC_NAME="<MACHINE_COLORED_NAME>"
|
|
|
|
else
|
|
|
|
MC_NAME=$1
|
|
|
|
MCC_NAME=$2
|
|
|
|
fi
|
|
|
|
|
2022-08-07 14:23:15 +00:00
|
|
|
UUID=`__uuid`
|
|
|
|
PASS=`__uuid`
|
2015-03-04 04:43:33 +00:00
|
|
|
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" )
|
2015-03-10 04:00:40 +00:00
|
|
|
UUID_TOK=$( echo "#_UUID_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
|
|
|
PASS_TOK=$( echo "#_PASSWD_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
2016-02-21 12:25:03 +00:00
|
|
|
COLOR_CODE_TOK=$( echo "#_COLOR_CODE_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
|
|
|
COLOR_CODE=$(( $RANDOM * 6 / 32767 + 1 ))
|
|
|
|
|
2015-03-10 04:00:40 +00:00
|
|
|
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" \
|
2016-02-21 12:29:20 +00:00
|
|
|
-e "s/$COLOR_CODE_TOK/$COLOR_CODE/g" \
|
2015-03-10 04:00:40 +00:00
|
|
|
$TMPFILE
|
|
|
|
|
2016-04-28 01:45:44 +00:00
|
|
|
mv $TMPFILE $__SCRIPT
|
2022-08-10 05:19:45 +00:00
|
|
|
|
|
|
|
# Clean up the old dir
|
|
|
|
if [ $? -eq 0 ] && [ -d "$BASH_SDIR" ]; then
|
|
|
|
rm -r "$BASH_SDIR"
|
|
|
|
fi
|
|
|
|
|
2016-04-28 01:45:44 +00:00
|
|
|
. $__SCRIPT
|
2015-03-04 04:43:33 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 03:24:05 +00:00
|
|
|
function rbash_run {
|
|
|
|
echo "Getting: $1"
|
2022-08-07 14:14:45 +00:00
|
|
|
__cacheDownload "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/$1"
|
2015-03-06 03:24:05 +00:00
|
|
|
shift
|
2022-08-07 14:23:15 +00:00
|
|
|
TMPID=`__uuid`
|
2016-02-21 12:00:52 +00:00
|
|
|
TMPFILE=/tmp/$TMPID
|
2015-03-10 04:00:40 +00:00
|
|
|
__cryptd "$__CFILE" "$TMPFILE"
|
|
|
|
|
2016-05-12 02:45:34 +00:00
|
|
|
chmod 700 "$TMPFILE"
|
2019-06-02 05:30:57 +00:00
|
|
|
"$TMPFILE" "$@"
|
2016-05-12 02:45:34 +00:00
|
|
|
rm "$TMPFILE"
|
2015-03-06 03:24:05 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 07:47:04 +00:00
|
|
|
export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '
|
2015-03-04 04:43:33 +00:00
|
|
|
export EDITOR=vim
|
|
|
|
|
|
|
|
# User specific aliases and functions
|
|
|
|
echo "Source:"
|
|
|
|
function __ns {
|
2015-03-23 07:59:03 +00:00
|
|
|
if [ -z "$2" ]; then
|
2015-03-23 08:02:13 +00:00
|
|
|
FPATH="sources/$1"
|
2015-03-23 07:59:03 +00:00
|
|
|
else
|
2015-03-23 08:02:13 +00:00
|
|
|
FPATH=$1
|
2015-03-23 07:59:03 +00:00
|
|
|
fi
|
|
|
|
|
2015-03-04 04:43:33 +00:00
|
|
|
echo " $1"
|
2022-08-07 14:14:45 +00:00
|
|
|
__cacheDownload "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/bash/bashrc/$FPATH"
|
2015-03-10 04:50:25 +00:00
|
|
|
shift
|
2022-08-07 14:23:15 +00:00
|
|
|
TMPID=`__uuid`
|
2016-02-21 12:00:52 +00:00
|
|
|
TMPFILE=/tmp/$TMPID
|
2015-03-10 04:50:25 +00:00
|
|
|
__cryptd "$__CFILE" "$TMPFILE"
|
2015-03-04 04:43:33 +00:00
|
|
|
. $TMPFILE
|
|
|
|
rm $TMPFILE
|
|
|
|
}
|
|
|
|
|
2015-03-23 07:59:03 +00:00
|
|
|
__ns "package.sh" 1
|
2015-03-04 04:43:33 +00:00
|
|
|
__ns "10_aliases"
|
2022-08-09 06:48:36 +00:00
|
|
|
__ns "12_shortcuts"
|
2015-03-04 04:43:33 +00:00
|
|
|
__ns "20_fast-greps"
|
|
|
|
__ns "40_go-command"
|
|
|
|
__ns "41_pivot-command"
|
|
|
|
|
|
|
|
# Source for additional rc
|
|
|
|
if [ -f ~/.bashrc_local ]; then
|
|
|
|
. ~/.bashrc_local
|
|
|
|
fi
|