1# /etc/rc - System startup script run by init before going multiuser. 2 3exec >/dev/log 4exec 2>/dev/log 5exec </dev/null 6 7umask 022 8FSTAB=/etc/fstab 9TERM="${TERM-minix}" 10PATH=/usr/local/bin:/bin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/sbin 11RC_TZ=/etc/rc.timezone 12export TERM PATH 13 14ARCH="`sysenv arch`" 15 16if [ ! "$ARCH" ] 17then # Older kernels do not provide an arch sysenv variable. 18 # We assume we are on x86 then, as existing systems with 19 # kernel and userland (i.e. this script) unsynchronized 20 # will be x86. 21 ARCH=i386 22fi 23 24usage() 25{ 26 echo >&2 "Usage: $0 [-saf] start|stop|down" 27 exec intr sh 28} 29 30up() 31{ 32 # Function to dynamically start a system service 33 opt="" 34 prefix=$(expr "$1 " : '\(-\)') 35 if [ "$prefix" = "-" ]; 36 then 37 opt=$1 38 shift 39 fi 40 service=$1 41 shift 42 43 service $opt up /sbin/$service "$@" 44} 45 46edit() 47{ 48 # Function to dynamically edit system service settings 49 opt="" 50 prefix=$(expr "$1 " : '\(-\)') 51 if [ "$prefix" = "-" ]; 52 then 53 opt=$1 54 shift 55 fi 56 service=$1 57 shift 58 59 # Assume binaries are always in /usr/sbin 60 service $opt edit /usr/sbin/$service -label $service "$@" 61} 62 63# This function parses the deprecated minix shellscript-style 64# /etc/fstab, and fscks and mounts its filesystems. 65mountfstab_poorman() 66{ 67 echo "WARNING: old fstab format, please upgrade!" 68 69 # /etc/fstab lists the root, home, and usr devices. 70 . $FSTAB 71 72 intr fsck.mfs $fsckopts $usr 73 if [ ! -z "$home" ] 74 then intr fsck.mfs $fsckopts $home 75 fi 76 77 # mount /usr 78 mount $bin_img $usr /usr 79 80 if [ ! -z "$home" ] 81 then mount $bin_img $home /home || echo "WARNING: couldn't mount $home on /home" 82 fi 83} 84 85while getopts 'saf' opt 86do 87 case $opt in 88 s) sflag=t ;; # Single user 89 a) aflag=t ;; # Ask for /usr 90 f) fflag=-f ;; # Force a full file system check 91 *) usage 92 esac 93done 94shift `expr $OPTIND - 1` 95 96case "$#:$1" in 971:start|1:stop|1:down) 98 action=$1 99 ;; 100*) usage 101esac 102 103case $action in 104start) 105 106 # National keyboard? 107 test -f /etc/keymap && loadkeys /etc/keymap 108 109 # options for fsck. default is -r, which prompts the user for repairs. 110 optname=fsckopts 111 fsckopts=-p 112 if sysenv $optname >/dev/null 113 then fsckopts="`sysenv $optname`" 114 fi 115 116 if [ "`sysenv debug_fkeys`" != 0 ] 117 then 118 up -n is -period 5HZ 119 fi 120 121 # Set timezone. 122 export TZ=GMT0 123 if [ -f "$RC_TZ" ] 124 then . "$RC_TZ" 125 fi 126 127 # Start real time clock driver & set system time, otherwise default date. 128 up readclock.drv 129 readclock -q || date 201301010000 130 131 # Initialize files. 132 >/etc/utmp # /etc/utmp keeps track of logins 133 134 # Use MFS binary only from kernel image? 135 if [ "`sysenv bin_img`" = 1 ] 136 then 137 bin_img="-i " 138 fi 139 140 # Are we booting from CD? 141 bootcd="`/bin/sysenv bootcd`" 142 143 # If booting from CD, mounting is a special case. 144 # We know what to do - only /usr is mounted and it's readonly. 145 if [ "$bootcd" = 1 ] 146 then usrdev="$cddev"p2 147 echo "/usr on cd is $usrdev" 148 mount -r $usrdev /usr 149 else 150 # If we're not booting from CD, fsck + mount using /etc/fstab. 151 read <$FSTAB fstabline 152 if [ "$fstabline" = "# Poor man's File System Table." ] 153 then mountfstab_poorman # Old minix /etc/fstab 154 else fsck -x / $fflag $fsckopts 155 mount -a 156 fi 157 fi 158 159 # Unmount and free now defunct ramdisk 160 umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk" 161 ramdisk 0 /dev/imgrd || echo "Failed to free boot ramdisk" 162 163 # Edit settings for boot system services 164 if [ "`sysenv skip_boot_config`" != 1 ] 165 then 166 edit rs 167 edit vm 168 edit pm 169 edit sched 170 edit vfs 171 edit ds 172 edit tty 173 edit memory 174 edit pfs 175 edit init 176 fi 177 178 # This file is necessary for above 'shutdown -C' check. 179 # (Silence stderr in case of running from cd.) 180 touch /usr/adm/wtmp /etc/wtmp 2>/dev/null 181 182 if [ "$sflag" ] 183 then 184 echo "Single user. Press ^D to resume multiuser startup." 185 intr sh 186 echo 187 fi 188 189 echo "Multiuser startup in progress ..." 190 191 case "`printroot -r`":$bootcd in 192 /dev/ram:) 193 # Remove boot-only things to make space, 194 # unless booting from CD, in which case we need them. 195 rm -rf /boot 196 # put the compiler on ram 197 cp /usr/lib/em* /usr/lib/cpp* /lib 198 esac 199 200 if [ $ARCH = i386 ] 201 then 202 echo -n "Starting hotplugging infrastructure... " 203 rm -f /var/run/devmand.pid 204 devmand -d /etc/devmand -d /usr/pkg/etc/devmand & 205 echo "done." 206 fi 207 208 # Things should be alright now. 209 ;; 210down|stop) 211 sync 212 if [ $ARCH = i386 ] 213 then 214 if [ -f /var/run/devmand.pid ] 215 then 216 kill -INT `cat /var/run/devmand.pid` 217 # without this delay the following will 218 # be printed in the console 219 # RS: devman not running? 220 sleep 1 221 fi 222 # 223 # usbd needs to be stopped exactly 224 # at this stage(before stopping devman 225 # and after stopping the services 226 # stated by devmand) 227 if [ -x /usr/pkg/etc/rc.d/usbd ] 228 then 229 /usr/pkg/etc/rc.d/usbd stop 230 fi 231 fi 232 233 # Tell RS server we're going down. 234 service shutdown 235 ;; 236esac 237 238# Further initialization. 239test -f /usr/etc/rc && sh /usr/etc/rc $action 240test -f /usr/local/etc/rc && sh /usr/local/etc/rc $action 241 242# Any messages? 243test "$action" = start -a -f /etc/issue && cat /etc/issue 244 245exit 0 246