Skip to content

Instantly share code, notes, and snippets.

@hannesm hannesm/opamrepro.sh Secret
Last active Dec 13, 2018

Embed
What would you like to do?
repro shell script
#!/bin/sh
# this script check for reproducibility.
# it's invoked by opam from the post-install script
# add
# post-install-commands: [
# "%{hooks}%/opamrepro.sh" "%{name}%" "%{version}%" "%{installed-files}%"
# ]
# in ~/.opam/config
#
# logs in the file /tmp/opamrepro/log
NAME=$1
VERSION=$2
shift 2
FILES=$*
mkdir -p /tmp/opamrepro
file=/tmp/opamrepro/${NAME}.${VERSION}
log=/tmp/opamrepro/log
#there is no artifact to check
if [ -z "$FILES" ]; then
exit 0
fi
hash=0
compute_hash () {
hash=$(openssl sha256 $OPAM_SWITCH_PREFIX/$1 | cut -d ' ' -f 2)
if [ $? -ne 0 ]; then
echo "couldn't compute sha256 of $i in $OPAM_SWITCH_PREFIX"
return 99
fi
return 0
}
filter_directory () {
if [ -d $OPAM_SWITCH_PREFIX/$1 ]; then
echo "$1 is a directory, ignoring"
return 1
else
return 0
fi
}
# TODO: need to verify that _all_ items in $file are checked by for loop
# TODO: uses "$i $hash", grep should be on entire line (as a regexp: ^$i $hash$)!?
if [ -f "$file" ] ; then
for i in $FILES; do
filter_directory $i
if [ $? -eq 0 ]; then
compute_hash $i
if [ $? -eq 0 ]; then
grep -q "$i $hash" "$file"
if [ $? -ne 0 ]; then
their_hash=$(grep "$i " "$file")
echo "file $i (of package $NAME $VERSION) hash does not match (theirs $their_hash, mine $hash)!" >> $log
exit 1
fi
fi
fi
done
echo "verified $NAME $VERSION" >> $log
else
echo "generating checksum file $file" >> $log
for i in $FILES; do
filter_directory $i
if [ $? -eq 0 ]; then
compute_hash $i
if [ $? -eq 0 ]; then
echo "$i $hash" >> "$file"
fi
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.