aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-03-25 14:06:05 +0000
committerRoy Marples <roy@marples.name>2008-03-25 14:06:05 +0000
commit55eb3794fb4ad563102d5ab30c1d5337a599b2e5 (patch)
tree0d052faeb050c1e18ba56f6f6189bff3ffca28c9 /sh
parent08aff6ef44ac5dc438d916b53aa61385f6d299f3 (diff)
Rework our folder structure so that we don't have OS specific dirs, making it easier to share init and conf files per OS.
Diffstat (limited to 'sh')
-rw-r--r--sh/Makefile6
-rw-r--r--sh/Makefile.BSD1
-rw-r--r--sh/Makefile.FreeBSD8
-rw-r--r--sh/Makefile.Linux9
-rw-r--r--sh/Makefile.NetBSD10
-rw-r--r--sh/ifwatchd-carrier.sh.in5
-rw-r--r--sh/ifwatchd-nocarrier.sh.in5
-rw-r--r--sh/init-early.Linux.sh.in20
-rw-r--r--sh/init.BSD.sh.in51
-rw-r--r--sh/init.Linux.sh.in185
10 files changed, 295 insertions, 5 deletions
diff --git a/sh/Makefile b/sh/Makefile
index 2f10ef53..43b796bd 100644
--- a/sh/Makefile
+++ b/sh/Makefile
@@ -2,14 +2,14 @@ DIR= ${RC_LIB}/sh
SRCS= functions.sh.in gendepends.sh.in net.sh.in \
rc-functions.sh.in runscript.sh.in
INC= init-common-post.sh rc-mount.sh functions.sh rc-functions.sh
-BIN= gendepends.sh net.sh runscript.sh
+BIN= gendepends.sh init.sh net.sh runscript.sh
INSTALLAFTER= _installafter
MK= ../mk
-# To get NET_LO
+include ${MK}/os.mk
+include Makefile.${OS}
include ${MK}/scripts.mk
-include Makefile.${SUBOS}
_installafter:
${INSTALL} -d ${DESTDIR}/${PREFIX}/${INITDIR}
diff --git a/sh/Makefile.BSD b/sh/Makefile.BSD
deleted file mode 100644
index f1e45618..00000000
--- a/sh/Makefile.BSD
+++ /dev/null
@@ -1 +0,0 @@
-NET_LO = net.lo0
diff --git a/sh/Makefile.FreeBSD b/sh/Makefile.FreeBSD
new file mode 100644
index 00000000..210ee0c3
--- /dev/null
+++ b/sh/Makefile.FreeBSD
@@ -0,0 +1,8 @@
+SRCS+= init.sh.in
+
+NET_LO= net.lo0
+
+.SUFFIXES: .BSD.sh.in
+.BSD.sh.in.sh:
+ sed ${SED_REPLACE} ${SED_EXTRA} $< > $@
+
diff --git a/sh/Makefile.Linux b/sh/Makefile.Linux
index 219c92fb..6546d92b 100644
--- a/sh/Makefile.Linux
+++ b/sh/Makefile.Linux
@@ -1 +1,8 @@
-NET_LO = net.lo
+NET_LO= net.lo
+SRCS+= init.sh.in init-early.sh.in
+BIN+= init-early.sh
+
+.SUFFIXES: .Linux.sh.in
+.Linux.sh.in.sh:
+ sed ${SED_REPLACE} ${SED_EXTRA} $< > $@
+
diff --git a/sh/Makefile.NetBSD b/sh/Makefile.NetBSD
new file mode 100644
index 00000000..5b13c88a
--- /dev/null
+++ b/sh/Makefile.NetBSD
@@ -0,0 +1,10 @@
+SRCS+= init.sh.in
+
+NET_LO= net.lo0
+SRCS+= ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in
+BIN+= ifwatchd-carrier.sh ifwatchd-nocarrier.sh
+
+.SUFFIXES: .BSD.sh.in
+.BSD.sh.in.sh:
+ sed ${SED_REPLACE} ${SED_EXTRA} $< > $@
+
diff --git a/sh/ifwatchd-carrier.sh.in b/sh/ifwatchd-carrier.sh.in
new file mode 100644
index 00000000..ec9c5abd
--- /dev/null
+++ b/sh/ifwatchd-carrier.sh.in
@@ -0,0 +1,5 @@
+#!@SHELL@
+# Wrapper for ifwatchd(8)
+
+export IN_BACKGROUND=yes
+${RC_SERVICE} --quiet start
diff --git a/sh/ifwatchd-nocarrier.sh.in b/sh/ifwatchd-nocarrier.sh.in
new file mode 100644
index 00000000..3ba111cb
--- /dev/null
+++ b/sh/ifwatchd-nocarrier.sh.in
@@ -0,0 +1,5 @@
+#!@SHELL@
+# Wrapper for ifwatchd(8)
+
+export IN_BACKGROUND=yes
+${RC_SERVICE} --quiet stop
diff --git a/sh/init-early.Linux.sh.in b/sh/init-early.Linux.sh.in
new file mode 100644
index 00000000..d6cb007d
--- /dev/null
+++ b/sh/init-early.Linux.sh.in
@@ -0,0 +1,20 @@
+#!@SHELL@
+# Copyright 2007-2008 Roy Marples <roy@marples.name>
+# All rights reserved. Released under the 2-clause BSD license.
+
+# Try and set a font and as early as we can
+if [ -e /etc/runlevels/"${RC_DEFAULTLEVEL}"/consolefont \
+ -o -e /etc/runlevels/"${RC_BOOTLEVEL}"/consolefont ]; then
+ termencoding="(K"
+ [ -e "${RC_LIBDIR}"/console/unicode ] && termencoding="%G"
+ CONSOLE="${CONSOLE:-/dev/console}"
+ printf "\033%s" "${termencoding}" >"${CONSOLE}" 2>/dev/null
+ if [ -r "${RC_LIBDIR}"/console/font -a -x /bin/setfont ]; then
+ font="$(cat "${RC_LIBDIR}"/console/font)"
+ [ -c "${CONSOLE}" ] && cons="-C ${CONSOLE}"
+ setfont ${cons} "${RC_LIBDIR}"/console/"${font}" 2>/dev/null
+ fi
+fi
+
+# Ensure we exit 0 so the boot continues
+exit 0
diff --git a/sh/init.BSD.sh.in b/sh/init.BSD.sh.in
new file mode 100644
index 00000000..dbff7368
--- /dev/null
+++ b/sh/init.BSD.sh.in
@@ -0,0 +1,51 @@
+#!@SHELL@
+# Copyright 2007-2008 Roy Marples <roy@marples.name>
+# All rights reserved. Released under the 2-clause BSD license.
+
+# This basically mounts $svcdir as a ramdisk, but preserving its content
+# which allows us to run depscan.sh
+# FreeBSD has a nice ramdisk - we don't set a size as we should always
+# be fairly small and we unmount them after the boot level is done anyway
+# NOTE we don't set a size for Linux either
+# FreeBSD-7 supports tmpfs now :)
+mount_svcdir()
+{
+ local dotmp=false release=false retval=0
+ if [ -e "${RC_SVCDIR}"/deptree ]; then
+ dotmp=true
+ if ! mount -t tmpfs none "${RC_LIBDIR}"/tmp 2>/dev/null; then
+ mdconfig -a -t malloc -s 1m -u 1
+ newfs /dev/md1
+ mount /dev/md1 "${RC_LIBDIR}"/tmp
+ release=true
+ fi
+ cp -p "${RC_SVCDIR}"/deptree "${RC_SVCDIR}"/depconfig \
+ "${RC_SVCDIR}"/nettree "${RC_LIBDIR}"/tmp 2>/dev/null
+ fi
+ if ! fstabinfo --mount "${RC_SVCDIR}"; then
+ if ! mount -t tmpfs -o rw,noexec,nosuid none "${RC_SVCDIR}" 2>/dev/null; then
+ mdconfig -a -t malloc -s "${rc_svcsize:-1024}"k -u 0
+ newfs -b 4096 -i 1024 -n /dev/md0
+ mount -o rw,noexec,nosuid /dev/md0 "${RC_SVCDIR}"
+ fi
+ fi
+ retval=$?
+ if ${dotmp}; then
+ cp -p "${RC_LIBDIR}"/tmp/deptree "${RC_LIBDIR}"/tmp/depconfig \
+ "${RC_LIBDIR}"/tmp/nettree "${RC_SVCDIR}" 2>/dev/null
+ umount "${RC_LIBDIR}"/tmp
+ ${release} && mdconfig -d -u 1
+ fi
+
+ return ${retval}
+}
+
+. "${RC_LIBDIR}"/sh/functions.sh
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+# Disable devd until we need it
+if [ -z "${RC_SYS}" -a "${RC_UNAME}" = "FreeBSD" ]; then
+ sysctl hw.bus.devctl_disable=1 >/dev/null
+fi
+
+. "${RC_LIBDIR}"/sh/init-common-post.sh
diff --git a/sh/init.Linux.sh.in b/sh/init.Linux.sh.in
new file mode 100644
index 00000000..25a3ecb7
--- /dev/null
+++ b/sh/init.Linux.sh.in
@@ -0,0 +1,185 @@
+#!@SHELL@
+# Copyright 1999-2007 Gentoo Foundation
+# Copyright 2007-2008 Roy Marples <roy@marples.name>
+# All rights reserved. Released under the 2-clause BSD license.
+
+# This basically mounts $RC_SVCDIR as a ramdisk, but preserving its content
+# which allows us to store service state and generate dependencies if needed.
+# The tricky part is finding something our kernel supports
+# tmpfs and ramfs are easy, so force one or the other.
+mount_svcdir()
+{
+ local fs= fsopts="-o rw,noexec,nodev,nosuid" devdir="rc-svcdir" devtmp="none" x=
+ local svcsize=${rc_svcsize:-1024}
+
+ if grep -Eq "[[:space:]]+tmpfs$" /proc/filesystems; then
+ fs="tmpfs"
+ fsopts="${fsopts},mode=0755,size=${svcsize}k"
+ elif grep -Eq "[[:space:]]+ramfs$" /proc/filesystems; then
+ fs="ramfs"
+ # ramfs has no special options
+ elif [ -e /dev/ram0 -a -e /dev/ram1 ] \
+ && grep -Eq "[[:space:]]+ext2$" /proc/filesystems; then
+ devdir="/dev/ram0"
+ devtmp="/dev/ram1"
+ fs="ext2"
+ for x in ${devdir} ${devtmp}; do
+ dd if=/dev/zero of="${x}" bs=1k count="${svcsize}"
+ mkfs -t "${fs}" -i 1024 -vm0 "${x}" "${svcsize}"
+ done
+ else
+ echo
+ eerror "OpenRC requires tmpfs, ramfs or 2 ramdisks + ext2"
+ eerror "compiled into the kernel"
+ echo
+ return 1
+ fi
+
+ local dotmp=false
+ if [ -e "${RC_SVCDIR}"/deptree ]; then
+ dotmp=true
+ mount -n -t "${fs}" -o rw "${devtmp}" "${RC_LIBDIR}"/tmp
+ cp -p "${RC_SVCDIR}"/deptree "${RC_SVCDIR}"/depconfig \
+ "${RC_SVCDIR}"/nettree "${RC_LIBDIR}"/tmp 2>/dev/null
+ fi
+
+ # If we have no entry in fstab for $RC_SVCDIR, provide our own
+ if ! fstabinfo --mount "${RC_SVCDIR}"; then
+ mount -n -t "${fs}" ${fsopts} "${devdir}" "${RC_SVCDIR}"
+ fi
+
+ if ${dotmp}; then
+ cp -p "${RC_LIBDIR}"/tmp/deptree "${RC_LIBDIR}"/tmp/depconfig \
+ "${RC_LIBDIR}"/tmp/nettree "${RC_SVCDIR}" 2>/dev/null
+ umount -n "${RC_LIBDIR}"/tmp
+ fi
+}
+
+. /etc/init.d/functions.sh
+. "${RC_LIBDIR}"/sh/rc-functions.sh
+[ -r /etc/conf.d/rc ] && . /etc/conf.d/rc
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+# Set the console loglevel to 1 for a cleaner boot
+# the logger should anyhow dump the ring-0 buffer at start to the
+# logs, and that with dmesg can be used to check for problems
+if [ -n "${dmesg_level}" -a "${RC_SYS}" != "VSERVER" ]; then
+ dmesg -n "${dmesg_level}"
+fi
+
+# By default VServer already has /proc mounted, but OpenVZ does not!
+# However, some of our users have an old proc image in /proc
+# NFC how they managed that, but the end result means we have to test if
+# /proc actually works or not. We to this by comparing uptime to one a second
+# ago
+mountproc=true
+if [ -e /proc/uptime ]; then
+ up="$(cat /proc/uptime)"
+ sleep 1
+ if [ "${up}" = "$(cat /proc/uptime)" ]; then
+ eerror "You have cruft in /proc that should be deleted"
+ else
+ einfo "/proc is already mounted, skipping"
+ mountproc=false
+ fi
+ unset up
+fi
+
+if ${mountproc}; then
+ procfs="proc"
+ [ "${RC_UNAME}" = "GNU/kFreeBSD" ] && proc="linprocfs"
+ ebegin "Mounting /proc"
+ if ! fstabinfo --mount /proc; then
+ mount -n -t "${procfs}" -o noexec,nosuid,nodev proc /proc
+ fi
+ eend $?
+fi
+unset mountproc
+
+# Read off the kernel commandline to see if there's any special settings
+# especially check to see if we need to set the CDBOOT environment variable
+# Note: /proc MUST be mounted
+if [ -r /sbin/livecd-functions.sh ]; then
+ . /sbin/livecd-functions.sh
+ livecd_read_commandline
+fi
+
+if [ "${RC_UNAME}" != "GNU/kFreeBSD" \
+ -a "${RC_SYS}" != "VSERVER" \
+ -a "${RC_SYS}" != "OPENVZ" ]
+then
+ if grep -Eq "[[:space:]]+sysfs$" /proc/filesystems; then
+ if [ -d /sys ]; then
+ if ! mountinfo --quiet /sys; then
+ ebegin "Mounting /sys"
+ if ! fstabinfo --mount /sys; then
+ mount -n -t sysfs -o noexec,nosuid,nodev sysfs /sys
+ fi
+ eend $?
+ fi
+ else
+ ewarn "No /sys to mount sysfs needed in 2.6 and later kernels!"
+ fi
+ fi
+fi
+
+# Try to figure out how the user wants /dev handled
+if [ "${rc_devices}" = "static" \
+ -o "${RC_SYS}" = "VSERVER" \
+ -o "${RC_SYS}" = "OPENVZ" \
+ -o "${RC_UNAME}" = "GNU/kFreeBSD" ]
+then
+ ebegin "Using existing device nodes in /dev"
+ eend 0
+else
+ case ${rc_devices} in
+ devfs) managers="devfs udev mdev";;
+ udev) managers="udev devfs mdev";;
+ mdev) managers="mdev udev devfs";;
+ *) managers="udev devfs mdev";;
+ esac
+
+ for m in ${managers}; do
+ # Check kernel params
+ if get_bootparam "no${m}" || ! has_addon ${m}-start; then
+ continue
+ fi
+ # Let's see if we can get this puppy rolling
+ start_addon ${m} && break
+
+ # Clean up
+ mountinfo -q /dev && umount -n /dev
+ done
+fi
+
+# Mount required stuff as user may not have then in /etc/fstab
+for x in "devpts /dev/pts 0755 ,gid=5,mode=0620 devpts" "tmpfs /dev/shm 1777 ,nodev shm"
+do
+ set -- ${x}
+ grep -Eq "[[:space:]]+$1$" /proc/filesystems || continue
+ mountinfo -q "$2" && continue
+
+ if [ ! -d "$2" ] && \
+ [ "${m}" = "devfs" -o "${m}" = "udev" ]; then
+ mkdir -m "$3" -p "$2" >/dev/null 2>&1 || \
+ ewarn "Could not create $2!"
+ fi
+
+ if [ -d "$2" ]; then
+ ebegin "Mounting $2"
+ if ! fstabinfo --mount "$2"; then
+ mount -n -t "$1" -o noexec,nosuid"$4" "$5" "$2"
+ fi
+ eend $?
+ fi
+done
+
+# If booting off CD, we want to update inittab before setting the runlevel
+if [ -f /sbin/livecd-functions.sh -a -n "${CDBOOT}" ]; then
+ ebegin "Updating inittab"
+ livecd_fix_inittab
+ eend $?
+ telinit q &>/dev/null
+fi
+
+. "${RC_LIBDIR}"/sh/init-common-post.sh