xref: /titanic_41/usr/src/grub/grub-0.97/util/grub-md5-crypt.in (revision 1b8adde7ba7d5e04395c141c5400dc2cffd7d809)
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.
21prefix=@prefix@
22exec_prefix=@exec_prefix@
23sbindir=@sbindir@
24
25# Initialize some variables.
26grub_shell=${sbindir}/grub
27progname="grub-md5-crypt"
28
29# Check the arguments.
30for option in "$@"; do
31    case "$option" in
32    -h | --help)
33	cat <<EOF
34Usage: $progname [OPTION]
35Encrypt 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
41Report bugs to <bug-grub@gnu.org>.
42EOF
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
62done
63
64# Suppress echo backs. I don't know if this is really portable. -okuji
65stty -echo
66
67# Prompt to enter a password.
68echo -n "Password: "
69read -r password
70echo
71
72# One more time.
73echo -n "Retype password: "
74read -r password2
75echo
76
77# Resume echo backs.
78stty echo
79
80if test "x$password" = x; then
81    echo "Empty password is not permitted."
82    exit 1
83fi
84
85if test "x$password" != "x$password2"; then
86    echo "Sorry, passwords do not match."
87    exit 1
88fi
89
90# Run the grub shell.
91$grub_shell --batch --device-map=/dev/null <<EOF \
92    | grep "^Encrypted: " | sed 's/^Encrypted: //'
93md5crypt
94$password
95quit
96EOF
97
98# Bye.
99exit 0
100