#!/bin/bash
#
# recordum_ssl_verify
#
# v0.1 2013-03-28 RE
#
# verify a backup with its signature

MYSELF=$( basename $0 )

script_help() {
    cat <<EOF
${MYSELF} help:

This script helps to verify a backup with its signature. It needs root privileges!

Usage: ${MYSELF} <TARGET>

where:
    TARGET ... absolut path / target file

EOF
}

if [[ $# -lt 1 ]] || [[ $# -gt 1 ]]
then
    echo "incorrect number of commandline parameters!"
    script_help
    exit 1
fi

if [[ $UID -gt 0 ]]
then
    echo "$MYSELF needs to be run as superuser. You are $USER."
    exit 2
fi

TARGET=$1

# Test signature
PUBKEY=/etc/ssl/private/pubserver.key

if [[ ! -f ${PUBKEY} ]]
then
    echo "$PUBKEY is not here."
    exit 3
fi

TEST=$(openssl dgst -sha1 -verify ${PUBKEY} -signature ${TARGET}.sig ${TARGET})
echo ${TEST}

exit 0
