Refactor the Debian mirror configuration.
[mirror-admin] / bin / debian-excludes
diff --git a/bin/debian-excludes b/bin/debian-excludes
new file mode 100755 (executable)
index 0000000..bac4992
--- /dev/null
@@ -0,0 +1,52 @@
+#! /bin/sh
+
+set -e
+case $# in
+  0 | 1 | 2 | 3)
+    echo >&2 "Usage: $0 HOST PATH ARCH:ARCH:... DIST..."
+    exit 1
+    ;;
+  *)
+    RSYNC_HOST=$1 RSYNC_PATH=$2 WANT_ARCH=$3; shift 3
+    ;;
+esac
+
+## Check the available distributions for architectures.
+for dist in "$@"; do
+  rsync --list-only $RSYNC_HOST::$RSYNC_PATH/dists/$dist/main/
+done | {
+
+  ## Gather up excluded architectures as we go.
+  excludes=""
+
+  while read mode size date time name; do
+
+    ## Check directories of binary packages.  If it's an architecture we
+    ## don't want to reject, then continue on.
+    case "$name" in
+      binary-all)
+       continue
+       ;;
+      binary-*)
+       arch=${name#binary-}
+       case ":$WANT_ARCH:" in *:"$arch":*) continue ;; esac
+       ;;
+      *)
+       continue
+       ;;
+    esac
+
+    ## Pick out the architecture name.  Check whether we've seen it before.
+    arch=${name#binary-}
+    case " $excludes " in
+      *" $arch "*)
+       ;;
+      *)
+       excludes="${excludes+$excludes }$arch"
+       ;;
+    esac
+  done
+
+  ## Done.  Print out the finished list.
+  echo $excludes
+}