myshellconfig/myshell_git_sync

164 lines
6.9 KiB
Text
Raw Normal View History

#!/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)
######################################
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
# defined values for a specific host
if [ -z ${MSC_GIT_REMOTE+x} ]; then
case $MSC_GIT_REMOTE_PROTOCOL in
git)
MSC_GIT_REMOTE_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_GIT}"
;;
ssh)
MSC_GIT_REMOTE_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_SSH}"
;;
http)
MSC_GIT_REMOTE_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_HTTP}"
;;
2020-03-04 10:56:48 +01:00
file)
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
;;
*)
MSC_GIT_REMOTE_PUBLIC="${MSC_GIT_REMOTE_DEFAULT}"
;;
esac
MSC_GIT_REMOTE="${MSC_GIT_REMOTE_PUBLIC}${MSC_GIT_REPO_NAME}"
fi
if [ -z ${MSC_GIT_REMOTE_PUSH+x} ]; then
case $MSC_GIT_REMOTE_PUSH_PROTOCOL in
git)
MSC_GIT_REMOTE_PUSH_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_GIT}"
;;
ssh)
MSC_GIT_REMOTE_PUSH_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_SSH}"
;;
http)
MSC_GIT_REMOTE_PUSH_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_HTTP}"
;;
2020-03-04 10:56:48 +01:00
file)
MSC_GIT_REMOTE_PUSH_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_FILE}"
2020-03-04 10:56:48 +01:00
;;
*)
MSC_GIT_REMOTE_PUSH_PUBLIC="${MSC_GIT_REMOTE_PUBLIC_DEFAULT}"
;;
esac
MSC_GIT_REMOTE_PUSH=${MSC_GIT_REMOTE_PUSH_PUBLIC}${MSC_GIT_REPO_NAME}
fi
[ -z "${MSC_GIT_REMOTE_NAME+x}" ] && export MSC_GIT_REMOTE_NAME=origin
[ -z "${MSC_GIT_BRANCH+x}" ] && export MSC_GIT_BRANCH=master
# 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"; }
#GIT_SSH_PATH="/srv/repos"
2020-08-05 08:03:26 +02:00
#echo "Run with $TERM" >&2
case $TERM in
2020-03-13 15:36:20 +01:00
#*term*|*linux*)
*term*)
if [ -d "${MSC_BASE}" -a $($SGIT status 1>/dev/null 2>&1; echo $?) -eq 0 ]; then
[ -d "${MSC_LOGDIR}" ] || mkdir -p "${MSC_LOGDIR}"
if ! $SGIT rev-parse --git-dir > /dev/null 2>&1 ; then
loginfo "Init ${MSC_BASE} as git-repo" >&2
$SGIT init
fi
# Update Userinformations for git
$SGIT config user.email "${USERNAME}"
$SGIT config user.name "${FULLNAME}"
# set upstream only if not detached
[ $($SGIT rev-parse --abbrev-ref HEAD) != "HEAD" ] && $SGIT branch --set-upstream-to=${MSC_GIT_REMOTE_NAME}/$($SGIT rev-parse --abbrev-ref HEAD)
# sync repo with origin if git is reachable
if ckrepo ; then
2020-10-28 00:46:56 +01:00
loginfo "git checkout" >&2
sync_config
. ${MSC_BASE}/functions.sh
create_symlinks "$MSC_BASE"
else
loginfo "${MSC_GIT_SERVER}" not reachable >&2;
2020-10-11 23:17:52 +02:00
loginfo "profile not syncing" >&2;
fi
else
loginfo "Clone ${MSC_GIT_REMOTE} and configure git" >&2
if $( timeout --foreground "${MSC_GIT_CHECKOUT_TIMEOUT-$MSC_GIT_CHECKOUT_TIMEOUT_DEFAULT}" \
git -C ${HOME} clone --recurse-submodules "${MSC_GIT_REMOTE}" "${MSC_BASE}" ); then
:
else
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
timeout --foreground "${MSC_GIT_CHECKOUT_TIMEOUT-$MSC_GIT_CHECKOUT_TIMEOUT_DEFAULT}" \
git -C ${HOME} clone --recurse-submodules "${MSC_GIT_REMOTE}" "${MSC_BASE}" || return 1 2>/dev/null || exit 1
fi
[ -d "${MSC_BASE}" ] && { loginfo create ${MSC_LOGDIR} >&2; mkdir -p "${MSC_LOGDIR}"; }
$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
sync_config
. ${MSC_BASE}/functions.sh
2020-09-21 21:24:47 +02:00
loginfo "config synced, functions.sh sourced" >&2
create_symlinks "$MSC_BASE"
# 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!"
fi
[ -z ${MSC_GIT_REMOTE_PUSH+x} ] || $SGIT remote set-url --push ${MSC_GIT_REMOTE_NAME} "${MSC_GIT_REMOTE_PUSH}"
;;
*screen*)
2020-11-03 08:23:35 +01:00
loginfo "I'm in sceen/tmux now - no profily syncing" >&2
;;
*dumb*)
2020-11-03 08:23:35 +01:00
loginfo "Run with dumb terminal - no profily syncing" 1>&2
;;
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
;;
esac
fi