From 55eb3794fb4ad563102d5ab30c1d5337a599b2e5 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Tue, 25 Mar 2008 14:06:05 +0000 Subject: Rework our folder structure so that we don't have OS specific dirs, making it easier to share init and conf files per OS. --- init.d/Makefile | 4 +- init.d/Makefile.FreeBSD | 1 + init.d/Makefile.Linux | 2 + init.d/Makefile.NetBSD | 6 ++ init.d/adjkerntz.in | 62 ++++++++++++++++++++ init.d/consolefont.in | 78 +++++++++++++++++++++++++ init.d/devd.in | 22 +++++++ init.d/dumpon.in | 25 ++++++++ init.d/hostid.in | 78 +++++++++++++++++++++++++ init.d/hwclock.in | 137 ++++++++++++++++++++++++++++++++++++++++++++ init.d/ipfw.in | 149 ++++++++++++++++++++++++++++++++++++++++++++++++ init.d/keymaps.in | 69 ++++++++++++++++++++++ init.d/mixer.in | 47 +++++++++++++++ init.d/modules.in | 59 +++++++++++++++++++ init.d/moused.in | 62 ++++++++++++++++++++ init.d/mtab.in | 30 ++++++++++ init.d/newsyslog.in | 18 ++++++ init.d/nscd.in | 22 +++++++ init.d/numlock.in | 42 ++++++++++++++ init.d/pf.in | 59 +++++++++++++++++++ init.d/powerd.in | 35 ++++++++++++ init.d/procfs.in | 89 +++++++++++++++++++++++++++++ init.d/rarpd.in | 28 +++++++++ init.d/rc-enabled.in | 54 ++++++++++++++++++ init.d/rpcbind.in | 21 +++++++ init.d/savecore.in | 36 ++++++++++++ init.d/swap-blk.in | 23 ++++++++ init.d/syscons.in | 83 +++++++++++++++++++++++++++ init.d/sysctl.in | 26 +++++++++ init.d/syslogd.in | 20 +++++++ init.d/ttys.in | 23 ++++++++ init.d/wscons.in | 100 ++++++++++++++++++++++++++++++++ 32 files changed, 1509 insertions(+), 1 deletion(-) create mode 100644 init.d/Makefile.FreeBSD create mode 100644 init.d/Makefile.Linux create mode 100644 init.d/Makefile.NetBSD create mode 100644 init.d/adjkerntz.in create mode 100644 init.d/consolefont.in create mode 100644 init.d/devd.in create mode 100644 init.d/dumpon.in create mode 100644 init.d/hostid.in create mode 100644 init.d/hwclock.in create mode 100644 init.d/ipfw.in create mode 100644 init.d/keymaps.in create mode 100644 init.d/mixer.in create mode 100644 init.d/modules.in create mode 100644 init.d/moused.in create mode 100644 init.d/mtab.in create mode 100644 init.d/newsyslog.in create mode 100644 init.d/nscd.in create mode 100644 init.d/numlock.in create mode 100644 init.d/pf.in create mode 100644 init.d/powerd.in create mode 100644 init.d/procfs.in create mode 100644 init.d/rarpd.in create mode 100644 init.d/rc-enabled.in create mode 100644 init.d/rpcbind.in create mode 100644 init.d/savecore.in create mode 100644 init.d/swap-blk.in create mode 100644 init.d/syscons.in create mode 100644 init.d/sysctl.in create mode 100644 init.d/syslogd.in create mode 100644 init.d/ttys.in create mode 100644 init.d/wscons.in (limited to 'init.d') diff --git a/init.d/Makefile b/init.d/Makefile index 38a3f41..a9f62e2 100644 --- a/init.d/Makefile +++ b/init.d/Makefile @@ -1,7 +1,9 @@ DIR= ${INITDIR} SRCS= bootmisc.in fsck.in halt.sh.in hostname.in local.in localmount.in \ - netmount.in root.in swap.in urandom.in + netmount.in root.in swap.in sysctl.in urandom.in BIN= ${OBJS} MK= ../mk +include ${MK}/os.mk +include Makefile.${OS} include ${MK}/scripts.mk diff --git a/init.d/Makefile.FreeBSD b/init.d/Makefile.FreeBSD new file mode 100644 index 0000000..81c7633 --- /dev/null +++ b/init.d/Makefile.FreeBSD @@ -0,0 +1 @@ +SRCS+= adjkerntz.in devd.in dumpon.in ipfw.in mixer.in nscd.in powerd.in syscons.in diff --git a/init.d/Makefile.Linux b/init.d/Makefile.Linux new file mode 100644 index 0000000..f8be1de --- /dev/null +++ b/init.d/Makefile.Linux @@ -0,0 +1,2 @@ +SRCS+= hwclock.in consolefont.in keymaps.in modules.in mtab.in numlock.in \ + procfs.in diff --git a/init.d/Makefile.NetBSD b/init.d/Makefile.NetBSD new file mode 100644 index 0000000..90832db --- /dev/null +++ b/init.d/Makefile.NetBSD @@ -0,0 +1,6 @@ +# Generic BSD scripts +SRCS+= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \ + rpcbind.in savecore.in sysctl.in syslogd.in + +# These are NetBSD specific +SRCS+= swap-blk.in ttys.in wscons.in diff --git a/init.d/adjkerntz.in b/init.d/adjkerntz.in new file mode 100644 index 0000000..cf8c1fa --- /dev/null +++ b/init.d/adjkerntz.in @@ -0,0 +1,62 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +extra_commands="save" + +description="Sets the local clock to UTC or Local Time." +description_save="Saves the current time in the BIOS." + +clock=${clock:-${CLOCK:-UTC}} +if [ "${clock}" = "UTC" ]; then + utc="UTC" +else + utc="Local Time" +fi + +depend() +{ + provide clock + # BSD adjkerntz needs to be able to write to /etc + if [ "${clock}" = "UTC" -a -e /etc/wall_cmos_clock ] || + [ "${clock}" != "UTC" -a ! -e /etc/wall_cmos_clock ]; then + need root + fi + keyword nojail noprefix +} + +start() +{ + ebegin "Starting the System Clock Adjuster [${utc}]" + if [ "${clock}" != "UTC" ]; then + echo >/etc/wall_cmos_clock + start-stop-daemon --start --exec /sbin/adjkerntz -- -i + else + rm -f /etc/wall_cmos_clock + /sbin/adjkerntz -i + fi + eend $? +} + +save() +{ + ebegin "Setting hardware clock using the system clock [${utc}]" + adjkerntz -a + eend $? +} + +stop() +{ + # Don't tweak the hardware clock on LiveCD halt. + if yesno "${clock_systohc:-${CLOCK_SYSTOHC}}"; then + [ -z "${CDBOOT}" ] && save + fi + + ebegin "Stopping the System Clock Adjuster" + if start-stop-daemon --test --quiet --stop --exec /sbin/adjkerntz; then + start-stop-daemon --stop --exec /sbin/adjkerntz + eend $? + else + eend 0 + fi +} diff --git a/init.d/consolefont.in b/init.d/consolefont.in new file mode 100644 index 0000000..a30961e --- /dev/null +++ b/init.d/consolefont.in @@ -0,0 +1,78 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +description="Sets a font for the consoles." + +depend() +{ + need localmount + need keymaps # sets up terminal encoding scheme + after hotplug + keyword noopenvz noprefix nouml novserver noxenu +} + +start() +{ + # Forget about any font until we are successful + rm -rf "${RC_LIBDIR}"/console + + ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}} + consolefont=${consolefont:-${CONSOLEFONT}} + unicodemap=${unicodemap:-${UNICODEMAP}} + consoletranslation=${consoletranslation:-${CONSOLETRANSLATION}} + + if [ -z "${consolefont}" ]; then + ebegin "Using the default console font" + eend 0 + return 0 + fi + + if [ "${ttyn}" = 0 ]; then + ebegin "Skipping font setup (rc_tty_number == 0)" + eend 0 + return 0 + fi + + local x= param= sf_param= retval=0 ttydev= + + # Get additional parameters + if [ -n "${consoletranslation}" ]; then + param="${param} -m ${consoletranslation}" + fi + if [ -n "${unicodemap}" ]; then + param="${param} -u ${unicodemap}" + fi + + # Set the console font + ebegin "Setting user font" + [ -d /dev/vc ] \ + && ttydev=/dev/vc/ \ + || ttydev=/dev/tty + + x=1 + while [ ${x} -le ${ttyn} ]; do + setfont ${consolefont} ${param} -C ${ttydev}${x} >/dev/null + retval=$((${retval} + $?)) + x=$((${x} + 1)) + done + eend ${retval} + + # Store the last font so we can use it ASAP on boot + if [ ${retval} -eq 0 -a -w "${RC_LIBDIR}" ]; then + mkdir -p "${RC_LIBDIR}"/console + + for font in /usr/share/consolefonts/"${consolefont}".*; do + : + done + cp "${font}" "${RC_LIBDIR}"/console + echo "${font##*/}" > "${RC_LIBDIR}"/console/font + if yesno ${unicode:-${UNICODE}}; then + cp /dev/null "${RC_LIBDIR}"/console/unicode + else + rm -f "${RC_LIBDIR}"/console/unicode + fi + fi + + return ${retval} +} diff --git a/init.d/devd.in b/init.d/devd.in new file mode 100644 index 0000000..039aa96 --- /dev/null +++ b/init.d/devd.in @@ -0,0 +1,22 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +command=/sbin/devd +command_args=${devd_args} +name="Device State Change Daemon" + +depend() { + need localmount + after bootmisc + before net.lo0 + keyword nojail noprefix +} + +start_pre() { + sysctl hw.bus.devctl_disable=0 >/dev/null +} + +stop_post() { + sysctl hw.bus.devctl_disable=1 >/dev/null +} diff --git a/init.d/dumpon.in b/init.d/dumpon.in new file mode 100644 index 0000000..f2b6530 --- /dev/null +++ b/init.d/dumpon.in @@ -0,0 +1,25 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +description="Configures a specific kernel dump device." + +depend() { + need swap + keyword nojail noprefix +} + +start() { + # Setup any user requested dump device + if [ -n "${dump_device}" ]; then + ebegin "Activating kernel core dump device (${dump_device})" + dumpon ${dump_device} + eend $? + fi +} + +stop() { + ebegin "Deactiving kernel core dump device" + dumpon off + eend $? +} diff --git a/init.d/hostid.in b/init.d/hostid.in new file mode 100644 index 0000000..a058884 --- /dev/null +++ b/init.d/hostid.in @@ -0,0 +1,78 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +extra_commands="reset" +hostid_file=${hostid_file:-/etc/hostid} + +depend() +{ + need root + before devd net + keyword nojail noprefix +} + +_set() +{ + local id=0 + + if [ -n "$1" ]; then + id=$(echo "$1" | md5) + id="0x${id%????????????????????????}" + fi + ebegin "Setting Host ID: ${id}" + sysctl -w kern.hostid="${id}" >/dev/null + eend $? || return 1 + + if sysctl -n kern.hostuuid >/dev/null 2>&1; then + [ -n "$1" ] && id=$1 + ebegin "Setting Host UUID: ${id}" + sysctl kern.hostuuid="${id}" >/dev/null + eend $? || return 1 + fi + +} + +# First we check to see if there is a system UUID +# If so then we use that and erase the hostid file, +# otherwise we generate a random UUID. +reset() +{ + local uuid=$(kenv smbios.system.uuid 2>/dev/null) + local x="[0-9a-f]" + local y="${x}${x}${x}${x}" + case "${uuid}" in + ${y}${y}-${y}-${y}-${y}-${y}${y}${y});; + *) uuid=;; + esac + + if [ -n "${uuid}" ]; then + rm -f "${hostid_file}" + else + uuid=$(uuidgen) + if [ -z "${uuid}" ]; then + eerror "Unable to generate a UUID" + return 1 + fi + if ! echo "${uuid}" > "${hostid_file}"; then + eerror "Failed to store UUID in \`${hostid_file}'" + return 1 + fi + fi + + _set "${uuid}" +} + +start() +{ + if [ -r "${hostid_file}" ]; then + _set $(cat "${hostid_file}") + else + reset + fi +} + +stop() +{ + _set +} diff --git a/init.d/hwclock.in b/init.d/hwclock.in new file mode 100644 index 0000000..9b1a87d --- /dev/null +++ b/init.d/hwclock.in @@ -0,0 +1,137 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +extra_commands="save show" + +description="Sets the local clock to UTC or Local Time." +description_save="Saves the current time in the BIOS." +description_show="Displays the current time in the BIOS." + +clock_adjfile=${clock_adjfile:-${CLOCK_ADJFILE}} +clock_args=${clock_args:-${CLOCK_OPTS}} +clock_systohc=${clock_systohc:-${CLOCK_SYSTOHC}} + +clock=${clock:-${CLOCK:-UTC}} +if [ "${clock}" = "UTC" ]; then + utc="UTC" + utc_cmd="--utc" +else + utc="Local Time" + utc_cmd="--localtime" +fi + +depend() +{ + provide clock + if yesno ${clock_adjfile}; then + use root + else + before * + fi + keyword noopenvz noprefix nouml novserver noxenu +} + +setupopts() +{ + case "$(uname -m)" in + s390*) + utc="s390" + ;; + *) + if [ -e /proc/devices ] && \ + grep -q " cobd$" /proc/devices + then + utc="coLinux" + fi + ;; + esac + + case "${utc}" in + UTC|Local" "Time);; + *) unset utc_cmd;; + esac +} + +# hwclock doesn't always return non zero on error +_hwclock() +{ + local err="$(hwclock "$@" 2>&1 >/dev/null)" + + [ -z "${err}" ] && return 0 + echo "${err}" >&2 + return 1 +} + +start() +{ + local retval=0 errstr="" + setupopts + + if [ -z "${utc_cmd}" ]; then + ewarn "Not setting clock for ${utc} system" + return 0 + fi + + ebegin "Setting system clock using the hardware clock [${utc}]" + if [ -e /proc/modules -a ! -e /dev/rtc ]; then + modprobe -q rtc || modprobe -q genrtc + fi + + if [ -e /etc/adjtime ] && yesno ${clock_adjfile}; then + _hwclock --adjust ${utc_cmd} + retval=$((${retval} + $?)) + fi + + # If setting UTC, don't bother to run hwclock when first booting + # as that's the default + if [ "${PREVLEVEL}" != "N" -o \ + "${utc_cmd}" != "--utc" -o \ + -n "${clock_args}" ]; + then + _hwclock --hctosys ${utc_cmd} ${clock_args} + retval=$((${retval} + $?)) + fi + + eend ${retval} "Failed to set the system clock" + + return 0 +} + +stop() +{ + # Don't tweak the hardware clock on LiveCD halt. + [ -n "${CDBOOT}" ] && return 0 + yesno ${clock_systohc} || return 0 + + local retval=0 errstr="" + setupopts + + [ -z "${utc_cmd}" ] && return 0 + + ebegin "Setting hardware clock using the system clock" "[${utc}]" + + if ! yesno "${clock_adjfile}"; then + # Some implementations don't handle adjustments + if LC_ALL=C hwclock --help | grep -q "\-\-noadjfile"; then + utc_cmd="${utc_cmd} --noadjfile" + fi + fi + + _hwclock --systohc ${utc_cmd} ${clock_args} + retval=$? + + eend ${retval} "Failed to sync clocks" +} + +save() +{ + clock_systohc="yes" + stop +} + +show() +{ + setupopts + hwclock --show "${utc_cmd}" ${clock_args} +} diff --git a/init.d/ipfw.in b/init.d/ipfw.in new file mode 100644 index 0000000..f8d9c3e --- /dev/null +++ b/init.d/ipfw.in @@ -0,0 +1,149 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +# This is based on /etc/rc.firewall and /etc/rc.firewall6 from FreeBSD + +ipfw_ip_in=${ipfw_ip_in-any} +ipfw_ports_in=${ipfw_ports_in-auth ssh} +ipfw_ports_nolog=${ipfw_ports_nolog-135-139,445 1026,1027 1433,1434} + +opts="panic showstatus" + +depend() { + before net + provide firewall + keyword nojail +} + +ipfw() { + /sbin/ipfw -f -q "$@" +} + +init() { + # Load the kernel module + if ! sysctl net.inet.ip.fw.enable=1 >/dev/null 2>&1; then + if ! kldload ipfw; then + eend 1 "Unable to load firewall module" + return 1 + fi + fi + + # Now all rules and give a good base + ipfw flush + + ipfw add pass all from any to any via lo0 + ipfw add deny all from any to 127.0.0.0/8 + ipfw add deny ip from 127.0.0.0/8 to any + + ipfw add pass ip6 from any to any via lo0 + ipfw add deny ip6 from any to ::1 + ipfw add deny ip6 from ::1 to any + + ipfw add pass ip6 from :: to ff02::/16 proto ipv6-icmp + ipfw add pass ip6 from fe80::/10 to fe80::/10 proto ipv6-icmp + ipfw add pass ip6 from fe80::/10 to ff02::/16 proto ipv6-icmp +} + +start() { + local i= p= log= + ebegin "Starting firewall rules" + if ! init; then + eend 1 "Failed to flush firewall ruleset" + return 1 + fi + + # Use a statefull firewall + ipfw add check-state + ipfw add pass tcp from me to any established + + # Allow any connection out, adding state for each. + ipfw add pass tcp from me to any setup keep-state + ipfw add pass udp from me to any keep-state + ipfw add pass icmp from me to any keep-state + + ipfw add pass tcp from me6 to any setup keep-state + ipfw add pass udp from me6 to any keep-state + ipfw add pass icmp from me6 to any keep-state + + # Allow DHCP. + ipfw add pass udp from 0.0.0.0 68 to 255.255.255.255 67 out + ipfw add pass udp from any 67 to me 68 in + ipfw add pass udp from any 67 to 255.255.255.255 68 in + # Some servers will ping the IP while trying to decide if it's + # still in use. + ipfw add pass icmp from any to any icmptype 8 + + # Allow "mandatory" ICMP in. + ipfw add pass icmp from any to any icmptype 3,4,11 + + # Allow ICMPv6 destination unreach + ipfw add pass ip6 from any to any icmp6types 1 proto ipv6-icmp + + # Allow NS/NA/toobig (don't filter it out) + ipfw add pass ip6 from any to any icmp6types 2,135,136 proto ipv6-icmp + + # Add permits for this workstations published services below + # Only IPs and nets in firewall_allowservices is allowed in. + for i in ${ipfw_ip_in}; do + for p in ${ipfw_ports_in}; do + ipfw add pass tcp from ${i} to me ${p} + done + done + + # Allow all connections from trusted IPs. + # Playing with the content of firewall_trusted could seriously + # degrade the level of protection provided by the firewall. + for i in ${ipfw_ip_trust}; do + ipfw add pass ip from ${i} to me + done + + ipfw add 65000 count ip from any to any + + # Drop packets to ports where we don't want logging + for p in ${ipfw_ports_nolog}; do + ipfw add deny { tcp or udp } from any to any ${p} in + done + + # Broadcasts and muticasts + ipfw add deny ip from any to 255.255.255.255 + ipfw add deny ip from any to 224.0.0.0/24 + + # Noise from routers + ipfw add deny udp from any to any 520 in + + # Noise from webbrowsing. + # The statefull filter is a bit agressive, and will cause some + # connection teardowns to be logged. + ipfw add deny tcp from any 80,443 to any 1024-65535 in + + # Deny and (if wanted) log the rest unconditionally. + if yesno ${ipfw_log_deny:-no}; then + log="log" + sysctl net.inet.ip.fw.verbose=1 >/dev/null + fi + ipfw add deny ${log} ip from any to any + + eend 0 +} + +stop() { + ebegin "Stopping firewall rules" + # We don't unload the kernel module as that action + # can cause memory leaks as of FreeBSD 6.x + sysctl net.inet.ip.fw.enable=0 >/dev/null + eend $? +} + +panic() { + ebegin "Stopping firewall rules - hard" + if ! init; then + eend 1 "Failed to flush firewall ruleset" + return 1 + fi + eend 0 +} + +showstatus() { + ipfw show +} diff --git a/init.d/keymaps.in b/init.d/keymaps.in new file mode 100644 index 0000000..2079e04 --- /dev/null +++ b/init.d/keymaps.in @@ -0,0 +1,69 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +description="Applies a keymap for the consoles." + +ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}} +unicode=${unicode:-${UNICODE}} +keymap=${keymap:-${KEYMAP}} +extended_keymaps=${extended_keymaps:-${EXTENDED_KEYMAPS}} +windowskeys=${windowskeys:-${SET_WINDOWSKEYS}} +fix_euro=${fix_euro:-${FIX_EURO}} +dumpkeys_charset=${dumpkeys_charset:-${DUMPKEYS_CHARSET}} + +depend() +{ + need localmount + keyword noopenvz noprefix nouml novserver noxenu +} + +start() +{ + if [ -z "${keymap}" ]; then + eerror "You need to setup keymap in /etc/conf.d/keymaps first" + return 1 + fi + + local ttydev= n= + [ -d /dev/vc ] \ + && ttydev=/dev/vc/ \ + || ttydev=/dev/tty + + # 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 + + ebegin "Loading key mappings" + local loadkeys_uni= wkeys= + yesno ${unicode} && loadkeys_uni="--unicode" + yesno ${windowskeys} && wkeys="windowkeys" + loadkeys -q ${loadkeys_uni} ${wkeys} ${keymap} ${extended_keymaps} + eend $? "Error loading key mappings" || return $? + + if yesno ${fix_euro}; then + # Fix some fonts displaying the Euro, #173528. + echo "altgr keycode 18 = U+20AC" | loadkeys -q + fi + + # Set terminal encoding to either ASCII or UNICODE. + # See utf-8(7) for more information. + local termencoding="%@" termmsg="ASCII" kmode="-a" + if yesno ${unicode}; then + dumpkeys ${dumpkeys_charset:+-c} \ + ${dumpkeys_charset} | loadkeys --unicode + termencoding="%G" + termmsg="UTF-8" + kmode="-u" + fi + + ebegin "Setting terminal encoding to" ${termmsg} + n=1 + while [ ${n} -le "${ttyn}" ]; do + printf "\033%s" "${termencoding}" >"${ttydev}${n}" + kbd_mode "${kmode}" -C "${ttydev}${n}" + n=$((${n} + 1)) + done + eend 0 +} diff --git a/init.d/mixer.in b/init.d/mixer.in new file mode 100644 index 0000000..f496bd1 --- /dev/null +++ b/init.d/mixer.in @@ -0,0 +1,47 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +extra_commands="restore" + +depend() +{ + need localmount + keyword nojail noprefix +} + +restore() +{ + local mixer= retval=0 + ebegin "Restoring mixer settings" + eindent + for mixer in /dev/mixer*; do + if [ -r "/var/db/${mixer#/dev/}-state" ]; then + vebegin "${mixer}" + mixer -f "${mixer}" \ + $(cat "/var/db/${mixer#/dev/}-state") >/dev/null + veend $? + : $((retval += $?)) + fi + done +} + +start() +{ + restore +} + +stop() +{ + local mixer= retval=0 + ebegin "Saving mixer settings" + eindent + for mixer in /dev/mixer*; do + vebegin "${mixer}" + mixer -f "${mixer}" -s >/var/db/"${mixer#/dev/}"-state + veend $? + : $((retval += $?)) + done + eoutdent + eend ${retval} +} diff --git a/init.d/modules.in b/init.d/modules.in new file mode 100644 index 0000000..1a0c745 --- /dev/null +++ b/init.d/modules.in @@ -0,0 +1,59 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +description="Loads a user defined list of kernel modules." + +depend() +{ + use isapnp + keyword noopenvz noprefix novserver +} + +start() +{ + # Should not fail if kernel do not have module + # support compiled in ... + [ ! -f /proc/modules ] && return 0 + + local KV=$(uname -r) + local KV_MAJOR=${KV%%.*} + local x=${KV#*.} + local KV_MINOR=${x%%.*} + x=${KV#*.*.} + local KV_MICRO=${x%%-*} + + local list= x= xx= y= args= cnt=0 + for x in "${KV}" \ + ${KV_MAJOR}.${KV_MINOR}.${KV_MICRO} \ + ${KV_MAJOR}.${KV_MINOR} \ + ; do + eval list=\$modules_$(shell_var "${x}") + [ -n "${list}" ] && break + done + [ -z "${list}" ] && list=${modules} + + for x in ${list}; do + ebegin "Loading module ${x}" + xx=$(shell_var "${x}") + for y in "${KV}" \ + ${KV_MAJOR}.${KV_MINOR}.${KV_MICRO} \ + ${KV_MAJOR}.${KV_MINOR} \ + ; do + eval args=\$module_${xx}_args_$(shell_var "${y}") + [ -n "${args}" ] && break + done + done + [ -z "${args}" ] && eval args=\$module_${xx}_args + eval modprobe -q "${x}" "${args}" + eend $? "Failed to load ${x}" && cnt=$((${cnt} + 1)) + done + einfo "Autoloaded ${cnt} module(s)" + + # 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 \* 2>/dev/null + + # Above test clobbers the return + return 0 +} diff --git a/init.d/moused.in b/init.d/moused.in new file mode 100644 index 0000000..a0e97cd --- /dev/null +++ b/init.d/moused.in @@ -0,0 +1,62 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +mouse=${RC_SVCNAME##*.} +if [ -n "${name}" -a "${mouse}" != "moused" ]; then + moused_device=/dev/"${mouse}" + pidfile=/var/run/moused-"${mouse}".pid +else + pidfile=/var/run/moused.pid +fi +name="Console Mouse Daemon" +[ -n "${moused_device}" ] && name="${name} (${moused_device})" + +depend() +{ + need localmount + after bootmisc + keyword nojail noprefix +} + +start() +{ + ebegin "Starting ${name}" + + if [ -z "${moused_device}" ]; then + local dev= + for dev in /dev/psm[0-9]* /dev/ums[0-9]*; do + [ -c "${dev}" ] || continue + [ -e /var/run/moused-"${dev##*/}".pid ] && continue + moused_device=${dev} + eindent + einfo "Using mouse on ${moused_device}" + eoutdent + break + done + fi + + if [ -z "${moused_device}" ]; then + eend 1 "No mouse device found" + return 1 + fi + + local args= + eval args=\$moused_args_${moused_device##*/} + [ -z "${args}" ] && args=${moused_args} + + start-stop-daemon --start --exec /usr/sbin/moused \ + --pidfile "${pidfile}" \ + -- ${args} -p "${moused_device}" -I "${pidfile}" + local retval=$? + + if [ ${retval} = 0 ]; then + local ttyv= + for ttyv in /dev/ttyv*; do + vidcontrol < "${ttyv}" -m on + : $((retval+= $?)) + done + fi + + eend ${retval} "Failed to start moused" +} diff --git a/init.d/mtab.in b/init.d/mtab.in new file mode 100644 index 0000000..a0f14b1 --- /dev/null +++ b/init.d/mtab.in @@ -0,0 +1,30 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +description="Update /etc/mtab to match what the kernel knows about" + +depend() +{ + need root + keyword noprefix +} + +start() +{ + ebegin "Updating /etc/mtab" + if ! echo 2>/dev/null >/etc/mtab; then + ewend 1 "/etc/mtab is not updateable" + return 0 + fi + + # With / as tmpfs we cannot umount -at tmpfs in localmount as that + # makes / readonly and dismounts all tmpfs even if in use which is + # not good. Luckily, umount uses /etc/mtab instead of /proc/mounts + # which allows this hack to work. + grep -v "^[^ ]* / tmpfs " /proc/mounts > /etc/mtab + + # Remove stale backups + rm -f /etc/mtab~ /etc/mtab~~ + eend 0 +} diff --git a/init.d/newsyslog.in b/init.d/newsyslog.in new file mode 100644 index 0000000..04ca792 --- /dev/null +++ b/init.d/newsyslog.in @@ -0,0 +1,18 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +required_files="/etc/newsyslog.conf" + +depend() +{ + need localmount + keyword noprefix +} + +start() +{ + ebegin "Creating and/or trimming log files" + newsyslog -s ${newsyslog_args} + eend $? +} diff --git a/init.d/nscd.in b/init.d/nscd.in new file mode 100644 index 0000000..e70ba4a --- /dev/null +++ b/init.d/nscd.in @@ -0,0 +1,22 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +command=/usr/sbin/nscd +command_args="${nscd_args}" +pidfile=/var/run/nscd.pid +name="Name Service Cache Daemon" + +extra_started_commands="flush" + +depend() { + need localmount + use net dns ldap ypbind + after bootmisc +} + +flush() { + ebegin "Flushing ${name}" + nscd -I all >/dev/null + eend $? +} diff --git a/init.d/numlock.in b/init.d/numlock.in new file mode 100644 index 0000000..1a71367 --- /dev/null +++ b/init.d/numlock.in @@ -0,0 +1,42 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +description="Turns numlock on for the consoles." + +ttyn=${rc_tty_number:-${RC_TTY_NUMBER}:-12} + +depend() +{ + need localmount + keyword noopenvz noprefix novserver +} + +_setleds() +{ + [ -z "$1" ] && return 1 + + local dev=/dev/tty t= i=1 retval=0 + [ -d /dev/vc ] && dev=/dev/vc/ + + while [ ${i} -le ${ttyn} ]; do + setleds -D "$1"num < ${dev}${i} || retval=1 + i=$((${i} + 1)) + done + + return ${retval} +} + +start() +{ + ebegin "Enabling numlock on ttys" + _setleds + + eend $? "Failed to enable numlock" +} + +stop() +{ + ebegin "Disabling numlock on ttys" + _setleds - + eend $? "Failed to disable numlock" +} diff --git a/init.d/pf.in b/init.d/pf.in new file mode 100644 index 0000000..fa55ea4 --- /dev/null +++ b/init.d/pf.in @@ -0,0 +1,59 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +name="Packet Filter" +pf_conf=${pf_conf:-${pf_rules:-/etc/pf.conf}} +required_files=${pf_conf} + +extra_commands="checkconfig showstatus" +extra_started_commands="reload" + +depend() { + need localmount + keyword nojail noprefix +} + +start() +{ + ebegin "Starting ${name}" + if type kldload >/dev/null 2>&1; then + kldload pf 2>/dev/null + fi + pfctl -q -F all + pfctl -q -f "${pf_conf}" ${pf_args} + pfctl -q -e + eend $? +} + +stop() +{ + ebegin "Stopping ${name}" + pfctl -q -d + eend $? +} + +checkconfig() +{ + ebegin "Checking ${name} configuration" + pfctl -n -f "${pf_conf}" + eend $? +} + +reload() +{ + ebegin "Reloading ${name} rules." + pfctl -q -n -f "${pf_conf}" && \ + { + # Flush everything but existing state entries that way when + # rules are read in, it doesn't break established connections. + pfctl -q -Fnat -Fqueue -Frules -FSources -Finfo -FTables -Fosfp + pfctl -q -f "${pf_conf}" ${pf_args} + } + eend $? +} + +showstatus() +{ + pfctl -s info +} diff --git a/init.d/powerd.in b/init.d/powerd.in new file mode 100644 index 0000000..1c2d845 --- /dev/null +++ b/init.d/powerd.in @@ -0,0 +1,35 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +command=/usr/sbin/powerd +command_args=${powerd_args} +pidfile=/var/run/powerd.pid +name="Power Control Daemon" + +depend() +{ + need localmount + use logger + after bootmisc + keyword nojail noprefix +} + +start_pre() +{ + if [ -n "${powerd_battery_mode}" ]; then + command_args="${command_args} -b ${powerd_battery_mode}" + fi + if [ -n "${powerd_ac_mode}" ]; then + command_args="${command_args} -a ${powerd_ac_mode}" + fi +} + +stop_post() +{ + local level=$(sysctl -n dev.cpu.0.freq_levels | + sed -e 's:/.*::') + if [ -n "${level}" ]; then + sysctl dev.cpu.0.freq="${level}" >/dev/null + fi +} diff --git a/init.d/procfs.in b/init.d/procfs.in new file mode 100644 index 0000000..a30fd92 --- /dev/null +++ b/init.d/procfs.in @@ -0,0 +1,89 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +description="Mounts misc filesystems in /proc." + +depend() +{ + need localmount + keyword noopenvz noprefix novserver +} + +start() +{ + # Make sure we insert usbcore if its a module + if [ -f /proc/modules -a ! -d /proc/bus/usb ]; then + modprobe -q usbcore + fi + + [ -e /proc/filesystems ] || return 0 + + # Check what USB fs the kernel support. Currently + # 2.5+ kernels, and later 2.4 kernels have 'usbfs', + # while older kernels have 'usbdevfs'. + if [ -d /proc/bus/usb -a ! -e /proc/bus/usb/devices ]; then + local usbfs=$(grep -Fow usbfs /proc/filesystems || + grep -Fow usbdevfs /proc/filesystems) + if [ -n "${usbfs}" ]; then + ebegin "Mounting USB device filesystem (${usbfs})" + local usbgid="$(getent group usb | \ + sed -e 's/.*:.*:\(.*\):.*/\1/')" + mount -t ${usbfs} \ + -o ${usbgid:+devmode=0664,devgid=${usbgid},}noexec,nosuid \ + usbfs /proc/bus/usb + eend $? + fi + fi + + # Setup Kernel Support for the NFS daemon status + if [ -d /proc/fs/nfsd ] && ! mountinfo -q /proc/fs/nfsd; then + if grep -qs nfsd /proc/filesystems; then + ebegin "Mounting nfsd filesystem" + mount -t nfsd -o nodev,noexec,nosuid \ + nfsd /proc/fs/nfsd + eend $? + fi + fi + + # Setup Kernel Support for miscellaneous Binary Formats + if [ -d /proc/sys/fs/binfmt_misc ] && ! mountinfo -q /proc/sys/fs/binfmt_misc; then + if grep -qs binfmt_misc /proc/filesystems; then + ebegin "Mounting misc binary format filesystem" + mount -t binfmt_misc -o nodev,noexec,nosuid \ + binfmt_misc /proc/sys/fs/binfmt_misc + eend $? + fi + fi + + # Setup Kernel Support for securityfs + if [ -d /sys/kernel/security ] && ! mountinfo -q /sys/kernel/security; then + if grep -qs securityfs /proc/filesystems; then + ebegin "Mounting security filesystem" + mount -t securityfs -o nodev,noexec,nosuid \ + securityfs /sys/kernel/security + eend $? + fi + fi + + # Setup Kernel Support for debugfs + if [ -d /sys/kernel/debug ] && ! mountinfo -q /sys/kernel/debug; then + if grep -qs debugfs /proc/filesystems; then + ebegin "Mounting debug filesystem" + mount -t debugfs -o nodev,noexec,nosuid \ + debugfs /sys/kernel/debug + eend $? + fi + fi + + # Setup Kernel Support for SELinux + if [ -d /selinux ] && ! mountinfo -q /selinux; then + if grep -qs selinuxfs /proc/filesystems; then + ebegin "Mounting SELinux filesystem" + mount -t selinuxfs selinuxfs /selinux + eend $? + fi + fi + + return 0 +} diff --git a/init.d/rarpd.in b/init.d/rarpd.in new file mode 100644 index 0000000..e751099 --- /dev/null +++ b/init.d/rarpd.in @@ -0,0 +1,28 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +command=/usr/sbin/rarpd +command_args="-f ${rarpd_args}" +pidfile=/var/run/rarpd.pid +name="Reverse ARP Daemon" +required_files="/etc/ethers" + +if [ -z "${rarpd_interface}" ]; then + command_args="${command_args} -a" +else + command_args="${command_args} ${rarpd_interface}" +fi +command_background="YES" + +depend() +{ + need localmount + after bootmisc + + if [ -z "${rarpd_interface}" ]; then + need net + else + net net."${rarpd_interface}" + fi +} diff --git a/init.d/rc-enabled.in b/init.d/rc-enabled.in new file mode 100644 index 0000000..9801203 --- /dev/null +++ b/init.d/rc-enabled.in @@ -0,0 +1,54 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +depend() +{ + need localmount net + after * + before local + keyword noprefix +} + +start() +{ + ebegin "Starting local rc services" + local svc= enabled= retval=0 service= + for svc in $(rcorder /etc/rc.d/* @PKG_PREFIX@/etc/rc.d/* 2>/dev/null); do + [ -x "$svc" ] || continue + service=${svc##*/} + + # Skip these services + for s in cleartmp moused; do + [ "${s}" = "${service}" ] && continue 2 + done + + # If we have an init script for this service, continue + [ -x @SYSCONFDIR@/init.d/"${service}" ] && continue + [ -x @PKG_PREFIX@/@SYSCONFDIR@/init.d/"${service}" ] && continue + [ -x @LOCAL_PREFIX@/@SYSCONFDIR@/init.d/"${service}" ] && continue + + # Ensure that the users rc.conf will start us - ignore the defaults + eval enabled=\$${svc##*/}_enable + yesno ${enabled} || yesno ${svc##*/} || continue + + # Good to go! + "$svc" start && started="${started} ${svc}" + : $((retval += $?)) + done + service_set_value started "${started}" + eend $retval "Some local rc services failed to start" + return 0 +} + +stop() +{ + ebegin "Stopping local rc services" + local svc= retval=0 + for svc in $(rcorder $(service_get_value started) 2>/dev/null | sort -r); do + "${svc}" stop + : $((retval += $?)) + done + eend $retval "Some local rc services failed to stop" + return 0 +} diff --git a/init.d/rpcbind.in b/init.d/rpcbind.in new file mode 100644 index 0000000..2d053eb --- /dev/null +++ b/init.d/rpcbind.in @@ -0,0 +1,21 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +command=/usr/sbin/rpcbind +command_args=${rpcbind_args} +name="RPC program number mapper" + +depend() +{ + provide rpc + need localmount + use net logger dns + before inetd xinetd ntpd ntp-client +} + +stop_post() +{ + # rpcbind returns too fast, so sleep for a second + sleep 1 +} diff --git a/init.d/savecore.in b/init.d/savecore.in new file mode 100644 index 0000000..e23bde4 --- /dev/null +++ b/init.d/savecore.in @@ -0,0 +1,36 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +description="Saves a kernel dump." + +depend() +{ + need localmount + keyword nojail noprefix +} + +start() +{ + local dump_dir=${dump_dir:-/var/crash} + if ! [ -d "${dump_dir}" ]; then + mkdir -p "${dump_dir}" + chmod 700 "${dump_dir}" + fi + + if [ "${RC_UNAME}" = "FreeBSD" ]; then + # Don't quote ${dump_device}, so that if it's unset, + # savecore will check on the partitions listed in fstab + # without errors in the output + savecore -C "${dump_dir}" ${dump_device} >/dev/null + else + ls "${dump_dir}"/bsd* > /dev/null 2>&1 + fi + [ $? = 0 ] || return 0 + + local sopts="${dump_dir} ${dump_device}" + yesno ${dump_compress} && sopts="-z ${sopts}" + ebegin "Saving kernel core dump in ${dump_dir}" + savecore ${sopts} >/dev/null + eend $? +} diff --git a/init.d/swap-blk.in b/init.d/swap-blk.in new file mode 100644 index 0000000..4708bff --- /dev/null +++ b/init.d/swap-blk.in @@ -0,0 +1,23 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +depend() +{ + before fsck + keyword nojail noprefix +} + +start() +{ + ebegin "Activating block swap devices" + swapctl -A -t blk >/dev/null + eend 0 # If swapon has nothing todo it errors, so always return 0 +} + +stop() +{ + ebegin "Deactivating block swap devices" + swapctl -U -t blk >/dev/null + eend 0 +} diff --git a/init.d/syscons.in b/init.d/syscons.in new file mode 100644 index 0000000..94c91a0 --- /dev/null +++ b/init.d/syscons.in @@ -0,0 +1,83 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +depend() { + need localmount + keyword nojail noprefix +} + +start() { + if [ -n "${allscreen_flags}" ]; then + ebegin "Setting mode to ${allscreen_flags} for all screens" + for v in /dev/ttyv*; do + vidcontrol ${allscreen_flags} <"${v}" + done + eend $? + fi + + if [ -n "${keymap}" ]; then + ebegin "Setting keymap to ${keymap}" + kbdcontrol -l ${keymap} \`$2'" + kbdcontrol -f "$1" "$2" +# All rights reserved. Released under the 2-clause BSD license. + +depend() +{ + use hostname + before bootmisc logger + keyword noprefix +} + +start() +{ + [ -e /etc/sysctl.conf ] || return 0 + + ebegin "Configuring kernel parameters" + local retval=0 var= comments= + while read var comments; do + case "${var}" in + ""|"#"*) continue;; + esac + sysctl -w "${var}" >/dev/null || retval=1 + done < /etc/sysctl.conf + eend ${retval} "Some errors were encountered" + eend $? +} diff --git a/init.d/syslogd.in b/init.d/syslogd.in new file mode 100644 index 0000000..b39a7d3 --- /dev/null +++ b/init.d/syslogd.in @@ -0,0 +1,20 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +command=/usr/sbin/syslogd +command_args=${syslogd_args} +case "${RC_UNAME}" in + FreeBSD|DragonFly) pidfile=/var/run/syslog.pid;; + *) pidfile=/var/run/syslogd.pid;; +esac +name="System Logger Daemon" + +depend() +{ + provide logger + use net newsyslog + need localmount + after bootmisc + keyword noprefix +} diff --git a/init.d/ttys.in b/init.d/ttys.in new file mode 100644 index 0000000..8381d04 --- /dev/null +++ b/init.d/ttys.in @@ -0,0 +1,23 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +depend() +{ + after fsck + keyword noprefix +} + +start() +{ + ebegin "Setting tty flags" + ttyflags -a + eend $? || return $? + + if [ -c /dev/ttyp0 ]; then + chmod 666 /dev/tty[p-uw-zP-T][0-9a-zA-Z] + fi + if [ -c /dev/ttyv1 ]; then + chmod 666 /dev/ttyv[0-9a-zA-Z] + fi +} diff --git a/init.d/wscons.in b/init.d/wscons.in new file mode 100644 index 0000000..15e5b56 --- /dev/null +++ b/init.d/wscons.in @@ -0,0 +1,100 @@ +#!@PREFIX@/sbin/runscript +# Copyright 2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +depend() +{ + need localmount + keyword noprefix +} + +start() +{ + wscfg=/usr/sbin/wsconscfg + wsfld=/usr/sbin/wsfontload + wsctl=/sbin/wsconsctl + config=/etc/wscons.conf + + # args mean: + # screen idx scr emul + # font name width height enc file + while read type arg1 arg2 arg3 arg4 arg5; do + case "${type}" in + \#*|"") + continue + ;; + + font) + cmd=${wsfld} + [ "${arg2}" != "-" ] && cmd="${cmd} -w ${arg2}" + [ "${arg3}" != "-" ] && cmd="${cmd} -h ${arg3}" + [ "${arg4}" != "-" ] && cmd="${cmd} -e ${arg4}" + cmd="${cmd} -N ${arg1} ${arg5}" + eval "${cmd}" + ;; + + screen) + cmd=${wscfg} + [ "${arg2}" != "-" ] && cmd="${cmd} -t ${arg2}" + [ "${arg3}" != "-" ] && cmd="${cmd} -e ${arg3}" + cmd="${cmd} ${arg1}" + eval "${cmd}" + ;; + + keyboard) + cmd=${wscfg} + case "${arg1}" in + -|auto) + cmd="${cmd} -k" + ;; + *) + cmd="${cmd} -k ${arg1}" + ;; + esac + ${cmd} + ;; + + encoding) + eval ${wsctl} -w "\"encoding=${arg1}\"" + ;; + + mapfile) + local entry= + while read entry; do + case "${entry}" in + \#*|"") + continue + ;; + *) + cmd="${wsctl} -w \"map+=${entry}\"" + eval "${cmd} >/dev/null" + ;; + esac + done < "${arg1}" + ;; + + mux) + eval "${wscfg} -m ${arg1}" + ;; + + setvar) + case "${arg1}" in + keyboard) + cmd="${wsctl} -kw ${arg2}" + ;; + display) + cmd="${wsctl} -dw ${arg2}" + ;; + mouse) + cmd="${wsctl} -mw ${arg2}" + ;; + *) + cmd="${wsctl} -w ${arg1}" + ;; + esac + eval "${cmd}" + ;; + + esac + done < "${config}" +} -- cgit v1.2.3