#!/bin/sh
PSRDIR=/etc/psr
USRDIR=$HOME/.psr_authr

do_pwstore () {
  local _pub=$PSRDIR/$1.pubkey
  local _usr=$USRDIR/$1.epass
  echo "--- Processing key $1"
  /usr/bin/pwstore -v $_pub
  if test $? -eq 0 ; then
    echo -e "Your AFS password has been encrypted and stored in the file:\n"
    echo -e "  $_usr\n"
  else
    echo "*** Error processing key $1"
    exit
  fi
}

if test ! -d $USRDIR ; then
  mkdir -p   $USRDIR
  test $? -ne 0 && exit
fi
fs sa $USRDIR system:anyuser rl
test $? -ne 0 && exit

for pubfile in `/bin/ls -1 $PSRDIR/*.pubkey`; do
  pub=`basename $pubfile            .pubkey`
  do_pwstore    $pub
done
