cleanup code

This commit is contained in:
Jakobus Schürz 2020-09-22 09:08:16 +02:00
parent 3572ea87af
commit 86045791d5
5 changed files with 110 additions and 79 deletions

View file

@ -10,7 +10,7 @@
# set SSHS to false, if not set # set SSHS to false, if not set
if [ -z ${SSHS+x} ]; then export SSHS=false;fi [ -z ${SSHS+x} ] && export SSHS=false
# check if we are a interactive shell # check if we are a interactive shell
# https://guide.bash.academy/expansions/ # https://guide.bash.academy/expansions/
@ -19,40 +19,51 @@ if [[ $- = *i* ]] ; then
#echo "interactive shell" >&2 #echo "interactive shell" >&2
# define variables # define variables
# default timeouts defined in myshellconfig_load_default # Base Path
#[ -z "${MYSHELLCONFIG_ROOT_TMOUT+x}" ] && MYSHELLCONFIG_ROOT_TMOUT=500 [ -z "${MYSHELLCONFIG_SUBPATH+x}" ] && export MYSHELLCONFIG_SUBPATH=".local/myshellconfig"
#[ -z "${MYSHELLCONFIG_USER_TMOUT+x}" ] && MYSHELLCONFIG_USER_TMOUT=0 [ -z "${MYSHELLCONFIG_BASE+x}" ] && export MYSHELLCONFIG_BASE="${HOME}/${MYSHELLCONFIG_SUBPATH}"
# hardcoded paths
export MYSHELLCONFIG_BASE_PARENT="$(dirname $MYSHELLCONFIG_BASE)"
export MYSHELLCONFIG_BASH_COMPLETION="${HOME}/${MYSHELLCONFIG_SUBPATH}/bash_completion.d"
# Userdata
[ -z "${USERNAME+x}" ] && export USERNAME="$USER" [ -z "${USERNAME+x}" ] && export USERNAME="$USER"
[ -z "${USEREMAIL+x}" ] && export USEREMAIL="$USER@$(domainname -d)" [ -z "${USEREMAIL+x}" ] && export USEREMAIL="$USER@$(domainname -d)"
[ -z "${FULLNAME+x}" ] && export FULLNAME="$(getent passwd $USER | cut -d ":" -f 5 | cut -d ',' -f 1)" [ -z "${FULLNAME+x}" ] && export FULLNAME="$(getent passwd $USER | cut -d ":" -f 5 | cut -d ',' -f 1)"
# GIT
[ -z "${GIT_AUTHOR_NAME+x}" ] && export GIT_AUTHOR_NAME=$FULLNAME [ -z "${GIT_AUTHOR_NAME+x}" ] && export GIT_AUTHOR_NAME=$FULLNAME
[ -z "${GIT_AUTHOR_EMAIL+x}" ] && export GIT_AUTHOR_EMAIL=$USEREMAIL [ -z "${GIT_AUTHOR_EMAIL+x}" ] && export GIT_AUTHOR_EMAIL=$USEREMAIL
[ -z "${GIT_COMMITTER_NAME+x}" ] && export GIT_COMMITTER_NAME=$FULLNAME [ -z "${GIT_COMMITTER_NAME+x}" ] && export GIT_COMMITTER_NAME=$FULLNAME
[ -z "${GIT_COMMITTER_EMAIL+x}" ] && export GIT_COMMITTER_EMAIL=$USEREMAIL [ -z "${GIT_COMMITTER_EMAIL+x}" ] && export GIT_COMMITTER_EMAIL=$USEREMAIL
[ -z "${MYSHELLCONFIG_SUBPATH+x}" ] && MYSHELLCONFIG_SUBPATH=".local/myshellconfig"
[ -z "${MYSHELLCONFIG_BASE+x}" ] && export MYSHELLCONFIG_BASE="${HOME}/${MYSHELLCONFIG_SUBPATH}"
MYSHELLCONFIG_BASE_PARENT="$(dirname $MYSHELLCONFIG_BASE)"
[ -z "${MYSHELLCONFIG_LOGDIR+x}" ] && export MYSHELLCONFIG_LOGDIR="${HOME}/logs"
[ -z "${MYSHELLCONFIG_LOGFILE+x}" ] && export MYSHELLCONFIG_LOGFILE="${MYSHELLCONFIG_LOGDIR}/myshellconfig.log"
[ -z "${MYSHELLCONFIG_GIT_TIMEOUT+x}" ] && MYSHELLCONFIG_GIT_TIMEOUT=5s [ -z "${MYSHELLCONFIG_GIT_TIMEOUT+x}" ] && MYSHELLCONFIG_GIT_TIMEOUT=5s
[ -z "${MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT+x}" ] && MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT=20s [ -z "${MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT+x}" ] && MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT=20s
MYSHELLCONFIG_BASH_COMPLETION="${HOME}/${MYSHELLCONFIG_SUBPATH}/bash_completion.d"
[ -z "${MYSHELLCONFIG_GIT_SYNC+x}" ] && MYSHELLCONFIG_GIT_SYNC=true [ -z "${MYSHELLCONFIG_GIT_SYNC+x}" ] && MYSHELLCONFIG_GIT_SYNC=true
# hardcoded git
[ -z "${MYHSELLCONFIG_LOGLEVEL_DEFAULT+x}" ] && { MYHSELLCONFIG_LOGLEVEL_DEFAULT="INFO"; export MYHSELLCONFIG_LOGLEVEL_DEFAULT; }
[ -z "${MYHSELLCONFIG_FILELOGLEVEL_DEFAULT+x}" ] && { MYHSELLCONFIG_FILELOGLEVEL_DEFAULT="INFO"; export MYHSELLCONFIG_FILELOGLEVEL_DEFAULT; }
export SGIT="git -C ${MYSHELLCONFIG_BASE}" export SGIT="git -C ${MYSHELLCONFIG_BASE}"
# git-repo-url for vim plugin
# TODO: check how to use
export MYSHELLCONFIG_VIM_PLUGINS export MYSHELLCONFIG_VIM_PLUGINS
# Create necessary directories
[ -n "${MYSHELLCONFIG_LOGDIR-x}" ] && mkdir -p "$MYSHELLCONFIG_LOGDIR"
[ -z "${SCRIPT_LOG+x}" ] && { SCRIPT_LOG="${MYSHELLCONFIG_LOGFILE}"; export SCRIPT_LOG; } # Logging
. ${MYSHELLCONFIG_BASE}/loggingfunctions [ -z "${MYSHELLCONFIG_LOGDIR+x}" ] && export MYSHELLCONFIG_LOGDIR="${HOME}/logs"
[ -z "${MYSHELLCONFIG_LOGFILE+x}" ] && export MYSHELLCONFIG_LOGFILE="${MYSHELLCONFIG_LOGDIR}/myshellconfig.log"
[ -z "${MYHSELLCONFIG_LOGLEVEL_DEFAULT+x}" ] && export MYHSELLCONFIG_LOGLEVEL_DEFAULT="INFO"
[ -z "${MYHSELLCONFIG_FILELOGLEVEL_DEFAULT+x}" ] && export MYHSELLCONFIG_FILELOGLEVEL_DEFAULT="INFO"
[ -z "${SCRIPT_LOG+x}" ] && { SCRIPT_LOG="${MYSHELLCONFIG_LOGFILE}"; export SCRIPT_LOG; }
[ -z "${LOGLEVEL_DEFAULT+x}" ] && { LOGLEVEL_DEFAULT="${MYHSELLCONFIG_LOGLEVEL_DEFAULT-INFO}"; export LOGLEVEL_DEFAULT; }
[ -z "${FILELOGLEVEL_DEFAULT+x}" ] && { FILELOGLEVEL_DEFAULT=${MYHSELLCONFIG_FILELOGLEVEL_DEFAULT-INFO}; export FILELOGLEVEL_DEFAULT; }
# Create necessary directories for logging
[ -n "${MYSHELLCONFIG_LOGDIR-x}" ] && mkdir -p "$MYSHELLCONFIG_LOGDIR"
# load logging functions
. ${MYSHELLCONFIG_BASE}/logging
cat << EOF >> "${MYSHELLCONFIG_LOGFILE}" cat << EOF >> "${MYSHELLCONFIG_LOGFILE}"
------- start -------------- $(date) ---------------8<-- ------- start configure new shell -------------- $(date) ---------------8<--
EOF EOF
@ -125,7 +136,7 @@ EOF
cat << EOF >> "${MYSHELLCONFIG_LOGFILE}" cat << EOF >> "${MYSHELLCONFIG_LOGFILE}"
--8<--- end ---------------- $(date) ---------------8<-- --8<--- finished configure new shell ---------------- $(date) ---------------8<--
SCRIPTEXIT SCRIPTEXIT
EOF EOF

View file

@ -10,6 +10,7 @@ logdebug "SSH_IDENTITIES_DIR: $SSH_IDENTITIES_DIR" >&2
[ -z "${SSH_AGENTS_DIR-x}" ] || mkdir -vp "$SSH_AGENTS_DIR" [ -z "${SSH_AGENTS_DIR-x}" ] || mkdir -vp "$SSH_AGENTS_DIR"
[ -z "${SSH_AGENT_SOCKETS_DIR-x}" ] || mkdir -vp "$SSH_AGENT_SOCKETS_DIR" [ -z "${SSH_AGENT_SOCKETS_DIR-x}" ] || mkdir -vp "$SSH_AGENT_SOCKETS_DIR"
[ -z "${SSH_IDENTITIES_DIR-x}" ] || mkdir -vp "$SSH_IDENTITIES_DIR" [ -z "${SSH_IDENTITIES_DIR-x}" ] || mkdir -vp "$SSH_IDENTITIES_DIR"
agent-start-or-restart () { agent-start-or-restart () {
ENTRY ENTRY
@ -26,33 +27,30 @@ agent-start-or-restart () {
logdebug "ssh-identität: $ssh_identity" >&2 logdebug "ssh-identität: $ssh_identity" >&2
if [ -e $agentfile ]; then if [ -e $agentfile ]; then
# look if agent is reachable loginfo "$(/bin/sh -c "unset SSH_AUTH_SOCK SSH_AGENT_PID; . $agentfile >/dev/null 2>&1; ssh-add -l >/dev/null")"
# local sshsock sshpid
# sshsock=$SSH_AUTH_SOCK
# sshpid=$SSH_AGENT_PID
# unset SSH_AUTH_SOCK SSH_AGENT_PID
logdebug "$(/bin/sh -c "unset SSH_AUTH_SOCK SSH_AGENT_PID; . $agentfile >/dev/null 2>&1; ssh-add -l")"
case $? in case $? in
0|1) 0)
logdebug "agent is running" >&2 loginfo "agent is running" >&2
;;
1)
logwarn "command failed on ssh-agent"
;; ;;
2) 2)
logdebug "agent is not running 1" >&2 loginfo "former agent is not running" >&2
[ -e $agentsocket ] && rm "$agentsocket" [ -e $agentsocket ] && { logdebug -n "remove socketfile: $( rm -v "$agentsocket" )"; }
ssh-agent -a $agentsocket $SSH_AGENT_OPTIONS > $agentfile 2>&2 logdebug "$(ssh-agent -a $agentsocket $SSH_AGENT_OPTIONS > $agentfile )"
logdebug "agent started" >&2 loginfo "agent started" >&2
;; ;;
esac esac
else else
logdebug "agent is not running 2" >&2 loginfo "agent did not exist" >&2
#rm "$agentsocket" #rm "$agentsocket"
logdebug "ssh-agent -a $agentsocket \> $agentfile" logdebug "ssh-agent -a $agentsocket \> $agentfile"
ssh-agent -a $agentsocket $SSH_AGENT_OPTIONS > $agentfile 2>&2 logdebug "$(ssh-agent -a $agentsocket $SSH_AGENT_OPTIONS > $agentfile )"
logdebug "agent started" >&2 loginfo "agent started" >&2
fi fi
loginfo "agent for $ssh_identity: $agentfile" logdebug "agent for $ssh_identity: $agentfile"
echo -n "agent for $ssh_identity: " >&2
echo $agentfile echo $agentfile
return 0 return 0
@ -79,37 +77,39 @@ agent-load-identity-keys () {
if [ -n "${1+x}" ]; then if [ -n "${1+x}" ]; then
ssh_identity="$1" ssh_identity="$1"
identitydir=${SSH_IDENTITIES_DIR}/${ssh_identity} identitydir=${SSH_IDENTITIES_DIR}/${ssh_identity}
[ -e "${identitydir}/.config" ] && . "${identitydir}/.config" [ -e "${identitydir}/config" ] && . "${identitydir}/config"
agentfile="${SSH_AGENTS_DIR}/agent-${ssh_identity}-$(hostname)" agentfile="${SSH_AGENTS_DIR}/agent-${ssh_identity}-$(hostname)"
agentsocket="${SSH_AGENT_SOCKETS_DIR}/socket-${ssh_identity}-$(hostname)" agentsocket="${SSH_AGENT_SOCKETS_DIR}/socket-${ssh_identity}-$(hostname)"
logdebug "agentfile: $agentfile" >&2 logdebug "agentfile: $agentfile" >&2
logdebug "agentsocket: $agentsocket" >&2 logdebug "agentsocket: $agentsocket" >&2
logdebug "ssh-identität: $ssh_identity" >&2 logdebug "identitydir: $identitydir"
loginfo "ssh-identität: $ssh_identity" >&2
loginfo "SSH_ADD_OPTIONS: $SSH_ADD_OPTIONS" loginfo "SSH_ADD_OPTIONS: $SSH_ADD_OPTIONS"
fingerprints=( $(ssh-runinagent $agentfile "ssh-add -l|awk '{print \$2}'") ) fingerprints=( $(ssh-runinagent $agentfile "ssh-add -l|awk '{print \$2}'") )
for key in $(ls ${SSH_IDENTITIES_DIR}/${ssh_identity}|grep -v "pub$\|so$"); do for key in $(ls ${SSH_IDENTITIES_DIR}/${ssh_identity}/id_*|grep -v "pub$\|so$\|config$\|public$"); do
logtrace "key: $key" logdebug "key: $key"
fingerprint=$(ssh-keygen -l -f ~/.ssh/identities/bmi/id_ed25519|awk '{print $2}') fingerprint=$(ssh-keygen -l -f ~/.ssh/identities/bmi/id_ed25519|awk '{print $2}')
logtrace "${fingerprints[*]} and $fingerprint" logtrace "${fingerprints[*]} and $fingerprint"
if [[ ${fingerprints[*]} =~ "$fingerprint" ]]; then if [[ ${fingerprints[*]} =~ "$fingerprint" ]]; then
logdebug "$key is loaded" >&2 logdebug "$key is loaded" >&2
else else
logdebug "$key is not loaded" >&2 logdebug "$key is not loaded" >&2
loginfo "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} ${identitydir}/${key})" loginfo "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} ${key})"
fi fi
done done
for token in $(ls ${SSH_IDENTITIES_DIR}/${ssh_identity}|grep "so$"); do for token in $(ls ${SSH_IDENTITIES_DIR}/${ssh_identity}/*|grep "\.so$"); do
logtrace "token: $token" logdebug "token: $token"
tokenfingerprint="$(ssh-keygen -l -D $token|tr -s ' '|awk '{print $2}')" tokenfingerprint="$(ssh-keygen -l -D $token|tr -s ' '|awk '{print $2}')"
logtrace "${fingerprints[*]} and $tokenfingerprint" logtrace "${fingerprints[*]} and $tokenfingerprint"
if [[ ${fingerprints[*]} =~ "$tokenfingerprint" ]]; then if [[ ${fingerprints[*]} =~ "$tokenfingerprint" ]]; then
logdebug "$token is loaded" >&2 logdebug "$token is loaded" >&2
else else
logdebug "$token is not loaded" >&2 logdebug "$token is not loaded" >&2
loginfo "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s ${identitydir}/${token})" loginfo "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s /${token})"
fi fi
done done
logdebug "current loaded keys: $(ssh-runinagent $agentfile ssh-add -l)"
fi fi
EXIT EXIT
} }
@ -124,7 +124,7 @@ ssh-runinagent () {
shift shift
sshcommand=${@} sshcommand=${@}
logtrace "run command »$sshcommand« in agent $agentfile" >&2 logdebug "run command »$sshcommand« in agent $agentfile" >&2
if [ -e "$agentfile" ]; then if [ -e "$agentfile" ]; then
/bin/sh -c "unset SSH_AUTH_SOCK SSH_AGENT_PID; . $agentfile >/dev/null 2>/dev/null; $sshcommand" /bin/sh -c "unset SSH_AUTH_SOCK SSH_AGENT_PID; . $agentfile >/dev/null 2>/dev/null; $sshcommand"
EXIT EXIT

View file

@ -844,7 +844,7 @@ loadagent() {
ENTRY ENTRY
local af local af
af=$(ssh-agent-start-or-restart $1 2>/dev/null) af=$(ssh-agent-start-or-restart $1 2>/dev/null)
echo $af loginfo "Load agent from $af"
# eval $(<$af) # eval $(<$af)
. $af . $af
EXIT EXIT
@ -871,6 +871,7 @@ ssh-runinagent () {
setloglevel () { setloglevel () {
ENTRY ENTRY
local loglevels local loglevels
local oldloglevel=$LOGLEVEL
declare -a loglevels declare -a loglevels
loglevels=("ERROR" "WARN" "INFO" "DEBUG" "TRACE") loglevels=("ERROR" "WARN" "INFO" "DEBUG" "TRACE")
if [[ ${loglevels[*]} =~ "$1" ]]; then if [[ ${loglevels[*]} =~ "$1" ]]; then
@ -878,13 +879,14 @@ setloglevel () {
else else
logerror "LOGLEVEL must be one of ERROR, WARN, INFO, DEBUG or TRACE" logerror "LOGLEVEL must be one of ERROR, WARN, INFO, DEBUG or TRACE"
fi fi
logerror "new LOGLEVEL is $LOGLEVEL" logerror "new LOGLEVEL is $LOGLEVEL (changed from $oldloglevel)"
EXIT EXIT
} }
setfileloglevel () { setfileloglevel () {
ENTRY ENTRY
local loglevels local loglevels
local oldloglevel=${FILELOGLEVEL-${MYSHELLCONFIG_FILELOGLEVEL_DEFAULT}}
declare -a loglevels declare -a loglevels
loglevels=("ERROR" "WARN" "INFO" "DEBUG" "TRACE") loglevels=("ERROR" "WARN" "INFO" "DEBUG" "TRACE")
if [[ ${loglevels[*]} =~ "$1" ]]; then if [[ ${loglevels[*]} =~ "$1" ]]; then
@ -892,7 +894,7 @@ setfileloglevel () {
else else
logerror "FILELOGLEVEL must be one of ERROR, WARN, INFO, DEBUG or TRACE" logerror "FILELOGLEVEL must be one of ERROR, WARN, INFO, DEBUG or TRACE"
fi fi
logerror "new FILELOGLEVEL is $FILELOGLEVEL" logerror "new FILELOGLEVEL is $FILELOGLEVEL (changed from $oldloglevel)"
EXIT EXIT
} }

View file

@ -5,32 +5,50 @@
mkdir -p "$(dirname ${SCRIPT_LOG})" mkdir -p "$(dirname ${SCRIPT_LOG})"
touch $SCRIPT_LOG touch $SCRIPT_LOG
[ -z "${MYHSELLCONFIG_LOGLEVEL_DEFAULT+x}" ] && { MYHSELLCONFIG_LOGLEVEL_DEFAULT="INFO"; export MYHSELLCONFIG_LOGLEVEL_DEFAULT; }
[ -z "${MYHSELLCONFIG_FILELOGLEVEL_DEFAULT+x}" ] && { MYHSELLCONFIG_FILELOGLEVEL_DEFAULT="INFO"; export MYHSELLCONFIG_FILELOGLEVEL_DEFAULT; }
function SCRIPTENTRY(){ function SCRIPTENTRY(){
timeAndDate=`date` local loglevels
script_name=`basename -- "$0"` declare -a loglevels
script_name="${script_name%.*}" loglevels=("ERROR" "WARN" "INFO")
echo "[$timeAndDate] [DEBUG] > $script_name $FUNCNAME" >> $SCRIPT_LOG if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
timeAndDate=`date`
script_name=`basename -- "$0"`
script_name="${script_name%.*}"
echo "[$timeAndDate] [DEBUG] > $script_name $FUNCNAME" >> $SCRIPT_LOG
fi
} }
function SCRIPTEXIT(){ function SCRIPTEXIT(){
script_name=`basename -- "$0"` local loglevels
script_name="${script_name%.*}" declare -a loglevels
echo "[$timeAndDate] [DEBUG] < $script_name $FUNCNAME" >> $SCRIPT_LOG loglevels=("ERROR" "WARN" "INFO")
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
script_name=`basename -- "$0"`
script_name="${script_name%.*}"
echo "[$timeAndDate] [DEBUG] < $script_name $FUNCNAME" >> $SCRIPT_LOG
fi
} }
function ENTRY(){ function ENTRY(){
local cfn="${FUNCNAME[1]}" local loglevels
timeAndDate=`date` declare -a loglevels
echo "[$timeAndDate] [DEBUG] > $cfn $FUNCNAME" >> $SCRIPT_LOG loglevels=("ERROR" "WARN" "INFO")
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
local cfn="${FUNCNAME[1]}"
timeAndDate=`date`
echo "[$timeAndDate] [DEBUG] > $cfn $FUNCNAME" >> $SCRIPT_LOG
fi
} }
function EXIT(){ function EXIT(){
local cfn="${FUNCNAME[1]}" local loglevels
timeAndDate=`date` declare -a loglevels
echo "[$timeAndDate] [DEBUG] < $cfn $FUNCNAME" >> $SCRIPT_LOG loglevels=("ERROR" "WARN" "INFO")
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
local cfn="${FUNCNAME[1]}"
timeAndDate=`date`
echo "[$timeAndDate] [DEBUG] < $cfn $FUNCNAME" >> $SCRIPT_LOG
fi
} }
function logerror(){ function logerror(){
@ -46,10 +64,10 @@ function logerror(){
local loglevels local loglevels
declare -a loglevels declare -a loglevels
loglevels=() loglevels=()
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$MYHSELLCONFIG_LOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
echo $opts $msg >&2 echo $opts $msg >&2
fi fi
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$MYHSELLCONFIG_FILELOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$FILELOGLEVEL_DEFAULT}" ]];then
echo "[$timeAndDate] [ERROR] $msg" >> $SCRIPT_LOG echo "[$timeAndDate] [ERROR] $msg" >> $SCRIPT_LOG
fi fi
} }
@ -67,10 +85,10 @@ function logwarn(){
local loglevels local loglevels
declare -a loglevels declare -a loglevels
loglevels=("ERROR" ) loglevels=("ERROR" )
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$MYHSELLCONFIG_LOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
echo $opts $msg >&2 echo $opts $msg >&2
fi fi
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$MYHSELLCONFIG_FILELOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$FILELOGLEVEL_DEFAULT}" ]];then
echo "[$timeAndDate] [WARN] $msg" >> $SCRIPT_LOG echo "[$timeAndDate] [WARN] $msg" >> $SCRIPT_LOG
fi fi
} }
@ -88,10 +106,10 @@ function loginfo(){
local loglevels local loglevels
declare -a loglevels declare -a loglevels
loglevels=("ERROR" "WARN" ) loglevels=("ERROR" "WARN" )
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$MYHSELLCONFIG_LOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
echo $opts $msg >&2 echo $opts $msg >&2
fi fi
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$MYHSELLCONFIG_FILELOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$FILELOGLEVEL_DEFAULT}" ]];then
echo "[$timeAndDate] [INFO] $msg" >> $SCRIPT_LOG echo "[$timeAndDate] [INFO] $msg" >> $SCRIPT_LOG
fi fi
} }
@ -110,10 +128,10 @@ function logdebug(){
local loglevels local loglevels
declare -a loglevels declare -a loglevels
loglevels=("ERROR" "WARN" "INFO") loglevels=("ERROR" "WARN" "INFO")
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$MYHSELLCONFIG_LOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
echo $opts $msg >&2 echo $opts $msg >&2
fi fi
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$MYHSELLCONFIG_FILELOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$FILELOGLEVEL_DEFAULT}" ]];then
echo "[$timeAndDate] [DEBUG] $msg" >> $SCRIPT_LOG echo "[$timeAndDate] [DEBUG] $msg" >> $SCRIPT_LOG
fi fi
} }
@ -131,10 +149,10 @@ function logtrace(){
local loglevels local loglevels
declare -a loglevels declare -a loglevels
loglevels=("ERROR" "WARN" "INFO" "DEBUG") loglevels=("ERROR" "WARN" "INFO" "DEBUG")
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$MYHSELLCONFIG_LOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
echo $opts $msg >&2 echo $opts $msg >&2
fi fi
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$MYHSELLCONFIG_FILELOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$FILELOGLEVEL_DEFAULT}" ]];then
echo "[$timeAndDate] [TRACE] $msg" >> $SCRIPT_LOG echo "[$timeAndDate] [TRACE] $msg" >> $SCRIPT_LOG
fi fi
} }

View file

@ -142,7 +142,7 @@ SSH_AGENT_PID=${SSH_AGENT_PID}; export SSH_AGENT_PID;
loginfo Agent pid ${SSH_AGENT_PID}; loginfo Agent pid ${SSH_AGENT_PID};
EOF EOF
[ -z "${SSH_ADD_DEFAULT_OPTIONS+x}" ] && { SSH_ADD_DEFAULT_OPTIONS="-t 7200"; export SSH_ADD_DEFAULT_OPTIONS; } [ -z "${SSH_ADD_DEFAULT_OPTIONS+x}" ] && { SSH_ADD_DEFAULT_OPTIONS="-t 7200"; export SSH_ADD_DEFAULT_OPTIONS; }
[ -z "${SSH_IDENTITIES_DEFAULT_DIR+x}" ] && { SSH_IDENTITIES_DEFAULT_DIR="${HOME}/.ssh/identities"; export SSH_IDENTITIES_DEFAULT_DIR; } [ -z "${SSH_IDENTITIES_DEFAULT_DIR+x}" ] && { SSH_IDENTITIES_DEFAULT_DIR="${HOME}/.ssh/identities"; export SSH_IDENTITIES_DEFAULT_DIR; }
[ -z "${SSH_AGENTS_DEFAULT_DIR+x}" ] && { SSH_AGENTS_DEFAULT_DIR="${HOME}/.ssh/agents"; export SSH_AGENTS_DEFAULT_DIR; } [ -z "${SSH_AGENTS_DEFAULT_DIR+x}" ] && { SSH_AGENTS_DEFAULT_DIR="${HOME}/.ssh/agents"; export SSH_AGENTS_DEFAULT_DIR; }
[ -z "${SSH_AGENT_SOCKETS_DEFAULT_DIR+x}" ] && { SSH_AGENT_SOCKETS_DEFAULT_DIR="${HOME}/.ssh/agents"; export SSH_AGENT_SOCKETS_DEFAULT_DIR; } [ -z "${SSH_AGENT_SOCKETS_DEFAULT_DIR+x}" ] && { SSH_AGENT_SOCKETS_DEFAULT_DIR="${HOME}/.ssh/agents"; export SSH_AGENT_SOCKETS_DEFAULT_DIR; }