905a222293
If configuration is updated, sometimes it needed two logins to get last configs, aliases and so on. Because first login it syncs the configuration and load-functions, on second login, the new configuration was used (valid for all functions in bashrc_add itself) Now the loading of defaults is in a own file. First the file is synced with git, then the new file gets sourced, so the script can use the new configuration on first login
73 lines
2.9 KiB
Bash
Executable file
73 lines
2.9 KiB
Bash
Executable file
#!/bin/bash
|
|
#debug
|
|
|
|
# set SSHS to false, if not set
|
|
if [ -z ${SSHS+x} ]; then SSHS=false;fi
|
|
|
|
# check if we are a interactive shell
|
|
# https://guide.bash.academy/expansions/
|
|
# https://www.tldp.org/LDP/abs/html/refcards.html#AEN22473
|
|
if [[ $- = *i* ]] ; then
|
|
#echo "interactive shell" >&2
|
|
|
|
# define variables
|
|
[ -z "${USERNAME+x}" ] && USERNAME="$USER"
|
|
[ -z "${USEREMAIL+x}" ] && USEREMAIL="$USER@$(domainname -f)"
|
|
[ -z "${FULLNAME+x}" ] && FULLNAME="$(getent passwd $USER | cut -d ":" -f 5 | cut -d ',' -f 1)"
|
|
[ -z "${GIT_AUTHOR_NAME+x}" ] && GIT_AUTHOR_NAME=$FULLNAME
|
|
[ -z "${GIT_AUTHOR_EMAIL+x}" ] && GIT_AUTHOR_EMAIL=$FULLNAME
|
|
[ -z "${GIT_COMMITTER_NAME+x}" ] && GIT_COMMITTER_NAME=$FULLNAME
|
|
[ -z "${GIT_COMMITTER_EMAIL+x}" ] && GIT_COMMITTER_EMAIL=$FULLNAME
|
|
|
|
[ -z "${MYSHELLCONFIG_SUBPATH+x}" ] && MYSHELLCONFIG_SUBPATH=".local/myshellconfig"
|
|
[ -z "${MYSHELLCONFIG_BASE+x}" ] && MYSHELLCONFIG_BASE="${HOME}/${MYSHELLCONFIG_SUBPATH}"
|
|
MYSHELLCONFIG_BASE_PARENT="$(dirname $MYSHELLCONFIG_BASE)"
|
|
[ -z "${MYSHELLCONFIG_LOGDIR+x}" ] && MYSHELLCONFIG_LOGDIR="${MYSHELLCONFIG_BASE}/logs"
|
|
[ -z "${MYSHELLCONFIG_LOGFILE+x}" ] && MYSHELLCONFIG_LOGFILE="${MYSHELLCONFIG_LOGDIR}/git.log"
|
|
[ -z "${MYSHELLCONFIG_GIT_TIMEOUT+x}" ] && MYSHELLCONFIG_GIT_TIMEOUT=5s
|
|
[ -z "${MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT+x}" ] && MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT=20s
|
|
MYSHELLCONFIG_BASH_COMPLETION="${HOME}/${MYSHELLCONFIG_SUBPATH}/bash_completion.d"
|
|
|
|
SGIT="git -C ${MYSHELLCONFIG_BASE}"
|
|
export MYSHELLCONFIG_BASE MYSHELLCONFIG_LOGDIR MYSHELLCONFIG_LOGFILE SGIT MYSHELLCONFIG_VIM_PLUGINS
|
|
|
|
# define functions
|
|
ckrepo () {
|
|
# check if remote repo is reachable
|
|
if $( timeout --foreground "${MYSHELLCONFIG_GIT_TIMEOUT}" $SGIT ls-remote >/dev/null 2>&1) ;then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
|
|
}
|
|
|
|
sync_config () {
|
|
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
|
|
else
|
|
echo "git not installed, no configuration possible, please install git" >&2
|
|
fi
|
|
}
|
|
|
|
|
|
|
|
# source git-sync part of myshellconfig
|
|
. "${MYSHELLCONFIG_BASE}/myshell_git_sync"
|
|
|
|
# source loading defaults part of myshellconfig
|
|
. "${MYSHELLCONFIG_BASE}/myshell_load_defaults"
|
|
|
|
|
|
fi
|
|
|