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