#!/bin/bash

if [ -z "$TARGET" -o ! -d "$TARGET" ]; then
  echo "Missing target directory"
  exit 1
fi

# user to give access to. can be hardcoded or fetched from some other place
: ${USER:="myuser"}
# keytype: rsa or dsa
: ${KEYTYPE:="rsa"}

if [ -f /home/$USER/.ssh/id_$KEYTYPE.pub ]; then
  install -D -m 0700 -o root -g root \
    /home/$USER/.ssh/id_$KEYTYPE.pub $TARGET/root/.ssh/authorized_keys
fi

exit 0
