minix/etc/rc

231 lines
4.8 KiB
Text
Raw Normal View History

2005-04-21 16:53:53 +02:00
# /etc/rc - System startup script run by init before going multiuser.
exec >/dev/log
exec 2>/dev/log
exec </dev/null
2005-04-21 16:53:53 +02:00
umask 022
TERM="${TERM-minix}"
2010-07-16 02:44:57 +02:00
PATH=/usr/local/bin:/bin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/llvm/bin
RC_TZ=/etc/rc.timezone
2005-04-21 16:53:53 +02:00
export TERM PATH
usage()
{
echo >&2 "Usage: $0 [-saf] start|stop|down"
exec intr sh
}
up()
{
# Function to dynamically start a system service
opt=""
prefix=$(expr "$1 " : '\(-\)')
if [ "$prefix" = "-" ];
then
opt=$1
shift
fi
service=$1
2005-11-28 16:39:01 +01:00
shift
service $opt up /sbin/$service "$@"
}
edit()
{
# Function to dynamically edit system service settings
opt=""
prefix=$(expr "$1 " : '\(-\)')
if [ "$prefix" = "-" ];
then
opt=$1
shift
fi
service=$1
shift
# Assume binaries are always in /usr/sbin
service $opt edit /usr/sbin/$service -label $service "$@"
}
2005-04-21 16:53:53 +02:00
while getopts 'saf' opt
do
case $opt in
s) sflag=t ;; # Single user
a) aflag=t ;; # Ask for /usr
f) fflag=t ;; # Force a full file system check
*) usage
esac
done
shift `expr $OPTIND - 1`
case "$#:$1" in
1:start|1:stop|1:down)
action=$1
;;
*) usage
esac
case $action in
start)
echo -n "Multiuser startup in progress ..."
2005-04-21 16:53:53 +02:00
# National keyboard?
test -f /etc/keymap && loadkeys /etc/keymap
# options for fsck. default is -r, which prompts the user for repairs.
fsckopts="`sysenv fsckopts`"
if [ ! "$fsckopts" ]
then fsckopts=-r
fi
if [ "`sysenv debug_fkeys`" != 0 ]
then
up -n is -period 5HZ
fi
echo
2005-04-21 16:53:53 +02:00
# Set timezone.
export TZ=GMT0
if [ -f "$RC_TZ" ]
then . "$RC_TZ"
fi
2005-04-21 16:53:53 +02:00
# Try to read the hardware real-time clock, otherwise do it manually.
readclock || intr date -q
# Initialize files.
printroot >/etc/mtab # /etc/mtab keeps track of mounts
>/etc/utmp # /etc/utmp keeps track of logins
# /etc/fstab lists the root, tmp and usr devices.
. /etc/fstab
2010-01-21 10:58:07 +01:00
# Unmount now defunct ramdisk
umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk"
# Use MFS binary only from kernel image?
if [ "`sysenv bin_img`" = 1 ]
then
bin_img="-i "
fi
# Are we booting from CD?
bootcd="`/bin/sysenv bootcd`"
# If booting from CD, /usr has to be mounted readonly.
# Also, $usr won't be specified correctly in the
# fstab (the CD could be anywhere), so we decide
# where it is based on sysenv (set by FS when probing for CD).
if [ "$bootcd" = 1 ]
then
#imagedev="`/bin/sysenv cdproberoot`"
#usrdev="`expr $imagedev + 1`"
usr_roflag="-r"
usr="$cddev"p2
echo "Setting /usr on cd is $usr"
fi
2005-04-21 16:53:53 +02:00
# Mount the /usr partition unless this is a single floppy Minix.
if [ ! -d /usr/bin ]
then
if [ "$aflag" -o "$usr" = unknown ]
then
# We need to ask what the /usr du jour is.
intr sh -c '
echo -n "Finish the name of device to mount as /usr: /dev/"
read usr
echo "usr=/dev/$usr" >/tmp/usr'
. /tmp/usr
fi
mount $bin_img $usr_roflag $usr /usr || {
2005-04-21 16:53:53 +02:00
echo "\
Please try to mount something else as /usr, then hit CTRL-D to continue startup.
Mount $usr /usr failed -- Single user."
intr sh
}
rm -f /tmp/usr
fi
# Check if the system crashed.
if shutdown -C
then
echo
echo "The system was not properly shut down. Checking file systems."
fflag=t
fi
if [ "$fflag" ]
then
umount $usr
2005-10-04 16:35:36 +02:00
echo "fsck / - $root"
intr fsck $fsckopts $root
2005-10-04 16:35:36 +02:00
echo "fsck /usr - $usr"
intr fsck $fsckopts $usr
2005-08-31 18:29:56 +02:00
if [ ! -z "$home" ]
2005-10-04 16:35:36 +02:00
then echo "fsck /home - $home"
intr fsck $fsckopts $home
2005-08-31 18:29:56 +02:00
fi
mount $bin_img $usr /usr
2005-09-01 18:26:22 +02:00
fi
# Edit settings for boot system services
if [ "`sysenv skip_boot_config`" != 1 ]
then
edit rs
edit vm
edit pm
edit sched
edit vfs
edit ds
edit tty
edit memory
edit -p log
edit -c pfs
edit init
fi
2005-09-01 18:26:22 +02:00
if [ ! -z "$home" ]
then mount $bin_img $home /home || echo "WARNING: couldn't mount $home on /home"
2005-04-21 16:53:53 +02:00
fi
# This file is necessary for above 'shutdown -C' check.
# (Silence stderr in case of running from cd.)
touch /usr/adm/wtmp 2>/dev/null
2005-04-21 16:53:53 +02:00
if [ "$sflag" ]
then
echo "Single user."
intr sh
fi
case "`printroot -r`":$bootcd in
/dev/ram:)
# Remove boot-only things to make space,
# unless booting from CD, in which case we need them.
rm -rf /boot
# put the compiler on ram
cp /usr/lib/em* /usr/lib/cpp* /lib
2005-04-21 16:53:53 +02:00
esac
# Things should be alright now.
;;
down|stop)
sync
# Tell RS server we're going down.
service shutdown
;;
2005-04-21 16:53:53 +02:00
esac
# Further initialization.
test -f /usr/etc/rc && sh /usr/etc/rc $action
test -f /usr/local/etc/rc && sh /usr/local/etc/rc $action
# Any messages?
test "$action" = start -a -f /etc/issue && cat /etc/issue
2005-08-31 18:29:56 +02:00
2005-04-21 16:53:53 +02:00
exit 0