On 7 Jan 2000, Niels M�ller wrote:
> I thought functions existed in the plain /bin/sh. If you can make
> that script more portable, that's appreciated.
Done. The hardest part was
SEXP_CONV=`PATH=$PATH:. \type -path sexp_conv`
As I couldn't find any equivelent, so I decided to just add the path from
the command line element $0 to the path, which has the minor advantage
that if lsh-authorize and sexp_conv are in the same directory, sexp_conv
will still be found even if that directory is not in the path, and is not
the current directory, if the user uses a full or relative
path to lsh-authorize. It seems that
hash=`$SEXP_CONV < $1 --once --hash sha1 --raw-hash`
sets $? to 127 if $SEXP_CONV isn't found, but I haven't tested that for
portability yet, so the "Can't find the sexp_conv program" may not always
appear.
Anyway, here's the result, feel free to use it, disregard it, butcher it,
etc.
#! /bin/sh
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
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
PATH=$PATH:`dirname $0`
SEXP_CONV="sexp_conv"
while [ $# != 0 ]; do
if [ -f $1 ]; then
hash=`$SEXP_CONV < $1 --once --hash sha1 --raw-hash`
if [ $? = 127 ]; then
echo "Can't find the sexp_conv program"
exit 1
fi
if [ -z "$hash" ] ; then
echo $0: File $1 not readable.
else
$SEXP_CONV < $1 -o canonical --once > ~/.lsh/authorized_keys_sha1/$hash
fi
else
echo $0: File $1 not found.
fi
shift
done