Skip to content

Instantly share code, notes, and snippets.

@shepmaster
Created May 8, 2014 20:49
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save shepmaster/bdc642d1a555ed1d5b02 to your computer and use it in GitHub Desktop.
Save shepmaster/bdc642d1a555ed1d5b02 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
shopt -s nullglob
if [[ -n ${RUN:-} ]]; then
dry=
else
dry=echo
fi
function keep_valid_tag() {
local readonly index_file=$1
local readonly tag_file=$2
local readonly tag_name=$(basename "${tag_file}" | sed 's@^tag_@@')
local readonly tag_id=$(cat "${tag_file}")
# Find tags that are not the correct ID, and remove them
jq -c -M ". - [.[] | select(.Tag == \"$tag_name\" and .id != \"$tag_id\")]" $index_file
}
function fix_repository() {
local readonly repo_dir=$1
local readonly infile=$(mktemp -t fix-images-XXXX)
local readonly outfile=$(mktemp -t fix-images-XXXX)
cp $repo_dir/_index_images $infile
for tag in $repo_dir/tag_*; do
keep_valid_tag $infile $tag > $outfile
mv $outfile $infile
done
$dry mv $repo_dir/_index_images $repo_dir/_index_images.original
$dry mv $infile $repo_dir/_index_images
}
for repo_dir in $@; do
echo "Processing repository $(basename $repo_dir)" >&2
fix_repository $repo_dir
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment