Browse Source

Add new `.external-pins/tag.sh` script for going from a filename to image:tag

This allows us to do things like ask Git for a list of `.external-pins/*/**` files changed and then convert that into a list of external image:tag references.
Tianon Gravi 2 years ago
parent
commit
c87f94ca53
2 changed files with 28 additions and 0 deletions
  1. 2 0
      .external-pins/file.sh
  2. 26 0
      .external-pins/tag.sh

+ 2 - 0
.external-pins/file.sh

@@ -1,6 +1,8 @@
 #!/usr/bin/env bash
 set -Eeuo pipefail
 
+# given an image (name:tag), return the appropriate filename
+
 dir="$(dirname "$BASH_SOURCE")"
 
 for img; do

+ 26 - 0
.external-pins/tag.sh

@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+set -Eeuo pipefail
+
+# given a filename, return the appropriate image (name:tag)
+
+origDir="$(dirname "$BASH_SOURCE")"
+dir="$(readlink -ve "$origDir")"
+
+for file; do
+	abs="$(readlink -vm "$file")"
+	rel="${abs#$dir/}"
+	rel="${rel##*.external-pins/}" # in case we weren't inside "$dir" but the path is legit
+	if [ "$rel" = "$abs" ]; then
+		echo >&2 "error: '$file' is not within '$origDir'"
+		echo >&2 "('$abs' vs '$dir')"
+		exit 1
+	fi
+
+	img="${rel/___/:}" # see ".external-pins/list.sh"
+	if [ "$img" = "$rel" ]; then
+		echo >&2 "error: '$file' does not contain ':' ('___') -- this violates our assumptions!"
+		exit 1
+	fi
+
+	echo "$img"
+done