conf/105568: [patch] Add more flexibility to rc.conf, to choose "_enable" values at startup

Pietro Cerutti pietro.cerutti at gmail.com
Wed Nov 15 21:50:26 UTC 2006


The following reply was made to PR conf/105568; it has been noted by GNATS.

From: "Pietro Cerutti" <pietro.cerutti at gmail.com>
To: bug-followup at freebsd.org
Cc:  
Subject: Re: conf/105568: [patch] Add more flexibility to rc.conf, to choose "_enable" values at startup
Date: Wed, 15 Nov 2006 22:49:17 +0100

 The patch is inline:
 
 --- /etc/rc.subr.orig	Wed Nov 15 14:03:59 2006
 +++ /etc/rc.subr	Wed Nov 15 20:10:32 2006
 @@ -56,6 +56,8 @@
  ID="/usr/bin/id"
  JID=`ps -p $$ -o jid=`
  IDCMD="if [ -x $ID ]; then $ID -un; fi"
 +ASK_TIMEOUT="5s"
 +ASK_DEFAULT="YES"
 
  case ${OSTYPE} in
  FreeBSD)
 @@ -122,7 +124,8 @@
 
  #
  # checkyesno var
 -#	Test $1 variable, and warn if not set to YES or NO.
 +#	Test $1 variable, and warn if not set to YES, NO or ASK.
 +#	If it's "ask", let the user choose at runtime between "yes" and "no".
  #	Return 0 if it's "yes" (et al), nonzero otherwise.
  #
  checkyesno()
 @@ -140,7 +143,52 @@
  	[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
  		return 1
  		;;
 -	*)
 +
 +      # "ask"
 +	[Aa][Ss][Kk])
 +
 +      # answer already stored in .ask file,
 +      # this should be the case on shutdown
 +      _file="/var/run/$name.ask"
 +      if [ -f $_file ]; then
 +         read _response < $_file
 +         if checkyesno _response; then
 +            return 0
 +         else
 +            return 1
 +         fi
 +      fi
 +      # prompt and save choice to file,
 +      # this should be the case on startup
 +
 +      # Read timeout and default answer for daemon
 +      eval _timeout=\$${name}_ask_timeout
 +      eval _response=\$${name}_ask_default
 +
 +      if [ ! $_timeout ]; then
 +         _timeout=$ASK_TIMEOUT
 +      fi
 +
 +      if [ ! $_response ]; then
 +         _response=$ASK_DEFAULT
 +      fi
 +
 +      read -t $_timeout -p "RC_ASK - Enable $name? [yes|no] " _enable
 +      if [ $? -eq 1 ]; then
 +         _enable=${_response}
 +      fi
 +      if checkyesno _enable; then
 +         _choice="yes"
 +         _return=0
 +      else
 +         _choice="no"
 +         _return=1
 +      fi
 +      echo "$_choice" > $_file
 +      return  $_return;
 +      ;;
 +
 +   *)
  		warn "\$${1} is not set properly - see ${rcvar_manpage}."
  		return 1
  		;;


More information about the freebsd-rc mailing list