Skip to content

Instantly share code, notes, and snippets.

@bureado
Last active January 17, 2022 22:42
Show Gist options
  • Save bureado/16df777c1f9883ef919a5cc0c30eaba3 to your computer and use it in GitHub Desktop.
Save bureado/16df777c1f9883ef919a5cc0c30eaba3 to your computer and use it in GitHub Desktop.
#!/bin/sh
# See: https://hackmd.io/@aeva/draft-gitbom-spec
# Also see: https://gist.github.com/bureado/0e4b53e90ac1263b7c5ed908dbe2cb50
# Today I would look at witness, tracee, and many others.
# TODO: make sure $BUILDDIR is a --git-dir
BUILDDIR=$1
TIMEOUT=5
REFHASH=`git --git-dir=$BUILDDIR/.git rev-parse HEAD`
EVENTS="open"
echo "Monitoring $EVENTS in $BUILDDIR ($REFHASH) with timeout: $TIMEOUT"
for blob in `inotifywait -q -r -e $EVENTS -m $BUILDDIR --exclude .git | grep -v ISDIR | LANG=C sort | uniq | cut -f1,3 -d' ' --output-delimiter=''`
do
echo $blob >> /tmp/raw-$REFHASH.txt
# TODO: handle OPEN events that aren't in the tree (e.g., transient files)
git --git-dir=$BUILDDIR/.git ls-tree HEAD $blob >> /tmp/$REFHASH
# TODO: add hash matching, but this is best done via capturing other inotify events
done
git --git-dir=$BUILDDIR/.git notes add -F /tmp/$REFHASH $REFHASH
echo -n "Wrote git note: " ; git --git-dir=$BUILDDIR/.git show-ref `git --git-dir=$BUILDDIR/.git notes get-ref`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment