17c478bd9Sstevel@tonic-gate#! /bin/sh 27c478bd9Sstevel@tonic-gate 37c478bd9Sstevel@tonic-gate# Encrypt a password in MD5 format 47c478bd9Sstevel@tonic-gate# Copyright (C) 2000,2002 Free Software Foundation, Inc. 57c478bd9Sstevel@tonic-gate# 67c478bd9Sstevel@tonic-gate# This file is free software; you can redistribute it and/or modify it 77c478bd9Sstevel@tonic-gate# under the terms of the GNU General Public License as published by 87c478bd9Sstevel@tonic-gate# the Free Software Foundation; either version 2 of the License, or 97c478bd9Sstevel@tonic-gate# (at your option) any later version. 107c478bd9Sstevel@tonic-gate# 117c478bd9Sstevel@tonic-gate# This program is distributed in the hope that it will be useful, but 127c478bd9Sstevel@tonic-gate# WITHOUT ANY WARRANTY; without even the implied warranty of 137c478bd9Sstevel@tonic-gate# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 147c478bd9Sstevel@tonic-gate# General Public License for more details. 157c478bd9Sstevel@tonic-gate# 167c478bd9Sstevel@tonic-gate# You should have received a copy of the GNU General Public License 177c478bd9Sstevel@tonic-gate# along with this program; if not, write to the Free Software 187c478bd9Sstevel@tonic-gate# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 197c478bd9Sstevel@tonic-gate 207c478bd9Sstevel@tonic-gate# Replaced by the configure script. 217c478bd9Sstevel@tonic-gateprefix=@prefix@ 227c478bd9Sstevel@tonic-gateexec_prefix=@exec_prefix@ 237c478bd9Sstevel@tonic-gatesbindir=@sbindir@ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate# Initialize some variables. 267c478bd9Sstevel@tonic-gategrub_shell=${sbindir}/grub 277c478bd9Sstevel@tonic-gateprogname="grub-md5-crypt" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate# Check the arguments. 307c478bd9Sstevel@tonic-gatefor option in "$@"; do 317c478bd9Sstevel@tonic-gate case "$option" in 327c478bd9Sstevel@tonic-gate -h | --help) 337c478bd9Sstevel@tonic-gate cat <<EOF 347c478bd9Sstevel@tonic-gateUsage: $progname [OPTION] 357c478bd9Sstevel@tonic-gateEncrypt a password in MD5 format. 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate -h, --help print this message and exit 387c478bd9Sstevel@tonic-gate -v, --version print the version information and exit 397c478bd9Sstevel@tonic-gate --grub-shell=FILE use FILE as the grub shell 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gateReport bugs to <bug-grub@gnu.org>. 427c478bd9Sstevel@tonic-gateEOF 437c478bd9Sstevel@tonic-gate exit 0 447c478bd9Sstevel@tonic-gate ;; 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate -v | --version) 477c478bd9Sstevel@tonic-gate echo "$progname (GNU GRUB ${VERSION})" 487c478bd9Sstevel@tonic-gate exit 0 497c478bd9Sstevel@tonic-gate ;; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate --grub-shell=*) 527c478bd9Sstevel@tonic-gate grub_shell=`echo "$option" | sed 's/--grub-shell=//'` 537c478bd9Sstevel@tonic-gate ;; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate *) 567c478bd9Sstevel@tonic-gate echo "$progname: unrecognized option \`$option'" 577c478bd9Sstevel@tonic-gate echo "Usage: $progname [OPTION]" 587c478bd9Sstevel@tonic-gate echo "Try \`$progname --help' for more information." 597c478bd9Sstevel@tonic-gate exit 1 607c478bd9Sstevel@tonic-gate ;; 617c478bd9Sstevel@tonic-gate esac 627c478bd9Sstevel@tonic-gatedone 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate# Suppress echo backs. I don't know if this is really portable. -okuji 657c478bd9Sstevel@tonic-gatestty -echo 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate# Prompt to enter a password. 687c478bd9Sstevel@tonic-gateecho -n "Password: " 697c478bd9Sstevel@tonic-gateread -r password 707c478bd9Sstevel@tonic-gateecho 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate# One more time. 737c478bd9Sstevel@tonic-gateecho -n "Retype password: " 747c478bd9Sstevel@tonic-gateread -r password2 757c478bd9Sstevel@tonic-gateecho 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate# Resume echo backs. 787c478bd9Sstevel@tonic-gatestty echo 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gateif test "x$password" = x; then 817c478bd9Sstevel@tonic-gate echo "Empty password is not permitted." 827c478bd9Sstevel@tonic-gate exit 1 837c478bd9Sstevel@tonic-gatefi 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gateif test "x$password" != "x$password2"; then 867c478bd9Sstevel@tonic-gate echo "Sorry, passwords do not match." 877c478bd9Sstevel@tonic-gate exit 1 887c478bd9Sstevel@tonic-gatefi 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate# Run the grub shell. 917c478bd9Sstevel@tonic-gate$grub_shell --batch --device-map=/dev/null <<EOF \ 927c478bd9Sstevel@tonic-gate | grep "^Encrypted: " | sed 's/^Encrypted: //' 937c478bd9Sstevel@tonic-gatemd5crypt 947c478bd9Sstevel@tonic-gate$password 957c478bd9Sstevel@tonic-gatequit 967c478bd9Sstevel@tonic-gateEOF 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate# Bye. 997c478bd9Sstevel@tonic-gateexit 0 100