Date: Wed, 15 Nov 2006 20:43:41 +0100 From: "Pietro Cerutti" <pietro.cerutti@gmail.com> To: freebsd-rc@freebsd.org Subject: PR 105568 Message-ID: <e572718c0611151143x434dbf4cjc867ef630c2c989@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Hello list,
I submitted a follow-up to [my own] PR 105568, here's the patch.
It sets a timeout of 5s and default answer of yes in rc.subr. After
the timeout has elapsed, the default answer will be taken as good, if
the user hasn't already chosen.
Furthermore, it allows setting per-daemon timeouts and default answers, with
DAEMON_ask_timeout={0-9}[s|m|h]
DAEMON_ask_default=[yes|no]
Ideas, feedback, .... welcome!
Please CC me since I'm not on the list
Reagards
--
Pietro Cerutti
ICQ: 117293691
PGP: 0x9571F78E
- ASCII Ribbon Campaign -
against HTML e-mail and
proprietary attachments
www.asciiribbon.org
[-- Attachment #2 --]
--- /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
;;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e572718c0611151143x434dbf4cjc867ef630c2c989>
