| [163a6701] | 1 | #!/bin/sh | 
|---|
|  | 2 | ######################################################################## | 
|---|
|  | 3 | # Begin $rc_base/init.d/rc | 
|---|
|  | 4 | # | 
|---|
|  | 5 | # Description : Main RunLevel Control Script - Interactive Version | 
|---|
|  | 6 | # | 
|---|
|  | 7 | # Authors     : Gerard Beekmans - gerard@linuxfromscratch.org | 
|---|
|  | 8 | # | 
|---|
|  | 9 | # Version     : 00.00 | 
|---|
|  | 10 | # | 
|---|
|  | 11 | # Notes       : | 
|---|
|  | 12 | # | 
|---|
|  | 13 | ######################################################################## | 
|---|
|  | 14 |  | 
|---|
|  | 15 | . /etc/sysconfig/rc | 
|---|
|  | 16 | . ${rc_functions} | 
|---|
|  | 17 |  | 
|---|
|  | 18 | # This sets a few default terminal options. | 
|---|
|  | 19 | stty sane | 
|---|
|  | 20 |  | 
|---|
|  | 21 | # These 3 signals will not cause our script to exit | 
|---|
|  | 22 | trap "" INT QUIT TSTP | 
|---|
|  | 23 |  | 
|---|
|  | 24 | [ "${1}" != "" ] && runlevel=${1} | 
|---|
|  | 25 | export runlevel | 
|---|
|  | 26 |  | 
|---|
|  | 27 | # Begin addition for tmpfs | 
|---|
|  | 28 | #export BOOTLOGCACHE="" | 
|---|
|  | 29 | if [ "${runlevel}" = "sysinit" ]; then | 
|---|
|  | 30 | mount -n -t tmpfs tmpfs /media/boottemp -o mode=600 | 
|---|
|  | 31 | fi | 
|---|
|  | 32 | # End addition for tmpfs | 
|---|
|  | 33 |  | 
|---|
|  | 34 | if [ "${runlevel}" = "" ] | 
|---|
|  | 35 | then | 
|---|
|  | 36 | echo "Usage: ${0} <runlevel>" >&2 | 
|---|
|  | 37 | exit 1 | 
|---|
|  | 38 | fi | 
|---|
|  | 39 |  | 
|---|
|  | 40 | previous=${PREVLEVEL} | 
|---|
|  | 41 | [ "${previous}" = "" ] && previous=N | 
|---|
|  | 42 |  | 
|---|
|  | 43 | # Begin addition for interactive starup. | 
|---|
|  | 44 | if [ "${runlevel}" != "sysinit" -a -f /media/boottemp/.interactive-start ]; then | 
|---|
|  | 45 | . /media/boottemp/.interactive-start | 
|---|
|  | 46 | fi | 
|---|
|  | 47 |  | 
|---|
|  | 48 | if [ "${INTERACTIVE}" = "I" -a "${runlevel}" != "sysinit" -a \ | 
|---|
|  | 49 | "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then | 
|---|
|  | 50 | echo -n -e "Proceed with interactive starup of runlevel " | 
|---|
|  | 51 | echo -n -e "${INFO}${runlevel}${NORMAL}?" | 
|---|
|  | 52 | echo -n -e "(${FAILURE}y${NORMAL})es/(${FAILURE}n${NORMAL})o " | 
|---|
|  | 53 | read -n 1 go_on | 
|---|
|  | 54 | echo "" | 
|---|
|  | 55 | if [ "${go_on}" = "n" ]; then | 
|---|
|  | 56 | # don't continue | 
|---|
|  | 57 | exit 0 | 
|---|
|  | 58 | fi | 
|---|
|  | 59 | fi | 
|---|
|  | 60 |  | 
|---|
|  | 61 | if [ "${runlevel}" = "sysinit" -a "${IPROMPT}" = "yes" ]; then | 
|---|
|  | 62 | ls -l /bin/sh | grep bash 2>&1 > /dev/null | 
|---|
|  | 63 | if [ "${?}" = "0" ]; then | 
|---|
|  | 64 | # Okay..we are using bash for the shell | 
|---|
|  | 65 | # so -t and -n are okay for read | 
|---|
|  | 66 | echo "" | 
|---|
|  | 67 | # DTAB is the amount of spaces needed to format the message | 
|---|
|  | 68 | # on the screen correctly. | 
|---|
|  | 69 | DTAB=$(( $(( ${COLUMNS} - ${DLEN} )) / 2 )) | 
|---|
|  | 70 | echo -e "\\033[${DTAB}G""Welcome to ${INFO}${DISTRO}" | 
|---|
|  | 71 | ITAB=$(( $(( ${COLUMNS} - ${ILEN} )) / 2 )) | 
|---|
|  | 72 | # The "Press 'I'" message is broken in two for readability here | 
|---|
|  | 73 | echo -n -e "\\033[${ITAB}G""${NORMAL}Press '${FAILURE}I${NORMAL}'" | 
|---|
|  | 74 | echo -e " to enter interactive startup" | 
|---|
|  | 75 | echo "" | 
|---|
|  | 76 | read -t ${ITIME} -n 1 INTERACTIVE 2> /dev/null | 
|---|
|  | 77 | export INTERACTIVE | 
|---|
|  | 78 | if [ "${INTERACTIVE}" = "I" ]; then | 
|---|
|  | 79 | echo -n -e "${CURS_UP}" | 
|---|
|  | 80 | echo -e "${INFO}Interactive mode selected...${NORMAL}" | 
|---|
|  | 81 | echo "INTERACTIVE=${INTERACTIVE}" | 
|---|
|  | 82 | echo "" | 
|---|
|  | 83 | fi | 
|---|
|  | 84 | fi | 
|---|
|  | 85 | fi | 
|---|
|  | 86 |  | 
|---|
|  | 87 | # End addition for interactive startup | 
|---|
|  | 88 |  | 
|---|
|  | 89 | if [ ! -d ${rc_base}/rc${runlevel}.d ] | 
|---|
|  | 90 | then | 
|---|
|  | 91 | boot_mesg "${rc_base}/rc${runlevel}.d does not exist." ${WARNING} | 
|---|
|  | 92 | boot_mesg_flush | 
|---|
|  | 93 | exit 1 | 
|---|
|  | 94 | fi | 
|---|
|  | 95 |  | 
|---|
|  | 96 | # Attempt to stop all service started by previous runlevel, | 
|---|
|  | 97 | # and killed in this runlevel | 
|---|
|  | 98 | if [ "${previous}" != "N" ] | 
|---|
|  | 99 | then | 
|---|
|  | 100 | for i in $(ls -v ${rc_base}/rc${runlevel}.d/K* 2> /dev/null) | 
|---|
|  | 101 | do | 
|---|
|  | 102 | check_script_status | 
|---|
|  | 103 |  | 
|---|
|  | 104 | suffix=${i#$rc_base/rc$runlevel.d/K[0-9][0-9]} | 
|---|
|  | 105 | prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix | 
|---|
|  | 106 | sysinit_start=$rc_base/rcsysinit.d/S[0-9][0-9]$suffix | 
|---|
|  | 107 |  | 
|---|
|  | 108 | if [ "${runlevel}" != "0" ] && [ "${runlevel}" != "6" ] | 
|---|
|  | 109 | then | 
|---|
|  | 110 | if [ ! -f ${prev_start} ] && [ ! -f ${sysinit_start} ] | 
|---|
|  | 111 | then | 
|---|
|  | 112 | boot_log "${i} cant be started in runlevel ${runlevel}, because it was not started in runlevel ${previous}" | 
|---|
|  | 113 | boot_mesg -n "WARNING:\n\n${i} can't be" ${WARNING} | 
|---|
|  | 114 | boot_mesg -n " executed because it was not" | 
|---|
|  | 115 | boot_mesg -n " not started in the previous" | 
|---|
|  | 116 | boot_mesg -n " runlevel (${previous})." | 
|---|
|  | 117 | boot_mesg "" ${NORMAL} | 
|---|
|  | 118 | boot_mesg_flush | 
|---|
|  | 119 | continue | 
|---|
|  | 120 | fi | 
|---|
|  | 121 | fi | 
|---|
|  | 122 | ${i} stop | 
|---|
|  | 123 | error_value=${?} | 
|---|
|  | 124 |  | 
|---|
|  | 125 | if [ "${error_value}" != "0" ] | 
|---|
|  | 126 | then | 
|---|
|  | 127 | print_error_msg | 
|---|
|  | 128 | fi | 
|---|
|  | 129 | done | 
|---|
|  | 130 | fi | 
|---|
|  | 131 |  | 
|---|
|  | 132 | #Start all functions in this runlevel | 
|---|
|  | 133 | for i in $( ls -v ${rc_base}/rc${runlevel}.d/S* 2> /dev/null) | 
|---|
|  | 134 | do | 
|---|
|  | 135 | if [ "${previous}" != "N" ] | 
|---|
|  | 136 | then | 
|---|
|  | 137 | suffix=${i#$rc_base/rc$runlevel.d/S[0-9][0-9]} | 
|---|
|  | 138 | stop=$rc_base/rc$runlevel.d/K[0-9][0-9]$suffix | 
|---|
|  | 139 | prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix | 
|---|
|  | 140 |  | 
|---|
|  | 141 | [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue | 
|---|
|  | 142 | fi | 
|---|
|  | 143 |  | 
|---|
|  | 144 | check_script_status | 
|---|
|  | 145 |  | 
|---|
|  | 146 | case ${runlevel} in | 
|---|
|  | 147 | 0|6) | 
|---|
|  | 148 | ${i} stop | 
|---|
|  | 149 | ;; | 
|---|
|  | 150 | *) | 
|---|
|  | 151 | # Begin setup for interactive starup | 
|---|
|  | 152 | if [ "${INTERACTIVE}" = "I" ]; then | 
|---|
|  | 153 | echo -n -e "Start ${INFO}${i}${NORMAL} ? " | 
|---|
|  | 154 | echo -n -e "(${FAILURE}y${NORMAL})es/" | 
|---|
|  | 155 | echo -n -e "(${FAILURE}n${NORMAL})o " | 
|---|
|  | 156 |  | 
|---|
|  | 157 | # Set startit variable to an unusable value | 
|---|
|  | 158 | startit="x" | 
|---|
|  | 159 | while [ "${startit}" != "y" -a \ | 
|---|
|  | 160 | "${startit}" != "n" ]; do | 
|---|
|  | 161 | read -n 1 startit > /dev/null | 
|---|
|  | 162 | done | 
|---|
|  | 163 |  | 
|---|
|  | 164 | if [ "${startit}" = "y" ]; then | 
|---|
|  | 165 | echo "" | 
|---|
|  | 166 | ${i} start | 
|---|
|  | 167 | echo "" | 
|---|
|  | 168 | else | 
|---|
|  | 169 | echo "" | 
|---|
|  | 170 | echo -e "Not starting ${INFO}${i}${NORMAL}!" | 
|---|
|  | 171 | echo "" | 
|---|
|  | 172 | fi | 
|---|
|  | 173 | unset startit | 
|---|
|  | 174 | unset testsok | 
|---|
|  | 175 | else | 
|---|
|  | 176 | # Non-Interactive Startup | 
|---|
|  | 177 | ${i} start | 
|---|
|  | 178 | fi | 
|---|
|  | 179 | ;; | 
|---|
|  | 180 | esac | 
|---|
|  | 181 | error_value=${?} | 
|---|
|  | 182 |  | 
|---|
|  | 183 | if [ "${error_value}" != "0" ] | 
|---|
|  | 184 | then | 
|---|
|  | 185 | print_error_msg | 
|---|
|  | 186 | fi | 
|---|
|  | 187 |  | 
|---|
|  | 188 | done | 
|---|
|  | 189 |  | 
|---|
|  | 190 | # Begin addition #3 for interactive starup | 
|---|
|  | 191 | if [ "${INTERACTIVE}" = "I" ]; then | 
|---|
|  | 192 | # Insert check for writeable /tmp here | 
|---|
|  | 193 | echo "INTERACTIVE='I'" > /media/boottemp/.interactive-start 2> /dev/null | 
|---|
|  | 194 | else | 
|---|
|  | 195 | # Clear any existing file | 
|---|
|  | 196 | rm -f /media/boottemp/.interactive-start 2>&1 > /dev/null | 
|---|
|  | 197 | fi | 
|---|
|  | 198 | # End addition #3 for interactive startup | 
|---|
|  | 199 |  | 
|---|
|  | 200 | # Begin addition for inital bootlog | 
|---|
|  | 201 | if [ "${runlevel}" = "sysinit" ]; then | 
|---|
|  | 202 | BTIMESPEC=$(echo `date +"%b %d %T"` `hostname`) | 
|---|
|  | 203 | cat /media/boottemp/.logcache | sed "s@bootlog:@${BTIMESPEC} bootlog:@g" >> /var/log/boot.log | 
|---|
|  | 204 | rm -f /media/boottemp/.logcache | 
|---|
|  | 205 | fi | 
|---|
|  | 206 | # End addition for inital bootlog | 
|---|
|  | 207 |  | 
|---|
|  | 208 | # Begin addition for tmpfs | 
|---|
|  | 209 | if [ "${runlevel}" != "sysinit" ]; then | 
|---|
|  | 210 | # Check to see if our temporary filesystem is mounted | 
|---|
|  | 211 | mount | grep boottemp 2>&1 > /dev/null | 
|---|
|  | 212 | if [ "$?" -eq "0" ]; then | 
|---|
|  | 213 | umount /media/boottemp | 
|---|
|  | 214 | fi | 
|---|
|  | 215 | fi | 
|---|
|  | 216 | # End addition for tempfs | 
|---|
|  | 217 |  | 
|---|
|  | 218 | # End $rc_base/init.d/rc | 
|---|