Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test if a zypper repository cache directory is OK. On openSuSE, you can test it with `for d in /var/cache/zypp/raw/*/repodata; do ~/repomd_test.sh $d; done`
#!/bin/bash
## https://github.com/Tojaj/librepo/issues/16
#set -e # Fail on error
echo "Sanity check"
echo "Testing if directory '$1' exists"
test -e $1 || exit 1
pushd $1
echo "Testing if the repomd.xml* files in directory '$1' exist"
test -e repomd.xml.key || exit 1
test -e repomd.xml || exit 1
test -e repomd.xml.asc || exit 1
echo "Creating a directory for temporary keyring"
TMP_KEYRING_DIR=`mktemp -d`
echo "testing if directory '$TMP_KEYRING_DIR' exists"
test -e $TMP_KEYRING_DIR || exit 1
## prevent "gpg: WARNING: unsafe permissions on homedir $TMP_KEYRING_DIR"
## http://lists.gnupg.org/pipermail/gnupg-users/2003-October/020342.html
chmod 700 $TMP_KEYRING_DIR
export GNUPGHOME=$TMP_KEYRING_DIR
echo "Trying to check signature of the repomd.xml with the empty keyring"
gpg --verify repomd.xml.asc repomd.xml
test $? -ne 0 || { echo "gpg --verify should failed!"; exit 1; }
echo "OK: Check failed as expected"
echo "Importing key to the temporary keyring"
gpg --import repomd.xml.key
test $? -eq 0 || { echo "Cannot import the key"; exit 1; }
echo "Fingerprinting all keys (there is only one)"
gpg --fingerprint
test $? -eq 0 || { echo "Cannot fingerprint the keys"; exit 1; }
echo "Trying to check signature of the repomd.xml with the key in the keyring"
gpg --verify repomd.xml.asc repomd.xml
test $? -eq 0 || { echo "gpg --verify should success!"; exit 1; }
echo "OK: Check passed"
rm $TMP_KEYRING_DIR/*.gpg
rm $TMP_KEYRING_DIR/*.gpg~
rmdir $TMP_KEYRING_DIR
popd
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.