aboutsummaryrefslogtreecommitdiff
#!/bin/sh

if [ -z "$NEW_USER" ]; then # ssh auth
	read method type key <$SSH_USER_AUTH
	user="$(grep -l -s -r -P '^\s*auth:\s*\Q'"$type"'\E\s+\Q'"$key"'\E(\s|$)' /opt/autopeer/dn42-registry/data/mntner/ | perl -ne 's@^.*/@@; s@-MNT$@@; print lc;' | head -1)"
else # pgp auth
	fpr="$(curl -s "$NEW_USER" | gpg --show-keys --with-colons | grep -Po 'fpr:*\K[^:]+' | head -1)"
	user="$(grep -l -s -r -P '^\s*auth:\s*pgp-fingerprint\s+\Q'"$fpr"'\E(\s|$)' /opt/autopeer/dn42-registry/data/mntner/ | perl -ne 's@^.*/@@; s@-MNT$@@; print lc;' | head -1)"
fi

if getent passwd "$user" >/dev/null 2>&1; then
	echo "Your account has been created, go ahead and log in:"
	echo "ssh $user@$(hostname -f)"
	echo
else
	echo "Some error occurred, the account $user didn't get created, please go ask steering" >&2
	echo
	exit 1
fi