grub-md5-crypt.in 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #! /bin/sh
  2. # Encrypt a password in MD5 format
  3. # Copyright (C) 2000,2002 Free Software Foundation, Inc.
  4. #
  5. # This file is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. # Replaced by the configure script.
  19. prefix=@prefix@
  20. exec_prefix=@exec_prefix@
  21. sbindir=@sbindir@
  22. # Initialize some variables.
  23. grub_shell=${sbindir}/grub
  24. progname="grub-md5-crypt"
  25. # Check the arguments.
  26. for option in "$@"; do
  27. case "$option" in
  28. -h | --help)
  29. cat <<EOF
  30. Usage: $progname [OPTION]
  31. Encrypt a password in MD5 format.
  32. -h, --help print this message and exit
  33. -v, --version print the version information and exit
  34. --grub-shell=FILE use FILE as the grub shell
  35. Report bugs to <bug-grub@gnu.org>.
  36. EOF
  37. exit 0
  38. ;;
  39. -v | --version)
  40. echo "$progname (GNU GRUB ${VERSION})"
  41. exit 0
  42. ;;
  43. --grub-shell=*)
  44. grub_shell=`echo "$option" | sed 's/--grub-shell=//'`
  45. ;;
  46. *)
  47. echo "$progname: unrecognized option \`$option'"
  48. echo "Usage: $progname [OPTION]"
  49. echo "Try \`$progname --help' for more information."
  50. exit 1
  51. ;;
  52. esac
  53. done
  54. # Suppress echo backs. I don't know if this is really portable. -okuji
  55. stty -echo
  56. # Prompt to enter a password.
  57. echo -n "Password: "
  58. read -r password
  59. echo
  60. # One more time.
  61. echo -n "Retype password: "
  62. read -r password2
  63. echo
  64. # Resume echo backs.
  65. stty echo
  66. if test "x$password" = x; then
  67. echo "Empty password is not permitted."
  68. exit 1
  69. fi
  70. if test "x$password" != "x$password2"; then
  71. echo "Sorry, passwords do not match."
  72. exit 1
  73. fi
  74. # Run the grub shell.
  75. $grub_shell --batch --device-map=/dev/null <<EOF \
  76. | grep "^Encrypted: " | sed 's/^Encrypted: //'
  77. md5crypt
  78. $password
  79. quit
  80. EOF
  81. # Bye.
  82. exit 0