Files

48 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
export PS4='(${BASH_SOURCE}:${LINENO}): - [${SHLVL},${BASH_SUBSHELL},$?] $ '
function error_out()
{
echo "Bailing out. See above for reason...."
exit 1
}
function handle_failure() {
local lineno=$1
local fn=$2
local exitstatus=$3
local msg=$4
local lineno_fns=${0% 0}
if [[ "$lineno_fns" != "-1" ]] ; then
lineno="${lineno} ${lineno_fns}"
fi
echo "${BASH_SOURCE[0]}: Function: ${fn} Line Number : [${lineno}] Failed with status ${exitstatus}: $msg"
}
trap 'handle_failure "${BASH_LINENO[*]}" "$LINENO" "${FUNCNAME[*]:-script}" "$?" "$BASH_COMMAND"' ERR
set -o errexit
set -o nounset
set -o pipefail
set -o functrace
WORKDIR="$(cd "$(dirname "$0")" && pwd)"
TARGET_DIR="${WORKDIR}/Docker"
cd "$TARGET_DIR"
# Iterate only over directories that are git repos
while IFS= read -r -d '' repo_dir; do
echo "Updating: ${repo_dir}"
pushd "$repo_dir" >/dev/null
if [[ -d .git ]]; then
git -c advice.detachedHead=false fetch --all --prune || true
# Fast-forward only to avoid unintended merges
git -c advice.detachedHead=false pull --ff-only || true
else
echo "Skipping (not a git repo): ${repo_dir}"
fi
popd >/dev/null
done < <(find . -mindepth 1 -maxdepth 1 -type d -print0)