#!/bin/sh ######################################################################## # Begin $rc_base/init.d/rc # # Description : Main RunLevel Control Script - Interactive Version # # Authors : Gerard Beekmans - gerard@linuxfromscratch.org # # Version : 00.00 # # Notes : # ######################################################################## . /etc/sysconfig/rc . ${rc_functions} # This sets a few default terminal options. stty sane # These 3 signals will not cause our script to exit trap "" INT QUIT TSTP [ "${1}" != "" ] && runlevel=${1} export runlevel # Begin addition for tmpfs #export BOOTLOGCACHE="" if [ "${runlevel}" = "sysinit" ]; then mount -n -t tmpfs tmpfs /media/boottemp -o mode=600 fi # End addition for tmpfs if [ "${runlevel}" = "" ] then echo "Usage: ${0} " >&2 exit 1 fi previous=${PREVLEVEL} [ "${previous}" = "" ] && previous=N # Begin addition for interactive starup. if [ "${runlevel}" != "sysinit" -a -f /media/boottemp/.interactive-start ]; then . /media/boottemp/.interactive-start fi if [ "${INTERACTIVE}" = "I" -a "${runlevel}" != "sysinit" -a \ "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then echo -n -e "Proceed with interactive starup of runlevel " echo -n -e "${INFO}${runlevel}${NORMAL}?" echo -n -e "(${FAILURE}y${NORMAL})es/(${FAILURE}n${NORMAL})o " read -n 1 go_on echo "" if [ "${go_on}" = "n" ]; then # don't continue exit 0 fi fi if [ "${runlevel}" = "sysinit" -a "${IPROMPT}" = "yes" ]; then ls -l /bin/sh | grep bash 2>&1 > /dev/null if [ "${?}" = "0" ]; then # Okay..we are using bash for the shell # so -t and -n are okay for read echo "" # DTAB is the amount of spaces needed to format the message # on the screen correctly. DTAB=$(( $(( ${COLUMNS} - ${DLEN} )) / 2 )) echo -e "\\033[${DTAB}G""Welcome to ${INFO}${DISTRO}" ITAB=$(( $(( ${COLUMNS} - ${ILEN} )) / 2 )) # The "Press 'I'" message is broken in two for readability here echo -n -e "\\033[${ITAB}G""${NORMAL}Press '${FAILURE}I${NORMAL}'" echo -e " to enter interactive startup" echo "" read -t ${ITIME} -n 1 INTERACTIVE 2> /dev/null export INTERACTIVE if [ "${INTERACTIVE}" = "I" ]; then echo -n -e "${CURS_UP}" echo -e "${INFO}Interactive mode selected...${NORMAL}" echo "INTERACTIVE=${INTERACTIVE}" echo "" fi fi fi # End addition for interactive startup if [ ! -d ${rc_base}/rc${runlevel}.d ] then boot_mesg "${rc_base}/rc${runlevel}.d does not exist." ${WARNING} boot_mesg_flush exit 1 fi # Attempt to stop all service started by previous runlevel, # and killed in this runlevel if [ "${previous}" != "N" ] then for i in $(ls -v ${rc_base}/rc${runlevel}.d/K* 2> /dev/null) do check_script_status suffix=${i#$rc_base/rc$runlevel.d/K[0-9][0-9]} prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix sysinit_start=$rc_base/rcsysinit.d/S[0-9][0-9]$suffix if [ "${runlevel}" != "0" ] && [ "${runlevel}" != "6" ] then if [ ! -f ${prev_start} ] && [ ! -f ${sysinit_start} ] then boot_log "${i} cant be started in runlevel ${runlevel}, because it was not started in runlevel ${previous}" boot_mesg -n "WARNING:\n\n${i} can't be" ${WARNING} boot_mesg -n " executed because it was not" boot_mesg -n " not started in the previous" boot_mesg -n " runlevel (${previous})." boot_mesg "" ${NORMAL} boot_mesg_flush continue fi fi ${i} stop error_value=${?} if [ "${error_value}" != "0" ] then print_error_msg fi done fi #Start all functions in this runlevel for i in $( ls -v ${rc_base}/rc${runlevel}.d/S* 2> /dev/null) do if [ "${previous}" != "N" ] then suffix=${i#$rc_base/rc$runlevel.d/S[0-9][0-9]} stop=$rc_base/rc$runlevel.d/K[0-9][0-9]$suffix prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue fi check_script_status case ${runlevel} in 0|6) ${i} stop ;; *) # Begin setup for interactive starup if [ "${INTERACTIVE}" = "I" ]; then echo -n -e "Start ${INFO}${i}${NORMAL} ? " echo -n -e "(${FAILURE}y${NORMAL})es/" echo -n -e "(${FAILURE}n${NORMAL})o " # Set startit variable to an unusable value startit="x" while [ "${startit}" != "y" -a \ "${startit}" != "n" ]; do read -n 1 startit > /dev/null done if [ "${startit}" = "y" ]; then echo "" ${i} start echo "" else echo "" echo -e "Not starting ${INFO}${i}${NORMAL}!" echo "" fi unset startit unset testsok else # Non-Interactive Startup ${i} start fi ;; esac error_value=${?} if [ "${error_value}" != "0" ] then print_error_msg fi done # Begin addition #3 for interactive starup if [ "${INTERACTIVE}" = "I" ]; then # Insert check for writeable /tmp here echo "INTERACTIVE='I'" > /media/boottemp/.interactive-start 2> /dev/null else # Clear any existing file rm -f /media/boottemp/.interactive-start 2>&1 > /dev/null fi # End addition #3 for interactive startup # Begin addition for inital bootlog if [ "${runlevel}" = "sysinit" ]; then BTIMESPEC=$(echo `date +"%b %d %T"` `hostname`) cat /media/boottemp/.logcache | sed "s@bootlog:@${BTIMESPEC} bootlog:@g" >> /var/log/boot.log rm -f /media/boottemp/.logcache fi # End addition for inital bootlog # Begin addition for tmpfs if [ "${runlevel}" != "sysinit" ]; then # Check to see if our temporary filesystem is mounted mount | grep boottemp 2>&1 > /dev/null if [ "$?" -eq "0" ]; then umount /media/boottemp fi fi # End addition for tempfs # End $rc_base/init.d/rc