From c2648ca5f539c450b27d35c7c0a3d41c6e193d8f Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Wed, 27 Feb 2008 20:29:32 +0000 Subject: Makefile SH variable now tweaks the default shell used by our scripts. --- etc.BSD/Makefile | 8 +- etc.BSD/rc.in | 2 +- etc.BSD/rc.shutdown.in | 2 +- init.d/halt.sh | 99 ------------------------ init.d/halt.sh.in | 99 ++++++++++++++++++++++++ mk/scripts.mk | 11 ++- mk/sys.mk | 1 + sh.BSD/init.sh | 47 ------------ sh.BSD/init.sh.in | 47 ++++++++++++ sh.Linux/init-early.sh | 20 ----- sh.Linux/init-early.sh.in | 20 +++++ sh.Linux/init.sh | 189 ---------------------------------------------- sh.Linux/init.sh.in | 189 ++++++++++++++++++++++++++++++++++++++++++++++ sh/Makefile | 9 +-- sh/functions.in | 86 --------------------- sh/functions.sh.in | 86 +++++++++++++++++++++ sh/gendepends.sh | 77 ------------------- sh/gendepends.sh.in | 77 +++++++++++++++++++ sh/rc-functions.in | 80 -------------------- sh/rc-functions.sh.in | 80 ++++++++++++++++++++ sh/runscript.sh | 185 --------------------------------------------- sh/runscript.sh.in | 185 +++++++++++++++++++++++++++++++++++++++++++++ 22 files changed, 799 insertions(+), 800 deletions(-) delete mode 100755 init.d/halt.sh create mode 100644 init.d/halt.sh.in delete mode 100755 sh.BSD/init.sh create mode 100644 sh.BSD/init.sh.in delete mode 100755 sh.Linux/init-early.sh create mode 100644 sh.Linux/init-early.sh.in delete mode 100755 sh.Linux/init.sh create mode 100644 sh.Linux/init.sh.in delete mode 100644 sh/functions.in create mode 100644 sh/functions.sh.in delete mode 100755 sh/gendepends.sh create mode 100644 sh/gendepends.sh.in delete mode 100644 sh/rc-functions.in create mode 100644 sh/rc-functions.sh.in delete mode 100755 sh/runscript.sh create mode 100644 sh/runscript.sh.in diff --git a/etc.BSD/Makefile b/etc.BSD/Makefile index 083823e4..ec3153cd 100644 --- a/etc.BSD/Makefile +++ b/etc.BSD/Makefile @@ -1,8 +1,5 @@ DIR= /etc -SRCS= rc.in rc.shutdown.in -OBJS= ${SRCS:.in=} -CONF= ${OBJS} - +CONF= ${CONTENTS} MK= ../mk include ${MK}/scripts.mk @@ -10,5 +7,4 @@ include Makefile.${OS} .SUFFIXES: .in .in: - sed -e s':@TERM@:${DEFTERM}:' $< > $@ - + sed -e 's:@SHELL@:${SHELL}:' -e 's:@TERM@:${DEFTERM}:' $< > $@ diff --git a/etc.BSD/rc.in b/etc.BSD/rc.in index 255ff72e..aab7cbb8 100644 --- a/etc.BSD/rc.in +++ b/etc.BSD/rc.in @@ -1,4 +1,4 @@ -#!/bin/sh +#!@SHELL@ # Copyright 2007-2008 Roy Marples # All rights reserved. Released under the 2-clause BSD license. diff --git a/etc.BSD/rc.shutdown.in b/etc.BSD/rc.shutdown.in index 48abe703..e26e8468 100644 --- a/etc.BSD/rc.shutdown.in +++ b/etc.BSD/rc.shutdown.in @@ -1,4 +1,4 @@ -#!/bin/sh +#!@SHELL@ # Copyright 2007-2008 Roy Marples # All rights reserved. Released under the 2-clause BSD license. diff --git a/init.d/halt.sh b/init.d/halt.sh deleted file mode 100755 index 044659bc..00000000 --- a/init.d/halt.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/sh -# Copyright 2007-2008 Roy Marples -# All rights reserved. Released under the 2-clause BSD license. - -. /etc/init.d/functions.sh -. "${RC_LIBDIR}"/sh/rc-functions.sh -[ -r /etc/rc.conf ] && . /etc/rc.conf - -# Support LiveCD foo -if [ -r /sbin/livecd-functions.sh ]; then - . /sbin/livecd-functions.sh - livecd_read_commandline -fi - -stop_addon devfs -stop_addon udev - -# Really kill things off before unmounting -if [ -x /sbin/killall5 ]; then - killall5 -15 - killall5 -9 -fi - -# Flush all pending disk writes now -sync; sync - -# If we are in a VPS, we don't need anything below here, because -# 1) we don't need (and by default can't) umount anything (VServer) or -# 2) the host utils take care of all umounting stuff (OpenVZ) -if [ "${RC_SYS}" = "VPS" ]; then - if [ -e /etc/init.d/"$1".sh ]; then - . /etc/init.d/"$1".sh - else - exit 0 - fi -fi - -# If $svcdir is still mounted, preserve it if we can -mnt=$(mountinfo --node "${RC_SVCDIR}") -if [ -n "${mnt}" -a -w "${RC_LIBDIR}" ]; then - f_opts="-m -c" - [ "${RC_UNAME}" = "Linux" ] && f_opts="-c" - if type fuser >/dev/null 2>&1; then - if [ -n "$(fuser ${f_opts} "${svcdir}" 2>/dev/null)" ]; then - fuser -k ${f_opts} "${svcdir}" >/dev/null 2>&1 - sleep 2 - fi - fi - cp -p "${RC_SVCDIR}"/deptree "${RC_SVCDIR}"/depconfig \ - "${RC_SVCDIR}"/softlevel "${RC_SVCDIR}"/nettree \ - "${RC_SVCDIR}"/rc.log \ - "${RC_LIBDIR}" 2>/dev/null - umount "${RC_SVCDIR}" - rm -rf "${RC_SVCDIR}"/* - # Pipe errors to /dev/null as we may have future timestamps - cp -p "${RC_LIBDIR}"/deptree "${RC_LIBDIR}"/depconfig \ - "${RC_LIBDIR}"/softlevel "${RC_LIBDIR}"/nettree \ - "${RC_LIBDIR}"/rc.log \ - "${RC_SVCDIR}" 2>/dev/null - rm -f "${RC_LIBDIR}"/deptree "${RC_LIBDIR}"/depconfig \ - "${RC_LIBDIR}"/softlevel "${RC_LIBDIR}"/nettree \ - "${RC_LIBDIR}"/rc.log - # Release the memory disk if we used it - case "${mnt}" in - "/dev/md"[0-9]*) mdconfig -d -u "${mnt#/dev/md*}";; - esac -fi - -unmounted=0 -# Remount the remaining filesystems read-only -# Most BSD's don't need this as the kernel handles it nicely -if [ "${RC_UNAME}" = "Linux" ]; then - ebegin "Remounting remaining filesystems read-only" - # We need the do_unmount function - . "${RC_LIBDIR}"/sh/rc-mount.sh - eindent - fs= - for x in ${net_fs_list}; do - fs="${fs}${fs:+|}${x}" - done - [ -n "${fs}" ] && fs="^(${fs})$" - do_unmount "mount -n -o remount,ro" \ - --skip-point-regex "^(/dev|/dev/.*|/proc|/proc/.*|/sys|/sys/.*)$" \ - ${fs:+--skip-fstype-regex} ${fs} --nonetdev - eoutdent - eend $? - unmounted=$? -fi - -if [ ${unmounted} -ne 0 ]; then - [ -x /sbin/sulogin ] && sulogin -t 10 /dev/console - exit 1 -fi - -# Load the final script - not needed on BSD so they should not exist -[ -e /etc/init.d/"$1".sh ] && . /etc/init.d/"$1".sh - -# Always exit 0 here -exit 0 diff --git a/init.d/halt.sh.in b/init.d/halt.sh.in new file mode 100644 index 00000000..39dd4f4f --- /dev/null +++ b/init.d/halt.sh.in @@ -0,0 +1,99 @@ +#!@SHELL@ +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +. /etc/init.d/functions.sh +. "${RC_LIBDIR}"/sh/rc-functions.sh +[ -r /etc/rc.conf ] && . /etc/rc.conf + +# Support LiveCD foo +if [ -r /sbin/livecd-functions.sh ]; then + . /sbin/livecd-functions.sh + livecd_read_commandline +fi + +stop_addon devfs +stop_addon udev + +# Really kill things off before unmounting +if [ -x /sbin/killall5 ]; then + killall5 -15 + killall5 -9 +fi + +# Flush all pending disk writes now +sync; sync + +# If we are in a VPS, we don't need anything below here, because +# 1) we don't need (and by default can't) umount anything (VServer) or +# 2) the host utils take care of all umounting stuff (OpenVZ) +if [ "${RC_SYS}" = "VPS" ]; then + if [ -e /etc/init.d/"$1".sh ]; then + . /etc/init.d/"$1".sh + else + exit 0 + fi +fi + +# If $svcdir is still mounted, preserve it if we can +mnt=$(mountinfo --node "${RC_SVCDIR}") +if [ -n "${mnt}" -a -w "${RC_LIBDIR}" ]; then + f_opts="-m -c" + [ "${RC_UNAME}" = "Linux" ] && f_opts="-c" + if type fuser >/dev/null 2>&1; then + if [ -n "$(fuser ${f_opts} "${svcdir}" 2>/dev/null)" ]; then + fuser -k ${f_opts} "${svcdir}" >/dev/null 2>&1 + sleep 2 + fi + fi + cp -p "${RC_SVCDIR}"/deptree "${RC_SVCDIR}"/depconfig \ + "${RC_SVCDIR}"/softlevel "${RC_SVCDIR}"/nettree \ + "${RC_SVCDIR}"/rc.log \ + "${RC_LIBDIR}" 2>/dev/null + umount "${RC_SVCDIR}" + rm -rf "${RC_SVCDIR}"/* + # Pipe errors to /dev/null as we may have future timestamps + cp -p "${RC_LIBDIR}"/deptree "${RC_LIBDIR}"/depconfig \ + "${RC_LIBDIR}"/softlevel "${RC_LIBDIR}"/nettree \ + "${RC_LIBDIR}"/rc.log \ + "${RC_SVCDIR}" 2>/dev/null + rm -f "${RC_LIBDIR}"/deptree "${RC_LIBDIR}"/depconfig \ + "${RC_LIBDIR}"/softlevel "${RC_LIBDIR}"/nettree \ + "${RC_LIBDIR}"/rc.log + # Release the memory disk if we used it + case "${mnt}" in + "/dev/md"[0-9]*) mdconfig -d -u "${mnt#/dev/md*}";; + esac +fi + +unmounted=0 +# Remount the remaining filesystems read-only +# Most BSD's don't need this as the kernel handles it nicely +if [ "${RC_UNAME}" = "Linux" ]; then + ebegin "Remounting remaining filesystems read-only" + # We need the do_unmount function + . "${RC_LIBDIR}"/sh/rc-mount.sh + eindent + fs= + for x in ${net_fs_list}; do + fs="${fs}${fs:+|}${x}" + done + [ -n "${fs}" ] && fs="^(${fs})$" + do_unmount "mount -n -o remount,ro" \ + --skip-point-regex "^(/dev|/dev/.*|/proc|/proc/.*|/sys|/sys/.*)$" \ + ${fs:+--skip-fstype-regex} ${fs} --nonetdev + eoutdent + eend $? + unmounted=$? +fi + +if [ ${unmounted} -ne 0 ]; then + [ -x /sbin/sulogin ] && sulogin -t 10 /dev/console + exit 1 +fi + +# Load the final script - not needed on BSD so they should not exist +[ -e /etc/init.d/"$1".sh ] && . /etc/init.d/"$1".sh + +# Always exit 0 here +exit 0 diff --git a/mk/scripts.mk b/mk/scripts.mk index 9bee14d1..114d5e2b 100644 --- a/mk/scripts.mk +++ b/mk/scripts.mk @@ -1,14 +1,23 @@ # Install rules for our scripts # Copyright 2007-2008 Roy Marples +_IN_SH= ls -1 | sed -n -e 's:\.in$$::p' | xargs +_IN!= ${_IN_SH} +OBJS+= ${_IN}$(shell ${_IN_SH}) + # We store the contents of the directory for ease of use in Makefiles -_CONTENTS_SH= ls -1 | grep -v Makefile | xargs +_CONTENTS_SH= ls -1 | grep -v "\(Makefile\|.in$$\)" | sed -e 's:\.in$$::g' | xargs _CONTENTS!= ${_CONTENTS_SH} CONTENTS= ${_CONTENTS}$(shell ${_CONTENTS_SH}) include ${MK}/sys.mk include ${MK}/os.mk +# Tweak our shell scripts +.SUFFIXES: .sh.in +.sh.in.sh: + sed -e 's:@SHELL@:${SH}:g' -e 's:@LIB@:${LIBNAME}:g' $< > $@ + all: ${OBJS} realinstall: ${BIN} ${CONF} ${CONF_APPEND} diff --git a/mk/sys.mk b/mk/sys.mk index dc70b0a3..7be86426 100644 --- a/mk/sys.mk +++ b/mk/sys.mk @@ -5,6 +5,7 @@ AR?= ar ECHO?= echo INSTALL?= install RANLIB?= ranlib +SH= /bin/sh PICFLAG?= -fPIC diff --git a/sh.BSD/init.sh b/sh.BSD/init.sh deleted file mode 100755 index a9797c95..00000000 --- a/sh.BSD/init.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh -# Copyright 2007-2008 Roy Marples -# 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 ! 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 - 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 -[ "${RC_UNAME}" = "FreeBSD" ] && sysctl hw.bus.devctl_disable=1 >/dev/null - -. "${RC_LIBDIR}"/sh/init-common-post.sh diff --git a/sh.BSD/init.sh.in b/sh.BSD/init.sh.in new file mode 100644 index 00000000..3bc52507 --- /dev/null +++ b/sh.BSD/init.sh.in @@ -0,0 +1,47 @@ +#!@SHELL@ +# Copyright 2007-2008 Roy Marples +# 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 ! 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 + 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 +[ "${RC_UNAME}" = "FreeBSD" ] && sysctl hw.bus.devctl_disable=1 >/dev/null + +. "${RC_LIBDIR}"/sh/init-common-post.sh diff --git a/sh.Linux/init-early.sh b/sh.Linux/init-early.sh deleted file mode 100755 index 784ddfda..00000000 --- a/sh.Linux/init-early.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -# Copyright 2007-2008 Roy Marples -# 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.Linux/init-early.sh.in b/sh.Linux/init-early.sh.in new file mode 100644 index 00000000..d6cb007d --- /dev/null +++ b/sh.Linux/init-early.sh.in @@ -0,0 +1,20 @@ +#!@SHELL@ +# Copyright 2007-2008 Roy Marples +# 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.Linux/init.sh b/sh.Linux/init.sh deleted file mode 100755 index c006d5f1..00000000 --- a/sh.Linux/init.sh +++ /dev/null @@ -1,189 +0,0 @@ -#!/bin/sh -# Copyright 1999-2007 Gentoo Foundation -# Copyright 2007-2008 Roy Marples -# 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 --quiet "${RC_SVCDIR}"; then - mount -n "${RC_SVCDIR}" - else - 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}" != "VPS" ]; 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 ${procfs} at /proc" - if fstabinfo --quiet /proc; then - mount -n /proc - else - 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}" != "VPS" ]; then - if grep -Eq "[[:space:]]+sysfs$" /proc/filesystems; then - if [ -d /sys ]; then - if ! mountinfo --quiet /sys; then - ebegin "Mounting sysfs at /sys" - if fstabinfo --quiet /sys; then - mount -n /sys - else - 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}" = "VPS" \ - -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 $1 at $2" - if fstabinfo --quiet "$2"; then - mount -n "$2" - else - 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 diff --git a/sh.Linux/init.sh.in b/sh.Linux/init.sh.in new file mode 100644 index 00000000..90dbea82 --- /dev/null +++ b/sh.Linux/init.sh.in @@ -0,0 +1,189 @@ +#!@SHELL@ +# Copyright 1999-2007 Gentoo Foundation +# Copyright 2007-2008 Roy Marples +# 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 --quiet "${RC_SVCDIR}"; then + mount -n "${RC_SVCDIR}" + else + 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}" != "VPS" ]; 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 ${procfs} at /proc" + if fstabinfo --quiet /proc; then + mount -n /proc + else + 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}" != "VPS" ]; then + if grep -Eq "[[:space:]]+sysfs$" /proc/filesystems; then + if [ -d /sys ]; then + if ! mountinfo --quiet /sys; then + ebegin "Mounting sysfs at /sys" + if fstabinfo --quiet /sys; then + mount -n /sys + else + 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}" = "VPS" \ + -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 $1 at $2" + if fstabinfo --quiet "$2"; then + mount -n "$2" + else + 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 diff --git a/sh/Makefile b/sh/Makefile index 47f431fa..364a59bc 100644 --- a/sh/Makefile +++ b/sh/Makefile @@ -1,7 +1,5 @@ DIR= ${RC_LIB}/sh -SRCS= functions.in rc-functions.in -OBJS= ${SRCS:.in=.sh} -INC= init-common-post.sh rc-mount.sh ${OBJS} +INC= init-common-post.sh rc-mount.sh functions.sh rc-functions.sh BIN= gendepends.sh net.sh runscript.sh INSTALLAFTER= _installafter @@ -12,11 +10,6 @@ include ${MK}/os.mk include Makefile.${SUBOS} include ${MK}/scripts.mk -# Ensure that the lib name is correct -.SUFFIXES: .in .sh -.in.sh: - sed -e 's:/lib/:/${LIBNAME}/:g' $< > $@ - _installafter: ${INSTALL} -d ${DESTDIR}/etc/init.d @# Provide an init script for the loopback interface diff --git a/sh/functions.in b/sh/functions.in deleted file mode 100644 index effce67d..00000000 --- a/sh/functions.in +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright 2007-2008 Roy Marples -# All rights reserved. Released under the 2-clause BSD license. - -# Allow any sh script to work with einfo functions and friends -# We also provide a few helpful functions for other programs to use - -RC_GOT_FUNCTIONS="yes" - -eindent() -{ - EINFO_INDENT=$((${EINFO_INDENT:-0} + 2)) - [ "${EINFO_INDENT}" -gt 40 ] && EINFO_INDENT=40 - export EINFO_INDENT -} - -eoutdent() -{ - EINFO_INDENT=$((${EINFO_INDENT:-0} - 2)) - [ "${EINFO_INDENT}" -lt 0 ] && EINFO_INDENT=0 - return 0 -} - -yesno() -{ - [ -z "$1" ] && return 1 - - case "$1" in - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; - [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; - esac - - local value= - eval value=\$${1} - case "${value}" in - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; - [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; - *) vewarn "\$${1} is not set properly"; return 1;; - esac -} - -_sanitize_path() -{ - local IFS=":" p= path= - for p in ${PATH}; do - case "${p}" in - /lib/rc/sbin|/bin|/sbin|/usr/bin|/usr/sbin|/usr/pkg/bin|/usr/pkg/sbin|/usr/local/bin|/usr/local/sbin);; - *) path="${path}:${p}";; - esac - done - - echo "${path}" -} - -# Allow our scripts to support zsh -if [ -n "${ZSH_VERSION}" ]; then - emulate sh - NULLCMD=: - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -fi - -# Add our bin to $PATH -export PATH="/lib/rc/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin$(_sanitize_path "${PATH}")" -unset _sanitize_path - -for arg; do - case "${arg}" in - --nocolor|--nocolour|-C) - export EINFO_COLOR="NO" - ;; - esac -done - -if [ -t 1 ] && yesno "${EINFO_COLOR:-YES}"; then - if [ -z "${GOOD}" ]; then - eval $(eval_ecolors) - fi -else - # We need to have shell stub functions so our init scripts can remember - # the last ecmd - for _e in ebegin eend error errorn einfo einfon ewarn ewarnn ewend \ - vebegin veend veinfo vewarn vewend; do - eval "${_e}() { local _r; /lib/rc/bin/${_e} \"\$@\"; _r=$?; \ - export EINFO_LASTCMD=${_e}; return \$_r; }" - done -fi diff --git a/sh/functions.sh.in b/sh/functions.sh.in new file mode 100644 index 00000000..effce67d --- /dev/null +++ b/sh/functions.sh.in @@ -0,0 +1,86 @@ +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +# Allow any sh script to work with einfo functions and friends +# We also provide a few helpful functions for other programs to use + +RC_GOT_FUNCTIONS="yes" + +eindent() +{ + EINFO_INDENT=$((${EINFO_INDENT:-0} + 2)) + [ "${EINFO_INDENT}" -gt 40 ] && EINFO_INDENT=40 + export EINFO_INDENT +} + +eoutdent() +{ + EINFO_INDENT=$((${EINFO_INDENT:-0} - 2)) + [ "${EINFO_INDENT}" -lt 0 ] && EINFO_INDENT=0 + return 0 +} + +yesno() +{ + [ -z "$1" ] && return 1 + + case "$1" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; + esac + + local value= + eval value=\$${1} + case "${value}" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; + *) vewarn "\$${1} is not set properly"; return 1;; + esac +} + +_sanitize_path() +{ + local IFS=":" p= path= + for p in ${PATH}; do + case "${p}" in + /lib/rc/sbin|/bin|/sbin|/usr/bin|/usr/sbin|/usr/pkg/bin|/usr/pkg/sbin|/usr/local/bin|/usr/local/sbin);; + *) path="${path}:${p}";; + esac + done + + echo "${path}" +} + +# Allow our scripts to support zsh +if [ -n "${ZSH_VERSION}" ]; then + emulate sh + NULLCMD=: + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +fi + +# Add our bin to $PATH +export PATH="/lib/rc/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin$(_sanitize_path "${PATH}")" +unset _sanitize_path + +for arg; do + case "${arg}" in + --nocolor|--nocolour|-C) + export EINFO_COLOR="NO" + ;; + esac +done + +if [ -t 1 ] && yesno "${EINFO_COLOR:-YES}"; then + if [ -z "${GOOD}" ]; then + eval $(eval_ecolors) + fi +else + # We need to have shell stub functions so our init scripts can remember + # the last ecmd + for _e in ebegin eend error errorn einfo einfon ewarn ewarnn ewend \ + vebegin veend veinfo vewarn vewend; do + eval "${_e}() { local _r; /lib/rc/bin/${_e} \"\$@\"; _r=$?; \ + export EINFO_LASTCMD=${_e}; return \$_r; }" + done +fi diff --git a/sh/gendepends.sh b/sh/gendepends.sh deleted file mode 100755 index 712d29ff..00000000 --- a/sh/gendepends.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/sh -# Shell wrapper to list our dependencies - -# Copyright 2007-2008 Roy Marples -# All rights reserved. Released under the 2-clause BSD license. - -. /etc/init.d/functions.sh - -config() { - [ -n "$*" ] && echo "${SVCNAME} config $*" >&3 -} -need() { - [ -n "$*" ] && echo "${SVCNAME} ineed $*" >&3 -} -use() { - [ -n "$*" ] && echo "${SVCNAME} iuse $*" >&3 -} -before() { - [ -n "$*" ] && echo "${SVCNAME} ibefore $*" >&3 -} -after() { - [ -n "$*" ] && echo "${SVCNAME} iafter $*" >&3 -} -provide() { - [ -n "$*" ] && echo "${SVCNAME} iprovide $*" >&3 -} -keyword() { - [ -n "$*" ] && echo "${SVCNAME} keyword $*" >&3 -} -depend() { - : -} - -for _dir in /etc/init.d /usr/local/etc/init.d; do - [ -d "${_dir}" ] || continue - cd "${_dir}" - for SVCNAME in *; do - [ -x "${SVCNAME}" ] || continue - - # Only generate dependencies for runscripts - read one two < "${SVCNAME}" - [ "${one}" = "#!/sbin/runscript" ] || continue - unset one two - - export SVCNAME=${SVCNAME##*/} - ( - # Save stdout in fd3, then remap it to stderr - exec 3>&1 1>&2 - - _rc_c=${SVCNAME%%.*} - if [ -n "${_rc_c}" -a "${_rc_c}" != "${SVCNAME}" ]; then - if [ -e "${_dir}/../conf.d/${_rc_c}" ]; then - . "${_dir}/../conf.d/${_rc_c}" - fi - fi - unset _rc_c - - if [ -e "${_dir}/../conf.d/${SVCNAME}" ]; then - . "${_dir}/../conf.d/${SVCNAME}" - fi - - [ -e /etc/rc.conf ] && . /etc/rc.conf - - if . "${_dir}/${SVCNAME}"; then - echo "${SVCNAME}" >&3 - depend - - # Add any user defined depends - for _deptype in config need use after before provide keyword; do - eval _depends=\$rc_$(shell_var "${SVCNAME}")_${_deptype} - [ -z "${_depends}" ] && eval _depends=\$rc_${_deptype} - ${_deptype} ${_depends} - done - fi - ) - done -done diff --git a/sh/gendepends.sh.in b/sh/gendepends.sh.in new file mode 100644 index 00000000..8e30a648 --- /dev/null +++ b/sh/gendepends.sh.in @@ -0,0 +1,77 @@ +#!@SHELL@ +# Shell wrapper to list our dependencies + +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +. /etc/init.d/functions.sh + +config() { + [ -n "$*" ] && echo "${SVCNAME} config $*" >&3 +} +need() { + [ -n "$*" ] && echo "${SVCNAME} ineed $*" >&3 +} +use() { + [ -n "$*" ] && echo "${SVCNAME} iuse $*" >&3 +} +before() { + [ -n "$*" ] && echo "${SVCNAME} ibefore $*" >&3 +} +after() { + [ -n "$*" ] && echo "${SVCNAME} iafter $*" >&3 +} +provide() { + [ -n "$*" ] && echo "${SVCNAME} iprovide $*" >&3 +} +keyword() { + [ -n "$*" ] && echo "${SVCNAME} keyword $*" >&3 +} +depend() { + : +} + +for _dir in /etc/init.d /usr/local/etc/init.d; do + [ -d "${_dir}" ] || continue + cd "${_dir}" + for SVCNAME in *; do + [ -x "${SVCNAME}" ] || continue + + # Only generate dependencies for runscripts + read one two < "${SVCNAME}" + [ "${one}" = "#!/sbin/runscript" ] || continue + unset one two + + export SVCNAME=${SVCNAME##*/} + ( + # Save stdout in fd3, then remap it to stderr + exec 3>&1 1>&2 + + _rc_c=${SVCNAME%%.*} + if [ -n "${_rc_c}" -a "${_rc_c}" != "${SVCNAME}" ]; then + if [ -e "${_dir}/../conf.d/${_rc_c}" ]; then + . "${_dir}/../conf.d/${_rc_c}" + fi + fi + unset _rc_c + + if [ -e "${_dir}/../conf.d/${SVCNAME}" ]; then + . "${_dir}/../conf.d/${SVCNAME}" + fi + + [ -e /etc/rc.conf ] && . /etc/rc.conf + + if . "${_dir}/${SVCNAME}"; then + echo "${SVCNAME}" >&3 + depend + + # Add any user defined depends + for _deptype in config need use after before provide keyword; do + eval _depends=\$rc_$(shell_var "${SVCNAME}")_${_deptype} + [ -z "${_depends}" ] && eval _depends=\$rc_${_deptype} + ${_deptype} ${_depends} + done + fi + ) + done +done diff --git a/sh/rc-functions.in b/sh/rc-functions.in deleted file mode 100644 index 2a57709c..00000000 --- a/sh/rc-functions.in +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright 2007 Gentoo Foundation -# Copyright 2007-2008 Roy Marples -# All rights reserved. Released under the 2-clause BSD license. - -has_addon() -{ - [ -e "${RC_LIBDIR}/addons/$1.sh" ] || [ -e /lib/rcscripts/addons/"$1".sh ] -} - -import_addon() -{ - if [ -e "${RC_LIBDIR}/addons/$1.sh" ]; then - . "${RC_LIBDIR}/addons/$1.sh" - elif [ -e /lib/rcscripts/addons/"$1".sh ]; then - . /lib/rcscripts/addons/"$1".sh - else - return 1 - fi -} - -start_addon() -{ - ( import_addon "$1-start" ) -} - -stop_addon() -{ - ( import_addon "$1-stop" ) -} - -net_fs_list="afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" -is_net_fs() -{ - [ -z "$1" ] && return 1 - - # Check OS specific flags to see if we're local or net mounted - mountinfo --quiet --netdev "$1" && return 0 - mountinfo --quiet --nonetdev "$1" && return 1 - - # Fall back on fs types - local t=$(mountinfo --fstype "$1") - for x in ${net_fs_list}; do - [ "${x}" = "${t}" ] && return 0 - done - return 1 -} - -is_union_fs() -{ - [ ! -x /sbin/unionctl ] && return 1 - unionctl "$1" --list >/dev/null 2>&1 -} - -get_bootparam() -{ - local match="$1" - [ -z "${match}" -o ! -r /proc/cmdline ] && return 1 - - set -- $(cat /proc/cmdline) - while [ -n "$1" ]; do - case "$1" in - gentoo=*) - local params="${1##*=}" - local IFS=, x= - for x in ${params}; do - [ "${x}" = "${match}" ] && return 0 - done - ;; - esac - shift - done - - return 1 -} - -# Add our sbin to $PATH -case "${PATH}" in - /lib/rc/sbin|/lib/rc/sbin:*);; - *) export PATH="/lib/rc/sbin:${PATH}";; -esac diff --git a/sh/rc-functions.sh.in b/sh/rc-functions.sh.in new file mode 100644 index 00000000..2a57709c --- /dev/null +++ b/sh/rc-functions.sh.in @@ -0,0 +1,80 @@ +# Copyright 2007 Gentoo Foundation +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +has_addon() +{ + [ -e "${RC_LIBDIR}/addons/$1.sh" ] || [ -e /lib/rcscripts/addons/"$1".sh ] +} + +import_addon() +{ + if [ -e "${RC_LIBDIR}/addons/$1.sh" ]; then + . "${RC_LIBDIR}/addons/$1.sh" + elif [ -e /lib/rcscripts/addons/"$1".sh ]; then + . /lib/rcscripts/addons/"$1".sh + else + return 1 + fi +} + +start_addon() +{ + ( import_addon "$1-start" ) +} + +stop_addon() +{ + ( import_addon "$1-stop" ) +} + +net_fs_list="afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" +is_net_fs() +{ + [ -z "$1" ] && return 1 + + # Check OS specific flags to see if we're local or net mounted + mountinfo --quiet --netdev "$1" && return 0 + mountinfo --quiet --nonetdev "$1" && return 1 + + # Fall back on fs types + local t=$(mountinfo --fstype "$1") + for x in ${net_fs_list}; do + [ "${x}" = "${t}" ] && return 0 + done + return 1 +} + +is_union_fs() +{ + [ ! -x /sbin/unionctl ] && return 1 + unionctl "$1" --list >/dev/null 2>&1 +} + +get_bootparam() +{ + local match="$1" + [ -z "${match}" -o ! -r /proc/cmdline ] && return 1 + + set -- $(cat /proc/cmdline) + while [ -n "$1" ]; do + case "$1" in + gentoo=*) + local params="${1##*=}" + local IFS=, x= + for x in ${params}; do + [ "${x}" = "${match}" ] && return 0 + done + ;; + esac + shift + done + + return 1 +} + +# Add our sbin to $PATH +case "${PATH}" in + /lib/rc/sbin|/lib/rc/sbin:*);; + *) export PATH="/lib/rc/sbin:${PATH}";; +esac diff --git a/sh/runscript.sh b/sh/runscript.sh deleted file mode 100755 index 63c780a6..00000000 --- a/sh/runscript.sh +++ /dev/null @@ -1,185 +0,0 @@ -#!/bin/sh -# Shell wrapper for runscript - -# Copyright 2007-2008 Roy Marples -# All rights reserved. Released under the 2-clause BSD license. - -. /etc/init.d/functions.sh -. "${RC_LIBDIR}"/sh/rc-functions.sh - -# Support LiveCD foo -if [ -r /sbin/livecd-functions.sh ]; then - . /sbin/livecd-functions.sh - livecd_read_commandline -fi - -if [ -z "$1" -o -z "$2" ]; then - eerror "${SVCNAME}: not enough arguments" - exit 1 -fi - -# Descript the init script to the user -describe() -{ - if [ -n "${description}" ]; then - einfo "${description}" - else - ewarn "No description for ${SVCNAME}" - fi - - local svc= desc= - for svc in ${extra_commands:-${opts}} ${extra_started_commands}; do - eval desc=\$description_${svc} - if [ -n "${desc}" ]; then - einfo "${HILITE}${svc}${NORMAL}: ${desc}" - else - ewarn "${HILITE}${svc}${NORMAL}: no description" - fi - done -} - -yesno ${RC_DEBUG} && set -x - -# If we're net.eth0 or openvpn.work then load net or openvpn config -_c=${SVCNAME%%.*} -if [ -n "${_c}" -a "${_c}" != "${SVCNAME}" ]; then - if [ -e "/etc/conf.d/${_c}.${RC_SOFTLEVEL}" ]; then - . "/etc/conf.d/${_c}.${RC_SOFTLEVEL}" - elif [ -e "/etc/conf.d/${_c}" ]; then - . "/etc/conf.d/${_c}" - fi -fi -unset _c - -# Overlay with our specific config -if [ -e "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" ]; then - . "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" -elif [ -e "/etc/conf.d/${SVCNAME}" ]; then - . "/etc/conf.d/${SVCNAME}" -fi - -# Load any system overrides -[ -e /etc/rc.conf ] && . /etc/rc.conf - -# Apply any ulimit defined -[ -n "${rc_ulimit:-${RC_ULIMIT}}" ] && ulimit ${rc_ulimit:-${RC_ULIMIT}} - -# Load our script -. $1 -shift - -for _d in ${required_dirs}; do - if [ ! -d ${_d} ]; then - eerror "${SVCNAME}: \`${_d}' is not a directory" - exit 1 - fi -done -unset _d - -for _f in ${required_files}; do - if [ ! -r ${_f} ]; then - eerror "${SVCNAME}: \`${_f}' is not readable" - exit 1 - fi -done -unset _f - -# If we have a default command then supply a default start function -if [ -n "${command}" ]; then - if ! type start >/dev/null 2>&1; then - start() { - local _background= - ebegin "Starting ${name:-${SVCNAME}}" - if yesno "${command_background}"; then - _background="--background --pidfile" - fi - if yesno "${start_inactive}"; then - local _inactive=false - service_inactive && _inactive=true - mark_service_inactive - fi - start-stop-daemon --start \ - --exec ${command} \ - ${procname:+--name} ${procname} \ - ${pidfile:+--pidfile} ${pidfile} \ - ${_background} ${start_stop_daemon_args} \ - -- ${command_args} - eend $? "Failed to start ${SVCNAME}" && return 0 - if yesno "${start_inactive}"; then - if ! ${_inactive}; then - mark_service_stopped - fi - fi - return 1 - } - fi -fi - -# If we have a default command, procname or pidfile then supply a default stop -# function -if [ -n "${command}" -o -n "${procname}" -o -n "${pidfile}" ]; then - if ! type stop >/dev/null 2>&1; then - stop() { - ebegin "Stopping ${name:-${SVCNAME}}" - start-stop-daemon --stop \ - ${command:+--exec} ${command} \ - ${procname:+--name} ${procname} \ - ${pidfile:+--pidfile} ${pidfile} - eend $? "Failed to stop ${SVCNAME}" - } - fi -fi - -while [ -n "$1" ]; do - # See if we have the required function and run it - for _cmd in describe start stop ${extra_commands:-${opts}} \ - ${extra_started_commands}; do - if [ "${_cmd}" = "$1" ]; then - if type "$1" >/dev/null 2>&1; then - # If we're in the background, we may wish to - # fake some commands. We do this so we can - # "start" ourselves from inactive which then - # triggers other services to start which depend - # on us. A good example of this is openvpn. - if yesno ${IN_BACKGROUND}; then - for _cmd in ${in_background_fake}; do - if [ "${_cmd}" = "$1" ]; then - shift - continue 3 - fi - done - fi - # Check to see if we need to be started before - # we can run this command - for _cmd in ${extra_started_commands}; do - if [ "${_cmd}" = "$1" ]; then - if ! service_started; then - eerror "${SVCNAME}: cannot \`$1' as it has not been started" - exit 1 - fi - fi - done - unset _cmd - if type "$1"_pre >/dev/null 2>&1; then - "$1"_pre || exit $? - fi - "$1" || exit $? - if type "$1"_post >/dev/null 2>&1; then - "$1"_post || exit $? - fi - shift - continue 2 - else - if [ "${_cmd}" = "start" -o "${_cmd}" = "stop" ]; then - shift - continue 2 - else - eerror "${SVCNAME}: function \`$1' defined but does not exist" - exit 1 - fi - fi - fi - done - eerror "${SVCNAME}: unknown function \`$1'" - exit 1 -done diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in new file mode 100644 index 00000000..6b8c3db2 --- /dev/null +++ b/sh/runscript.sh.in @@ -0,0 +1,185 @@ +#!@SHELL@ +# Shell wrapper for runscript + +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +. /etc/init.d/functions.sh +. "${RC_LIBDIR}"/sh/rc-functions.sh + +# Support LiveCD foo +if [ -r /sbin/livecd-functions.sh ]; then + . /sbin/livecd-functions.sh + livecd_read_commandline +fi + +if [ -z "$1" -o -z "$2" ]; then + eerror "${SVCNAME}: not enough arguments" + exit 1 +fi + +# Descript the init script to the user +describe() +{ + if [ -n "${description}" ]; then + einfo "${description}" + else + ewarn "No description for ${SVCNAME}" + fi + + local svc= desc= + for svc in ${extra_commands:-${opts}} ${extra_started_commands}; do + eval desc=\$description_${svc} + if [ -n "${desc}" ]; then + einfo "${HILITE}${svc}${NORMAL}: ${desc}" + else + ewarn "${HILITE}${svc}${NORMAL}: no description" + fi + done +} + +yesno ${RC_DEBUG} && set -x + +# If we're net.eth0 or openvpn.work then load net or openvpn config +_c=${SVCNAME%%.*} +if [ -n "${_c}" -a "${_c}" != "${SVCNAME}" ]; then + if [ -e "/etc/conf.d/${_c}.${RC_SOFTLEVEL}" ]; then + . "/etc/conf.d/${_c}.${RC_SOFTLEVEL}" + elif [ -e "/etc/conf.d/${_c}" ]; then + . "/etc/conf.d/${_c}" + fi +fi +unset _c + +# Overlay with our specific config +if [ -e "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" ]; then + . "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" +elif [ -e "/etc/conf.d/${SVCNAME}" ]; then + . "/etc/conf.d/${SVCNAME}" +fi + +# Load any system overrides +[ -e /etc/rc.conf ] && . /etc/rc.conf + +# Apply any ulimit defined +[ -n "${rc_ulimit:-${RC_ULIMIT}}" ] && ulimit ${rc_ulimit:-${RC_ULIMIT}} + +# Load our script +. $1 +shift + +for _d in ${required_dirs}; do + if [ ! -d ${_d} ]; then + eerror "${SVCNAME}: \`${_d}' is not a directory" + exit 1 + fi +done +unset _d + +for _f in ${required_files}; do + if [ ! -r ${_f} ]; then + eerror "${SVCNAME}: \`${_f}' is not readable" + exit 1 + fi +done +unset _f + +# If we have a default command then supply a default start function +if [ -n "${command}" ]; then + if ! type start >/dev/null 2>&1; then + start() { + local _background= + ebegin "Starting ${name:-${SVCNAME}}" + if yesno "${command_background}"; then + _background="--background --pidfile" + fi + if yesno "${start_inactive}"; then + local _inactive=false + service_inactive && _inactive=true + mark_service_inactive + fi + start-stop-daemon --start \ + --exec ${command} \ + ${procname:+--name} ${procname} \ + ${pidfile:+--pidfile} ${pidfile} \ + ${_background} ${start_stop_daemon_args} \ + -- ${command_args} + eend $? "Failed to start ${SVCNAME}" && return 0 + if yesno "${start_inactive}"; then + if ! ${_inactive}; then + mark_service_stopped + fi + fi + return 1 + } + fi +fi + +# If we have a default command, procname or pidfile then supply a default stop +# function +if [ -n "${command}" -o -n "${procname}" -o -n "${pidfile}" ]; then + if ! type stop >/dev/null 2>&1; then + stop() { + ebegin "Stopping ${name:-${SVCNAME}}" + start-stop-daemon --stop \ + ${command:+--exec} ${command} \ + ${procname:+--name} ${procname} \ + ${pidfile:+--pidfile} ${pidfile} + eend $? "Failed to stop ${SVCNAME}" + } + fi +fi + +while [ -n "$1" ]; do + # See if we have the required function and run it + for _cmd in describe start stop ${extra_commands:-${opts}} \ + ${extra_started_commands}; do + if [ "${_cmd}" = "$1" ]; then + if type "$1" >/dev/null 2>&1; then + # If we're in the background, we may wish to + # fake some commands. We do this so we can + # "start" ourselves from inactive which then + # triggers other services to start which depend + # on us. A good example of this is openvpn. + if yesno ${IN_BACKGROUND}; then + for _cmd in ${in_background_fake}; do + if [ "${_cmd}" = "$1" ]; then + shift + continue 3 + fi + done + fi + # Check to see if we need to be started before + # we can run this command + for _cmd in ${extra_started_commands}; do + if [ "${_cmd}" = "$1" ]; then + if ! service_started; then + eerror "${SVCNAME}: cannot \`$1' as it has not been started" + exit 1 + fi + fi + done + unset _cmd + if type "$1"_pre >/dev/null 2>&1; then + "$1"_pre || exit $? + fi + "$1" || exit $? + if type "$1"_post >/dev/null 2>&1; then + "$1"_post || exit $? + fi + shift + continue 2 + else + if [ "${_cmd}" = "start" -o "${_cmd}" = "stop" ]; then + shift + continue 2 + else + eerror "${SVCNAME}: function \`$1' defined but does not exist" + exit 1 + fi + fi + fi + done + eerror "${SVCNAME}: unknown function \`$1'" + exit 1 +done -- cgit v1.2.3