LFS-Hint: Interactive boot scripts

Simon Perreault nomis80 at yahoo.com
Thu Aug 3 08:22:57 PDT 2000


Paul, please put this in the hints section. Put the attached binary file
in the hints section too.

-----------------------------------------
Interactive boot scripts

Purpose: When rcS is run, it prints "Press I for interactive startup".
If the user presses I, he has to confirm everything that happens in the
rc script, and can then choose which things are run and which are not.
This was inspired by RedHat 6.2's interactive bootscripts.

How to do it:
First of all, a C program is used to get the key pressed during the rcS
script. I yanked it from RedHat, and should be found at
http://www.pcrdallas.com/docs/lfs-hints/getkey. Get this file, and put
it under /sbin.

We must then modify four scripts: rcS, rc, functions, and then ethnet.

rcS:
After "trap ":"  INT QUIT TSTP", insert a line containing the following:
"echo -e "\t\tPress I to get into interactive startup"". Then, after the
final "done", insert these lines:
( sleep 1 ; running=$(/bin/ps -x | /usr/bin/grep getkey) ; [ "$running"
= "" ] || /bin/kill -TERM `/bin/pidof getkey` >/dev/null 2>&1 ) &
/sbin/getkey i && ( echo -e "\t\tEntering interactive startup" ; touch
/var/run/interactive )

rc:
Before the startup() function, insert these lines:
. /etc/init.d/functions

if [ "$STOP" = "y" ]
then
	STOP = ""
	exit 0
fi

Then, after the final "fi", insert these lines:
rm -f /var/run/interactive >/dev/null 2>&1
rm -r /var/run/stop >/dev/null 2>&1

functions:
In the "print_status" function, you can see two cases: success, and
failure. Add another one, before the "esac", that should look like this:
	cancelled)
		$SET_COL
		echo -n "["
		$FAILURE
		echo -n "CANCEL"
		$NORMAL
		echo "]"
		;;

In the "loadproc" function, add "action" before "$*" so that it looks
like "action $*".

After the "statusproc" function, enter these lines (this is long):
confirm()
{
	[ -f /var/run/stop ] && return 1
	[ ! -f /var/run/interactive ] && return 0
	echo ""
	echo "If you want explanations about the choices you have, press h"
	echo -n "Do you want me to run $* ? (n/[y]/N/Y)"
	read answer
	case $answer in
		y|"")
			return 0
			;;
		n)
			return 1
			;;
		Y)
			return 2
			;;
		N)
			return 3
			;;
		h)
			return 4
			;;
		*)
			return 5
			;;
	esac
}

action()
{
	confirm $*
	case "$?" in
		0)
			$*
			evaluate_retval
			;;
		1)
			print_status cancelled
			return 0
			;;
		2)
			rm -f /var/run/interactive	
			$*
			evaluate_retval
			;;
		3)
			rm -f /var/run/interactive
			touch /var/run/stop
			print_status cancelled
			return 0
			;;
		4)
			echo ""
			echo ""
			echo "The available choices are:"
			echo "	y: run this process"
			echo "	n: do not run this process"
			echo "	Y: run this process and don't ask this question again"
			echo "	N: don't run this process and don't run any following
processes"
			echo "Now, let me ask that question again:"
			action $*
			return $?
			;;
		5)
			echo ""
			echo "Please enter one of those: n, y, N, Y, h"
			action $*
			return $?
			;;
	esac
}



ethnet:
In the "start" case, add "action" before "/sbin/ifconfig [...]", and
remove the "evaluate_retval" below it. Do this for each bootscript that
does not use the "loadproc" function, that is run at startup, and that
you wish to be asked for confirmation if you press the I key.

I hope I haven't forgotten anything. Send bugs, question, etc, to
nomis80 at yahoo.com.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: getkey
Type: application/octet-stream
Size: 3120 bytes
Desc: not available
URL: <http://lists.linuxfromscratch.org/pipermail/lfs-dev/attachments/20000803/c6c7630c/attachment.obj>


More information about the lfs-dev mailing list