11#! /bin/sh
22
3- #  Copyright (c) 2002, 2012 , Oracle and/or its affiliates. All rights reserved.
3+ #  Copyright (c) 2002, 2016 , Oracle and/or its affiliates. All rights reserved.
44#  
55#  This program is free software; you can redistribute it and/or modify
66#  it under the terms of the GNU General Public License as published by
@@ -33,6 +33,20 @@ set_echo_compat() {
3333    esac 
3434}
3535
36+ validate_reply  () {
37+     ret=0
38+     if  [ -z  " $1 "   ];  then 
39+ 	reply=y
40+ 	return  $ret 
41+     fi 
42+     case  $1  in 
43+         y|Y|yes|Yes|YES) reply=y ;;
44+         n|N|no|No|NO)    reply=n ;;
45+         * ) ret=1 ;;
46+     esac 
47+     return  $ret 
48+ }
49+ 
3650prepare () {
3751    touch $config  $command 
3852    chmod 600 $config  $command 
@@ -284,15 +298,18 @@ echo "Setting the root password ensures that nobody can log into the MySQL"
284298echo  " root user without the proper authorisation." 
285299echo 
286300
287- if  [ $hadpass  -eq  0 ];  then 
288-     echo  $echo_n  " Set root password? [Y/n] $echo_c " 
289- else 
290-     echo  " You already have a root password set, so you can safely answer 'n'." 
291-     echo 
292-     echo  $echo_n  " Change the root password? [Y/n] $echo_c " 
293- fi 
301+ while  true  ;  do 
302+     if  [ $hadpass  -eq  0 ];  then 
303+ 	echo  $echo_n  " Set root password? [Y/n] $echo_c " 
304+     else 
305+ 	echo  " You already have a root password set, so you can safely answer 'n'." 
306+ 	echo 
307+ 	echo  $echo_n  " Change the root password? [Y/n] $echo_c " 
308+     fi 
309+     read  reply
310+     validate_reply $reply  &&  break 
311+ done 
294312
295- read  reply
296313if  [ " $reply "   =  " n"   ];  then 
297314    echo  "  ... skipping." 
298315else 
@@ -316,9 +333,11 @@ echo "go a bit smoother.  You should remove them before moving into a"
316333echo  " production environment." 
317334echo 
318335
319- echo  $echo_n  " Remove anonymous users? [Y/n] $echo_c " 
320- 
321- read  reply
336+ while  true  ;  do 
337+     echo  $echo_n  " Remove anonymous users? [Y/n] $echo_c " 
338+     read  reply
339+     validate_reply $reply  &&  break 
340+ done 
322341if  [ " $reply "   =  " n"   ];  then 
323342    echo  "  ... skipping." 
324343else 
@@ -334,9 +353,11 @@ echo
334353echo  " Normally, root should only be allowed to connect from 'localhost'.  This" 
335354echo  " ensures that someone cannot guess at the root password from the network." 
336355echo 
337- 
338- echo  $echo_n  " Disallow root login remotely? [Y/n] $echo_c " 
339- read  reply
356+ while  true  ;  do 
357+     echo  $echo_n  " Disallow root login remotely? [Y/n] $echo_c " 
358+     read  reply
359+     validate_reply $reply  &&  break 
360+ done 
340361if  [ " $reply "   =  " n"   ];  then 
341362    echo  "  ... skipping." 
342363else 
@@ -354,8 +375,12 @@ echo "access.  This is also intended only for testing, and should be removed"
354375echo  " before moving into a production environment." 
355376echo 
356377
357- echo  $echo_n  " Remove test database and access to it? [Y/n] $echo_c " 
358- read  reply
378+ while  true  ;  do 
379+     echo  $echo_n  " Remove test database and access to it? [Y/n] $echo_c " 
380+     read  reply
381+     validate_reply $reply  &&  break 
382+ done 
383+ 
359384if  [ " $reply "   =  " n"   ];  then 
360385    echo  "  ... skipping." 
361386else 
@@ -372,8 +397,12 @@ echo "Reloading the privilege tables will ensure that all changes made so far"
372397echo  " will take effect immediately." 
373398echo 
374399
375- echo  $echo_n  " Reload privilege tables now? [Y/n] $echo_c " 
376- read  reply
400+ while  true  ;  do 
401+     echo  $echo_n  " Reload privilege tables now? [Y/n] $echo_c " 
402+     read  reply
403+     validate_reply $reply  &&  break 
404+ done 
405+ 
377406if  [ " $reply "   =  " n"   ];  then 
378407    echo  "  ... skipping." 
379408else 
0 commit comments