2020-01-22 09:17:13 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Sync myshellconfig with configured git repo
|
|
|
|
if ! $SSHS; then
|
|
|
|
### set userspecific variables #######
|
|
|
|
[ -z "$PDSH_RCMD_TYPE" ] && export PDSH_RCMD_TYPE=ssh
|
|
|
|
[ -z "$XDG_RUNTIME_DIR" ] && export export XDG_RUNTIME_DIR=/run/user/$(id -u $USER)
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_PROTOCOL_GIT="git://"
|
|
|
|
MSC_GIT_PROTOCOL_HTTP="http://"
|
|
|
|
MSC_GIT_PROTOCOL_SSH="git@"
|
|
|
|
MSC_GIT_PROTOCOL_FILE=""
|
|
|
|
[ -z "${MSC_GIT_SERVER+x}" ] && MSC_GIT_SERVER="git.schuerz.at"
|
|
|
|
[ -z "${MSC_GIT_REPO_NAME+x}" ] && MSC_GIT_REPO_NAME="$(basename $MSC_BASE).git"
|
|
|
|
[ -z "${MSC_GIT_REPO_PATH_HTTP+x}" ] && MSC_GIT_REPO_PATH_HTTP="/public/"
|
|
|
|
[ -z "${MSC_GIT_REPO_PATH_SSH+x}" ] && MSC_GIT_REPO_PATH_SSH=":public/"
|
|
|
|
[ -z "${MSC_GIT_REPO_PATH_GIT+x}" ] && MSC_GIT_REPO_PATH_GIT="/public/"
|
|
|
|
# [ -z "${MSC_GIT_REPO_PATH_FILE+x}" ] && MSC_GIT_REPO_PATH_FILE="/media/$USER/gitstick/"
|
|
|
|
[ -z "${MSC_GIT_REPO_PATH_FILE+x}" ] && MSC_GIT_REPO_PATH_FILE="/srv/git/"
|
|
|
|
|
|
|
|
|
|
|
|
MSC_GIT_REMOTE_PUBLIC_GIT="${MSC_GIT_PROTOCOL_GIT}${MSC_GIT_SERVER}${MSC_GIT_REPO_PATH_GIT}"
|
|
|
|
MSC_GIT_REMOTE_PUBLIC_SSH="${MSC_GIT_PROTOCOL_SSH}${MSC_GIT_SERVER}${MSC_GIT_REPO_PATH_SSH}"
|
|
|
|
MSC_GIT_REMOTE_PUBLIC_HTTP="${MSC_GIT_PROTOCOL_HTTP}${MSC_GIT_SERVER}${MSC_GIT_REPO_PATH_HTTP}"
|
|
|
|
MSC_GIT_REMOTE_PUBLIC_FILE="${MSC_GIT_PROTOCOL_FILE}${MSC_GIT_REPO_PATH_FILE}"
|
|
|
|
MSC_GIT_REMOTE_PUBLIC_DEFAULT="${MSC_GIT_REMOTE_PUBLIC_GIT}"
|
|
|
|
|
|
|
|
MSC_GIT_REMOTE_DEFAULT="${MSC_GIT_PROTOCOL_GIT}${MSC_GIT_SERVER}${MSC_GIT_REPO_PATH_GIT}"
|
|
|
|
|
|
|
|
# If MSC_GIT_REMOTE is set in ~/.bashrc before sourcing this file, take value from ~/.bashrc
|
|
|
|
# If set MSC_GIT_REMOTE_PROTOCOL in ~/.bashrc before sourcing this file, you cange choose one of the above
|
2020-01-22 09:17:13 +01:00
|
|
|
# defined values for a specific host
|
|
|
|
|
2020-12-10 09:31:38 +01:00
|
|
|
if [ -z ${MSC_GIT_REMOTE+x} ]; then
|
|
|
|
case $MSC_GIT_REMOTE_PROTOCOL in
|
2020-01-22 09:17:13 +01:00
|
|
|
git)
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_GIT}"
|
2020-01-22 09:17:13 +01:00
|
|
|
;;
|
|
|
|
ssh)
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_SSH}"
|
2020-01-22 09:17:13 +01:00
|
|
|
;;
|
|
|
|
http)
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_HTTP}"
|
2020-01-22 09:17:13 +01:00
|
|
|
;;
|
2020-03-04 10:56:48 +01:00
|
|
|
file)
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_FILE}"
|
|
|
|
MSC_GIT_SERVER="${MSC_GIT_REPO_PATH_FILE}"
|
2020-03-04 10:56:48 +01:00
|
|
|
;;
|
2020-01-22 09:17:13 +01:00
|
|
|
*)
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE_PUBLIC="${MSC_GIT_REMOTE_DEFAULT}"
|
2020-01-22 09:17:13 +01:00
|
|
|
;;
|
|
|
|
esac
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE="${MSC_GIT_REMOTE_PUBLIC}${MSC_GIT_REPO_NAME}"
|
2020-01-22 09:17:13 +01:00
|
|
|
fi
|
|
|
|
|
2020-12-10 09:31:38 +01:00
|
|
|
if [ -z ${MSC_GIT_REMOTE_PUSH+x} ]; then
|
|
|
|
case $MSC_GIT_REMOTE_PUSH_PROTOCOL in
|
2020-01-22 09:17:13 +01:00
|
|
|
git)
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE_PUSH_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_GIT}"
|
2020-01-22 09:17:13 +01:00
|
|
|
;;
|
|
|
|
ssh)
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE_PUSH_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_SSH}"
|
2020-01-22 09:17:13 +01:00
|
|
|
;;
|
|
|
|
http)
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE_PUSH_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_HTTP}"
|
2020-01-22 09:17:13 +01:00
|
|
|
;;
|
2020-03-04 10:56:48 +01:00
|
|
|
file)
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE_PUSH_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_FILE}"
|
2020-03-04 10:56:48 +01:00
|
|
|
;;
|
2020-01-22 09:17:13 +01:00
|
|
|
*)
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE_PUSH_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_DEFAULT}"
|
2020-01-22 09:17:13 +01:00
|
|
|
;;
|
|
|
|
esac
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE_PUSH=${MSC_GIT_REMOTE_PUSH_PUBLIC}${MSC_GIT_REPO_NAME}
|
2020-01-22 09:17:13 +01:00
|
|
|
fi
|
|
|
|
|
2020-12-10 09:31:38 +01:00
|
|
|
[ -z "${MSC_GIT_REMOTE_NAME+x}" ] && export MSC_GIT_REMOTE_NAME=origin
|
|
|
|
[ -z "${MSC_GIT_BRANCH+x}" ] && export MSC_GIT_BRANCH=master
|
2020-01-22 09:17:13 +01:00
|
|
|
# If TAG is set, checkout is always headless.
|
2021-10-03 23:09:57 +02:00
|
|
|
[ -z "${MSC_GIT_TAG:+x}" ] || { export MSC_GIT_BRANCH=${MSC_GIT_TAG}; export MSC_GIT_CHECKOUTSCRIPT_OPTIONS="-h"; }
|
2020-01-22 09:17:13 +01:00
|
|
|
|
|
|
|
#GIT_SSH_PATH="/srv/repos"
|
|
|
|
|
2020-08-05 08:03:26 +02:00
|
|
|
#echo "Run with $TERM" >&2
|
2020-01-22 09:17:13 +01:00
|
|
|
case $TERM in
|
2020-03-13 15:36:20 +01:00
|
|
|
#*term*|*linux*)
|
|
|
|
*term*)
|
2020-01-22 09:17:13 +01:00
|
|
|
|
2020-12-10 09:31:38 +01:00
|
|
|
if [ -d "${MSC_BASE}" -a $($SGIT status 1>/dev/null 2>&1; echo $?) -eq 0 ]; then
|
|
|
|
[ -d "${MSC_LOGDIR}" ] || mkdir -p "${MSC_LOGDIR}"
|
2020-01-22 09:17:13 +01:00
|
|
|
if ! $SGIT rev-parse --git-dir > /dev/null 2>&1 ; then
|
2020-12-10 09:31:38 +01:00
|
|
|
loginfo "Init ${MSC_BASE} as git-repo" >&2
|
2020-01-22 09:17:13 +01:00
|
|
|
$SGIT init
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Update Userinformations for git
|
|
|
|
$SGIT config user.email "${USERNAME}"
|
|
|
|
$SGIT config user.name "${FULLNAME}"
|
|
|
|
|
|
|
|
# set upstream only if not detached
|
2020-12-10 09:31:38 +01:00
|
|
|
[ $($SGIT rev-parse --abbrev-ref HEAD) != "HEAD" ] && $SGIT branch --set-upstream-to=${MSC_GIT_REMOTE_NAME}/$($SGIT rev-parse --abbrev-ref HEAD)
|
2020-01-22 09:17:13 +01:00
|
|
|
|
|
|
|
# sync repo with origin if git is reachable
|
|
|
|
if ckrepo ; then
|
2020-10-28 00:46:56 +01:00
|
|
|
loginfo "git checkout" >&2
|
2020-01-22 09:17:13 +01:00
|
|
|
sync_config
|
2020-12-10 09:31:38 +01:00
|
|
|
. ${MSC_BASE}/functions.sh
|
|
|
|
create_symlinks "$MSC_BASE"
|
2020-01-22 09:17:13 +01:00
|
|
|
else
|
2022-09-17 12:26:12 +02:00
|
|
|
loginfo "${MSC_GIT_SERVER}" not reachable or sync-time not reached>&2;
|
2020-10-11 23:17:52 +02:00
|
|
|
loginfo "profile not syncing" >&2;
|
2020-01-22 09:17:13 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
2020-12-10 09:31:38 +01:00
|
|
|
loginfo "Clone ${MSC_GIT_REMOTE} and configure git" >&2
|
2020-01-22 09:17:13 +01:00
|
|
|
|
2020-12-23 13:16:32 +01:00
|
|
|
if $( timeout --foreground "${MSC_GIT_CHECKOUT_TIMEOUT-$MSC_GIT_CHECKOUT_TIMEOUT_DEFAULT}" \
|
2020-12-10 09:31:38 +01:00
|
|
|
git -C ${HOME} clone --recurse-submodules "${MSC_GIT_REMOTE}" "${MSC_BASE}" ); then
|
2020-01-22 09:17:13 +01:00
|
|
|
:
|
|
|
|
else
|
2020-12-10 09:31:38 +01:00
|
|
|
MSC_GIT_REMOTE="${MSC_GIT_REMOTE_PUBLIC_HTTP}${MSC_GIT_REPO_NAME}"
|
|
|
|
loginfo "Clone ${MSC_GIT_REMOTE} (http, because other protocol is not reachable) and configure git" >&2
|
2020-12-23 13:16:32 +01:00
|
|
|
timeout --foreground "${MSC_GIT_CHECKOUT_TIMEOUT-$MSC_GIT_CHECKOUT_TIMEOUT_DEFAULT}" \
|
2020-12-10 09:31:38 +01:00
|
|
|
git -C ${HOME} clone --recurse-submodules "${MSC_GIT_REMOTE}" "${MSC_BASE}" || return 1 2>/dev/null || exit 1
|
2020-01-22 09:17:13 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-10 09:31:38 +01:00
|
|
|
[ -d "${MSC_BASE}" ] && { loginfo create ${MSC_LOGDIR} >&2; mkdir -p "${MSC_LOGDIR}"; }
|
2020-01-22 09:17:13 +01:00
|
|
|
|
|
|
|
$SGIT config user.email "${USERNAME}"
|
|
|
|
$SGIT config user.name "${FULLNAME}"
|
|
|
|
|
|
|
|
# Initialize Vundle as preconfigured Submodule
|
|
|
|
#$SGIT submodule update --init --recursive
|
|
|
|
#$SGIT submodule foreach 'git checkout master'
|
|
|
|
|
2020-09-21 21:24:47 +02:00
|
|
|
loginfo "sync config" >&2
|
2020-01-22 09:17:13 +01:00
|
|
|
sync_config
|
2020-12-10 09:31:38 +01:00
|
|
|
. ${MSC_BASE}/functions.sh
|
2020-09-21 21:24:47 +02:00
|
|
|
loginfo "config synced, functions.sh sourced" >&2
|
2020-12-10 09:31:38 +01:00
|
|
|
create_symlinks "$MSC_BASE"
|
2020-01-22 09:17:13 +01:00
|
|
|
|
|
|
|
# Install vim Plugins
|
2020-11-03 08:23:35 +01:00
|
|
|
# echo "Run Vim, and in Vim run :PluginInstall to install all Plugins"
|
|
|
|
# not necessary any more. Vim plugins are updated through git submodules
|
|
|
|
#vim -c "PluginInstall" -c ":qa!"
|
2020-01-22 09:17:13 +01:00
|
|
|
fi
|
2020-12-10 09:31:38 +01:00
|
|
|
[ -z ${MSC_GIT_REMOTE_PUSH+x} ] || $SGIT remote set-url --push ${MSC_GIT_REMOTE_NAME} "${MSC_GIT_REMOTE_PUSH}"
|
2020-01-22 09:17:13 +01:00
|
|
|
;;
|
|
|
|
*screen*)
|
2020-11-03 08:23:35 +01:00
|
|
|
loginfo "I'm in sceen/tmux now - no profily syncing" >&2
|
2020-01-22 09:17:13 +01:00
|
|
|
;;
|
|
|
|
*dumb*)
|
2020-11-03 08:23:35 +01:00
|
|
|
loginfo "Run with dumb terminal - no profily syncing" 1>&2
|
2020-01-22 09:17:13 +01:00
|
|
|
;;
|
2020-03-12 22:10:16 +01:00
|
|
|
*)
|
2020-11-03 08:23:35 +01:00
|
|
|
loginfo "Run with $TERM - no profily syncing" >&2
|
2020-03-12 22:10:16 +01:00
|
|
|
;;
|
2020-01-22 09:17:13 +01:00
|
|
|
esac
|
|
|
|
fi
|