#!/bin/sh

if [ -z "$1" ] || [ -z "$2" ]; then
	echo "Usage: pull-updates keyring dir" >&2
	exit 1
fi

mkdir updates/
scripts/explode-keyring $1 updates

cd updates
for i in 0x*; do
	if [ ! -e ../$2/$i ]; then
		echo $i no longer exists, removing.
		rm $i
	elif cmp -s $i ../$2/$i; then
		echo $i matches old key version, removing.
		rm $i
	fi
done

echo Updated keys are:
ls

cd ..

for i in updates/0x*; do
	if [ -f $i ]; then
		scripts/update-key $i $2
		rm $i
	fi
done

rmdir updates/
