#! /bin/sh

function usage () {
    echo Usage: $0 key-file
}

while [ $# != 0 ]; do
    case $1 in
    	-help | --help | --hel | --he)
	    usage
	    exit 0
    	    ;;
	--*)
	    echo Unknown option $1
	    usage
	    exit 1
	    ;;
	*)
	    break
	    ;;
    esac

    options="$options $1"
    shift
done

if [ $# = 0 ] ; then
    usage
    exit 0
fi

function create-dir () {
    if mkdir $1 2>/dev/null; then
	echo Created $1
	chmod $2 $1 || exit 1
    fi
}

# Create directories
create-dir ~/.lsh 0700
create-dir ~/.lsh/authorized_keys_sha1 0700

SEXP_CONV=`PATH=$PATH:. \type -path sexp_conv`

if [ -z $SEXP_CONV ] ; then
    echo "Can't find the sexp_conv program"
    exit 1
fi

while [ $# != 0 ]; do
    hash=`$SEXP_CONV < $1 --once --hash sha1 --raw-hash`
    if [ -z $hash ] ; then
	echo $0: File $1 not found.
    else
        $SEXP_CONV < $1 -o canonical --once > ~/.lsh/authorized_keys_sha1/$hash
    fi
    shift
done
