#!/bin/bash # Run this in the directory that contains the git repository (branch) with the output readarray -t profiles /dev/null 2>&1; pwd -P)" # Check that we're in the right place; there should be one dir for each profile and a dockerhub-metadata.retrieve.log in this directory and nothing else (except possibly hidden stuff like .git) files=("${profiles[@]}" dockerhub-metadata.profiles dockerhub-metadata.retrieve.log) if ! diff -q <(printf "%s\0" "${files[@]}" | LC_ALL=C sort -z) <(printf "%s\0" * | LC_ALL=C sort -z) >/dev/null then echo "ERROR: Current directory appears to not match the expected structure; refusing to continue" >&2 echo "Expected: ${files[@]}" >&2 exit 1 fi # Create a temporary directory for the new run's output (hidden so it isn't caught in the deletion below) tmpDir="$(mktemp --directory --tmpdir=. .tmp.XXXXXXXXXX)" # Run (and exit if something goes wrong) pushd "${tmpDir}" 2>/dev/null set -e PYTHONUNBUFFERED=1 "${codePath}"/retrieve "${profiles[@]}" 2> >(tee dockerhub-metadata.retrieve.log >&2) set +e popd 2>/dev/null # Delete the old stuff rm -r * # Move new stuff here mv -n "${tmpDir}"/* . # Delete the temporary directory, which should now be empty rmdir "${tmpDir}" if [[ $? -ne 0 ]] then echo "ERROR: Could not delete temporary directory ${tmpDir}; not empty?" >&2 #TODO: This should block future runs as well to prevent mixed up data or something. exit 1 fi # Recreate the profiles file, sorted printf "%s\n" "${profiles[@]}" | LC_ALL=C sort >dockerhub-metadata.profiles # git stuffs git add --all -- ':!.tmp.*' git commit --message 'Automatic run' git push