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