1N/A#! /bin/sh
1N/A
1N/A# Encrypt a password in MD5 format
1N/A# Copyright (C) 2000,2002 Free Software Foundation, Inc.
1N/A#
1N/A# This file is free software; you can redistribute it and/or modify it
1N/A# under the terms of the GNU General Public License as published by
1N/A# the Free Software Foundation; either version 2 of the License, or
1N/A# (at your option) any later version.
1N/A#
1N/A# This program is distributed in the hope that it will be useful, but
1N/A# WITHOUT ANY WARRANTY; without even the implied warranty of
1N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1N/A# General Public License for more details.
1N/A#
1N/A# You should have received a copy of the GNU General Public License
1N/A# along with this program; if not, write to the Free Software
1N/A# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1N/A
1N/A# Replaced by the configure script.
1N/Aprefix=@prefix@
1N/Aexec_prefix=@exec_prefix@
1N/Asbindir=@sbindir@
1N/A
1N/A# Initialize some variables.
1N/Agrub_shell=${sbindir}/grub
1N/Aprogname="grub-md5-crypt"
1N/A
1N/A# Check the arguments.
1N/Afor option in "$@"; do
1N/A case "$option" in
1N/A -h | --help)
1N/A cat <<EOF
1N/AUsage: $progname [OPTION]
1N/AEncrypt a password in MD5 format.
1N/A
1N/A -h, --help print this message and exit
1N/A -v, --version print the version information and exit
1N/A --grub-shell=FILE use FILE as the grub shell
1N/A
1N/AReport bugs to <bug-grub@gnu.org>.
1N/AEOF
1N/A exit 0
1N/A ;;
1N/A
1N/A -v | --version)
1N/A echo "$progname (GNU GRUB ${VERSION})"
1N/A exit 0
1N/A ;;
1N/A
1N/A --grub-shell=*)
1N/A grub_shell=`echo "$option" | sed 's/--grub-shell=//'`
1N/A ;;
1N/A
1N/A *)
1N/A echo "$progname: unrecognized option \`$option'"
1N/A echo "Usage: $progname [OPTION]"
1N/A echo "Try \`$progname --help' for more information."
1N/A exit 1
1N/A ;;
1N/A esac
1N/Adone
1N/A
1N/A# Suppress echo backs. I don't know if this is really portable. -okuji
1N/Astty -echo
1N/A
1N/A# Prompt to enter a password.
1N/Aecho -n "Password: "
1N/Aread -r password
1N/Aecho
1N/A
1N/A# One more time.
1N/Aecho -n "Retype password: "
1N/Aread -r password2
1N/Aecho
1N/A
1N/A# Resume echo backs.
1N/Astty echo
1N/A
1N/Aif test "x$password" = x; then
1N/A echo "Empty password is not permitted."
1N/A exit 1
1N/Afi
1N/A
1N/Aif test "x$password" != "x$password2"; then
1N/A echo "Sorry, passwords do not match."
1N/A exit 1
1N/Afi
1N/A
1N/A# Run the grub shell.
1N/A$grub_shell --batch --device-map=/dev/null <<EOF \
1N/A | grep "^Encrypted: " | sed 's/^Encrypted: //'
1N/Amd5crypt
1N/A$password
1N/Aquit
1N/AEOF
1N/A
1N/A# Bye.
1N/Aexit 0