You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
720 B

  1. #!/bin/sh
  2. keys=
  3. for x in $HOME/.ssh/*.pub; do
  4. if [ -s "$x" ]; then
  5. keys="$keys $x"
  6. else
  7. rm "$x"
  8. fi
  9. done
  10. ak="$HOME/.ssh/authorized_keys"
  11. if [ -s "$ak" ]; then
  12. while read l; do
  13. found=
  14. for k in $keys; do
  15. read l2 < $k || true
  16. if [ "$l" = "$l2" ]; then
  17. found=yes
  18. echo "$l"
  19. break
  20. fi
  21. done
  22. if [ -z "$found" ]; then
  23. name="$(echo "$l" | cut -d' ' -f3)"
  24. if [ -n "$name" ]; then
  25. echo "$l" > .ssh/$name.pub
  26. fi
  27. fi
  28. done < $ak > $ak~
  29. else
  30. touch $ak
  31. for x in amery@geeks.cl \
  32. amery@builder.geeks.cl \
  33. amery@shell.easy-cloud.net; do
  34. x="$HOME/.ssh/$x.pub"
  35. [ -s "$x" ] || continue
  36. cat "$x"
  37. done > $ak~
  38. fi
  39. if ! cmp $ak $ak~; then
  40. diff -u $ak $ak~ || true
  41. mv $ak~ $ak
  42. fi