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.

47 lines
737 B

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