#!/usr/bin/env bash
# Identity of a host-config payload: the whole tree, mode and content, order-independent.
# Shipped inside the payload so the box computes the same id the workstation does.

buildbox_change_id() { # payload-dir
  local dir="$1"
  { cd "$dir" && find . -type f -printf '%P\n' | LC_ALL=C sort | while IFS= read -r f; do
      printf '%s %s ' "$(stat -c %a "$f")" "$f"; sha256sum "$f" | cut -d' ' -f1
    done; } | sha256sum | cut -c1-16
}
