forked from tilde.black/ops
31 lines
813 B
Bash
Executable File
31 lines
813 B
Bash
Executable File
#!/bin/sh
|
|
email="$1"
|
|
key="$2"
|
|
keystore="$HOME/keystore.txt"
|
|
|
|
if [ -n "$email" ] && [ -n "$key" ]; then
|
|
all_users=$(grep /home < /etc/passwd | awk -F: '{print $1}' | gshuf)
|
|
# once we find 10 matches quit
|
|
matches=1
|
|
match_users=$(
|
|
printf "%s" "$all_users" | while read -r n; do
|
|
if [ $matches -gt 10 ]; then
|
|
exit
|
|
fi
|
|
if [ ! -s "/home/${n}/.ssh/authorized_keys" ]; then
|
|
printf "%s " "$n"
|
|
matches=$((matches+1))
|
|
printf "%s\\n" "$key" > "/home/${n}/.ssh/authorized_keys"
|
|
fi
|
|
done
|
|
)
|
|
sed -e "s/USERS/${match_users}/" /etc/templates/assign.tmpl | sendmail "${email}"
|
|
{
|
|
printf "Email: %s\\n" "$email"
|
|
printf "Key: %s\\n" "$key"
|
|
printf "Users: %s\\n\\n" "$match_users"
|
|
} >> "$keystore"
|
|
else
|
|
printf "Provide email address and ssh-key as params."
|
|
fi
|