diff options
Diffstat (limited to 'init.d')
-rwxr-xr-x | init.d/bootmisc | 141 | ||||
-rwxr-xr-x | init.d/checkfs | 54 | ||||
-rwxr-xr-x | init.d/checkroot | 124 | ||||
-rwxr-xr-x | init.d/clock | 144 | ||||
-rwxr-xr-x | init.d/consolefont | 68 | ||||
-rwxr-xr-x | init.d/domainname | 60 | ||||
-rwxr-xr-x | init.d/halt.sh | 242 | ||||
-rwxr-xr-x | init.d/hostname | 39 | ||||
-rwxr-xr-x | init.d/keymaps | 79 | ||||
-rwxr-xr-x | init.d/local | 34 | ||||
-rwxr-xr-x | init.d/localmount | 47 | ||||
-rwxr-xr-x | init.d/modules | 122 | ||||
l--------- | init.d/net.eth0 | 1 | ||||
-rwxr-xr-x | init.d/netmount | 93 | ||||
-rwxr-xr-x | init.d/numlock | 34 | ||||
-rwxr-xr-x | init.d/reboot.sh | 8 | ||||
-rwxr-xr-x | init.d/rmnologin | 16 | ||||
-rwxr-xr-x | init.d/shutdown.sh | 8 | ||||
-rwxr-xr-x | init.d/urandom | 37 |
19 files changed, 1351 insertions, 0 deletions
diff --git a/init.d/bootmisc b/init.d/bootmisc new file mode 100755 index 0000000..ad7637f --- /dev/null +++ b/init.d/bootmisc @@ -0,0 +1,141 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + use clock hostname + need localmount + before logger +} + +start() { + [[ ${BOOT} != "yes" ]] && return 0 + + # + # Put a nologin file in /etc to prevent people from logging in before + # system startup is complete. + # + if [[ ${DELAYLOGIN} == "yes" ]] ; then + echo "System bootup in progress - please wait" > /etc/nologin + cp /etc/nologin /etc/nologin.boot &> /dev/null + fi + + if [[ -e /etc/sysctl.conf ]] ; then + ebegin "Configuring kernel parameters" + /sbin/sysctl -q -p /etc/sysctl.conf + eend 0 + fi + + if [[ -z ${CDBOOT} ]] && ! touch /var/run/.keep 2> /dev/null ; then + ewarn "Skipping /var and /tmp initialization (ro root?)" + return 0 + fi + + if [[ -x /sbin/env-update.sh ]] ; then + ebegin "Updating environment" + /sbin/env-update.sh -u > /dev/null + eend 0 + fi + + # + # Take care of random stuff [ /var/lock | /var/run | pam ] + # + + if [[ -d /var/lib/net-scripts/state ]] ; then + ebegin "Cleaning /var/lib/net-scripts/state" + rm -rf /var/lib/net-scripts/state/* + eend 0 + fi + + ebegin "Cleaning /var/lock, /var/run" + rm -rf /var/run/console.lock /var/run/console/* + + if [[ -z ${CDBOOT} ]] ; then + # + # Clean up any stale locks. + # + find /var/lock -type f -print0 | xargs -0 rm -f -- + # + # Clean up /var/run and create /var/run/utmp so that we can login. + # + for x in $(find /var/run/ ! -type d ! -name utmp ! -name innd.pid ! -name random-seed) ; do + local daemon=${x##*/} + daemon=${daemon%*.pid} + # Do not remove pidfiles of already running daemons + if [[ -z $(ps --no-heading -C "${daemon}") ]] ; then + if [[ -f ${x} || -L ${x} ]] ; then + rm -f "${x}" + fi + fi + done + fi + + # Reset pam_console permissions if we are actually using it + if [[ -x /sbin/pam_console_apply && ! -c /dev/.devfsd && \ + -n $(grep -v -e '^[[:space:]]*#' /etc/pam.d/* | grep 'pam_console') ]] ; then + /sbin/pam_console_apply -r + fi + + # Create the .keep to stop portage from removing /var/lock + > /var/lock/.keep + eend 0 + + # + # Clean up /tmp directory + # + if [[ -z ${CDBOOT} ]] && [[ -d /tmp ]] ; then + cd /tmp + if [[ ${WIPE_TMP} == "yes" ]] ; then + ebegin "Wiping /tmp directory" + # This eval stuff sucks, so if someone has a better *working* + # solution, please file a bug at http://bugs.gentoo.org/ + # Originally ripped from Debian init scripts + local exceptions=" + '!' -name . -a + '!' '(' -uid 0 -a + '(' + -path './lost+found/*' -o + -path './quota.user/*' -o + -path './aquota.user/*' -o + -path './quota.group/*' -o + -path './aquota.group/*' -o + -path './.journal/*' + ')' + ')'" + # First kill most files, then kill empty dirs + eval find . -xdev -depth ${exceptions} ! -type d -print0 | xargs -0 rm -f -- + eval find . -xdev -depth ${exceptions} -type d -empty -exec rmdir '{}' \\';' + eend 0 + else + ebegin "Cleaning /tmp directory" + ( + rm -f /tmp/.X*-lock /tmp/esrv* /tmp/kio* /tmp/jpsock.* /tmp/.fam* + rm -rf /tmp/.esd* /tmp/orbit-* /tmp/ssh-* /tmp/ksocket-* /tmp/.*-unix + ) &> /dev/null + eend 0 + fi + + ( + # Make sure our X11 stuff have the correct permissions + mkdir -p /tmp/.{ICE,X11}-unix + chown 0:0 /tmp/.{ICE,X11}-unix + chmod 1777 /tmp/.{ICE,X11}-unix + [[ -x /sbin/restorecon ]] && restorecon /tmp/.{ICE,X11}-unix + ) &> /dev/null + fi + + # + # Create an 'after-boot' dmesg log + # + touch /var/log/dmesg + chmod 640 /var/log/dmesg + dmesg > /var/log/dmesg + + # + # Check for /etc/resolv.conf, and create if missing + # + [[ -f /etc/resolv.conf ]] || touch /etc/resolv.conf &> /dev/null +} + + +# vim:ts=4 diff --git a/init.d/checkfs b/init.d/checkfs new file mode 100755 index 0000000..dbdfd0a --- /dev/null +++ b/init.d/checkfs @@ -0,0 +1,54 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + need checkroot modules +} + +start() { + local retval=0 + + # Start RAID/LVM/EVMS/DM volumes for /usr, /var, etc. + # NOTE: this should be done *before* mounting anything + [[ -z ${CDBOOT} ]] && start_volumes + + # Setup dm-crypt mappings if any + start_addon dm-crypt + + if [[ -f /fastboot ]] || [[ -n ${CDBOOT} ]] ; then + rm -f /fastboot + else + ebegin "Checking all filesystems" + if [[ -f /forcefsck ]] ; then + ewarn "A full fsck has been forced" + fsck -C -R -A -a -f + retval=$? + rm -f /forcefsck + else + fsck -C -T -R -A -a + retval=$? + fi + if [[ ${retval} -eq 0 ]] ; then + eend 0 + elif [[ ${retval} -ge 1 && ${retval} -le 3 ]] ; then + ewend 1 "Filesystem errors corrected." + # Everything should be ok, so return a pass + return 0 + else + if [[ ${RC_FORCE_AUTO} == "yes" ]] ; then + eend 2 "Fsck could not correct all errors, rerunning" + fsck -C -T -R -A -a -y + retval=$? + fi + + if [[ ${retval} -gt 3 ]] ; then + eend 2 "Fsck could not correct all errors, manual repair needed" + /sbin/sulogin ${CONSOLE} + fi + fi + fi +} + + +# vim:ts=4 diff --git a/init.d/checkroot b/init.d/checkroot new file mode 100755 index 0000000..613f88a --- /dev/null +++ b/init.d/checkroot @@ -0,0 +1,124 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + before * +} + +start() { + local retval=0 + + if [[ ! -f /fastboot && -z ${CDBOOT} ]] && ! is_net_fs / ; then + if touch -c / >& /dev/null ; then + ebegin "Remounting root filesystem read-only" + mount -n -o remount,ro / + eend $? + fi + + if [[ -f /forcefsck ]] || get_bootparam "forcefsck" ; then + ebegin "Checking root filesystem (full fsck forced)" + fsck -C -a -f / + # /forcefsck isn't deleted because checkfs needs it. + # it'll be deleted in that script. + retval=$? + else + # Obey the fs_passno setting for / (see fstab(5)) + # - find the / entry + # - make sure we have 6 fields + # - see if fs_passno is something other than 0 + if [[ -n $(awk '($1 ~ /^(\/|UUID|LABEL)/ && $2 == "/" \ + && NF == 6 && $6 != 0) { print }' /etc/fstab) ]] + then + ebegin "Checking root filesystem" + fsck -C -T -a / + retval=$? + else + ebegin "Skipping root filesystem check (fstab's passno == 0)" + retval=0 + fi + fi + + if [[ ${retval} -eq 0 ]] ; then + eend 0 + elif [[ ${retval} -eq 1 ]] ; then + ewend 1 "Filesystem repaired" + elif [[ ${retval} -eq 2 || ${retval} -eq 3 ]] ; then + ewend 1 "Filesystem repaired, but reboot needed!" + echo -ne "\a"; sleep 1; echo -ne "\a"; sleep 1 + echo -ne "\a"; sleep 1; echo -ne "\a"; sleep 1 + ewarn "Rebooting in 10 seconds ..." + sleep 10 + einfo "Rebooting" + /sbin/reboot -f + else + if [[ ${RC_FORCE_AUTO} == "yes" ]] ; then + eend 2 "Rerunning fsck in force mode" + fsck -y -C -T -a / + else + eend 2 "Filesystem couldn't be fixed :(" + /sbin/sulogin ${CONSOLE} + fi + einfo "Unmounting filesystems" + /bin/mount -a -o remount,ro &> /dev/null + einfo "Rebooting" + /sbin/reboot -f + fi + fi + + # Should we mount root rw ? + if mount -vf -o remount / 2> /dev/null | \ + awk '{ if ($6 ~ /rw/) exit 0; else exit 1; }' + then + ebegin "Remounting root filesystem read/write" + mount -n -o remount,rw / &> /dev/null + if [[ $? -ne 0 ]] ; then + eend 2 "Root filesystem could not be mounted read/write :(" + if [[ ${RC_FORCE_AUTO} != "yes" ]] ; then + /sbin/sulogin ${CONSOLE} + fi + else + eend 0 + fi + fi + + if [[ ${BOOT} == "yes" ]] ; then + local x= + local y= + + # + # Create /etc/mtab + # + + # Don't create mtab if /etc is readonly + if ! touch /etc/mtab 2> /dev/null ; then + ewarn "Skipping /etc/mtab initialization (ro root?)" + return 0 + fi + + # Clear the existing mtab + > /etc/mtab + + # Add the entry for / to mtab + mount -f / + + # Don't list root more than once + awk '$2 != "/" {print}' /proc/mounts >> /etc/mtab + + # Now make sure /etc/mtab have additional info (gid, etc) in there + for x in $(awk '{ print $2 }' /proc/mounts | sort -u) ; do + for y in $(awk '{ print $2 }' /etc/fstab) ; do + if [[ ${x} == ${y} ]] ; then + mount -f -o remount $x + continue + fi + done + done + + # Remove stale backups + rm -f /etc/mtab~ /etc/mtab~~ + fi +} + + +# vim:ts=4 diff --git a/init.d/clock b/init.d/clock new file mode 100755 index 0000000..2ce9616 --- /dev/null +++ b/init.d/clock @@ -0,0 +1,144 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +opts="save" + +depend() { + need localmount +} + +setupopts() { + if is_uml_sys ; then + TBLURB="UML" + fakeit=1 + elif is_vserver_sys ; then + TBLURB="VServer" + fakeit=1 + elif is_xenU_sys ; then + TBLURB="xen" + fakeit=1 + elif grep -q ' cobd$' /proc/devices ; then + TBLURB="coLinux" + fakeit=1 + elif [[ ${CLOCK} == "UTC" ]] ; then + myopts="--utc" + TBLURB="UTC" + else + myopts="--localtime" + TBLURB="Local Time" + fi + [[ ${fakeit} -eq 1 ]] && return 0 + + if [[ ${readonly} == "yes" ]] ; then + myadj="--noadjfile" + else + myadj="--adjust" + fi + + if [[ ${SRM} == "yes" ]] ; then + myopts="${myopts} --srm" + fi + if [[ ${ARC} == "arc" ]] ; then + myopts="${myopts} --arc" + fi + myopts="${myopts} ${CLOCK_OPTS}" + + # Make sure user isn't using rc.conf anymore. + if grep -qs ^CLOCK= /etc/rc.conf ; then + ewarn "CLOCK should not be set in /etc/rc.conf but in /etc/conf.d/clock" + fi +} + +start() { + local myopts="" + local myadj="" + local TBLURB="" fakeit=0 + local errstr="" + local readonly="no" + local ret=0 + + if ! touch /etc/adjtime 2>/dev/null ; then + readonly="yes" + elif [[ ! -s /etc/adjtime ]] ; then + echo "0.0 0 0.0" > /etc/adjtime + fi + + setupopts + + if [[ ${fakeit} -ne 1 && ! -e /dev/rtc ]] ; then + local x + einfon "Waiting for /dev/rtc to appear" + for x in $(seq 10) ; do + if [[ ! -e /dev/rtc ]] ; then + echo -n "." + sleep 1 + else + echo + fi + done + fi + + ebegin "Setting system clock to hardware clock [${TBLURB}]" + if [[ ${fakeit} -eq 1 ]] ; then + ret=0 + + elif [[ -x /sbin/hwclock ]] ; then + # Since hwclock always exit's with a 0, need to check its output. + errstr=$(/sbin/hwclock ${myadj} ${myopts} 2>&1 >/dev/null) + errstr="${errstr}$(/sbin/hwclock --hctosys ${myopts} 2>&1 >/dev/null)" + + if [[ -n ${errstr} ]] ; then + ewarn "${errstr}" + ret=1 + else + ret=0 + fi + errstr="Failed to set system clock to hardware clock" + else + ret=1 + errstr="/sbin/hwclock not found" + fi + eend ${ret} "${errstr}" +} + +stop() { + # Don't tweak the hardware clock on LiveCD halt. + [[ -n ${CDBOOT} ]] && return 0 + + [[ ${CLOCK_SYSTOHC} != "yes" ]] && return 0 + + local myopts="" + local TBLURB="" + local errstr="" + local ret=0 + + setupopts + + ebegin "Syncing system clock to hardware clock [${TBLURB}]" + if [[ ${fakeit} -eq 1 ]] ; then + ret=0 + + elif [[ -x /sbin/hwclock ]] ; then + errstr=$(/sbin/hwclock --systohc ${myopts} 2>&1 >/dev/null) + + if [[ -n ${errstr} ]] ; then + ret=1 + else + ret=0 + fi + errstr="Failed to sync clocks" + else + ret=1 + errstr="/sbin/hwclock not found" + fi + eend ${ret} "${errstr}" +} + +save() { + CLOCK_SYSTOHC="yes" + stop +} + + +# vim:ts=4 diff --git a/init.d/consolefont b/init.d/consolefont new file mode 100755 index 0000000..35daa11 --- /dev/null +++ b/init.d/consolefont @@ -0,0 +1,68 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + need localmount + need keymaps # sets up terminal encoding scheme + after hotplug +} + +start() { + if is_uml_sys ; then + ebegin "Setting user font" + eend 0 + return 0 + elif [[ -z ${CONSOLEFONT} ]] ; then + ebegin "Using the default console font" + eend 0 + return 0 + fi + + local x= + local param= + local sf_param= + local retval=1 + + # Get additional parameters + if [[ -n ${CONSOLETRANSLATION} ]] ; then + param="-m ${CONSOLETRANSLATION}" + fi + + # Set the console font + local errmsg="" + ebegin "Setting user font" + if [[ -x /bin/setfont ]] ; then + # We patched setfont to have --tty support ... + if [[ -n $(setfont --help 2>&1 | grep -e '--tty') || \ + -n $(setfont --help 2>&1 | grep -e '-C') ]] + then + if [[ -n $(setfont --help 2>&1 | grep -e '--tty') ]] ; then + sf_param="--tty=" + else + sf_param="-C " + fi + local ttydev= + [[ -d /dev/vc ]] \ + && ttydev=/dev/vc/ \ + || ttydev=/dev/tty + + for x in $(seq 1 "${RC_TTY_NUMBER}") ; do + /bin/setfont ${CONSOLEFONT} ${param} \ + ${sf_param}/${ttydev}${x} > /dev/null + retval=$? + done + else + /bin/setfont ${CONSOLEFONT} ${param} > /dev/null + retval=$? + fi + errmsg="Failed to set user font" + else + retval=1 + errmsg="/bin/setfont not found" + fi + eend ${retval} "${errmsg}" +} + + +# vim:ts=4 diff --git a/init.d/domainname b/init.d/domainname new file mode 100755 index 0000000..aa5fbc7 --- /dev/null +++ b/init.d/domainname @@ -0,0 +1,60 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + need checkroot hostname + before bootmisc +} + +checkconfig_nis() { + if [[ -f /etc/nisdomainname ]] ; then + ewarn "You should stop using /etc/nisdomainname and use /etc/conf.d/domainname" + export NISDOMAIN=$(</etc/nisdomainname) + return 0 + fi + [[ -n ${NISDOMAIN} ]] +} + +checkconfig_dns() { + if [[ -f /etc/dnsdomainname ]] ; then + ewarn "You should stop using /etc/dnsdomainname and use /etc/conf.d/domainname" + export DNSDOMAIN=$(</etc/dnsdomainname) + fi + [[ -z ${DNSDOMAIN} ]] && return 1 + + if ! touch /etc/resolv.conf 2> /dev/null ; then + ewarn "Unable to set domain in resolv.conf (ro root?)" + return 1 + else + return 0 + fi +} + +start() { + local retval=0 + local retval2=0 + + if checkconfig_nis ; then + ebegin "Setting NIS domainname to ${NISDOMAIN}" + /bin/domainname "${NISDOMAIN}" + retval=$? + eend ${retval} "Failed to set the NIS domainname" + fi + + if checkconfig_dns ; then + ebegin "Setting DNS domainname to ${DNSDOMAIN}" + resolv=$(grep -v '^[[:space:]]*domain' /etc/resolv.conf) + [[ ${OVERRIDE} == "1" ]] \ + && resolv="${resolv}"$'\n'"domain ${DNSDOMAIN}" \ + || resolv="domain ${DNSDOMAIN}"$'\n'"${resolv}" + echo "${resolv}" > /etc/resolv.conf + retval2=$? + eend ${retval2} "Failed to set the DNS domainname" + fi + + return $((retval + retval2)) +} + + +# vim:ts=4 diff --git a/init.d/halt.sh b/init.d/halt.sh new file mode 100755 index 0000000..1d7a670 --- /dev/null +++ b/init.d/halt.sh @@ -0,0 +1,242 @@ +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +# Check to see if this is a livecd, if it is read the commandline +# this mainly makes sure $CDBOOT is defined if it's a livecd +[[ -f /sbin/livecd-functions.sh ]] && \ + source /sbin/livecd-functions.sh && \ + livecd_read_commandline + +# Reset pam_console permissions if we are actually using it +if [[ -x /sbin/pam_console_apply && ! -c /dev/.devfsd && \ + -n $(grep -v -e '^[[:space:]]*#' /etc/pam.d/* | grep 'pam_console') ]]; then + /sbin/pam_console_apply -r +fi + +# We need to properly terminate devfsd to save the permissions +if [[ -n $(ps --no-heading -C 'devfsd') ]]; then + ebegin "Stopping devfsd" + killall -15 devfsd &>/dev/null + eend $? +elif [[ ! -e /dev/.devfsd && -e /dev/.udev && -z ${CDBOOT} && \ + ${RC_DEVICE_TARBALL} == "yes" ]] && \ + touch /lib/udev-state/devices.tar.bz2 2>/dev/null +then + ebegin "Saving device nodes" + # Handle our temp files + devices_udev=$(mktemp /tmp/devices.udev.XXXXXX) + devices_real=$(mktemp /tmp/devices.real.XXXXXX) + devices_totar=$(mktemp /tmp/devices.totar.XXXXXX) + device_tarball=$(mktemp /tmp/devices-XXXXXX) + + if [[ -z ${devices_udev} || -z ${devices_real} || \ + -z ${device_tarball} ]]; then + eend 1 "Could not create temporary files!" + else + cd /dev + # Find all devices + find . -xdev -type b -or -type c -or -type l | cut -d/ -f2- > \ + "${devices_real}" + # Figure out what udev created + eval $(grep '^[[:space:]]*udev_db=' /etc/udev/udev.conf) + if [[ -d ${udev_db} ]]; then + # New udev_db is clear text ... + udevinfo=$(cat "${udev_db}"/*) + else + # Old one is not ... + udevinfo=$(udevinfo -d) + fi + # This basically strips 'S:' and 'N:' from the db output, and then + # print all the nodes/symlinks udev created ... + echo "${udevinfo}" | gawk ' + /^(N|S):.+/ { + sub(/^(N|S):/, "") + split($0, nodes) + for (x in nodes) + print nodes[x] + }' > "${devices_udev}" + # These ones we also do not want in there + for x in MAKEDEV core fd initctl pts shm stderr stdin stdout; do + echo "${x}" >> "${devices_udev}" + done + fgrep -x -v -f "${devices_udev}" < "${devices_real}" > "${devices_totar}" + # Now only tarball those not created by udev if we have any + if [[ -s ${devices_totar} ]]; then + try tar --one-file-system -jcpf "${device_tarball}" -T "${devices_totar}" + try mv -f "${device_tarball}" /lib/udev-state/devices.tar.bz2 + try rm -f "${devices_udev}" "${devices_real}" + else + rm -f /lib/udev-state/devices.tar.bz2 + fi + eend 0 + fi +fi + +# Try to unmount all tmpfs filesystems not in use, else a deadlock may +# occure, bug #13599. +umount -at tmpfs &>/dev/null + +if [[ -n $(swapon -s 2>/dev/null) ]]; then + ebegin "Deactivating swap" + swapoff -a + eend $? +fi + +# Write a reboot record to /var/log/wtmp before unmounting + +halt -w &>/dev/null + +# Unmounting should use /proc/mounts and work with/without devfsd running + +# Credits for next function to unmount loop devices, goes to: +# +# Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org> +# Modified for RHS Linux by Damien Neil +# +# +# Unmount file systems, killing processes if we have to. +# Unmount loopback stuff first +# Use `umount -d` to detach the loopback device + +# Remove loopback devices started by dm-crypt + +remaining=$(awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts | \ + sort -r | grep -v '/newroot' | grep -v '/mnt/livecd') +[[ -n ${remaining} ]] && { + sig= + retry=3 + + while [[ -n ${remaining} && ${retry} -gt 0 ]]; do + if [[ ${retry} -lt 3 ]]; then + ebegin "Unmounting loopback filesystems (retry)" + umount -d ${remaining} &>/dev/null + eend $? "Failed to unmount filesystems this retry" + else + ebegin "Unmounting loopback filesystems" + umount -d ${remaining} &>/dev/null + eend $? "Failed to unmount filesystems" + fi + + remaining=$(awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts | \ + sort -r | grep -v '/newroot' | grep -v '/mnt/livecd') + [[ -z ${remaining} ]] && break + + /bin/fuser -k -m ${sig} ${remaining} &>/dev/null + sleep 5 + retry=$((${retry} - 1)) + sig=-9 + done +} + +# Try to unmount all filesystems (no /proc,tmpfs,devfs,etc). +# This is needed to make sure we dont have a mounted filesystem +# on a LVM volume when shutting LVM down ... +ebegin "Unmounting filesystems" +unmounts=$( \ + awk '{ \ + if (($3 !~ /^(proc|devpts|sysfs|devfs|tmpfs|usb(dev)?fs)$/) && \ + ($1 != "none") && \ + ($1 !~ /^(rootfs|\/dev\/root)$/) && \ + ($2 != "/")) \ + print $2 }' /proc/mounts | sort -ur) +for x in ${unmounts}; do + # Do not umount these if we are booting off a livecd + if [[ -n ${CDBOOT} ]] && \ + [[ ${x} == "/mnt/cdrom" || ${x} == "/mnt/livecd" ]] ; then + continue + fi + + x=${x//\\040/ } + if ! umount "${x}" &>/dev/null; then + # Kill processes still using this mount + /bin/fuser -k -m -9 "${x}" &>/dev/null + sleep 2 + # Now try to unmount it again ... + umount -f -r "${x}" &>/dev/null + fi +done +eend 0 + +# Try to remove any dm-crypt mappings +stop_addon dm-crypt + +# Stop LVM, etc +stop_volumes + +# This is a function because its used twice below +ups_kill_power() { + local UPS_CTL UPS_POWERDOWN + if [[ -f /etc/killpower ]] ; then + UPS_CTL=/sbin/upsdrvctl + UPS_POWERDOWN="${UPS_CTL} shutdown" + elif [[ -f /etc/apcupsd/powerfail ]] ; then + UPS_CTL=/etc/apcupsd/apccontrol + UPS_POWERDOWN="${UPS_CTL} killpower" + else + return 0 + fi + if [[ -x ${UPS_CTL} ]] ; then + ewarn "Signalling ups driver(s) to kill the load!" + ${UPS_POWERDOWN} + ewarn "Halt system and wait for the UPS to kill our power" + /sbin/halt -id + while [ 1 ]; do sleep 60; done + fi +} + +mount_readonly() { + local x= + local retval=0 + local cmd=$1 + + # Get better results with a sync and sleep + sync; sync + sleep 1 + + for x in $(awk '$1 != "none" { print $2 }' /proc/mounts | sort -ur) ; do + x=${x//\\040/ } + if [[ ${cmd} == "u" ]]; then + umount -n -r "${x}" + else + mount -n -o remount,ro "${x}" &>/dev/null + fi + retval=$((${retval} + $?)) + done + [[ ${retval} -ne 0 ]] && killall5 -9 &>/dev/null + + return ${retval} +} + +# Since we use `mount` in mount_readonly(), but we parse /proc/mounts, we +# have to make sure our /etc/mtab and /proc/mounts agree +cp /proc/mounts /etc/mtab &>/dev/null +ebegin "Remounting remaining filesystems readonly" +mount_worked=0 +if ! mount_readonly ; then + if ! mount_readonly ; then + # If these things really don't want to remount ro, then + # let's try to force them to unmount + if ! mount_readonly u ; then + mount_worked=1 + fi + fi +fi +eend ${mount_worked} +if [[ ${mount_worked} -eq 1 ]]; then + ups_kill_power + /sbin/sulogin -t 10 /dev/console +fi + +# Inform if there is a forced or skipped fsck +if [[ -f /fastboot ]]; then + echo + ewarn "Fsck will be skipped on next startup" +elif [[ -f /forcefsck ]]; then + echo + ewarn "A full fsck will be forced on next startup" +fi + +ups_kill_power + + +# vim:ts=4 diff --git a/init.d/hostname b/init.d/hostname new file mode 100755 index 0000000..7d10dd8 --- /dev/null +++ b/init.d/hostname @@ -0,0 +1,39 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + need checkroot +} + +start() { + local myhost=$(/bin/hostname 2>/dev/null) + local retval=0 + + # If the hostname is already set via the kernel, and /etc/hostname + # isn't setup, then we shouldn't go reseting the configuration #38172. + if [[ -z ${myhost} ]] || [[ ${myhost} == "(none)" ]] ; then + myhost="localhost" + fi + + if [[ -f /etc/hostname ]] ; then + ewarn "You should stop using /etc/hostname and use /etc/conf.d/hostname" + myhost=$(</etc/hostname) + else + myhost=${HOSTNAME} + fi + + ebegin "Setting hostname to ${myhost}" + /bin/hostname "${myhost}" + retval=$? + eend ${retval} "Failed to set the hostname" + + if [[ ${retval} -eq 0 ]] ; then + # setup $HOSTNAME, ignore errors in case /etc is readonly. + echo "HOSTNAME=\"${myhost}\"" 2>/dev/null > /etc/env.d/01hostname + fi + + return ${retval} +} + +# vim:ts=4 diff --git a/init.d/keymaps b/init.d/keymaps new file mode 100755 index 0000000..255abd2 --- /dev/null +++ b/init.d/keymaps @@ -0,0 +1,79 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + need localmount +} + +checkconfig() { + if [[ -z ${KEYMAP} ]] ; then + eerror "You need to setup KEYMAP in /etc/conf.d/keymaps first" + return 1 + fi + + # Make sure user isn't using rc.conf anymore + if grep -qs ^KEYMAP= /etc/rc.conf ; then + ewarn "KEYMAP should not be set in /etc/rc.conf but in /etc/conf.d/keymaps" + fi +} + +start() { + if is_uml_sys ; then + ebegin "Loading key mappings" + eend 0 + return 0 + fi + + local WINDOWKEYS_KEYMAP= + + checkconfig || return 1 + + # Force linux keycodes for PPC. + if [[ -f /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes ]] ; then + echo 1 > /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes + fi + + # Turn on unicode if user wants it + if [[ ${UNICODE} == "yes" ]] ; then + /usr/bin/kbd_mode -u + fi + + ebegin "Loading key mappings" + if [[ -x /bin/loadkeys ]] ; then + [[ ${SET_WINDOWKEYS} == "yes" ]] && WINDOWKEYS_KEYMAP="windowkeys" + /bin/loadkeys -q ${WINDOWKEYS_KEYMAP} ${KEYMAP} \ + ${EXTENDED_KEYMAPS} > /dev/null + eend $? "Error loading key mappings" + else + eend 1 "/bin/loadkeys not found" + return 1 + fi + + # Set terminal encoding to either ASCII or UNICODE. + # See utf-8(7) for more information. + local termencoding="" termmsg="" + if [[ ${UNICODE} == "yes" ]] ; then + local dumpkey_opts="" + [[ -n ${DUMPKEYS_CHARSET} ]] && dumpkey_opts="-c ${DUMPKEYS_CHARSET}" + + dumpkeys ${dumpkey_opts} | loadkeys --unicode + termencoding=$'\033%G' + termmsg="UTF-8" + else + termencoding=$'\033(K' + termmsg="ASCII" + fi + local n ttydev="" + [[ -d /dev/vc ]] \ + && ttydev=/dev/vc/ \ + || ttydev=/dev/tty + ebegin "Setting terminal encoding to ${termmsg}" + for n in $(seq 1 "${RC_TTY_NUMBER}") ; do + echo -n -e ${termencoding} > ${ttydev}${n} + done + eend 0 +} + + +# vim:ts=4 diff --git a/init.d/local b/init.d/local new file mode 100755 index 0000000..b729e9d --- /dev/null +++ b/init.d/local @@ -0,0 +1,34 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + after * +} + +start() { + ebegin "Starting local" + + # Add any misc programs that should be started + # to /etc/conf.d/local.start + if [[ -e /etc/conf.d/local.start ]] ; then + source /etc/conf.d/local.start + fi + + eend $? "Failed to start local" +} + +stop() { + ebegin "Stopping local" + + # Add any misc programs that should be stopped + # to /etc/conf.d/local.stop + if [[ -e /etc/conf.d/local.stop ]] ; then + source /etc/conf.d/local.stop + fi + + eend $? "Failed to stop local" +} + + +# vim:ts=4 diff --git a/init.d/localmount b/init.d/localmount new file mode 100755 index 0000000..fc49539 --- /dev/null +++ b/init.d/localmount @@ -0,0 +1,47 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + need checkfs +} + +start() { + # Mount local filesystems in /etc/fstab. + ebegin "Mounting local filesystems" + mount -at noproc,noshm,no${NET_FS_LIST// /,no} >/dev/null + eend $? "Some local filesystem failed to mount" + + # Make sure we insert usbcore if its a module + if [[ -f /proc/modules && ! -d /proc/bus/usb ]] ; then + # >/dev/null to hide errors from non-USB users + modprobe usbcore &> /dev/null + fi + + # Check what USB fs the kernel support. Currently + # 2.5+ kernels, and later 2.4 kernels have 'usbfs', + # while older kernels have 'usbdevfs'. + local usbfs=$(grep -Fow usbfs /proc/filesystems || + grep -Fow usbdevfs /proc/filesystems) + + if [[ -n ${usbfs} ]] && \ + [[ -e /proc/bus/usb && ! -e /proc/bus/usb/devices ]] + then + ebegin "Mounting USB device filesystem (${usbfs})" + usbgid=$(awk -F: '/^usb:/{print $3; exit}' /etc/group) + mount -t ${usbfs} usbfs /proc/bus/usb \ + ${usbgid:+-o devmode=0664,devgid=${usbgid}} + eend $? "Failed to mount USB device filesystem" + fi + + # Swap on loopback devices, and other weirdnesses + ebegin "Activating (possibly) more swap" + /sbin/swapon -a + eend $? + + # Start dm-crypt mappings, if any + start_addon dm-crypt +} + + +# vim:ts=4 diff --git a/init.d/modules b/init.d/modules new file mode 100755 index 0000000..38e0f44 --- /dev/null +++ b/init.d/modules @@ -0,0 +1,122 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + need checkroot hostname + use isapnp +} + +load_modules() { + local x= + local i=0 + local retval=0 + local modules= + local modargs= + local modcount=0 + local config="$1" + + [[ -z ${config} || ! -r ${config} ]] && return 0 + + # Loop over every line in $config + eval $(awk ' + BEGIN { + COUNT = 0 # Make sure COUNT is set + } + + $0 !~ /(^[[:space:]]*(#|$))/ { + if (MODULES == "") + MODULES = $1 + else + MODULES = MODULES " " $1 + + # Not the greatest method to remove $1 from $0, but it works + sub(/^[[:space:]]*[^[:space:]]*[[:space:]]*/, "") + # Trim trailing comments on the line + sub(/#.*$/, "") + ARGS[COUNT] = $0 + COUNT++ + } + + END { + # 'eval' will make sure these are set to proper bash variables + print "modcount=" COUNT + print "modules=\"" MODULES "\"" + for (x = 0;x < COUNT;x++) + print "modargs[" x "]=\"" ARGS[x] "\"" + } + ' "${config}") + + if [[ ${modcount} -gt 0 ]]; then + einfo "Using ${config} as config:" + + for x in ${modules}; do + ebegin " Loading module ${x}" + modprobe -q ${x} ${modargs[${i}]} &>/dev/null + retval=$? + eend ${retval} " Failed to load ${x}" + + i=$((i+1)) + [[ ${retval} -eq 0 ]] || modcount=$((modcount-1)) + done + + einfo "Autoloaded ${modcount} module(s)" + fi + + return 0 +} + +start() { + local KV=$(uname -r) + local KV_MAJOR=$(KV_major "${KV}") + local KV_MINOR=$(KV_minor "${KV}") + local KV_MICRO=$(KV_micro "${KV}") + + # Should not fail if kernel do not have module + # support compiled in ... + [[ -f /proc/modules ]] || return 0 + + # Make sure depmod from modutils do not whine, but do not bother if + # we are on a 2.6 kernel without modprobe.old + if [[ -z "${CDBOOT}" ]] && [[ ! -e /etc/modules.conf ]] && \ + [[ $(get_KV) -lt $(KV_to_int '2.5.48') || -x /sbin/modprobe.old ]] + then + echo '### This file is automatically generated by modules-update' \ + > /etc/modules.conf 2>/dev/null + [[ ! -f /etc/modules.conf ]] && \ + ewarn "Cannot update /etc/modules.conf!" + fi + + # Only do this if we have modules.conf or a 2.6 kernel + if [[ -z "${CDBOOT}" ]] && \ + [[ -f /etc/modules.conf || $(get_KV) -ge $(KV_to_int '2.5.48') ]] + then + /sbin/modules-update + fi + + local autoload="" + if [[ -f /etc/modules.autoload && ! -L /etc/modules.autoload ]]; then + autoload=/etc/modules.autoload + else + local x + for x in "${KV}" ${KV_MAJOR}.${KV_MINOR}.${KV_MICRO} ${KV_MAJOR}.${KV_MINOR} ; do + if [[ -f /etc/modules.autoload.d/kernel-"${x}" ]] ; then + autoload="/etc/modules.autoload.d/kernel-${x}" + break + fi + done + fi + [[ -n ${autoload} ]] && load_modules "${autoload}" + + # + # Just in case a sysadmin prefers generic symbolic links in + # /lib/modules/boot for boot time modules we will load these modules + # + [[ -n $(modprobe -l -t boot) ]] && modprobe -a -t boot \* &>/dev/null + + # Above test clobbers the return + return 0 +} + + +# vim:ts=4 diff --git a/init.d/net.eth0 b/init.d/net.eth0 new file mode 120000 index 0000000..3843c79 --- /dev/null +++ b/init.d/net.eth0 @@ -0,0 +1 @@ +net.lo
\ No newline at end of file diff --git a/init.d/netmount b/init.d/netmount new file mode 100755 index 0000000..104bfd8 --- /dev/null +++ b/init.d/netmount @@ -0,0 +1,93 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + local myneed="net" + local myuse="" + + # Only have Portmap as a dependency if there is a nfs mount in fstab + # that should be mounted at boot time. Also filter out comments. + local nfsmounts=$(awk '!/^#/ && ($3=="nfs" || $3=="nfs4") && $4 !~ /noauto/ { print $0 }' /etc/fstab) + + if [ -n "${nfsmounts}" ] + then + myneed="${myneed} portmap" + myuse="${myuse} nfs nfsmount" + fi + + need ${myneed} + use ${myuse} +} + +start() { + local rcfilesystems="" + + # Only try to mount NFS filesystems if portmap was started. + # This is to fix "hang" problems for new users who do not + # add portmap to the default runlevel. + if [ -L "${svcdir}/started/portmap" ] + then + rcfilesystems="${NET_FS_LIST// /,}" # convert to comma-separated + else + rcfilesystems=" ${NET_FS_LIST} " + rcfilesystems=${rcfilesystems// nfs /} # remove nfs + rcfilesystems=${rcfilesystems// nfs4 /} # remove nfs4 + rcfilesystems=${rcfilesystems# } # remove front and + rcfilesystems=${rcfilesystems% } # back spaces + rcfilesystems=${rcfilesystems// /,} # convert to comma-separated + fi + + ebegin "Mounting network filesystems" + mount -at ${rcfilesystems} >/dev/null + + if [ "$?" -ne 0 ] + then + ewend 1 "Could not mount all network filesystems!" + else + eend 0 + fi + + return 0 +} + +stop() { + local ret + ebegin "Unmounting network filesystems" + [ -z "$(umount -art ${NET_FS_LIST// /,} 2>&1)" ] + ret=$? + eend ${ret} "Failed to simply unmount filesystems" + [ ${ret} -eq 0 ] && return 0 + + # `umount -a` will fail if the filesystems are in use. + # Here we use fuser to kill off processes that are using + # the filesystems so that we can unmount properly. + # We will gradually use harsher kill signals so that the + # processes know we aren't screwing around here ;). + declare -a siglist=( "TERM" "KILL" "KILL" ) + local retry=0 + local remaining="go" + + while [ -n "${remaining}" -a ${retry} -lt 3 ] + do + # Populate $remaining with a newline-delimited list of network + # filesystems. Mount points have spaces swapped for '\040' (see + # fstab(5)) so we have to translate them back to spaces. + remaining="$(awk '$3 ~ /'${NET_FS_LIST// /|}'/ { if ($2 != "/") print $2 }' /proc/mounts | sort -r)" + # Since we have to worry about the spaces being quoted properly, + # we'll use `set --` and then "$@" to get the correct result. + IFS=$'\n' + set -- ${remaining//\\040/ } + unset IFS + [ -z "${remaining}" ] && break + + # try to unmount again + ebegin $'\t'"Unmounting network filesystems (retry #$((retry+1)))" + /bin/fuser -k -${siglist[$((retry++))]} -m "$@" &>/dev/null + sleep 5 + umount "$@" &>/dev/null + eend $? $'\t'"Failed to unmount filesystems" + done +} + +# vim:ts=4 diff --git a/init.d/numlock b/init.d/numlock new file mode 100755 index 0000000..22654f0 --- /dev/null +++ b/init.d/numlock @@ -0,0 +1,34 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + need localmount +} + +start() { + ebegin "Enabling numlock on ttys" + local dev + [[ -d /dev/vc ]] \ + && dev=/dev/vc/ \ + || dev=/dev/tty + for tty in $(seq 1 "${RC_TTY_NUMBER}") ; do + setleds -D +num < ${dev}${tty} &> /dev/null + done + eend $? "Failed to enable numlock" +} + +stop() { + ebegin "Disabling numlock on ttys" + local dev + [[ -d /dev/vc ]] \ + && dev=/dev/vc/ \ + || dev=/dev/tty + for tty in $(seq 1 "${RC_TTY_NUMBER}") ; do + setleds -D -num < ${dev}${tty} &> /dev/null + done + eend $? "Failed to disable numlock" +} + + +# vim:ts=4 diff --git a/init.d/reboot.sh b/init.d/reboot.sh new file mode 100755 index 0000000..fb67439 --- /dev/null +++ b/init.d/reboot.sh @@ -0,0 +1,8 @@ +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +/sbin/reboot -idp + +# hmm, if the above failed, that's kind of odd ... +# so let's force a reboot +/sbin/reboot -f diff --git a/init.d/rmnologin b/init.d/rmnologin new file mode 100755 index 0000000..559b660 --- /dev/null +++ b/init.d/rmnologin @@ -0,0 +1,16 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + need localmount +} + +start() { + if [[ -f /etc/nologin.boot ]] ; then + rm -f /etc/nologin /etc/nologin.boot &> /dev/null + fi +} + + +# vim:ts=4 diff --git a/init.d/shutdown.sh b/init.d/shutdown.sh new file mode 100755 index 0000000..4672211 --- /dev/null +++ b/init.d/shutdown.sh @@ -0,0 +1,8 @@ +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +/sbin/halt -ihdp + +# hmm, if the above failed, that's kind of odd ... +# so let's force a halt +/sbin/halt -f diff --git a/init.d/urandom b/init.d/urandom new file mode 100755 index 0000000..368130d --- /dev/null +++ b/init.d/urandom @@ -0,0 +1,37 @@ +#!/sbin/runscript +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + need localmount +} + +start() { + [[ -c /dev/urandom ]] || return + if [[ -f /var/run/random-seed ]] ; then + cat /var/run/random-seed > /dev/urandom + fi + if ! rm -f /var/run/random-seed &> /dev/null ; then + ewarn "Skipping /var/run/random-seed initialization (ro root?)" + return 0 + fi + ebegin "Initializing random number generator" + umask 077 + dd if=/dev/urandom of=/var/run/random-seed count=1 &> /dev/null + eend $? "Error initializing random number generator" + umask 022 +} + +stop() { + [[ -n ${CDBOOT} ]] && return 0 + + ebegin "Saving random seed" + # Carry a random seed from shut-down to start-up; + # see documentation in linux/drivers/char/random.c + umask 077 + dd if=/dev/urandom of=/var/run/random-seed count=1 &> /dev/null + eend $? "Failed to save random seed" +} + + +# vim:ts=4 |