summaryrefslogtreecommitdiff
path: root/localresetpasswd
blob: 17f41fe73b2fb110dc4465a44f1063f9134d64b4 (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/bin/localresetpasswd
  4. # Copyright 2006 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # $Id: localresetpasswd,v 1.1 2006-08-31 22:51:03 jonas Exp $
  7. #
  8. # Generate random password and apply to account through sudo
  9. #
  10. # TODO: Check for bad arguments
  11. # TODO: Use getopts to offer help
  12. # TODO: Support overriding options in /etc/local file
  13. #
  14. set -e
  15. pass_len=11
  16. verbose=1
  17. #simulate=true
  18. interactive=0
  19. # echo something, but only if in verbose mode
  20. vecho() {
  21. test -n "$verbose" && echo "$@" >&2
  22. }
  23. randompass() {
  24. gpw 1 $pass_len 2>&- ||
  25. pwgen $pass_len 1 2>&- ||
  26. tr -d '[\000-\057][\072-\100][\133-\140][\173-\377]' < /dev/urandom |
  27. dd bs=$pass_len count=1 2>&-
  28. }
  29. u=$1
  30. shift
  31. vecho -n "Generating random password..."
  32. pass=$(randompass)
  33. vecho " Done!"
  34. vecho -n "Applying new password to account $u..."
  35. echo "$u:$pass" | eval $simulate sudo "/usr/sbin/chpasswd"
  36. vecho " Done!"
  37. eval $simulate localresetpasswdexpiry "$u"
  38. vecho "New password is $pass"