#!/bin/sh

set -e

if ! [ -n "$AUTOPKGTEST_TMP" -a -d "$AUTOPKGTEST_TMP" ]; then
  echo "$0: AUTOPKGTEST_TMP not set or not a directory" >&2
  exit 1
fi

if [ -n "`ls \"$AUTOPKGTEST_TMP\"`" ]; then
  echo "$0: \`$AUTOPKGTEST_TMP' directory not empty" >&2
  exit 1
fi

cp /usr/share/osg-ca-certs/* "$AUTOPKGTEST_TMP"
cd "$AUTOPKGTEST_TMP"

ls [a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9].[0-9] \
  | LC_ALL=C sort \
  > autopkgtest-hash-list

openssl rehash -compat "$AUTOPKGTEST_TMP"

ls [a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9].[0-9] \
  | LC_ALL=C sort \
  > autopkgtest-hash-list.check

diff -u autopkgtest-hash-list autopkgtest-hash-list.check

while read cert_hash; do
  ls "/etc/grid-security/certificates/$cert_hash"
done < autopkgtest-hash-list
