#!/bin/sh -e
if test -f "$1" && grep -q ssh-rsa "$1" && test $(wc -l <"$1") -eq 1&& test "${1##*.}" == "pub"
then
username=$(basename $1 .pub)
echo Create account for $username ?
read -p "Press [enter] to continue..."
else
echo $0 requires a ssh pub key of the format username.pub
exit
fi
sudo useradd -s /usr/bin/git-shell -m $username
sudo mkdir /home/$username/.ssh
sudo cp $1 /home/$username/.ssh/authorized_keys
sudo chown -R $username:$username /home/$username/.ssh/
sudo adduser $username git
echo ssh://$username@example.com/srv/git/test