[Frugalware-darcs] fwrunit-scripts: fwrunit-scripts: merged all startup.d scripts to bootctl, get rid of startup.d

AlexExtreme alex at alex-smith.me.uk
Sat Oct 28 16:14:20 CEST 2006


Darcsweb-Url: http://darcs.frugalware.org/darcsweb/darcsweb.cgi?r=fwrunit-scripts;a=darcs_commitdiff;h=20061028141403-46e39-3954312aa69ae705be6be9dec3ca9a93e447051c.gz;

[fwrunit-scripts: merged all startup.d scripts to bootctl, get rid of startup.d
AlexExtreme <alex at alex-smith.me.uk>**20061028141403] {
hunk ./lib/init/startup.d/00udev 1
-#!/bin/bash
-
-# Frugalware udev startup script - v0.9.1
-# Copyright (C) 2004 Vajna Miklos <vmiklos at frugalware.org>
-# Copyright (C) 2006 Alex Smith <alex at alex-smith.me.uk>
-# Copyright (C) 2004 Greg Kroah-Hartman <greg at kroah.com>
-
-# This code is published under the terms of the GNU General Public License v2
-
-. /lib/init/functions
-. /etc/udev/udev.conf
-
-TEXTDOMAIN=udev
-
-make_extra_nodes () {
-	# There are a few things that sysfs does not export for us.
-	
-	# Thanks to Gentoo for the initial list of these.
-	/usr/bin/ln -snf /proc/self/fd /dev/fd
-	/usr/bin/ln -snf /proc/self/fd/0 /dev/stdin
-	/usr/bin/ln -snf /proc/self/fd/1 /dev/stdout
-	/usr/bin/ln -snf /proc/self/fd/2 /dev/stderr
-	/usr/bin/ln -snf /proc/kcore /dev/core
-
-	mkdir /dev/pts
-	mkdir /dev/shm
-}
-
-case "${1}" in
-	start)
-		# We need a writable /
-		mount / -o rw,remount
-		if [ $? -ne 0 ]; then
-			error $"Could not remount / as read-write"
-			exit 1
-		fi
-		
-		# Mount /sys
-		msg $"Mounting /sys..."
-		/bin/mount none -t sysfs /sys
-		ok $?
-		
-		# If sysfs is not mounted, die
-		if [ ! -d /sys/block ]; then
-			error $"System cannot boot without sysfs mounted!"
-			exit 1
-		fi
-		
-		# Create the ramfs for Udev
-		msg $"Mounting ramfs on /dev..."
-		/bin/mount -n -t ramfs none /dev
-		retval=$?
-		ok $retval
-		if [ $retval -ne 0 ]; then
-			error $"Udev cannot run without ramfs!"
-			exit 1
-		fi
-
-		# Propogate /dev from /sys
-		export ACTION=add
-		export UDEV_NO_SLEEP=1
-		
-		msg $"Creating initial device nodes..."
-		
-		/sbin/udevstart
-		retval=$?
-		ok $retval
-		if [ $retval -ne 0 ]; then
-			error $"Failed to run udevstart!"
-			exit 1
-		fi
-		
-		msg "Creating extra device nodes..."
-		make_extra_nodes
-		ok 0
-
-		if /usr/bin/ls /lib/udev/devices/* 2>/dev/null >/dev/null;then
-			/usr/bin/cp -a /lib/udev/devices/* /dev
-		fi
-		
-		# Check if udevd is already running
-		if ! [ `pidof -o %PPID /sbin/udevd` ]; then
-			msg $"Starting udevd..."
-			/sbin/udevd --daemon
-			ok $?
-		fi
-		
-		# Make udevsend the hotplug multiplexer
-		if [ -f "/sys/class/tty/console/uevent" ]; then
-			# Trigger the sorted events
-			/usr/bin/echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
-		else
-			/usr/bin/echo "/sbin/udevsend" > /proc/sys/kernel/hotplug
-		fi
-		
-		mount / -o ro,remount
-		if [ $? -ne 0 ]; then
-			error $"Could not remount / as read-only"
-			exit 1
-		fi
-		
-		;;
-	stop)
-		exit 0
-		;;
-	*)
-		msg_help "start"
-		exit 1
-		;;
-esac
rmfile ./lib/init/startup.d/00udev
hunk ./lib/init/startup.d/05font 1
-#!/bin/bash
-
-# Frugalware font initscript
-# Copyright (C) 2003-2006 Miklos Vajna <vmiklos at frugalware.org>
-# Copyright (C) 2006 Alex Smith <alex at alex-smith.me.uk>
-
-# This code is published under the terms of the GNU General Public License v2
-
-. /lib/init/functions
-
-TEXTDOMAIN=font
-
-case "${1}" in
-	start)
-		msg $"Loading console font"
-		
-		if [ -e /etc/sysconfig/font ] ; then
-			source /etc/sysconfig/font
-			if [ ! -z ${font} ] ; then
-				/usr/bin/setfont ${font}
-				ok $?
-			else
-				ok 999
-			fi
-		else
-			ok 999
-		fi
-
-		if echo $LANG |grep -qi utf; then
-			/usr/bin/kbd_mode -u
-			/usr/bin/dumpkeys | /bin/loadkeys --unicode
-		fi
-		
-		;;
-	stop)
-		exit 0
-		;;
-	*)
-		msg_help "start"
-		exit 1
-		;;
-esac
rmfile ./lib/init/startup.d/05font
hunk ./lib/init/startup.d/12fsck 1
-#!/bin/sh
-
-# Frugalware fsck init script
-# Copyright (C) 2003-2004 Vajna Miklos <vmiklos at frugalware.org>
-# Copyright (C) 2005 Laszlo Dvornik <dvornik at gnome.hu>
-# Copyright (C) 2006 Alex Smith <alex at alex-smith.me.uk>
-
-# This code is published under the terms of the GNU General Public License v2
-
-# Copyright 1993-2003 Patrick J. Volkerding, All rights reserved
-# Patrick J. Volkerding's scripts were distributed under an OSI approved
-# BSD License, which can be found in the COPYRIGHT file.
-
-. /lib/init/functions
-
-TEXTDOMAIN=fsck
-
-case "${1}" in
-	start)
-		# Test to see if the root partition is read-only, like it ought to be.
-		if /usr/bin/touch /fsrwtestfile 2>/dev/null; then
-			/usr/bin/rm -f /fsrwtestfile
-			rw=yes
-		else
-			msg $"Testing root filesystem status: read-only"
-			rw=no
-			ok $?
-		fi
-		
-		# See if a forced filesystem check was requested at shutdown:
-		if [ -r /etc/forcefsck ]; then
-			ffsck="-f"
-		fi
-		
-		# Check the root filesystem:
-		if [ ! $rw = yes ]; then
-			if [ ! -r /etc/fastboot ]; then
-				msg $"Checking root filesystem:"
-				/sbin/fsck $ffsck -C -a -T /
-				fsstate=$?
-				ok $?
-			else
-				fsstate=0
-			fi
-			
-			# An error code of 2 or higher will require a reboot.
-			if [ $fsstate -ge 2 ]; then
-				# An error code equal to or greater than 4 means that some
-				# errors could not be corrected.  This requires manual 
-				# attention, so we offer a chance to try to fix the
-				# problem in single-user mode:
-				if [ $fsstate -ge 4 ]; then
-					error $"An error occurred during the root filesystem check. You will"
-					error $"now be given a chance to log in and fix the problem."
-					echo
-					error $"If you are using ext2/3, 'e2fsck -v -y <partition>' might help"
-					error $"Once you exit the shell, the system will reboot"
-					
-					PS1="(Repair filesystem) \#"; export PS1
-					/sbin/sulogin
-				else
-					# With an error code of 2 or 3,
-					# reboot the machine automatically:
-					hint $"File system was changed, rebooting..."
-				fi
-				
-				/bin/umount -a -r
-				msg $"Rebooting..."
-				/usr/bin/sleep 2
-				
-				# If we exit 1, startup will exit 1, which means that /etc/runit/1 exits with 100, which causes runit to reboot :)
-				exit 1
-			fi
-			
-			# Remount the root filesystem in read-write mode
-			msg "Remounting root file system in read-write mode..."
-			/bin/mount -w -n -o remount /
-			if [ $? -gt 0 ]; then
-				ok 1
-				error $"Attempt to remount root device as read-write failed"
-				error $"Try adding 'rw' (without quotes) to the kernel command line"
-				error $"Press ENTER to reboot"
-				read junk
-				
-				/bin/umount -a -r
-				/bin/mount -n -o remount,ro /
-				msg $"Rebooting..."
-				sleep 2
-				
-				# If we exit 1, startup will exit 1, which means that /etc/runit/1 exits with 100, which causes runit to reboot :)
-				exit 1
-			else
-				ok 0
-			fi
-		else
-			msg $"Testing root filesystem status: read-write"
-			ok 1
-
-			hint $"Root partition already mounted read-write, cannot check!"
-			hint $"For filesystem checking to work properly, your system must"
-			hint $"initially mount the root partition as read only. Add 'ro'"
-			hint $"(without quotes) to the kernel command line."
-			echo
-			hint $"Press ENTER to continue"
-			read junk
-			echo
-		fi
-		
-		# Any /etc/mtab that exists here is old, so we delete it to start over:
-		/bin/rm -f /etc/mtab*
-		
-		# Remounting the / partition will initialize the new /etc/mtab:
-		/bin/mount -w -o remount /
-		
-		# Fix /etc/mtab to list sys and proc if they were not yet entered in
-		# /etc/mtab because / was still mounted read-only:
-		if [ -d /proc/sys ]; then
-			/bin/mount -f proc /proc -t proc
-		fi
-		if [ -d /sys/bus ]; then
-			/bin/mount -f sysfs /sys -t sysfs
-		fi
-		
-		;;
-	stop)
-		exit 0
-		;;
-	*)
-		msg_help "start"
-		exit 1
-		;;
-esac
rmfile ./lib/init/startup.d/12fsck
hunk ./lib/init/startup.d/15mount 1
-#!/bin/bash
-
-# Frugalware mount initscript
-# Copyright (C) 2003-2006 Miklos Vajna <vmiklos at frugalware.org>
-# Copyright (C) 2006 Alex Smith <alex at alex-smith.me.uk>
-
-# This code is published under the terms of the GNU General Public License v2
-
-. /lib/init/functions
-. /etc/init.conf
-
-[ -z "$FSCK_VERBOSE" ] && FSCK_VERSBOSE="1"
-
-TEXTDOMAIN=mount
-
-case "${1}" in
-	start)
-		# See if a forced filesystem check was requested at shutdown.
-		if [ -r /etc/forcefsck ]; then
-			ffsck="-f"
-		fi
-		
-		# Check all the non-root filesystems.
-		if ! [ -r /etc/fastboot ]; then
-			msg $"Checking non-root filesystems"
-			if [ "$FSCK_VERBOSE" = "0" ]; then
-				/sbin/fsck $ffsck -T -C -R -A -a >> /dev/null 2>&1
-			else
-				/sbin/fsck $ffsck -T -C -R -A -a
-			fi
-			ok $?
-		fi
-		
-		# Mount non-root file systems in fstab (but not NFS or SMB 
-		# because TCP/IP is not yet configured).
-		msg $"Mounting local filesystems"
-		/bin/mount -a -t nonfs,nosmbfs,noproc,nosysfs
-		ok $?
-		
-		# Clean up some temporary files.
-		/bin/rm -f /var/run/utmp /var/run/*pid /etc/nologin /var/run/lpd* \
-			/var/run/ppp* /etc/dhcpc/dhcpcd-eth*.pid /etc/forcefsck \
-			/etc/fastboot
-		
-		# Create a fresh utmp file.
-		/usr/bin/cat /dev/null > /var/run/utmp
-		
-		if cat /etc/fstab | grep ' / ' | grep -q umsdos ; then
-			rfstype="umsdos"
-		fi
-		if [ "$rfstype" = "umsdos" ]; then
-			# We need to update any files added in DOS.
-			msg $"Synchronizing UMSDOS directory structure"
-			umssync -r99 -v- /
-			ok $?
-		fi
-		
-		;;
-	stop)
-		if [ -x /etc/runit/stopping ]; then
-			msg $"Unmounting local filesystems"
-			/bin/umount -a -r -t nonfs,noumsdos,nosmbfs,noproc
-			ok $?
-			
-			# Don't remount UMSDOS root volumes.
-			if [ ! "`mount | head -n 1 | cut -d ' ' -f 5`" = "umsdos" ]; then
-				msg $"Remounting root filesystem read-only"
-				/bin/mount -n -o remount,ro /
-				ok $?
-			fi
-		fi
-		
-		# This never hurts. :)
-		/usr/bin/sync
-		
-		;;
-	*)
-		msg_help "start|stop"
-		exit 1
-		;;
-esac
-
rmfile ./lib/init/startup.d/15mount
hunk ./lib/init/startup.d/16killall 1
-#!/bin/sh
-
-# Frugalware random initscript
-# Copyright (C) 2003-2006 Miklos Vajna <vmiklos at frugalware.org>
-# Copyright (C) 2006 Alex Smith <alex at alex-smith.me.uk>
-
-# This code is published under the terms of the GNU General Public License v2
-
-. /lib/init/functions
-
-TEXTDOMAIN=random
-
-case "${1}" in
-	start)
-		exit 0
-		;;
-	stop)
-		if [ -x /etc/runit/stopping ]; then
-			msg $"Sending all processes the SIGTERM signal"
-			/sbin/killall5 -15
-			ok $?
-			
-			msg $"Sending all processes the SIGKILL signal"
-			/usr/bin/sleep 3
-			/sbin/killall5 -9
-			ok $?
-		fi
-		;;
-	*)
-		msg_help "stop"
-		exit 1
-		;;
-esac
rmfile ./lib/init/startup.d/16killall
hunk ./lib/init/startup.d/17swap 1
-#!/bin/bash
-
-# Frugalware swap initscript
-# Copyright (C) 2003-2006 Miklos Vajna <vmiklos at frugalware.org>
-# Copyright (C) 2006 Alex Smith <alex at alex-smith.me.uk>
-
-# This code is published under the terms of the GNU General Public License v2
-
-. /lib/init/functions
-
-TEXTDOMAIN=swap
-
-case "${1}" in
-	start)
-		msg $"Activating swap"
-		/sbin/swapon -a
-		ok $?
-		
-		;;
-	stop)
-		msg $"Turning off swap"
-		if [ -x /etc/runit/stopping ]; then
-			/sbin/swapoff -a
-			ok $?
-		else
-			ok 999
-		fi
-		
-		;;
-	*)
-		msg_help "start|stop"
-		exit 1
-		;;
-esac
rmfile ./lib/init/startup.d/17swap
hunk ./lib/init/startup.d/18time 1
-#!/bin/bash
-
-# Frugalware time initscript
-# Copyright (C) 2003-2006 Miklos Vajna <vmiklos at frugalware.org>
-# Copyright (C) 2006 Alex Smith <alex at alex-smith.me.uk>
-
-# This code is published under the terms of the GNU General Public License v2
-
-. /lib/init/functions
-
-TEXTDOMAIN=time
-
-case "${1}" in
-	start)
-		msg $"Setting system time from the hardware clock"
-		if grep -q "^UTC" /etc/hardwareclock ; then
-			/sbin/hwclock --utc --hctosys
-			ok $?
-			hint $"Using UTC"
-		else
-			/sbin/hwclock --localtime --hctosys
-			ok $?
-			hint $"Using localtime"
-		fi
-		;;
-	stop)
-		msg $"Saving the system time to the hardware clock"
-		if [ -x /etc/runit/stopping ]; then
-			if grep -q "^UTC" /etc/hardwareclock ; then
-				/sbin/hwclock --utc --systohc
-				ok $?
-				hint $"Using UTC"
-			else
-				/sbin/hwclock --localtime --systohc
-				ok $?
-				hint $"Using localtime"
-			fi
-		else
-			ok 999
-		fi
-		;;
-	*)
-		msg_help "start|stop"
-		exit 1
-		;;
-esac
rmfile ./lib/init/startup.d/18time
hunk ./lib/init/startup.d/19bootclean 1
-#!/bin/bash
-
-# Frugalware bootclean initscript
-# Copyright (C) 2003-2006 Miklos Vajna <vmiklos at frugalware.org>
-# Copyright (C) 2006 Alex Smith <alex at alex-smith.me.uk>
-
-# This code is published under the terms of the GNU General Public License v2
-
-. /lib/init/functions
-
-TEXTDOMAIN=bootclean
-
-case "${1}" in
-	start)
-		msg $"Cleaning /tmp, /var/lock, /var/run"
-		EXCEPT='! -name .
-			! ( -path ./lost+found -uid 0 )
-			! ( -path ./quota.user -uid 0 )
-			! ( -path ./aquota.user -uid 0 )
-			! ( -path ./quota.group -uid 0 )
-			! ( -path ./aquota.group -uid 0 )
-			! ( -path ./.journal -uid 0 )
-			! ( -path ./.clean -uid 0 )
-			! ( -path ./.ICE-unix -uid 0 )
-			! ( -path ./.X11-unix -uid 0 )
-			! ( -path './...security*' -uid 0 )'
-		
-		( if cd /tmp && [ "`find . -maxdepth 0 -perm -002`" = "." ]; then
-			# First remove all old files.
-			find . -depth -xdev $EXCEPT \
-					! -type d -print0 | xargs -0r rm -f
-			# And then all empty directories.
-			find . -depth -xdev $EXCEPT \
-					-type d -empty -exec rmdir \{\} \;
-			rm -f .X*-lock
-		fi )
-		
-		( cd /var/lock && find . ! -type d -exec rm -f -- {} \; )
-		
-		( cd /var/run && \
-			find . ! -type d ! -name utmp ! -name innd.pid \
-			-exec rm -f -- {} \; )
-		ok $?
-		;;
-	stop)
-		exit 0
-		;;
-	*)
-		msg_help "start"
-		exit 1
-		;;
-esac
rmfile ./lib/init/startup.d/19bootclean
hunk ./lib/init/startup.d/20modules 1
-#!/bin/sh
-
-# Frugalware modules initscript
-# Copyright (C) 2003-2006 Miklos Vajna <vmiklos at frugalware.org>
-# Copyright (C) 2006 Alex Smith <alex at alex-smith.me.uk>
-
-# This code is published under the terms of the GNU General Public License v2
-
-. /lib/init/functions
-
-TEXTDOMAIN=modules
-
-MODPROBEBIN=/sbin/modprobe
-MODCONFFILE=/etc/sysconfig/modules
-
-case "${1}" in
-	start)
-		# Update module dependencies
-		kernelver=`uname -r`
-		
-		# If /usr is mounted and we have 'find', we can try to take a shortcut:
-		if [ -x /usr/bin/find -a -e /lib/modules/$kernelver/modules.dep \
-			-a /lib/modules/$kernelver/modules.dep \
-			-nt /etc/modules.conf ]; then
-			news="`/usr/bin/find /lib/modules/$kernelver -type f -newer /lib/modules/$kernelver/modules.dep`"
-			
-			# Only rebuild dependencies if new module(s) are found:
-			if ! [ "" = "$news" ]; then
-				msg $"Updating module dependencies"
-				/sbin/depmod -a
-				ok $?
-			else
-				msg $"Module dependencies up to date (no new kernel modules found)"
-				ok 0
-			fi
-		else
-			# We don't have find, or there is no existing modules.dep, or it is out of date.
-			msg $"Updating module dependencies"
-			/sbin/depmod -A
-			ok $?
-		fi
-		
-		## Put global modules to load. 
-		## (eg.: Hardcoded modules that needs to load at startup)
-		## At here you can do anything, run any commands, example iptables or any other base
-		## commands like in the older rc.modules file.
-		if grep -q quota /etc/fstab ; then
-			$MODPROBEBIN quota_v2
-		fi
-		
-		## Starting reading conf file and loading modules
-		if [ -r $MODCONFFILE ]; then
-			msg $"Loading modules"
-			Firstcount=$(wc -l < "$MODCONFFILE")
-			## Fix line count
-			NUM=$(expr $Firstcount + 1)
-			
-			for module in $(seq $NUM)
-			do
-				read module
-				
-				## Removing bad lines
-				if [ "$module" != "" -a "$(echo $module | grep -v '#')" ]; then
-		  			## Then check if module has an argument
-  					if echo $module | grep '"' > /dev/null; then
-  						## If yes:  			
-  						arg=$(echo $module | cut -f2 -d '"')
-  						module=$(echo $module | cut -f1 -d '"')
-	  					$MODPROBEBIN $module $arg
-	  				else
-  						## If not simply modprobe it
-  						$MODPROBEBIN $module
-	  				fi
-  				fi
-			done < $MODCONFFILE
-			
-			ok $?
-		else
-			msg $"No modules config found!"
-			ok 1
-		fi
-		;;
-	stop)
-		exit 0
-		;;
-	*)
-		msg_help "start"
-		exit 1
-		;;
-esac
rmfile ./lib/init/startup.d/20modules
hunk ./lib/init/startup.d/22random 1
-#!/bin/sh
-
-# Frugalware random initscript
-# Copyright (C) 2003-2006 Miklos Vajna <vmiklos at frugalware.org>
-# Copyright (C) 2006 Alex Smith <alex at alex-smith.me.uk>
-
-# This code is published under the terms of the GNU General Public License v2
-
-. /lib/init/functions
-
-TEXTDOMAIN=random
-
-case "${1}" in
-	start)
-		msg $"Initializing /dev/urandom"
-		
-		# Some cleaning up
-		/usr/bin/rm -f /var/lock/* /var/spool/uucp/LCK..* /tmp/.X*lock /tmp/core /core \
-			1> /dev/null 2> /dev/null
-		
-		if [ -r /tmp/hunt -o -r /tmp/hunt.stats ]; then
-			/usr/bin/rm -f /tmp/hunt*
-		fi
-		/usr/bin/chmod 755 / 2> /dev/null
-		/usr/bin/chmod 1777 /tmp /var/tmp
-		
-		if [ -f /etc/random-seed ]; then
-			/usr/bin/cat /etc/random-seed >/dev/urandom
-		fi
-		dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
-		ok $?
-		;;
-	stop)
-		if [ -x /etc/runit/stopping ]; then
-			msg $"Saving /dev/urandom"
-			# Clear /var/lock/subsys
-			if [ -d /var/lock/subsys ]; then
-				/usr/bin/rm -f /var/lock/subsys/*
-			fi
-		  	
-			dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
-			ok $?
-		fi
-		;;
-	restart)
-		"$0" stop
-		sleep 1
-		"$0" start
-		;;
-	*)
-		msg_help "start|stop|restart"
-		exit 1
-		;;
-esac
rmfile ./lib/init/startup.d/22random
rmdir ./lib/init/startup.d
hunk ./lib/init/bootctl 19
-[ -z "$1" ] && exit 1
-
-case "${1}" in
-	startup)
-		# Hello, World!
-		
-		msg $"Welcome to Frugalware Linux!"
-		msg $"Copyright (C) 2004-2006 Frugalware Linux Development Team."
-		msg $"Licensed under the terms of the GNU General Public License v2"
-		echo
+startup() {
+	# Hello, World!		
+	msg $"Welcome to ${CYAN}Frugalware${WHITE} Linux!"
+	msg $"Copyright (C) 2004-2006 Frugalware Linux Development Team."
+	msg $"Licensed under the terms of the GNU General Public License v2"
+	echo
+	
+	# Mount /proc
+	if [ ! -d /proc/1 ]; then
+		msg $"Mounting /proc..."
+		mount none -t proc /proc
+		if [ $? -ne 0 ]; then
+			ok 1
+			die
+		else
+			ok 0
+		fi
+	fi
+	
+	# Mount /sys
+	if [ ! -d /sys/block ]; then
+		msg $"Mounting /sys..."
+		/bin/mount none -t sysfs /sys
+		if [ $? -ne 0 ]; then
+			ok 1
+			die
+		else
+			ok 0
+		fi
+	fi
+	
+	# @begin udev
+	
+	# We need a writable / for udev
+	mount / -o rw,remount
+	if [ $? -ne 0 ]; then
+		error $"Could not remount / as read-write"
+		die
+	fi
+	
+	# If sysfs is not mounted, die
+	if [ ! -d /sys/block ]; then
+		error $"System cannot boot without sysfs mounted!"
+		die
+	fi
+	
+	# Create the ramfs for Udev
+	msg $"Mounting ramfs on /dev..."
+	/bin/mount -n -t ramfs none /dev
+	retval=$?
+	ok $retval
+	if [ $retval -ne 0 ]; then
+		error $"Udev cannot run without ramfs!"
+		die
+	fi
+	
+	# Propogate /dev from /sys
+	export ACTION=add
+	export UDEV_NO_SLEEP=1
+	
+	msg $"Creating initial device nodes..."
+	
+	/sbin/udevstart
+	retval=$?
+	ok $retval
+	if [ $retval -ne 0 ]; then
+		error $"Failed to run udevstart!"
+		die
+	fi
+	
+	# There are a few things that sysfs does not export for us.
+	# Thanks to Gentoo for the initial list of these.
+	msg $"Creating extra device nodes..."
+	
+	/usr/bin/ln -snf /proc/self/fd /dev/fd
+	/usr/bin/ln -snf /proc/self/fd/0 /dev/stdin
+	/usr/bin/ln -snf /proc/self/fd/1 /dev/stdout
+	/usr/bin/ln -snf /proc/self/fd/2 /dev/stderr
+	/usr/bin/ln -snf /proc/kcore /dev/core
+	
+	mkdir /dev/pts
+	mkdir /dev/shm
+	
+	ok 0
+	
+	# Does the user have any custom device nodes that he/she wants?
+	if /usr/bin/ls /lib/udev/devices/* 2>/dev/null >/dev/null;then
+		/usr/bin/cp -a /lib/udev/devices/* /dev
+	fi
+	
+	# Check if udevd is already running
+	if ! [ `pidof -o %PPID /sbin/udevd` ]; then
+		msg $"Starting udevd..."
+		/sbin/udevd --daemon
+		ok $?
+	fi
+	
+	# Make udevsend the hotplug multiplexer
+	if [ -f "/sys/class/tty/console/uevent" ]; then
+		# Trigger the sorted events
+		/usr/bin/echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
+	else
+		/usr/bin/echo "/sbin/udevsend" > /proc/sys/kernel/hotplug
+	fi
+	
+	mount / -o ro,remount
+	if [ $? -ne 0 ]; then
+		error $"Could not remount / as read-only"
+		die
+	fi
+	
+	# @end udev
+	# @begin font
+	
+	if [ -e /etc/sysconfig/font ] ; then
+		source /etc/sysconfig/font
+		if [ ! -z ${font} ] ; then
+			msg $"Loading console font"
+			/usr/bin/setfont ${font}
+			ok $?
+		fi
+	fi
+	
+	if echo $LANG |grep -qi utf; then
+		/usr/bin/kbd_mode -u
+		/usr/bin/dumpkeys | /bin/loadkeys --unicode
+	fi
+	
+	# @end font
+	# @begin fsck
+	
+	# Test to see if the root partition is read-only, like it ought to be.
+	if /usr/bin/touch /fsrwtestfile 2>/dev/null; then
+		/usr/bin/rm -f /fsrwtestfile
+		rw=yes
+	else
+		msg $"Testing root filesystem status: read-only"
+		rw=no
+		ok $?
+	fi
+	
+	# See if a forced filesystem check was requested at shutdown:
+	if [ -r /etc/forcefsck ]; then
+		ffsck="-f"
+	fi
+	
+	# Check the root filesystem:
+	if [ ! $rw = yes ]; then
+		if [ ! -r /etc/fastboot ]; then
+			msg $"Checking root filesystem:"
+			/sbin/fsck $ffsck -C -a -T /
+			fsstate=$?
+			ok $?
+		else
+			fsstate=0
+		fi
hunk ./lib/init/bootctl 176
-		if [ ! -d /proc/1 ]; then
-			msg $"Mounting /proc..."
-			mount none -t proc /proc
-			if [ $? -ne 0 ]; then
-				ok 1
-				die
+		# An error code of 2 or higher will require a reboot.
+		if [ $fsstate -ge 2 ]; then
+			# An error code equal to or greater than 4 means that some
+			# errors could not be corrected.  This requires manual 
+			# attention, so we offer a chance to try to fix the
+			# problem in single-user mode:
+			if [ $fsstate -ge 4 ]; then
+				error $"An error occurred during the root filesystem check. You will"
+				error $"now be given a chance to log in and fix the problem."
+				echo
+				error $"If you are using ext2/3, 'e2fsck -v -y <partition>' might help"
+				error $"Once you exit the shell, the system will reboot"
+				
+				PS1="(Repair filesystem) \#"; export PS1
+				/sbin/sulogin
hunk ./lib/init/bootctl 192
-				ok 0
+				# With an error code of 2 or 3,
+				# reboot the machine automatically:
+				hint $"File system was changed, rebooting..."
hunk ./lib/init/bootctl 196
+			
+			/bin/umount -a -r
+			msg $"Rebooting..."
+			/usr/bin/sleep 2
+			
+			# Make /etc/runit/1 exit with 100, which causes runit to reboot
+			die
hunk ./lib/init/bootctl 205
-		# Run all the startup scripts
-		for script in /lib/init/startup.d/*; do
-			${script} start || die
-		done
-		
-		if grep -q single /proc/cmdline; then
-			/sbin/sulogin
-		else
-			# Run all the startup scripts
-			for script in /lib/init/multi.d/*; do
-				${script} start
-			done
+		# Remount the root filesystem in read-write mode
+		msg "Remounting root file system in read-write mode..."
+		/bin/mount -w -n -o remount /
+		if [ $? -gt 0 ]; then
+			ok 1
+			error $"Attempt to remount root device as read-write failed"
+			error $"Try adding 'rw' (without quotes) to the kernel command line"
+			error $"Press ENTER to reboot"
+			read junk
hunk ./lib/init/bootctl 215
-			if [ -x /lib/init/local ]; then
-				/lib/init/local start
-			fi
+			/bin/umount -a -r
+			/bin/mount -n -o remount,ro /
+			msg $"Rebooting..."
+			sleep 2
+			
+			# Make /etc/runit/1 exit with 100, which causes runit to reboot
+			die
+		else
+			ok 0
hunk ./lib/init/bootctl 225
-		
-		;;
-	shutdown)
+	else
+		msg $"Testing root filesystem status: read-write"
+		ok 1
+		hint $"Root partition already mounted read-write, cannot check!"
+		hint $"For filesystem checking to work properly, your system must"
+		hint $"initially mount the root partition as read only. Add 'ro'"
+		hint $"(without quotes) to the kernel command line."
hunk ./lib/init/bootctl 233
-		msg $"Shutting down the system..."
+		hint $"Press ENTER to continue"
+		read junk
hunk ./lib/init/bootctl 236
+	fi
+	
+	# Any /etc/mtab that exists here is old, so we delete it to start over:
+	/bin/rm -f /etc/mtab*
+	
+	# Remounting the / partition will initialize the new /etc/mtab:
+	/bin/mount -w -o remount /
+	
+	# Fix /etc/mtab to list sys and proc if they were not yet entered in
+	# /etc/mtab because / was still mounted read-only:
+	if [ -d /proc/sys ]; then
+		/bin/mount -f proc /proc -t proc
+	fi
+	if [ -d /sys/bus ]; then
+		/bin/mount -f sysfs /sys -t sysfs
+	fi
+	
+	# @end fsck
+	# @begin mount
+	
+	# See if a forced filesystem check was requested at shutdown.
+	if [ -r /etc/forcefsck ]; then
+		ffsck="-f"
+	fi
+	
+	# Check all the non-root filesystems.
+	if ! [ -r /etc/fastboot ]; then
+		msg $"Checking non-root filesystems"
+		if [ "$FSCK_VERBOSE" = "0" ]; then
+			/sbin/fsck $ffsck -T -C -R -A -a >> /dev/null 2>&1
+		else
+			/sbin/fsck $ffsck -T -C -R -A -a
+		fi
+		ok $?
+	fi
+	
+	# Mount non-root file systems in fstab (but not NFS or SMB 
+	# because TCP/IP is not yet configured).
+	msg $"Mounting local filesystems"
+	/bin/mount -a -t nonfs,nosmbfs,noproc,nosysfs
+	ok $?
+	
+	# Clean up some temporary files.
+	/bin/rm -f /var/run/utmp /var/run/*pid /etc/nologin /var/run/lpd* \
+		/var/run/ppp* /etc/dhcpc/dhcpcd-eth*.pid /etc/forcefsck \
+		/etc/fastboot
+	
+	# Create a fresh utmp file.
+	/usr/bin/cat /dev/null > /var/run/utmp
+	
+	if cat /etc/fstab | grep ' / ' | grep -q umsdos ; then
+		rfstype="umsdos"
+	fi
+	if [ "$rfstype" = "umsdos" ]; then
+		# We need to update any files added in DOS.
+		msg $"Synchronizing UMSDOS directory structure"
+		umssync -r99 -v- /
+		ok $?
+	fi
+	
+	# @end mount
+	# @begin swap
+	
+	msg $"Activating swap"
+	/sbin/swapon -a
+	ok $?
+	
+	# @end swap
+	# @begin time
+	
+	msg $"Setting system time from the hardware clock"
+	if grep -q "^UTC" /etc/hardwareclock ; then
+		/sbin/hwclock --utc --hctosys
+		ok $?
+		hint $"Using UTC"
+	else
+		/sbin/hwclock --localtime --hctosys
+		ok $?
+		hint $"Using localtime"
+	fi
+	
+	# @end time
+	# @begin bootclean
+	
+	msg $"Cleaning /tmp, /var/lock, /var/run"
+	EXCEPT='! -name .
+		! ( -path ./lost+found -uid 0 )
+		! ( -path ./quota.user -uid 0 )
+		! ( -path ./aquota.user -uid 0 )
+		! ( -path ./quota.group -uid 0 )
+		! ( -path ./aquota.group -uid 0 )
+		! ( -path ./.journal -uid 0 )
+		! ( -path ./.clean -uid 0 )
+		! ( -path ./.ICE-unix -uid 0 )
+		! ( -path ./.X11-unix -uid 0 )
+		! ( -path './...security*' -uid 0 )'
+	
+	( if cd /tmp && [ "`find . -maxdepth 0 -perm -002`" = "." ]; then
+		# First remove all old files.
+		find . -depth -xdev $EXCEPT \
+				! -type d -print0 | xargs -0r rm -f
+		# And then all empty directories.
+		find . -depth -xdev $EXCEPT \
+				-type d -empty -exec rmdir \{\} \;
+		rm -f .X*-lock
+	fi )
+	
+	( cd /var/lock && find . ! -type d -exec rm -f -- {} \; )
+	
+	( cd /var/run && \
+		find . ! -type d ! -name utmp ! -name innd.pid \
+		-exec rm -f -- {} \; )
+	ok $?
+	
+	# @end bootclean
+	# @begin modules
+	
+	# Update module dependencies
+	kernelver=`uname -r`
+	
+	# If /usr is mounted and we have 'find', we can try to take a shortcut:
+	if [ -x /usr/bin/find -a -e /lib/modules/$kernelver/modules.dep \
+		-a /lib/modules/$kernelver/modules.dep \
+		-nt /etc/modules.conf ]; then
+		news="`/usr/bin/find /lib/modules/$kernelver -type f -newer /lib/modules/$kernelver/modules.dep`"
hunk ./lib/init/bootctl 362
-		if ! grep -q single /proc/cmdline; then
-			# Reverse the script order
-			for script in /lib/init/multi.d/*; do
-				scripts="$script $scripts"
-			done
-			
-			# Stop all the multi-user scripts
-			for script in $scripts; do
-				${script} stop
-			done
+		# Only rebuild dependencies if new module(s) are found:
+		if ! [ "" = "$news" ]; then
+			msg $"Updating module dependencies"
+			/sbin/depmod -a
+			ok $?
+		else
+			msg $"Module dependencies up to date (no new kernel modules found)"
+			ok 0
hunk ./lib/init/bootctl 371
+	else
+		# We don't have find, or there is no existing modules.dep, or it is out of date.
+		msg $"Updating module dependencies"
+		/sbin/depmod -A
+		ok $?
+	fi
+	
+	## Put global modules to load. 
+	## (eg.: Hardcoded modules that needs to load at startup)
+	## At here you can do anything, run any commands, example iptables or any other base
+	## commands like in the older rc.modules file.
+	if grep -q quota /etc/fstab ; then
+		$MODPROBEBIN quota_v2
+	fi
+	
+	## Starting reading conf file and loading modules
+	if [ -r $MODCONFFILE ]; then
+		msg $"Loading modules"
+		Firstcount=$(wc -l < "$MODCONFFILE")
+		## Fix line count
+		NUM=$(expr $Firstcount + 1)
hunk ./lib/init/bootctl 393
-		scripts=""
+		for module in $(seq $NUM)
+		do
+			read module
+			
+			## Removing bad lines
+			if [ "$module" != "" -a "$(echo $module | grep -v '#')" ]; then
+	  			## Then check if module has an argument
+				if echo $module | grep '"' > /dev/null; then
+					## If yes:  			
+					arg=$(echo $module | cut -f2 -d '"')
+					module=$(echo $module | cut -f1 -d '"')
+					$MODPROBEBIN $module $arg
+				else
+					## If not simply modprobe it
+					$MODPROBEBIN $module
+  				fi
+			fi
+		done < $MODCONFFILE
+		ok $?
+	else
+		msg $"No modules config found!"
+		ok 1
+	fi
+	
+	# @end modules
+	# @begin random
+	
+	msg $"Initializing /dev/urandom"
+	
+	# Some cleaning up
+	/usr/bin/rm -f /var/lock/* /var/spool/uucp/LCK..* /tmp/.X*lock /tmp/core /core \
+		1> /dev/null 2> /dev/null
+	
+	if [ -r /tmp/hunt -o -r /tmp/hunt.stats ]; then
+		/usr/bin/rm -f /tmp/hunt*
+	fi
+	/usr/bin/chmod 755 / 2> /dev/null
+	/usr/bin/chmod 1777 /tmp /var/tmp
+	
+	if [ -f /etc/random-seed ]; then
+		/usr/bin/cat /etc/random-seed >/dev/urandom
+	fi
+	dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
+	ok $?
+	
+	# @end random
+	
+	if grep -q single /proc/cmdline; then
+		/sbin/sulogin
+	else
+		# Run all the startup scripts
+		for script in /lib/init/multi.d/*; do
+			${script} start
+		done
hunk ./lib/init/bootctl 448
+		if [ -x /lib/init/local ]; then
+			/lib/init/local start
+		fi
+	fi
+}
+
+shutdown() {
+	if ! grep -q single /proc/cmdline; then
hunk ./lib/init/bootctl 457
-		for script in /lib/init/startup.d/*; do
+		for script in /lib/init/multi.d/*; do
hunk ./lib/init/bootctl 461
-		# Stop all the startup scripts
+		# Stop all the multi-user scripts
hunk ./lib/init/bootctl 465
+	fi
+	
+	# @begin random
+	
+	if [ -x /etc/runit/stopping ]; then
+		msg $"Saving /dev/urandom"
+		# Clear /var/lock/subsys
+		if [ -d /var/lock/subsys ]; then
+			/usr/bin/rm -f /var/lock/subsys/*
+		fi
+	  	
+		dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
+		ok $?
+	fi
+	
+	# @end random
+	# @begin time
+	
+	msg $"Saving the system time to the hardware clock"
+	if [ -x /etc/runit/stopping ]; then
+		if grep -q "^UTC" /etc/hardwareclock ; then
+			/sbin/hwclock --utc --systohc
+			ok $?
+			hint $"Using UTC"
+		else
+			/sbin/hwclock --localtime --systohc
+			ok $?
+			hint $"Using localtime"
+		fi
+	else
+		ok 999
+	fi
+	
+	# @end time
+	# @begin swap
+	
+	msg $"Turning off swap"
+	if [ -x /etc/runit/stopping ]; then
+		/sbin/swapoff -a
+		ok $?
+	else
+		ok 999
+	fi
+	
+	# @end swap
+	# @begin killall
+	
+	if [ -x /etc/runit/stopping ]; then
+		msg $"Sending all processes the SIGTERM signal"
+		/sbin/killall5 -15
+		ok $?
hunk ./lib/init/bootctl 517
-		echo
-		msg $"Goodbye!"
-		echo
+		msg $"Sending all processes the SIGKILL signal"
+		/usr/bin/sleep 3
+		/sbin/killall5 -9
+		ok $?
+	fi
+	
+	# @end killall
+	# @begin mount
+	
+	if [ -x /etc/runit/stopping ]; then
+		msg $"Unmounting local filesystems"
+		/bin/umount -a -r -t nonfs,noumsdos,nosmbfs,noproc
+		ok $?
hunk ./lib/init/bootctl 531
+		# Don't remount UMSDOS root volumes.
+		if [ ! "`mount | head -n 1 | cut -d ' ' -f 5`" = "umsdos" ]; then
+			msg $"Remounting root filesystem read-only"
+			/bin/mount -n -o remount,ro /
+			ok $?
+		fi
+	fi
+	
+	# This never hurts. :)
+	/usr/bin/sync
+	
+	# @end mount
+	
+	echo
+	msg $"Goodbye!"
+	echo
+}
+
+[ -z "$1" ] && exit 1
+
+case "${1}" in
+	startup)
+		startup
+		;;
+	shutdown)
+		shutdown
}


More information about the Frugalware-darcs mailing list