2020-01-14 10:11:36 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#debug
|
|
|
|
|
2020-09-21 18:02:07 +02:00
|
|
|
#failure() {
|
|
|
|
# local lineno=$1
|
|
|
|
# local msg=$2
|
|
|
|
# echo "Failed at $lineno: $msg"
|
|
|
|
#}
|
|
|
|
#trap 'failure ${LINENO} "$BASH_COMMAND"' ERR
|
2020-09-21 17:03:48 +02:00
|
|
|
|
|
|
|
|
2020-01-14 10:11:36 +01:00
|
|
|
# set SSHS to false, if not set
|
2020-09-11 09:21:07 +02:00
|
|
|
if [ -z ${SSHS+x} ]; then export SSHS=false;fi
|
|
|
|
|
2020-01-14 10:11:36 +01:00
|
|
|
# check if we are a interactive shell
|
2020-01-15 18:09:34 +01:00
|
|
|
# https://guide.bash.academy/expansions/
|
|
|
|
# https://www.tldp.org/LDP/abs/html/refcards.html#AEN22473
|
|
|
|
if [[ $- = *i* ]] ; then
|
2020-03-12 22:07:18 +01:00
|
|
|
#echo "interactive shell" >&2
|
2020-01-14 10:11:36 +01:00
|
|
|
|
|
|
|
# define variables
|
2020-09-21 13:00:29 +02:00
|
|
|
# default timeouts defined in myshellconfig_load_default
|
2020-03-12 20:59:57 +01:00
|
|
|
#[ -z "${MYSHELLCONFIG_ROOT_TMOUT+x}" ] && MYSHELLCONFIG_ROOT_TMOUT=500
|
|
|
|
#[ -z "${MYSHELLCONFIG_USER_TMOUT+x}" ] && MYSHELLCONFIG_USER_TMOUT=0
|
2020-09-21 13:00:29 +02:00
|
|
|
[ -z "${USERNAME+x}" ] && export USERNAME="$USER"
|
|
|
|
[ -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 "${GIT_AUTHOR_NAME+x}" ] && export GIT_AUTHOR_NAME=$FULLNAME
|
|
|
|
[ -z "${GIT_AUTHOR_EMAIL+x}" ] && export GIT_AUTHOR_EMAIL=$USEREMAIL
|
|
|
|
[ -z "${GIT_COMMITTER_NAME+x}" ] && export GIT_COMMITTER_NAME=$FULLNAME
|
|
|
|
[ -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}"
|
2020-01-15 01:38:33 +01:00
|
|
|
MYSHELLCONFIG_BASE_PARENT="$(dirname $MYSHELLCONFIG_BASE)"
|
2020-09-21 23:59:18 +02:00
|
|
|
[ -z "${MYSHELLCONFIG_LOGDIR+x}" ] && export MYSHELLCONFIG_LOGDIR="${HOME}/logs"
|
2020-09-21 13:00:29 +02:00
|
|
|
[ -z "${MYSHELLCONFIG_LOGFILE+x}" ] && export MYSHELLCONFIG_LOGFILE="${MYSHELLCONFIG_LOGDIR}/myshellconfig.log"
|
|
|
|
[ -z "${MYSHELLCONFIG_GIT_TIMEOUT+x}" ] && MYSHELLCONFIG_GIT_TIMEOUT=5s
|
|
|
|
[ -z "${MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT+x}" ] && MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT=20s
|
2020-01-14 10:11:36 +01:00
|
|
|
MYSHELLCONFIG_BASH_COMPLETION="${HOME}/${MYSHELLCONFIG_SUBPATH}/bash_completion.d"
|
2020-09-21 13:00:29 +02:00
|
|
|
[ -z "${MYSHELLCONFIG_GIT_SYNC+x}" ] && MYSHELLCONFIG_GIT_SYNC=true
|
2020-01-14 10:11:36 +01:00
|
|
|
|
2020-09-21 21:08:08 +02:00
|
|
|
[ -z "${MYHSELLCONFIG_LOGLEVEL_DEFAULT+x}" ] && { MYHSELLCONFIG_LOGLEVEL_DEFAULT="INFO"; export MYHSELLCONFIG_LOGLEVEL_DEFAULT; }
|
2020-09-21 22:02:58 +02:00
|
|
|
[ -z "${MYHSELLCONFIG_FILELOGLEVEL_DEFAULT+x}" ] && { MYHSELLCONFIG_FILELOGLEVEL_DEFAULT="INFO"; export MYHSELLCONFIG_FILELOGLEVEL_DEFAULT; }
|
2020-09-21 13:00:29 +02:00
|
|
|
|
|
|
|
export SGIT="git -C ${MYSHELLCONFIG_BASE}"
|
|
|
|
export MYSHELLCONFIG_VIM_PLUGINS
|
|
|
|
|
|
|
|
# Create necessary directories
|
2020-09-21 17:49:55 +02:00
|
|
|
[ -n "${MYSHELLCONFIG_LOGDIR-x}" ] && mkdir -p "$MYSHELLCONFIG_LOGDIR"
|
2020-01-14 10:11:36 +01:00
|
|
|
|
2020-09-21 23:59:18 +02:00
|
|
|
[ -z "${SCRIPT_LOG+x}" ] && { SCRIPT_LOG="${MYSHELLCONFIG_LOGFILE}"; export SCRIPT_LOG; }
|
|
|
|
. ${MYSHELLCONFIG_BASE}/loggingfunctions
|
2020-09-21 23:55:10 +02:00
|
|
|
SCRIPTENTRY
|
2020-01-22 10:20:53 +01:00
|
|
|
cat << EOF >> "${MYSHELLCONFIG_LOGFILE}"
|
|
|
|
------- start -------------- $(date) ---------------8<--
|
|
|
|
|
|
|
|
EOF
|
2020-01-14 10:11:36 +01:00
|
|
|
# define functions
|
|
|
|
ckrepo () {
|
|
|
|
# check if remote repo is reachable
|
2020-03-04 11:10:18 +01:00
|
|
|
if $MYSHELLCONFIG_GIT_SYNC; then
|
2020-02-25 12:12:05 +01:00
|
|
|
if $( timeout --foreground "${MYSHELLCONFIG_GIT_TIMEOUT}" $SGIT ls-remote >/dev/null 2>&1) ;then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
2020-03-04 11:10:18 +01:00
|
|
|
else
|
2020-09-21 21:14:18 +02:00
|
|
|
logwarn "no sync allowed from config" >&2
|
2020-03-04 11:10:18 +01:00
|
|
|
return 0
|
2020-01-14 10:11:36 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sync_config () {
|
2020-02-25 16:15:32 +01:00
|
|
|
if $MYSHELLCONFIG_GIT_SYNC; then
|
|
|
|
local nok=""
|
|
|
|
local gco=""
|
|
|
|
if which git >/dev/null; then
|
|
|
|
echo -n "Sync config with ${MYSHELLCONFIG_GIT_SERVER}: " 1>&2
|
|
|
|
# MYSHELLCONFIG_GITCHECKOUTSCRIPT_OPTIONS are options for bin/git-myshellconfig-checkout
|
|
|
|
if [ -z ${MYSHELLCONFIG_GIT_CHECKOUTSCRIPT_OPTIONS+x} ]; then
|
|
|
|
gco="-h"
|
|
|
|
else
|
|
|
|
gco="$MYSHELLCONFIG_GIT_CHECKOUTSCRIPT_OPTIONS"
|
|
|
|
fi
|
|
|
|
${MYSHELLCONFIG_BASE}/bin/git-myshellconfig-checkout ${gco}|| nok="not " 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1
|
|
|
|
printf '%s\n' "${nok}synced" 1>&2
|
|
|
|
[ -z "$nok" ] && mkdir -pv "${MYSHELLCONFIG_LOGDIR}"
|
|
|
|
|
2020-01-14 10:11:36 +01:00
|
|
|
else
|
2020-09-21 21:14:18 +02:00
|
|
|
logwarn "git not installed, no configuration possible, please install git" >&2
|
2020-01-14 10:11:36 +01:00
|
|
|
fi
|
|
|
|
else
|
2020-09-21 21:14:18 +02:00
|
|
|
logwarn "Not syncing profile in case of configuration"
|
2020-01-14 10:11:36 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-02-27 09:08:43 +01:00
|
|
|
# Check for interactive bash and that we haven't already been sourced.
|
|
|
|
if [ -n "${BASH_VERSION-}" -a -n "${PS1-}" -a -z "${BASH_COMPLETION_VERSINFO-}" ]; then
|
|
|
|
|
|
|
|
# Check for recent enough version of bash.
|
|
|
|
if [ ${BASH_VERSINFO[0]} -gt 4 ] || \
|
|
|
|
[ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 ]; then
|
|
|
|
[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
|
|
|
|
. "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
|
|
|
|
if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
|
|
|
|
# Source completion code.
|
2020-09-21 21:14:18 +02:00
|
|
|
logdebug "Source bash-completion"
|
2020-02-27 09:08:43 +01:00
|
|
|
. /usr/share/bash-completion/bash_completion
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
2020-01-14 10:11:36 +01:00
|
|
|
|
|
|
|
|
2020-02-05 12:18:12 +01:00
|
|
|
# source git-sync part of myshellconfig
|
2020-04-05 01:42:17 +02:00
|
|
|
. "${MYSHELLCONFIG_BASE}/myshell_git_sync"
|
2020-01-14 10:11:36 +01:00
|
|
|
|
2020-02-05 12:18:12 +01:00
|
|
|
# source loading defaults part of myshellconfig
|
2020-04-05 01:42:17 +02:00
|
|
|
. "${MYSHELLCONFIG_BASE}/myshell_load_defaults"
|
2020-01-14 10:11:36 +01:00
|
|
|
|
2020-09-16 21:42:56 +02:00
|
|
|
# source loading workaround for x2go to forward local etoken to remote machine with forwardagent
|
|
|
|
. "${MYSHELLCONFIG_BASE}/myshell_load_x2go_tokenforward"
|
|
|
|
|
2020-09-21 13:00:29 +02:00
|
|
|
|
2020-01-22 10:20:53 +01:00
|
|
|
cat << EOF >> "${MYSHELLCONFIG_LOGFILE}"
|
|
|
|
--8<--- end ---------------- $(date) ---------------8<--
|
2020-09-21 23:55:10 +02:00
|
|
|
SCRIPTEXIT
|
2020-01-22 10:20:53 +01:00
|
|
|
|
|
|
|
EOF
|
2020-09-21 21:14:18 +02:00
|
|
|
else
|
2020-09-21 23:55:10 +02:00
|
|
|
echo "non-interactive shell" >&2
|
2020-02-05 07:36:58 +01:00
|
|
|
fi
|
|
|
|
|