moved gpg-agent into config

This commit is contained in:
斟酌 鵬兄 2022-08-11 20:46:58 +08:00
parent 878e1f5fcb
commit 3574300184
3 changed files with 37 additions and 50 deletions

View File

@ -23,18 +23,3 @@ function __func_help() {
# echo "Usage:" ${FUNCNAME[1]} $1 # echo "Usage:" ${FUNCNAME[1]} $1
echo " ${FUNCNAME[1]} $1" echo " ${FUNCNAME[1]} $1"
} }
# Run through all sources
SDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/sources
if [ -d "$SDIR" ]; then
echo "Begin source:"
for i in $( find $SDIR -maxdepth 1 -type f -perm $PERM | sort )
do
echo " Source:" $( basename $i )
. $i
if [[ $? -ne 0 ]]; then
echo " .. failed"
fi
done
fi

View File

@ -7,6 +7,7 @@ esac
__SCRIPT=$BASH_SOURCE __SCRIPT=$BASH_SOURCE
RBASH_HOME="$HOME/.rbash" RBASH_HOME="$HOME/.rbash"
RBASH_SOURCES="$RBASH_HOME/sources" RBASH_SOURCES="$RBASH_HOME/sources"
RBASH_CONFIG="$RBASH_HOME/config"
# Source global definitions # Source global definitions
if [ -f /etc/bashrc ]; then if [ -f /etc/bashrc ]; then
@ -72,26 +73,6 @@ if ! shopt -oq posix; then
fi fi
fi fi
which gpg-agent 2>&1 > /dev/null
if [ $? -eq 0 ]; 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
function __download { function __download {
which curl 2>&1 > /dev/null which curl 2>&1 > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
@ -167,30 +148,30 @@ function rbash_run {
"$f" "$@" "$f" "$@"
} }
export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '
export EDITOR=vim
# User specific aliases and functions # User specific aliases and functions
function rbash_load { function rbash_load {
local f path local f path
echo " $1" echo " $1"
path="sources/$1" f=`rbash_cache "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/bash/bashrc/$1"`
f=`rbash_cache "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/bash/bashrc/$path"`
source "$f" source "$f"
} }
export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '
export EDITOR=vim
# Create default source config # Create default source config
if [ ! -f "$RBASH_HOME/source.conf" ]; then if [ ! -f "$RBASH_CONFIG" ]; then
cat <<___DEFAULT___ > "$RBASH_HOME/source.conf" cat <<___DEFAULT___ > "$RBASH_CONFIG"
echo "Source:" echo "Source:"
rbash_load "package.sh" 1 rbash_load "package.sh"
rbash_load "10_aliases" rbash_load "sources/10_aliases"
rbash_load "12_shortcuts" rbash_load "sources/12_shortcuts"
rbash_load "20_fast-greps" rbash_load "sources/15_gpg-agent"
rbash_load "40_go-command" rbash_load "sources/20_fast-greps"
rbash_load "41_pivot-command" rbash_load "sources/40_go-command"
rbash_load "sources/41_pivot-command"
___DEFAULT___ ___DEFAULT___
chmod 600 "$RBASH_HOME/source.conf" chmod 600 "$RBASH_CONFIG"
fi fi
source "$RBASH_HOME/source.conf" source "$RBASH_CONFIG"

View File

@ -0,0 +1,21 @@
#!/bin/bash
which gpg-agent 2>&1 > /dev/null
if [ $? -eq 0 ]; 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