view core/rc/rc.init @ 694:2bac0c29807f

core/rc: improve messages and fix deletion
author David Demelier <markand@malikania.fr>
date Thu, 01 Aug 2019 21:20:00 +0200
parents 58211c615a8c
children b7264d4a5172
line wrap: on
line source

#!/bin/sh
#
# /etc/rc.init -- system initialization script
#
# Copyright (c) 2019 David Demelier <markand@malikania.fr>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

if [ -f /etc/rc.conf ]; then
	. /etc/rc.conf
fi

if [ "${BANNER:-yes}" = "yes" ]; then
	printf "\nWelcome to \033[33;1mVanilla Linux\033[0m\n\n"
fi

if [ -n "$HOSTNAME" ]; then
	echo "Setting hostname: $HOSTNAME"
	hostname "$HOSTNAME"
fi

echo "Setting kernel parameters."
sysctl -p >/dev/null 2>&1

echo -n "Mounting filesystems: "

if ! mountpoint /dev >/dev/null 2>&1; then
	mount -t devtmpfs devtmpfs /dev >/dev/null 2>&1
	echo -n "/dev "
fi

if ! mountpoint /proc >/dev/null 2>&1; then
	mount -t proc proc /proc >/dev/null 2>&1
	echo -n "/proc "
fi

if ! mountpoint /sys >/dev/null 2>&1; then
	mount -t sysfs sysfs /sys >/dev/null 2>&1
	echo -n "/sys "
fi

if ! mountpoint /run >/dev/null 2>&1; then
	mount -t tmpfs tmpfs /run >/dev/null 2>&1
	echo -n "/run "
fi

echo ""

#
# Start a device service. Both eudev and busybox's mdev are supported but only
# one at a time must be enabled.
#
if [ -x /etc/rc.d/udevd ] && [ -x /etc/rc.d/busybox.mdev ]; then
	echo "Warning: both /etc/rc.d/udevd and /etc/rc.d/busybox.mdev are enabled" 1>&2
	echo "Warning: using udevd instead" 1>&2
fi

if [ -x /etc/rc.d/udevd ]; then
	/etc/rc.d/udevd start
elif [ -x /etc/rc.d/busybox.mdev ]; then
	/etc/rc.d/busybox.mdev start
fi

# Make sure / is ro in case of initrd.
mount -o remount,ro /

# If /etc/forcefsck is there, force check.
if [ -f /etc/forcefsck ]; then
	force="-f"
fi

fsck $force -A -T >/dev/null 2>&1

if [ "$?" -gt 1 ]; then
	echo "* Filesystem check failed"
	sulogin
	reboot
fi

# Remount / and enable swap as the system is ready.
mount -o remount,rw /
swapon -a

# Clean pid files before starting any services.
find /var/run -type f -name "*.pid" -delete

# Update shared library caches.
ldconfig

if [ -n "$TIMEZONE" ] && [ "$TIMEZONE" != "UTC" ]; then
	echo -n "Setting timezone: "

	if [ -f /share/zoneinfo/$TIMEZONE ]; then
		ln -sf /share/zoneinfo/$TIMEZONE /etc/localtime
		echo "$TIMEZONE"
	else
		echo "$TIMEZONE not found"
	fi
fi

# Console font and keymap.
if [ -n "$FONT" ]; then
	echo "Setting font: $FONT"
	setfont $FONT
fi

if [ -n "$KEYMAP" ]; then
	echo "Setting keymap: $KEYMAP"
	loadkeys $KEYMAP
fi

# Cleanup some files.
rm -f /etc/forcefsck

# Startup networking.
if [ -x /etc/rc.networking ]; then
	/etc/rc.networking start
fi