#!/bin/sh

pr_basename=`basename $0`

runlevel=$RUNLEVEL
previous=$PREVLEVEL

if [ -w /proc/progress ] && [ "$previous" = "N" ]; then
	# Get the number and the name of the service
	pr_num=`echo $pr_basename | sed 's/.*S\([0-9][0-9]\).*/\1/'`
	pr_name=`echo $pr_basename | sed 's/.*S[0-9][0-9]//'`

	# Change the 00-99 value to a 75-100 one
	pr_value=$(($pr_num/4+75))

	# Get the text to display for the current service
	pr_text=`cat /etc/progress.dat | sed --silent "s/$pr_name //p"`

	# If there is something to display, go ahead!
	if [ -n "$pr_text" ]; then
		echo $pr_value $pr_text > /proc/progress
	fi
fi

# Basic functions used in rc.sysinit (and can be used in each service script)

function pr_warn()
{
	if [ -w /proc/progress ]; then
		echo w > /proc/progress
	fi
}


function pr_fail()
{
	if [ -w /proc/progress ]; then
		echo f > /proc/progress
	fi
}

 
function pr_set()
{
	if [ -w /proc/progress ]; then
		echo $1 $2 > /proc/progress
	fi
}

