diff --git a/.gitignore b/.gitignore index ce0f4eb..9aa67e1 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ bashrc_local .local_scripts .git-token .last_update_submodules +.last_update_repo diff --git a/bashrc_add b/bashrc_add index 24f8671..c041de1 100755 --- a/bashrc_add +++ b/bashrc_add @@ -27,29 +27,28 @@ 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=48 #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 + # hardcoded git export SGIT="git -C ${MSC_BASE}" @@ -61,15 +60,11 @@ 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 "${SCRIPT_LOG+x}" ] && export SCRIPT_LOG="${MSC_LOGFILE}" # 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,26 +85,39 @@ EOF ckrepo () { # check if remote repo is reachable - if $MSC_GIT_SYNC; then - if $( timeout --foreground "${MSC_GIT_TIMEOUT}" $SGIT ls-remote >/dev/null 2>&1) ;then - return 0 - else - return 1 + if ${MSC_GIT_SYNC-$MSC_GIT_REPO_UPDATE}; then + + if [ $(stat --printf %Y ${MSC_GIT_UPD_REPO_STATFILE} 2>/dev/null || echo 0 ) \ + -lt $(date --date="${MSC_GIT_REPO_UPDATE_INTERVALL-${MSC_GIT_REPO_UPDATE_INTERVALL_DEFAULT}} hours ago" "+%s") ]; then + logwarn "check if reachable" + if $( timeout --foreground "${MSC_GIT_TIMEOUT-$MSC_GIT_TIMEOUT_DEFAULT}" $SGIT ls-remote >/dev/null 2>&1) ;then + logwarn "reachable" + return 0 + else + logwarn "not reachable" + return 3 + fi + else + local seconds=$(( $( date --date="@$(stat --printf %Y ${MSC_GIT_UPD_REPO_STATFILE} 2>/dev/null || echo 0 )" "+%s") - $(date --date="${MSC_GIT_REPO_UPDATE_INTERVALL-${MSC_GIT_REPO_UPDATE_INTERVALL_DEFAULT}} hours ago" "+%s") )) + logwarn "sync-intervall (${MSC_GIT_REPO_UPDATE_INTERVALL-${MSC_GIT_REPO_UPDATE_INTERVALL_DEFAULT}} hours) not reached yes. $((seconds/86400)) days $(date -d "1970-01-01 + $seconds seconds" "+%H hours %M minutes %S seconds") left." + return 2 fi else logwarn "no sync allowed from config" >&2 - return 0 + return 1 fi } 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 diff --git a/bin/git-myshellconfig-checkout b/bin/git-myshellconfig-checkout index 0313c70..cb72aae 100755 --- a/bin/git-myshellconfig-checkout +++ b/bin/git-myshellconfig-checkout @@ -35,7 +35,7 @@ cat << EOF >> "${MSC_LOGFILE}" +-----BEGINN git update repo $(date) -------------------------------+ EOF -set -- $(getopt -u -o hs --long headless,submodules-update -- "$@" ) +set -- $(getopt -u -o hrs --long headless,force-repo-update,force-submodules-update -- "$@" ) while [ $# -gt 0 ]; do case $1 in @@ -44,7 +44,11 @@ while [ $# -gt 0 ]; do PRE="${MSC_GIT_REMOTE_NAME}" shift ;; - -s|--submodules-update) + -r|--force-repo-update) + dosubmodupdate="true" + shift + ;; + -s|--force-submodules-update) dosubmodupdate="true" shift ;; @@ -61,71 +65,73 @@ 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 ) \ - -lt $(date --date="${MSC_GIT_SUBMODULES_UPDATE_INTERVALL} hours ago" "+%s") \ +#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-${MSC_GIT_SUBMODULES_UPDATE_INTERVALL_DEFAULT}} hours ago" "+%s") \ -a ${MSC_GIT_SUBMODULES_UPDATE-${MSC_GIT_SUBMODULES_UPDATE_DEFAULT-true}} ]; then - [ -z "${dosrepoupdate+x}" ] && dorepoupdate="true" + [ -z "${dorepoupdate+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-${MSC_GIT_REPO_UPDATE_INTERVALL_DEFAULT}} hours ago" "+%s") \ + -a ${MSC_GIT_REPO_UPDATE-${MSC_GIT_REPO_UPDATE_DEFAULT-true}} ]; then [ -z "${dosubmodupdate+x}" ] && dosubmodupdate="true" fi #echo $SGIT fetch ${MSC_GIT_REMOTE_NAME} -p 1>&2 -loginfo "fetch repo${dosubmodupdate:+ and submodules}" -$SGIT fetch ${dosubmodupdate:+--recurse-submodules} ${MSC_GIT_REMOTE_NAME} -p 2>>"${MSC_LOGFILE}"|| { logwarn fetch failed; gitupdateend; exit 1; } -if ${dosubmodupdate:-false}; then - lastupdatesubmodules -fi +if $dorepoupdate; then + loginfo "fetch repo${dosubmodupdate:+ and submodules}" + $SGIT fetch ${dosubmodupdate:+--recurse-submodules} ${MSC_GIT_REMOTE_NAME} -p 2>>"${MSC_LOGFILE}"|| { logwarn fetch failed; gitupdateend; exit 1; } + if ${dosubmodupdate:-false}; then + lastupdatesubmodules + fi -echo "Check for local changes:" >> "${MSC_LOGFILE}" -if $SGIT diff-index --ignore-submodules --exit-code HEAD -- >> "${MSC_LOGFILE}" ; then - cat << EOF >> "${MSC_LOGFILE}" - no changes in local repo - $SGIT checkout repo ${PRE}${PRE:+/}${MSC_GIT_BRANCH} -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; } -else - logwarn -n " Lokale Änderungen festgestellt:" - echo " Siehe Logfile ${MSC_LOGFILE}" >&2 - cat << EOF >> "${MSC_LOGFILE}" - um die Änderung zurückzusetzen bitte + echo "Check for local changes:" >> "${MSC_LOGFILE}" + if $SGIT diff-index --ignore-submodules --exit-code HEAD -- >> "${MSC_LOGFILE}" ; then + cat << EOF >> "${MSC_LOGFILE}" + no changes in local repo + $SGIT checkout repo ${PRE}${PRE:+/}${MSC_GIT_BRANCH} + 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 + cat << EOF >> "${MSC_LOGFILE}" + um die Änderung zurückzusetzen bitte - $SGIT checkout \$FILENAME + $SGIT checkout \$FILENAME - oder um alle lokalen Änderungen auf einmal zurückzusetzen: + oder um alle lokalen Änderungen auf einmal zurückzusetzen: - $SGIT checkout . + $SGIT checkout . - ausführen + ausführen - Die Änderungen sind: - $($SGIT diff-index HEAD --|awk '{print $5, $6}') - $($SGIT diff-index -p HEAD --) + Die Änderungen sind: + $($SGIT diff-index HEAD --|awk '{print $5, $6}') + $($SGIT diff-index -p HEAD --) EOF - gitupdateend - exit 4 + gitupdateend + exit 4 -fi + fi -loginfo "repo${dosubmodupdate:+ and submodules} synced" + 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 + touch $MSC_GIT_UPD_SUBMOD_STATFILE 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 +fi EXIT exit $rc diff --git a/defaults.conf b/defaults.conf index 91d5cc7..9f514cf 100644 --- a/defaults.conf +++ b/defaults.conf @@ -1,8 +1,15 @@ +### GIT #### +export MSC_GIT_REPO_UPDATE_DEFAULT=true +export MSC_GIT_REPO_UPDATE_INTERVALL_DEFAULT=48 #intervall in hours export MSC_GIT_SUBMODULES_UPDATE_DEFAULT=true -export MSC_GIT_SUBMODULES_UPDATE_INTERVALL=48 #intervall in hours +export MSC_GIT_SUBMODULES_UPDATE_INTERVALL_DEFAULT=196 #intervall in hours export MSC_GIT_SUBMODULES_SERVER_DEFAULT="git://git.schuerz.at/github.com/" export MSC_GIT_CHECKOUTSCRIPT_OPTIONS_DEFAULT="-h" +export MSC_GIT_TIMEOUT_DEFAULT=5s +export MSC_GIT_CHECKOUT_TIMEOUT_DEFAULT=20s +### LOGGING ### +# Possible loglevel-values: ERROR, WARN, INFO, DEBUG, TRACE export MSC_LOGLEVEL_DEFAULT="INFO" export MSC_FILELOGLEVEL_DEFAULT="DEBUG" -export LOGLEVEL_DEFAULT="${MSC_LOGLEVEL_DEFAULT-INFO}" -export FILELOGLEVEL_DEFAULT="${MSC_FILELOGLEVEL_DEFAULT-INFO}" +export LOGLEVEL_DEFAULT="${MSC_LOGLEVEL_DEFAULT}" +export FILELOGLEVEL_DEFAULT="${MSC_FILELOGLEVEL_DEFAULT}" diff --git a/functions.sh b/functions.sh index ef86ae2..585f338 100755 --- a/functions.sh +++ b/functions.sh @@ -946,4 +946,32 @@ get_crtime() { # return 0 #} + +is_btrfs_subvolume() { + sudo btrfs subvolume show "$1" >/dev/null +} + +convert_to_subvolume () { + local XSUDO + local DIR + case $1 in + --sudo|-s) + XSUDO=sudo + shift + ;; + esac + DIR="${1}" + [ -d "${DIR}" ] || return 1 + is_btrfs_subvolume "${DIR}" && return 0 + set -x + #btrfs subvolume create "${DIR}".new && \ + ${XSUDO:+sudo} btrfs subvolume create "${DIR}.new" && \ + /bin/cp -aTr --reflink=always "${DIR}" "${DIR}".new && \ + mv "${DIR}" "${DIR}".orig && \ + mv "${DIR}".new "${DIR}" || return 2 + + set +x + return 0 + +} #EOF diff --git a/myshell_git_sync b/myshell_git_sync index 00bdbd4..2694e95 100644 --- a/myshell_git_sync +++ b/myshell_git_sync @@ -116,13 +116,13 @@ if ! $SSHS; then else loginfo "Clone ${MSC_GIT_REMOTE} and configure git" >&2 - if $( timeout --foreground "${MSC_GIT_CHECKOUT_TIMEOUT}" \ + 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}" \ + 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 diff --git a/vim/pack/plugins/start/vim-gnupg b/vim/pack/plugins/start/vim-gnupg new file mode 160000 index 0000000..96be0be --- /dev/null +++ b/vim/pack/plugins/start/vim-gnupg @@ -0,0 +1 @@ +Subproject commit 96be0be1240a848da56d665b38e1b0fe7ee3f1af