#!/bin/sh # $UFP$ # Copyright © 2019-2021 Trond Endrestøl # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. #set -x #set -eu -o pipefail set -u -o pipefail ## Kids, remember the simplicity of running Subversion through GNU Parallel. #parallel svn update --accept=theirs-full --non-interactive ::: /usr/ports /usr/src ## Now, compare that to what follows. # Determine which git executable to run. GIT_CANDIDATES="/usr/local/bin/git /usr/bin/git /usr/bin/gitlite" readonly GIT_CANDIDATES for cand in ${GIT_CANDIDATES}; do if [ -x ${cand} ]; then GIT=${cand} break fi done if [ -z "${GIT}" ]; then echo "${0}: neither of ${GIT_CANDIDATES} are useable" >/dev/stderr exit 69 fi readonly GIT ncpu=`sysctl -n hw.ncpu` readonly ncpu # Usage: update_git_wc # # E.g.: update_git_wc /usr/src main main+local # update_git_wc /usr/src stable/13 stable/13+local # update_git_wc /usr/ports main main+local # update_git_wc () { if [ ${#} -ne 3 ]; then echo "Usage: ${0} " >/dev/stderr return 69 fi date || return echo "Updating Git WC in ${1} ..." || return local BASENAME=`basename ${1}` local FSTYPE=`df -T ${1} | tail -1 | awk '{print $2;exit}'` local FSDEV=`df ${1} | tail -1 | awk '{print $1;exit}'` local TIMESTAMP=`date +%Y%m%d-%H%M%S` if [ "${FSTYPE}" = zfs ]; then zfs snapshot -r ${FSDEV}/.git@${TIMESTAMP} || return fi ${GIT} -C ${1} diff ${2}..${3} > /var/backups/git-diff-${BASENAME}-${TIMESTAMP}.diff || return ${GIT} -C ${1} stash || return ${GIT} -C ${1} checkout ${2} || return ${GIT} -C ${1} pull -j ${ncpu} --no-edit --no-ff -p || { ${GIT} -C ${1} prune -v || return ${GIT} -C ${1} remote prune freebsd || return ${GIT} -C ${1} gc --auto || return ${GIT} -C ${1} pull -j ${ncpu} --no-edit --no-ff -p || return } ${GIT} -C ${1} rebase ${2} ${3} || return [ -n "`${GIT} -C ${1} stash list`" ] && { ${GIT} -C ${1} stash pop || return; } || true echo || return } update_git_wc /usr/src main main+local || exit #update_git_wc /usr/ports main main+local || exit #update_git_wc /usr/zstd-3.src main main+local || exit #update_git_wc /usr/zstd-3.ports main main+local || exit #update_git_wc /usr/zstd-3.src main main+local || exit #update_git_wc /usr/zstd-9.ports main main+local || exit #update_git_wc /usr/zstd-9.src main main+local || exit #update_git_wc /usr/zstd-9.ports main main+local || exit #update_git_wc /usr/zstd-12.src main main+local || exit #update_git_wc /usr/zstd-12.ports main main+local || exit #update_git_wc /usr/zstd-19.src main main+local || exit #update_git_wc /usr/zstd-19.ports main main+local || exit date # EOF