update submods and repo only after intervall

This commit is contained in:
Jakobus Schürz 2020-12-23 12:51:04 +01:00
parent 007ba8bc13
commit 615df5a035
2 changed files with 47 additions and 41 deletions

View file

@ -27,29 +27,32 @@ if [[ $- = *i* ]] ; then
# hardcoded paths
export MSC_BASE_PARENT="$(dirname $MSC_BASE)"
export MSC_BASH_COMPLETION="${HOME}/${MSC_SUBPATH}/bash_completion.d"
export MSC_GIT_UPD_SUBMOD_STATFILE="${MSC_BASE%/}${MSC_BASE:+/}.last_update_submodules"
export MSC_GIT_UPD_REPO_STATFILE="${MSC_BASE%/}${MSC_BASE:+/}.last_update_repo"
# Load DEFAULTS
[ -e ${MSC_BASE}/defaults.conf ] && . ${MSC_BASE}/defaults.conf
# Userdata
[ -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 "${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)"
# GIT
[ -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 "${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 "${MSC_GIT_TIMEOUT+x}" ] && export MSC_GIT_TIMEOUT=5s
[ -z "${MSC_GIT_CHECKOUT_TIMEOUT+x}" ] && export MSC_GIT_CHECKOUT_TIMEOUT=20s
[ -z "${MSC_GIT_SYNC+x}" ] && export MSC_GIT_SYNC=true
[ -z "${MSC_GIT_SUBMODULES_UPDATE_DEFAULT+x}" ] && export MSC_GIT_SUBMODULES_UPDATE_DEFAULT=true
[ -z "${MSC_GIT_SUBMODULES_UPDATE_INTERVALL+x}" ] && export MSC_GIT_SUBMODULES_UPDATE_INTERVALL=96 #intervall in hours
[ -z "${MSC_GIT_SUBMODULES_SERVER_DEFAULT+x}" ] && export MSC_GIT_SUBMODULES_SERVER_DEFAULT="git://git.schuerz.at/github.com/"
[ -z "${MSC_GIT_CHECKOUTSCRIPT_OPTIONS_DEFAULT+x}" ] && export MSC_GIT_CHECKOUTSCRIPT_OPTIONS_DEFAULT="-h"
[ -z "${MSC_GIT_TIMEOUT+x}" ] && export MSC_GIT_TIMEOUT=5s
[ -z "${MSC_GIT_CHECKOUT_TIMEOUT+x}" ] && export MSC_GIT_CHECKOUT_TIMEOUT=20s
[ -z "${MSC_GIT_SYNC+x}" ] && export MSC_GIT_SYNC=true
[ -z "${MSC_GIT_SUBMODULES_UPDATE_DEFAULT+x}" ] && export MSC_GIT_SUBMODULES_UPDATE_DEFAULT=true
[ -z "${MSC_GIT_SUBMODULES_UPDATE_INTERVALL+x}" ] && export MSC_GIT_SUBMODULES_UPDATE_INTERVALL=96 #intervall in hours
[ -z "${MSC_GIT_SUBMODULES_SERVER_DEFAULT+x}" ] && export MSC_GIT_SUBMODULES_SERVER_DEFAULT="git://git.schuerz.at/github.com/"
[ -z "${MSC_GIT_CHECKOUTSCRIPT_OPTIONS_DEFAULT+x}" ] && export MSC_GIT_CHECKOUTSCRIPT_OPTIONS_DEFAULT="-h"
# hardcoded git
export SGIT="git -C ${MSC_BASE}"
@ -61,15 +64,15 @@ if [[ $- = *i* ]] ; then
# Logging
[ -z "${MSC_LOGDIR+x}" ] && export MSC_LOGDIR="${HOME}/logs"
[ -z "${MSC_LOGFILE+x}" ] && export MSC_LOGFILE="${MSC_LOGDIR}/myshellconfig.log"
[ -z "${MSC_LOGLEVEL_DEFAULT+x}" ] && export MSC_LOGLEVEL_DEFAULT="INFO"
[ -z "${MSC_FILELOGLEVEL_DEFAULT+x}" ] && export MSC_FILELOGLEVEL_DEFAULT="DEBUG"
[ -z "${SCRIPT_LOG+x}" ] && export SCRIPT_LOG="${MSC_LOGFILE}"
[ -z "${LOGLEVEL_DEFAULT+x}" ] && export LOGLEVEL_DEFAULT="${MSC_LOGLEVEL_DEFAULT-INFO}"
[ -z "${FILELOGLEVEL_DEFAULT+x}" ] && export FILELOGLEVEL_DEFAULT="${MSC_FILELOGLEVEL_DEFAULT-INFO}"
[ -z "${MSC_LOGDIR+x}" ] && export MSC_LOGDIR="${HOME}/logs"
[ -z "${MSC_LOGFILE+x}" ] && export MSC_LOGFILE="${MSC_LOGDIR}/myshellconfig.log"
[ -z "${MSC_LOGLEVEL_DEFAULT+x}" ] && export MSC_LOGLEVEL_DEFAULT="INFO"
[ -z "${MSC_FILELOGLEVEL_DEFAULT+x}" ] && export MSC_FILELOGLEVEL_DEFAULT="DEBUG"
[ -z "${SCRIPT_LOG+x}" ] && export SCRIPT_LOG="${MSC_LOGFILE}"
[ -z "${LOGLEVEL_DEFAULT+x}" ] && export LOGLEVEL_DEFAULT="${MSC_LOGLEVEL_DEFAULT-INFO}"
[ -z "${FILELOGLEVEL_DEFAULT+x}" ] && export FILELOGLEVEL_DEFAULT="${MSC_FILELOGLEVEL_DEFAULT-INFO}"
# Create necessary directories for logging
[ -n "${MSC_LOGDIR-x}" ] && mkdir -p "$MSC_LOGDIR"
[ -n "${MSC_LOGDIR-x}" ] && mkdir -p "$MSC_LOGDIR"
# load logging functions
. ${MSC_BASE}/logging
@ -90,7 +93,8 @@ EOF
ckrepo () {
# check if remote repo is reachable
if $MSC_GIT_SYNC; then
if [ $MSC_GIT_SYNC -a $(stat --printf %Y ${MSC_GIT_UPD_REPO_STATFILE} 2>/dev/null || echo 0 ) \
-lt $(date --date="${MSC_GIT_REPO_UPDATE_INTERVALL-0} hours ago" "+%s") ]; then
if $( timeout --foreground "${MSC_GIT_TIMEOUT}" $SGIT ls-remote >/dev/null 2>&1) ;then
return 0
else
@ -104,12 +108,14 @@ EOF
}
lastupdatesubmodules () {
date "+%s" > ${MSC_BASE%/}${MSC_BASE:+/}.last_update_submodules
#date "+%s" > ${MSC_GIT_UPD_SUBMOD_STATFILE}
touch ${MSC_GIT_UPD_REPO_STATFILE}
}
export -f lastupdatesubmodules
lastupdaterepo () {
date "+%s" > ${MSC_BASE%/}${MSC_BASE:+/}.last_update_repo
#date "+%s" > ${MSC_GIT_UPD_REPO_STATFILE}
touch ${MSC_GIT_UPD_REPO_STATFILE}
}
export -f lastupdaterepo

View file

@ -61,15 +61,19 @@ done
#echo -n " remote: ${MSC_GIT_REMOTE_NAME}, branch: ${MSC_GIT_BRANCH}: "
# Check for updates in submodules only if last check was INTERVALL hours in the past
if [ $(cat ${MSC_BASE%/}${MSC_BASE:+/}.last_update_submodules 2>/dev/null || echo 0 ) \
#if [ $(cat ${MSC_BASE%/}${MSC_BASE:+/}.last_update_submodules 2>/dev/null || echo 0 ) \
[ -z "${MSC_GIT_UPD_SUBMOD_STATFILE+x}" ] && export MSC_GIT_UPD_SUBMOD_STATFILE="${MSC_BASE%/}${MSC_BASE:+/}.last_update_submodules"
[ -z "${MSC_GIT_UPD_REPO_STATFILE+x}" ] && export MSC_GIT_UPD_REPO_STATFILE="${MSC_BASE%/}${MSC_BASE:+/}.last_update_repo"
if [ $(stat --printf %Y ${MSC_GIT_UPD_SUBMOD_STATFILE} 2>/dev/null || echo 0 ) \
-lt $(date --date="${MSC_GIT_SUBMODULES_UPDATE_INTERVALL} hours ago" "+%s") \
-a ${MSC_GIT_SUBMODULES_UPDATE-${MSC_GIT_SUBMODULES_UPDATE_DEFAULT-true}} ]; then
[ -z "${dosrepoupdate+x}" ] && dorepoupdate="true"
fi
if [ $(cat ${MSC_BASE%/}${MSC_BASE:+/}.last_update_submodules 2>/dev/null || echo 0 ) \
-lt $(date --date="${MSC_GIT_SUBMODULES_UPDATE_INTERVALL} hours ago" "+%s") \
-a ${MSC_GIT_SUBMODULES_UPDATE-${MSC_GIT_SUBMODULES_UPDATE_DEFAULT-true}} ]; then
if [ $(stat --printf %Y ${MSC_GIT_UPD_REPO_STATFILE} 2>/dev/null || echo 0 ) \
-lt $(date --date="${MSC_GIT_REPO_UPDATE_INTERVALL} hours ago" "+%s") \
-a ${MSC_GIT_REPO_UPDATE-${MSC_GIT_REPO_UPDATE_DEFAULT-true}} ]; then
[ -z "${dosubmodupdate+x}" ] && dosubmodupdate="true"
fi
@ -88,6 +92,7 @@ if $SGIT diff-index --ignore-submodules --exit-code HEAD -- >> "${MSC_LOGFILE}"
EOF
$SGIT checkout ${PRE}${PRE:+/}${MSC_GIT_BRANCH} 1>>"${MSC_LOGFILE}" 2>>"${MSC_LOGFILE}"|| { gitupdateend; exit 2; }
$SGIT merge FETCH_HEAD 1>>"${MSC_LOGFILE}" 2>>"${MSC_LOGFILE}"|| { gitupdateend; exit 3; }
touch $MSC_GIT_UPD_REPO_STATFILE
else
logwarn -n " Lokale Änderungen festgestellt:"
echo " Siehe Logfile ${MSC_LOGFILE}" >&2
@ -114,18 +119,13 @@ fi
loginfo "repo${dosubmodupdate:+ and submodules} synced"
#if ${MSC_GIT_SUBMODULES_UPDATE-${MSC_GIT_SUBMODULES_UPDATE_DEFAULT-true}}; then
if ${dosubmodupdate:-false}; then
loginfo "update and commit submodules"
logdebug "$($SGIT submodule update --remote)"
logdebug "$($SGIT commit -a -m 'update submodules')"
lastupdatesubmodules
logwarn "submodules synced"
fi
#else
# loginfo -n ", submodules not synced"
# logdebug "Do not update submodules. It's denied by environment MSC_GIT_UPDATE_SUBMODULES: ${MSC_GIT_SUBMODULES_UPDATE-${MSC_GIT_SUBMODULES_UPDATE_DEFAULT-true}}"
#fi
if ${dosubmodupdate:-false}; then
loginfo "update and commit submodules"
logdebug "$($SGIT submodule update --remote)"
logdebug "$($SGIT commit -a -m 'update submodules')"
touch $MSC_GIT_UPD_SUBMOD_STATFILE
logwarn "submodules synced"
fi
EXIT
exit $rc