From: root Date: Sat, 28 Jan 2012 20:25:52 +0000 (+0100) Subject: saving uncommitted changes in /etc prior to emerge run X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=7e7e4398fd978f6fcfa9b12ed8510ae3dee47a29;p=config%2Fuhu1%2Fetc.git saving uncommitted changes in /etc prior to emerge run --- diff --git a/._cfg0000_rc.conf b/._cfg0000_rc.conf new file mode 100644 index 0000000..d3f5eb9 --- /dev/null +++ b/._cfg0000_rc.conf @@ -0,0 +1,135 @@ +# Global OpenRC configuration settings + +# Set rc_interactive to "YES" and you'll be able to press the I key during +# boot so you can choose to start specific services. Set to "NO" to disable +# this feature. +#rc_interactive="YES" + +# If we need to drop to a shell, you can specify it here. +# If not specified we use $SHELL, otherwise the one specified in /etc/passwd, +# otherwise /bin/sh +# Linux users could specify /sbin/sulogin +rc_shell=/sbin/sulogin + +# Do we allow any started service in the runlevel to satisfy the dependency +# or do we want all of them regardless of state? For example, if net.eth0 +# and net.eth1 are in the default runlevel then with rc_depend_strict="NO" +# both will be started, but services that depend on 'net' will work if either +# one comes up. With rc_depend_strict="YES" we would require them both to +# come up. +#rc_depend_strict="YES" + +# rc_hotplug is a list of services that we allow to be hotplugged. +# By default we do not allow hotplugging. +# A hotplugged service is one started by a dynamic dev manager when a matching +# hardware device is found. +# This service is intrinsically included in the boot runlevel. +# To disable services, prefix with a ! +# Example - rc_hotplug="net.wlan !net.*" +# This allows net.wlan and any service not matching net.* to be plugged. +# Example - rc_hotplug="*" +# This allows all services to be hotplugged +#rc_hotplug="*" + +# rc_logger launches a logging daemon to log the entire rc process to +# /var/log/rc.log +# NOTE: Linux systems require the devfs service to be started before +# logging can take place and as such cannot log the sysinit runlevel. +#rc_logger="YES" + +# Through rc_log_path you can specify a custom log file. +# The default value is: /var/log/rc.log +#rc_log_path="/var/log/rc.log" + +# By default we filter the environment for our running scripts. To allow other +# variables through, add them here. Use a * to allow all variables through. +#rc_env_allow="VAR1 VAR2" + +# By default we assume that all daemons will start correctly. +# However, some do not - a classic example is that they fork and return 0 AND +# then child barfs on a configuration error. Or the daemon has a bug and the +# child crashes. You can set the number of milliseconds start-stop-daemon +# waits to check that the daemon is still running after starting here. +# The default is 0 - no checking. +#rc_start_wait=100 + +# rc_nostop is a list of services which will not stop when changing runlevels. +# This still allows the service itself to be stopped when called directly. +#rc_nostop="" + +# rc will attempt to start crashed services by default. +# However, it will not stop them by default as that could bring down other +# critical services. +#rc_crashed_stop=NO +#rc_crashed_start=YES + +############################################################################## +# MISC CONFIGURATION VARIABLES +# There variables are shared between many init scripts + +# Set unicode to YES to turn on unicode support for keyboards and screens. +unicode="YES" + +# Below is the default list of network fstypes. +# +# afs cifs coda davfs fuse fuse.sshfs gfs glusterfs lustre ncpfs +# nfs nfs4 ocfs2 shfs smbfs +# +# If you would like to add to this list, you can do so by adding your +# own fstypes to the following variable. +#extra_net_fs_list="" + +############################################################################## +# SERVICE CONFIGURATION VARIABLES +# These variables are documented here, but should be configured in +# /etc/conf.d/foo for service foo and NOT enabled here unless you +# really want them to work on a global basis. + +# Some daemons are started and stopped via start-stop-daemon. +# We can set some things on a per service basis, like the nicelevel. +#export SSD_NICELEVEL="-19" + +# Pass ulimit parameters +#rc_ulimit="-u 30" + +# It's possible to define extra dependencies for services like so +#rc_config="/etc/foo" +#rc_need="openvpn" +#rc_use="net.eth0" +#rc_after="clock" +#rc_before="local" +#rc_provide="!net" + +# You can also enable the above commands here for each service. Below is an +# example for service foo. +#rc_foo_config="/etc/foo" +#rc_foo_need="openvpn" +#rc_foo_after="clock" + +# You can also remove dependencies. +# This is mainly used for saying which servies do NOT provide net. +#rc_net_tap0_provide="!net" + +############################################################################## +# LINUX SPECIFIC OPTIONS + +# This is the subsystem type. Valid options on Linux: +# "" - nothing special +# "lxc" - Linux Containers +# "openvz" - Linux OpenVZ +# "prefix" - Prefix +# "uml" - Usermode Linux +# "vserver" - Linux vserver +# "xen0" - Xen0 Domain +# "xenU" - XenU Domain +# If this is commented out, automatic detection will be attempted. +# Note that autodetection will not work in a prefix environment or in a +# linux container. +# +# This should be set to the value representing the environment this file is +# PRESENTLY in, not the virtualization the environment is capable of. +#rc_sys="" + +# This is the number of tty's used in most of the rc-scripts (like +# consolefont, numlock, etc ...) +rc_tty_number=12 diff --git a/.etckeeper b/.etckeeper index a60323d..a3337ad 100755 --- a/.etckeeper +++ b/.etckeeper @@ -25,6 +25,7 @@ mkdir -p './texmf/dvipdfm/config' mkdir -p './texmf/dvips.d' mkdir -p './unixODBC/ODBCDataSources' maybe chmod 0755 '.' +maybe chmod 0644 './._cfg0000_rc.conf' maybe chmod 0700 './.etckeeper' maybe chmod 0644 './.gitignore' maybe chmod 0644 './.make.conf.swp' @@ -105,7 +106,9 @@ maybe chmod 0644 './clamd.conf' maybe chmod 0644 './colordiffrc' maybe chmod 0644 './colordiffrc-lightbg' maybe chmod 0755 './conf.d' +maybe chmod 0644 './conf.d/._cfg0000_fsck' maybe chmod 0644 './conf.d/._cfg0000_udev' +maybe chmod 0644 './conf.d/._cfg0000_urandom' maybe chmod 0644 './conf.d/apache2' maybe chmod 0644 './conf.d/auditd' maybe chmod 0644 './conf.d/bootmisc' @@ -459,9 +462,22 @@ maybe chmod 0644 './idn.conf.sample' maybe chmod 0644 './idnalias.conf' maybe chmod 0644 './idnalias.conf.sample' maybe chmod 0755 './init.d' +maybe chmod 0755 './init.d/._cfg0000_bootmisc' +maybe chmod 0755 './init.d/._cfg0000_consolefont' +maybe chmod 0755 './init.d/._cfg0000_fsck' +maybe chmod 0755 './init.d/._cfg0000_hwclock' +maybe chmod 0755 './init.d/._cfg0000_keymaps' +maybe chmod 0755 './init.d/._cfg0000_modules' +maybe chmod 0755 './init.d/._cfg0000_net.lo' +maybe chmod 0755 './init.d/._cfg0000_network' +maybe chmod 0755 './init.d/._cfg0000_numlock' +maybe chmod 0755 './init.d/._cfg0000_staticroute' +maybe chmod 0755 './init.d/._cfg0000_sysfs' +maybe chmod 0755 './init.d/._cfg0000_termencoding' maybe chmod 0755 './init.d/._cfg0000_udev' maybe chmod 0755 './init.d/._cfg0000_udev-mount' maybe chmod 0755 './init.d/._cfg0000_udev-postmount' +maybe chmod 0755 './init.d/._cfg0000_urandom' maybe chmod 0755 './init.d/apache2' maybe chmod 0755 './init.d/atd' maybe chmod 0755 './init.d/auditd' diff --git a/conf.d/._cfg0000_fsck b/conf.d/._cfg0000_fsck new file mode 100644 index 0000000..16aa575 --- /dev/null +++ b/conf.d/._cfg0000_fsck @@ -0,0 +1,34 @@ +# Pass any arguments to fsck. +# By default we preen. +# Linux systems also force -C0 and -T. +# If fsck_args is not specified then Linux systems also use -A +# (and -R if / is rw) +#fsck_args="-p" + +# We can also specify the passno in /etc/fstab to check +# If you multiplex fsck (ie ln -s fsck /etc/init.d/fsck.late) then you can +# do an fsck outside of the normal scope, say for /home. +# Here are some exampes:- +#fsck_passno="=1 =2" +#fsck_passno=">1" +#fsck_passno="<2" + +# If passno is not enough granularity, you can also specify mountpoints to +# check. This should NOT be used for the default non-multiplexed fsck, or your +# system might not be checked. Additionally, it is mutually exclusive with +# the fsck_passno setting. +#fsck_mnt="" +#fsck_mnt="/home" + +# Most modern fs's don't require a full fsck on boot, but for those that do +# it may be advisable to skip this when running on battery. +# WARNING: Do not turn this off if you have any JFS partitions. +fsck_on_battery="YES" + +# fsck_shutdown causes fsck to trigger during shutdown as well as startup. +# The end result of this is that if any periodic non-root filesystem checks are +# scheduled, under normal circumstances the actual check will happen during +# shutdown rather than at next boot. +# This is useful when periodic filesystem checks are causing undesirable +# delays at startup, but such delays at shutdown are acceptable. +fsck_shutdown="NO" diff --git a/conf.d/._cfg0000_urandom b/conf.d/._cfg0000_urandom new file mode 100644 index 0000000..f721a24 --- /dev/null +++ b/conf.d/._cfg0000_urandom @@ -0,0 +1,5 @@ +# Sometimes you want to have urandom start before "localmount" +# (say for crypt swap), so you will need to customize this +# behavior. If you have /var on a separate partition, then +# make sure this path lives on your root device somewhere. +urandom_seed="/var/lib/misc/random-seed" diff --git a/init.d/._cfg0000_bootmisc b/init.d/._cfg0000_bootmisc new file mode 100755 index 0000000..0e03938 --- /dev/null +++ b/init.d/._cfg0000_bootmisc @@ -0,0 +1,204 @@ +#!/sbin/runscript +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +depend() +{ + need localmount + before logger + after clock sysctl + keyword -prefix -timeout +} + +dir_writable() +{ + mkdir "$1"/.test.$$ 2>/dev/null && rmdir "$1"/.test.$$ +} + +: ${wipe_tmp:=${WIPE_TMP:-yes}} +: ${log_dmesg:=${LOG_DMESG:-yes}} + +cleanup_tmp_dir() +{ + local dir="$1" + + if ! [ -d "$dir" ]; then + mkdir -p "$dir" || return $? + fi + dir_writable "$dir" || return 1 + chmod a+rwt "$dir" 2> /dev/null + cd "$dir" || return 1 + if yesno $wipe_tmp; then + ebegin "Wiping $dir directory" + + # Faster than raw find + if ! rm -rf -- [^ajlq\.]* 2>/dev/null ; then + # Blah, too many files + find . -maxdepth 1 -name '[^ajlq\.]*' -exec rm -rf -- {} + + fi + + # pam_mktemp creates a .private directory within which + # each user gets a private directory with immutable + # bit set; remove the immutable bit before trying to + # remove it. + [ -d /tmp/.private ] && chattr -R -a /tmp/.private 2> /dev/null + + # Prune the paths that are left + find . -maxdepth 1 \ + ! -name . \ + ! -name lost+found \ + ! -name quota.user \ + ! -name aquota.user \ + ! -name quota.group \ + ! -name aquota.group \ + ! -name journal \ + -exec rm -rf -- {} + + eend 0 + else + ebegin "Cleaning $dir directory" + rm -rf -- .X*-lock esrv* kio* \ + jpsock.* .fam* .esd* \ + orbit-* ssh-* ksocket-* \ + .*-unix + eend 0 + fi +} + +mkutmp() +{ + : >"$1" + # Not all systems have the utmp group + chgrp utmp "$1" 2>/dev/null + chmod 0664 "$1" +} + +migrate_to_run() +{ + src="$1" + dst="$2" + if [ -L $src -a "$(readlink -f $src)" != $dst ]; then + ewarn "$src does not point to $dst." + ewarn "Setting $src to point to $dst." + rm $src + elif [ ! -L $src -a -d $src ]; then + ebegin "Migrating $src to $dst" + cp -a $src/* $dst/ + rm -rf $src + eend $? + fi + # If $src doesn't exist at all, just run this + if [ ! -e $src ]; then + ln -s $dst $src + fi +} + +start() +{ + # Remove any added console dirs + rm -rf "$RC_LIBEXECDIR"/console/* + + local logw=false runw=false extra= + # Ensure that our basic dirs exist + if [ "$RC_UNAME" = Linux ]; then + # Satisfy Linux FHS + extra=/var/lib/misc + if [ ! -d /run ]; then + extra="/var/run $extra" + fi + else + extra=/var/run + fi + for x in /var/log /tmp $extra; do + if ! [ -d $x ]; then + if ! mkdir -p $x; then + eend 1 "failed to create needed directory $x" + return 1 + fi + fi + done + + if [ "$RC_UNAME" = Linux -a -d /run ] && false; then + migrate_to_run /var/lock /run/lock + migrate_to_run /var/run /run + fi + + if dir_writable /var/run; then + ebegin "Creating user login records" + local xtra= + [ "$RC_UNAME" = NetBSD ] && xtra=x + for x in "" $xtra; do + mkutmp /var/run/utmp$x + done + [ -e /var/log/wtmp ] || mkutmp /var/log/wtmp + eend 0 + + ebegin "Cleaning /var/run" + for x in $(find /var/run ! -type d ! -name utmp \ + ! -name random-seed ! -name dev.db \ + ! -name ld-elf.so.hints ! -name ld.so.hints); + do + # Clean stale sockets + if [ -S "$x" ]; then + if type fuser >/dev/null 2>&1; then + fuser "$x" >/dev/null 2>&1 || rm -- "$x" + else + rm -- "$x" + fi + fi + [ ! -f "$x" ] && continue + # Do not remove pidfiles of already running daemons + case "$x" in + *.pid) + start-stop-daemon --test --quiet \ + --stop --pidfile "$x" && continue + ;; + esac + rm -f -- "$x" + done + eend 0 + fi + + # Clean up /tmp directories + local tmp= + for tmp in ${clean_tmp_dirs:-${wipe_tmp_dirs-/tmp}}; do + cleanup_tmp_dir "$tmp" + done + + if dir_writable /tmp; then + # Make sure our X11 stuff have the correct permissions + # Omit the chown as bootmisc is run before network is up + # and users may be using lame LDAP auth #139411 + rm -rf /tmp/.ICE-unix /tmp/.X11-unix + mkdir -p /tmp/.ICE-unix /tmp/.X11-unix + chmod 1777 /tmp/.ICE-unix /tmp/.X11-unix + if [ -x /sbin/restorecon ]; then + restorecon /tmp/.ICE-unix /tmp/.X11-unix + fi + fi + + if yesno $log_dmesg; then + if $logw || dir_writable /var/log; then + # Create an 'after-boot' dmesg log + if [ "$RC_SYS" != VSERVER -a "$RC_SYS" != OPENVZ ]; then + dmesg > /var/log/dmesg + chmod 640 /var/log/dmesg + fi + fi + fi + + [ -w /etc/nologin ] && rm -f /etc/nologin + return 0 +} + +stop() +{ + # Write a halt record if we're shutting down + if [ "$RC_RUNLEVEL" = shutdown ]; then + [ "$RC_UNAME" = Linux ] && halt -w + if [ "$RC_SYS" = OPENVZ ]; then + yesno $RC_REBOOT && printf "" >/reboot + fi + fi + + return 0 +} diff --git a/init.d/._cfg0000_consolefont b/init.d/._cfg0000_consolefont new file mode 100755 index 0000000..f989d2d --- /dev/null +++ b/init.d/._cfg0000_consolefont @@ -0,0 +1,67 @@ +#!/sbin/runscript +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Sets a font for the consoles." + +depend() +{ + need localmount termencoding + after hotplug bootmisc + keyword -openvz -prefix -uml -vserver -xenu -lxc +} + +start() +{ + 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=/dev/tty + + # 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 console font [$consolefont]" + [ -d /dev/vc ] && ttydev=/dev/vc/ + x=1 + while [ $x -le $ttyn ]; do + if ! setfont $consolefont $param -C $ttydev$x >/dev/null; then + retval=1 + break + fi + : $(( x += 1 )) + done + eend $retval + + # Store the last font so we can use it ASAP on boot + if [ $retval -eq 0 -a -w "$RC_LIBEXECDIR" ]; then + mkdir -p "$RC_LIBEXECDIR"/console + for font in /usr/share/consolefonts/"$consolefont".*; do + : + done + cp "$font" "$RC_LIBEXECDIR"/console + echo "${font##*/}" >"$RC_LIBEXECDIR"/console/font + fi + + return $retval +} diff --git a/init.d/._cfg0000_fsck b/init.d/._cfg0000_fsck new file mode 100755 index 0000000..9cf35b8 --- /dev/null +++ b/init.d/._cfg0000_fsck @@ -0,0 +1,120 @@ +#!/sbin/runscript +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Check and repair filesystems according to /etc/fstab" +_IFS=" +" + +depend() +{ + use dev clock modules + keyword -jail -openvz -prefix -timeout -vserver -lxc +} + +_abort() { + rc-abort + return 1 +} + +# We should only reboot when first booting +_reboot() { + if [ "$RC_RUNLEVEL" = "$RC_BOOTLEVEL" ]; then + reboot "$@" + _abort || return 1 + fi +} + +_forcefsck() +{ + [ -e /forcefsck ] || get_bootparam forcefsck +} + +start() +{ + local fsck_opts= p= check_extra= + + if [ -e /fastboot ]; then + ewarn "Skipping fsck due to /fastboot" + return 0 + fi + if _forcefsck; then + fsck_opts="$fsck_opts -f" + check_extra="(check forced)" + elif ! yesno ${fsck_on_battery:-YES} && ! on_ac_power; then + ewarn "Skipping fsck due to not being on AC power" + return 0 + fi + + if [ -n "$fsck_passno" ]; then + check_extra="[passno $fsck_passno] $check_extra" + if [ -n "$fsck_mnt" ]; then + eerror "Only 1 of fsck_passno and fsck_mnt must be set!" + return 1 + fi + fi + ebegin "Checking local filesystems $check_extra" + # Append passno mounts + for p in $fsck_passno; do + local IFS="$_IFS" + case "$p" in + [0-9]*) p="=$p";; + esac + set -- "$@" $(fstabinfo --passno "$p") + unset IFS + done + # Append custom mounts + for m in $fsck_mnt ; do + local IFS="$_IFS" + set -- "$@" "$m" + unset IFS + done + + if [ "$RC_UNAME" = Linux ]; then + fsck_opts="$fsck_opts -C0 -T" + if [ -z "$fsck_passno" -a -z "$fsck_mnt" ]; then + fsck_args=${fsck_args--A -p} + if echo 2>/dev/null >/.test.$$; then + rm -f /.test.$$ + fsck_opts="$fsck_opts -R" + fi + fi + fi + + trap : INT QUIT + fsck ${fsck_args--p} $fsck_opts "$@" + case $? in + 0) eend 0; return 0;; + 1) ewend 1 "Filesystems repaired"; return 0;; + 2|3) if [ "$RC_UNAME" = Linux ]; then + ewend 1 "Filesystems repaired, but reboot needed" + _reboot -f + else + ewend 1 "Filesystems still have errors;" \ + "manual fsck required" + _abort + fi;; + 4) if [ "$RC_UNAME" = Linux ]; then + ewend 1 "Fileystem errors left uncorrected, aborting" + _abort + else + ewend 1 "Filesystems repaired, but reboot needed" + _reboot + fi;; + 8) ewend 1 "Operational error"; return 0;; + 12) ewend 1 "fsck interrupted";; + *) eend 2 "Filesystems couldn't be fixed";; + esac + _abort || return 1 +} + +stop() +{ + # Fake function so we always shutdown correctly. + _abort() { return 0; } + _reboot() { return 0; } + _forcefsck() { return 1; } + + yesno $fsck_shutdown && start + return 0 +} diff --git a/init.d/._cfg0000_hwclock b/init.d/._cfg0000_hwclock new file mode 100755 index 0000000..28d675a --- /dev/null +++ b/init.d/._cfg0000_hwclock @@ -0,0 +1,146 @@ +#!/sbin/runscript +# Copyright (c) 2007-2008 Roy Marples +# 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_args:=${CLOCK_OPTS}} +: ${clock_systohc:=${CLOCK_SYSTOHC}} +: ${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 -openvz -prefix -uml -vserver -xenu -lxc +} + +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 ]; then + local rtc= + for rtc in /dev/rtc /dev/rtc[0-9]*; do + [ -e "$rtc" ] && break + done + if [ ! -e "${rtc}" ]; then + modprobe -q rtc-cmos || modprobe -q rtc || modprobe -q genrtc + fi + fi + + if [ -e /etc/adjtime ] && yesno $clock_adjfile; then + _hwclock --adjust $utc_cmd + : $(( 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 + if yesno $clock_hctosys; then + _hwclock --hctosys $utc_cmd $clock_args + else + _hwclock --systz $utc_cmd $clock_args + fi + : $(( 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 2>&1 | 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/._cfg0000_keymaps b/init.d/._cfg0000_keymaps new file mode 100755 index 0000000..211fdd3 --- /dev/null +++ b/init.d/._cfg0000_keymaps @@ -0,0 +1,70 @@ +#!/sbin/runscript +# Copyright (c) 2007-2008 Roy Marples +# Released under the 2-clause BSD license. + +description="Applies a keymap for the consoles." + +depend() +{ + need localmount termencoding + after bootmisc + keyword -openvz -prefix -uml -vserver -xenu -lxc +} + +start() +{ + ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}} + : ${unicode:=$UNICODE} + : ${keymap:=$KEYMAP} + : ${extended_keymaps:=$EXTENDED_KEYMAPS} + : ${windowkeys:=$SET_WINDOWSKEYS} + : ${fix_euro:=$FIX_EURO} + : ${dumpkeys_charset:=${DUMPKEYS_CHARSET}} + + if [ -z "$keymap" ]; then + eerror "You need to setup keymap in /etc/conf.d/keymaps first" + return 1 + fi + + local ttydev=/dev/tty n= + [ -d /dev/vc ] && ttydev=/dev/vc/ + + # 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 + + local wkeys= kmode="-a" msg="ASCII" + if yesno $unicode; then + kmode="-u" + msg="UTF-8" + fi + yesno $windowkeys && wkeys="windowkeys" + + # Set terminal encoding to either ASCII or UNICODE. + # See utf-8(7) for more information. + ebegin "Setting keyboard mode [$msg]" + n=1 + while [ $n -le $ttyn ]; do + kbd_mode $kmode -C $ttydev$n + : $(( n += 1 )) + done + eend 0 + + ebegin "Loading key mappings [$keymap]" + loadkeys -q $wkeys $keymap $extended_keymaps + eend $? "Error loading key mappings" || return $? + + if yesno $fix_euro; then + ebegin "Fixing font for euro symbol" + # Fix some fonts displaying the Euro, #173528. + echo "altgr keycode 18 = U+20AC" | loadkeys -q + eend $? + fi + + # Save the keymapping for use immediately at boot + if [ -w "$RC_LIBEXECDIR" ]; then + mkdir -p "$RC_LIBEXECDIR"/console + dumpkeys >"$RC_LIBEXECDIR"/console/keymap + fi +} diff --git a/init.d/._cfg0000_modules b/init.d/._cfg0000_modules new file mode 100755 index 0000000..17f60ce --- /dev/null +++ b/init.d/._cfg0000_modules @@ -0,0 +1,63 @@ +#!/sbin/runscript +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Loads a user defined list of kernel modules." + +depend() +{ + use isapnp + keyword -openvz -prefix -vserver -lxc +} + +start() +{ + # Should not fail if kernel do not have module + # support compiled in ... + [ ! -f /proc/modules ] && return 0 + + local KV x y kv_variant_list + KV=$(uname -r) + # full $KV + kv_variant_list="${KV}" + # remove any KV_EXTRA options to just get the full version + x=${KV%%-*} + # now slowly strip them + while [ -n "$x" ] && [ "$x" != "$y" ]; do + kv_variant_list="${kv_variant_list} $x" + y=$x + x=${x%.*} + done + + local list= x= xx= y= args= mpargs= cnt=0 a= + for x in $kv_variant_list ; do + eval list=\$modules_$(shell_var "$x") + [ -n "$list" ] && break + done + [ -z "$list" ] && list=$modules + + for x in $list; do + a=${x#*:} + if [ "$a" = "$x" ]; then + unset mpargs + ebegin "Loading module $x" + else + x=${x%%:*} + mpargs="-o $a" + ebegin "Loading module $x as $a" + fi + aa=$(shell_var "$a") + xx=$(shell_var "$x") + for y in $kv_variant_list ; do + eval args=\$module_${aa}_args_$(shell_var "$y") + [ -n "${args}" ] && break + eval args=\$module_${xx}_args_$(shell_var "$y") + [ -n "${args}" ] && break + done + [ -z "$args" ] && eval args=\$module_${aa}_args + [ -z "$args" ] && eval args=\$module_${xx}_args + eval modprobe -q "$mpargs" "$x" "$args" + eend $? "Failed to load $x" && : $(( cnt += 1 )) + done + einfo "Autoloaded $cnt module(s)" +} diff --git a/init.d/._cfg0000_net.lo b/init.d/._cfg0000_net.lo new file mode 100755 index 0000000..2314363 --- /dev/null +++ b/init.d/._cfg0000_net.lo @@ -0,0 +1,765 @@ +#!/sbin/runscript +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +MODULESDIR="${RC_LIBEXECDIR}/net" +MODULESLIST="${RC_SVCDIR}/nettree" +_config_vars="config routes" + +[ -z "${IN_BACKGROUND}" ] && IN_BACKGROUND="NO" + +description="Configures network interfaces." + +# Handy var so we don't have to embed new lines everywhere for array splitting +__IFS=" +" +depend() +{ + local IFACE=${RC_SVCNAME#*.} + local IFVAR=$(shell_var "${IFACE}") + + need localmount + after bootmisc + provide net + keyword -shutdown -jail -prefix -vserver + + case "${IFACE}" in + lo|lo0);; + *) after net.lo net.lo0 dbus;; + esac + + if [ "$(command -v "depend_${IFVAR}")" = "depend_${IFVAR}" ]; then + depend_${IFVAR} + fi + + local dep= prov= + for dep in need use before after provide keyword; do + eval prov=\$rc_${dep}_${IFVAR} + if [ -n "${prov}" ]; then + ${dep} ${prov} + fi + done +} + +# Support bash arrays - sigh +_array_helper() +{ + local _a= + + eval _a=\$$1 + _a=$(echo "${_a}" | sed -e 's:^[[:space:]]*::' -e 's:[[:space:]]*$::' -e '/^$/d' -e 's:[[:space:]]\{1,\}: :g') + + [ -n "${_a}" ] && printf "%s\n" "${_a}" +} + +_get_array() +{ + local _a= + if [ -n "${BASH}" ]; then + case "$(declare -p "$1" 2>/dev/null)" in + "declare -a "*) + ewarn "You are using a bash array for $1." + ewarn "This feature will be removed in the future." + ewarn "Please see net.example for the correct format for $1." + eval "set -- \"\${$1[@]}\"" + for _a; do + printf "%s\n" "${_a}" + done + return 0 + ;; + esac + fi + + _array_helper $1 +} + +# Flatten bash arrays to simple strings +_flatten_array() +{ + if [ -n "${BASH}" ]; then + case "$(declare -p "$1" 2>/dev/null)" in + "declare -a "*) + ewarn "You are using a bash array for $1." + ewarn "This feature will be removed in the future." + ewarn "Please see net.example for the correct format for $1." + eval "set -- \"\${$1[@]}\"" + for x; do + printf "'%s' " "$(printf "$x" | sed "s:':'\\\'':g")" + done + return 0 + ;; + esac + fi + + _array_helper $1 +} + +_wait_for_carrier() +{ + local timeout= efunc=einfon + + _has_carrier && return 0 + + eval timeout=\$carrier_timeout_${IFVAR} + timeout=${timeout:-${carrier_timeout:-5}} + + # Incase users don't want this nice feature ... + [ ${timeout} -le 0 ] && return 0 + + yesno ${RC_PARALLEL} && efunc=einfo + ${efunc} "Waiting for carrier (${timeout} seconds) " + while [ ${timeout} -gt 0 ]; do + sleep 1 + if _has_carrier; then + [ "${efunc}" = "einfon" ] && echo + eend 0 + return 0 + fi + : $(( timeout -= 1 )) + [ "${efunc}" = "einfon" ] && printf "." + done + + [ "${efunc}" = "einfon" ] && echo + eend 1 + return 1 +} + +_netmask2cidr() +{ + # Some shells cannot handle hex arithmetic, so we massage it slightly + # Buggy shells include FreeBSD sh, dash and busybox. + # bash and NetBSD sh don't need this. + case $1 in + 0x*) + local hex=${1#0x*} quad= + while [ -n "${hex}" ]; do + local lastbut2=${hex#??*} + quad=${quad}${quad:+.}0x${hex%${lastbut2}*} + hex=${lastbut2} + done + set -- ${quad} + ;; + esac + + local i= len= + local IFS=. + for i in $1; do + while [ ${i} -ne 0 ]; do + : $(( len += i % 2 )) + : $(( i >>= 1 )) + done + done + + echo "${len}" +} + +_configure_variables() +{ + local var= v= t= + + for var in ${_config_vars}; do + local v= + for t; do + eval v=\$${var}_${t} + if [ -n "${v}" ]; then + eval ${var}_${IFVAR}=\$${var}_${t} + continue 2 + fi + done + done +} + +_which() +{ + local i OIFS + # Empty + [ -z "$1" ] && return + # check paths + OIFS="$IFS" + IFS=: + for i in $PATH ; do + [ -x $i/$1 ] && echo $i/$1 && break + done + IFS=$OIFS +} + +# Like _which, but also consider shell builtins, and multiple alternatives +_program_available() +{ + [ -z "$1" ] && return 0 + local x= + for x; do + case "${x}" in + /*) [ -x "${x}" ] && break;; + *) type "${x}" >/dev/null 2>&1 && break;; + esac + unset x + done + [ -n "${x}" ] && echo $x && return 0 + return 1 +} + +_show_address() +{ + einfo "received address $(_get_inet_address "${IFACE}")" +} + +# Basically sorts our modules into order and saves the list +_gen_module_list() +{ + local x= f= force=$1 + if ! ${force} && [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt "${MODULESDIR}" ]; then + local update=false + for x in "${MODULESDIR}"/*.sh; do + [ -e "${x}" ] || continue + if [ "${x}" -nt "${MODULESLIST}" ]; then + update=true + break + fi + done + ${update} || return 0 + fi + + einfo "Caching network module dependencies" + # Run in a subshell to protect the main script + ( + after() { + eval ${MODULE}_after="\"\${${MODULE}_after}\${${MODULE}_after:+ }$*\"" + } + + before() { + local mod=${MODULE} + local MODULE= + for MODULE; do + after "${mod}" + done + } + + program() { + if [ "$1" = "start" -o "$1" = "stop" ]; then + local s="$1" + shift + eval ${MODULE}_program_${s}="\"\${${MODULE}_program_${s}}\${${MODULE}_program_${s}:+ }$*\"" + else + eval ${MODULE}_program="\"\${${MODULE}_program}\${${MODULE}_program:+ }$*\"" + fi + } + + provide() { + eval ${MODULE}_provide="\"\${${MODULE}_provide}\${${MODULE}_provide:+ }$*\"" + local x + for x in $*; do + eval ${x}_providedby="\"\${${MODULE}_providedby}\${${MODULE}_providedby:+ }${MODULE}\"" + done + } + + for MODULE in "${MODULESDIR}"/*.sh; do + sh -n "${MODULE}" || continue + . "${MODULE}" || continue + MODULE=${MODULE#${MODULESDIR}/} + MODULE=${MODULE%.sh} + eval ${MODULE}_depend + MODULES="${MODULES} ${MODULE}" + done + + VISITED= + SORTED= + visit() { + case " ${VISITED} " in + *" $1 "*) return;; + esac + VISITED="${VISITED} $1" + + eval AFTER=\$${1}_after + for MODULE in ${AFTER}; do + eval PROVIDEDBY=\$${MODULE}_providedby + if [ -n "${PROVIDEDBY}" ]; then + for MODULE in ${PROVIDEDBY}; do + visit "${MODULE}" + done + else + visit "${MODULE}" + fi + done + + eval PROVIDE=\$${1}_provide + for MODULE in ${PROVIDE}; do + visit "${MODULE}" + done + + eval PROVIDEDBY=\$${1}_providedby + [ -z "${PROVIDEDBY}" ] && SORTED="${SORTED} $1" + } + + for MODULE in ${MODULES}; do + visit "${MODULE}" + done + + printf "" > "${MODULESLIST}" + i=0 + for MODULE in ${SORTED}; do + eval PROGRAM=\$${MODULE}_program + eval PROGRAM_START=\$${MODULE}_program_start + eval PROGRAM_STOP=\$${MODULE}_program_stop + eval PROVIDE=\$${MODULE}_provide + echo "module_${i}='${MODULE}'" >> "${MODULESLIST}" + echo "module_${i}_program='${PROGRAM}'" >> "${MODULESLIST}" + echo "module_${i}_program_start='${PROGRAM_START}'" >> "${MODULESLIST}" + echo "module_${i}_program_stop='${PROGRAM_STOP}'" >> "${MODULESLIST}" + echo "module_${i}_provide='${PROVIDE}'" >> "${MODULESLIST}" + : $(( i += 1 )) + done + echo "module_${i}=" >> "${MODULESLIST}" + ) + + return 0 +} + +_load_modules() +{ + local starting=$1 mymods= + + # Ensure our list is up to date + _gen_module_list false + if ! . "${MODULESLIST}"; then + _gen_module_list true + . "${MODULESLIST}" + fi + + MODULES= + if [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then + eval mymods=\$modules_${IFVAR} + [ -z "${mymods}" ] && mymods=${modules} + fi + + local i=-1 x= mod= f= provides= + while true; do + : $(( i += 1 )) + eval mod=\$module_${i} + [ -z "${mod}" ] && break + [ -e "${MODULESDIR}/${mod}.sh" ] || continue + + eval set -- \$module_${i}_program + if [ -n "$1" ]; then + if ! _program_available "$@" >/dev/null; then + vewarn "Skipping module $mod due to missing program: $@" + continue + fi + fi + if ${starting}; then + eval set -- \$module_${i}_program_start + else + eval set -- \$module_${i}_program_stop + fi + if [ -n "$1" ]; then + if ! _program_available "$@" >/dev/null; then + vewarn "Skipping module $mod due to missing program: $@" + continue + fi + fi + + eval provides=\$module_${i}_provide + if ${starting}; then + case " ${mymods} " in + *" !${mod} "*) continue;; + *" !${provides} "*) [ -n "${provides}" ] && continue;; + esac + fi + MODULES="${MODULES}${MODULES:+ }${mod}" + + # Now load and wrap our functions + if ! . "${MODULESDIR}/${mod}.sh"; then + eend 1 "${RC_SVCNAME}: error loading module \`${mod}'" + exit 1 + fi + + [ -z "${provides}" ] && continue + + # Wrap our provides + local f= + for f in pre_start start post_start; do + eval "${provides}_${f}() { [ "$(command -v "${mod}_${f}")" = "${mod}_${f}" ] || return 0; ${mod}_${f} \"\$@\"; }" + done + + eval module_${mod}_provides="${provides}" + eval module_${provides}_providedby="${mod}" + done + + # Wrap our preferred modules + for mod in ${mymods}; do + case " ${MODULES} " in + *" ${mod} "*) + eval x=\$module_${mod}_provides + [ -z "${x}" ] && continue + for f in pre_start start post_start; do + eval "${x}_${f}() { [ "$(command -v "${mod}_${f}")" = "${mod}_${f}" ] || return 0; ${mod}_${f} \"\$@\"; }" + done + eval module_${x}_providedby="${mod}" + ;; + esac + done + + # Finally remove any duplicated provides from our list if we're starting + # Otherwise reverse the list + local LIST="${MODULES}" p= + MODULES= + if ${starting}; then + for mod in ${LIST}; do + eval x=\$module_${mod}_provides + if [ -n "${x}" ]; then + eval p=\$module_${x}_providedby + [ "${mod}" != "${p}" ] && continue + fi + MODULES="${MODULES}${MODULES:+ }${mod}" + done + else + for mod in ${LIST}; do + MODULES="${mod}${MODULES:+ }${MODULES}" + done + fi + + veinfo "Loaded modules: ${MODULES}" +} + +_load_config() +{ + local config="$(_get_array "config_${IFVAR}")" + local fallback="$(_get_array fallback_${IFVAR})" + + config_index=0 + local IFS="$__IFS" + set -- ${config} + + # We should support a space separated array for cidr configs + # But only as long as they do not contain other parameters for the address + if [ $# = 1 ]; then + unset IFS + set -- ${config} + # Of course, we may have a single address added old style. + # If the NEXT argument is a v4 or v6 address, it's the next config. + # Otherwise, it's arguments to the first config... + if [ "${2#*.*}" = "${2}" -a "${2#*:*}" = "${2}" ]; then + # Not an IPv4/IPv6 + local IFS="$__IFS" + set -- ${config} + fi + fi + + # Ensure that loopback has the correct address + if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ]; then + if [ "$1" != "null" ]; then + config_0="127.0.0.1/8" + config_index=1 + fi + else + if [ -z "$1" ]; then + ewarn "No configuration specified; defaulting to DHCP" + config_0="dhcp" + config_index=1 + fi + fi + + + # We store our config in an array like vars + # so modules can influence it + for cmd; do + eval config_${config_index}="'${cmd}'" + : $(( config_index += 1 )) + done + # Terminate the list + eval config_${config_index}= + + config_index=0 + for cmd in ${fallback}; do + eval fallback_${config_index}="'${cmd}'" + : $(( config_index += 1 )) + done + # Terminate the list + eval fallback_${config_index}= + + # Don't set to zero, so any net modules don't have to do anything extra + config_index=-1 +} + +# Support functions +_run_if() +{ + local cmd=$1 iface=$2 ifr=${IFACE} ifv=${IFVAR} + # Ensure that we don't stamp on real values + local IFACE= IFVAR= + shift + if [ -n "${iface}" ]; then + IFACE="${iface}" + [ "${iface}" != "${ifr}" ] && IFVAR=$(shell_var "${IFACE}") + else + IFACE=${ifr} + IFVAR=${ifv} + fi + ${cmd} +} +interface_exists() +{ + _run_if _exists "$@" +} +interface_up() +{ + _run_if _up "$@" +} +interface_down() +{ + _run_if _down "$@" +} + +start() +{ + local IFACE=${RC_SVCNAME#*.} oneworked=false fallback=false module= + local IFVAR=$(shell_var "${IFACE}") cmd= our_metric= + local metric=0 _up_before_preup + eval _up_before_preup="\$up_before_preup_${IFVAR}" + [ -z "${_up_before_preup}" ] && _up_before_preup=$up_before_preup + + einfo "Bringing up interface ${IFACE}" + eindent + + if [ -z "${MODULES}" ]; then + local MODULES= + _load_modules true + fi + + # We up the iface twice if we have a preup to ensure it's up if + # available in preup and afterwards incase the user inadvertently + # brings it down + if [ "$(command -v preup)" = "preup" ]; then + yesno "${_up_before_preup:-yes}" && _up 2>/dev/null + ebegin "Running preup" + eindent + preup || return 1 + eoutdent + fi + + _up 2>/dev/null + + for module in ${MODULES}; do + if [ "$(command -v "${module}_pre_start")" = "${module}_pre_start" ]; then + ${module}_pre_start || exit $? + fi + done + + if ! _exists; then + eerror "ERROR: interface ${IFACE} does not exist" + eerror "Ensure that you have loaded the correct kernel module for your hardware" + return 1 + fi + + if ! _wait_for_carrier; then + if service_started devd; then + ewarn "no carrier, but devd will start us when we have one" + mark_service_inactive "${RC_SVCNAME}" + else + eerror "no carrier" + fi + return 1 + fi + + local config= config_index= + _load_config + config_index=0 + + eval our_metric=\$metric_${IFVAR} + if [ -n "${our_metric}" ]; then + metric=${our_metric} + elif [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then + : $(( metric += $(_ifindex) )) + fi + + while true; do + eval config=\$config_${config_index} + [ -z "${config}" ] && break + + set -- ${config} + if [ "$1" != "null" -a "$1" != "noop" ]; then + ebegin "$1" + fi + eindent + case "$1" in + noop) + if [ -n "$(_get_inet_address)" ]; then + oneworked=true + break + fi + ;; + null) :;; + [0-9]*|*:*) _add_address ${config};; + *) + if [ "$(command -v "${config}_start")" = "${config}_start" ]; then + "${config}"_start + else + eerror "nothing provides \`${config}'" + fi + ;; + esac + if eend $?; then + oneworked=true + else + eval config=\$fallback_${config_index} + if [ -n "${config}" ]; then + fallback=true + eoutdent + ewarn "Trying fallback configuration ${config}" + eindent + eval config_${config_index}=\$config + unset fallback_${config_index} + : $(( config_index -= 1 )) + fi + fi + eoutdent + : $(( config_index += 1 )) + done + + if ! ${oneworked}; then + if [ "$(command -v failup)" = "failup" ]; then + ebegin "Running failup" + eindent + failup + eoutdent + fi + return 1 + fi + + local hidefirstroute=false first=true routes= + if ${fallback}; then + routes="$(_get_array "fallback_routes_${IFVAR}")" + fi + if [ -z "${routes}" ]; then + routes="$(_get_array "routes_${IFVAR}")" + fi + if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ]; then + if [ "${config_0}" != "null" ]; then + routes="127.0.0.0/8 via 127.0.0.1 +${routes}" + hidefirstroute=true + fi + fi + + local OIFS="${IFS}" SIFS="${IFS-y}" + local IFS="$__IFS" + for cmd in ${routes}; do + unset IFS + if ${first}; then + first=false + einfo "Adding routes" + fi + eindent + ebegin ${cmd} + # Work out if we're a host or a net if not told + case ${cmd} in + -net" "*|-host" "*);; + *" "netmask" "*) cmd="-net ${cmd}";; + *.*.*.*/32*) cmd="-host ${cmd}";; + *.*.*.*/*|0.0.0.0|0.0.0.0" "*) cmd="-net ${cmd}";; + default|default" "*) cmd="-net ${cmd}";; + *) cmd="-host ${cmd}";; + esac + if ${hidefirstroute}; then + _add_route ${cmd} >/dev/null 2>&1 + hidefirstroute=false + else + _add_route ${cmd} >/dev/null + fi + eend $? + eoutdent + done + if [ "${SIFS}" = "y" ]; then + unset IFS + else + IFS="${OIFS}" + fi + + for module in ${MODULES}; do + if [ "$(command -v "${module}_post_start")" = "${module}_post_start" ]; then + ${module}_post_start || exit $? + fi + done + + if [ "$(command -v postup)" = "postup" ]; then + ebegin "Running postup" + eindent + postup + eoutdent + fi + + return 0 +} + +stop() +{ + local IFACE=${RC_SVCNAME#*.} module= + local IFVAR=$(shell_var "${IFACE}") opts= + + einfo "Bringing down interface ${IFACE}" + eindent + + if [ -z "${MODULES}" ]; then + local MODULES= + _load_modules false + fi + + if [ "$(command -v predown)" = "predown" ]; then + ebegin "Running predown" + eindent + predown || return 1 + eoutdent + else + if is_net_fs /; then + eerror "root filesystem is network mounted -- can't stop ${IFACE}" + return 1 + fi + fi + + for module in ${MODULES}; do + if [ "$(command -v "${module}_pre_stop")" = "${module}_pre_stop" ]; then + ${module}_pre_stop || exit $? + fi + done + + for module in ${MODULES}; do + if [ "$(command -v "${module}_stop")" = "${module}_stop" ]; then + ${module}_stop + fi + done + + # Only delete addresses for interfaces that exist + if _exists; then + # PPP can manage it's own addresses when IN_BACKGROUND + # Important in case "demand" set on the ppp link + if ! (yesno ${IN_BACKGROUND} && is_ppp) ; then + _delete_addresses "${IFACE}" + fi + fi + + for module in ${MODULES}; do + if [ "$(command -v "${module}_post_stop")" = "${module}_post_stop" ]; then + ${module}_post_stop + fi + done + + # If not in background, and not loopback then bring the interface down + # unless overridden. + if ! yesno ${IN_BACKGROUND} && \ + [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then + eval module=\$ifdown_${IFVAR} + module=${module:-${ifdown:-YES}} + yesno ${module} && _down 2>/dev/null + fi + + type resolvconf >/dev/null 2>&1 && resolvconf -d "${IFACE}" 2>/dev/null + + if [ "$(command -v "postdown")" = "postdown" ]; then + ebegin "Running postdown" + eindent + postdown + eoutdent + fi + + return 0 +} diff --git a/init.d/._cfg0000_network b/init.d/._cfg0000_network new file mode 100755 index 0000000..7ba4f48 --- /dev/null +++ b/init.d/._cfg0000_network @@ -0,0 +1,358 @@ +#!/sbin/runscript +# Copyright (c) 2009 Roy Marples +# Released under the 2-clause BSD license. + +# This script was inspired by the equivalent rc.d network from NetBSD. + +description="Configures network interfaces." +__nl=" +" + +depend() +{ + need localmount + after bootmisc + provide net + keyword -jail -prefix -vserver +} + +uniqify() +{ + local result= i= + for i; do + case " $result " in + *" $i "*);; + *) result="$result $i";; + esac + done + echo "${result# *}" +} + +reverse() +{ + local result= i= + for i; do + result="$i $result" + done + echo "${result# *}" +} + +sys_interfaces() +{ + case "$RC_UNAME" in + Linux) + local w= rest= i= cmd=$1 + while read w rest; do + i=${w%%:*} + [ "$i" != "$w" ] || continue + if [ "$cmd" = u ]; then + ifconfig "$i" | grep -q "[ ]*UP" || continue + fi + printf "%s " "$i" + done /dev/null); do + for f in /etc/ifconfig.${c}[0-9]*; do + [ -f "$f" ] && printf "%s" "$f{##*.} " + done + done + ;; + *) + for f in /etc/ifconfig.*; do + [ -f "$f" ] && printf "%s" "${f##*.} " + done + for f in /etc/ip.*; do + [ -f "$f" ] && printf "%s" "${f##*.} " + done + ;; + esac + echo +} + +interfaces() +{ + uniqify $(sys_interfaces "$@") $interfaces $(auto_interfaces) +} + +dumpargs() +{ + local f="$1" + + shift + case "$@" in + '') [ -f "$f" ] && cat "$f";; + *"$__nl"*) echo "$@";; + *) + ( + set -o noglob + IFS=';'; set -- $@ + IFS="$__nl"; echo "$*" + );; + esac +} + +intup=false +runip() +{ + local int="$1" err= + shift + + # Ensure we have a valid broadcast address + case "$@" in + *" broadcast "*|*" brd "*) ;; + *:*) ;; # Ignore IPv6 + *) set -- "$@" brd +;; + esac + + err=$(LC_ALL=C ip address add "$@" dev "$int" 2>&1) + if [ -z "$err" ]; then + # ip does not bring up the interface when adding addresses + if ! $intup; then + ip link set "$int" up + intup=true + fi + return 0 + fi + if [ "$err" = "RTNETLINK answers: File exists" ]; then + ip address del "$@" dev "$int" 2>/dev/null + fi + # Localise the error + ip address add "$@" dev "$int" +} + +routeflush() +{ + if [ "$RC_UNAME" = Linux ]; then + if [ -x /sbin/ip ] || [ -x /bin/ip ]; then + ip route flush scope global + ip route delete default 2>/dev/null + else + # Sadly we also delete some link routes, but + # this cannot be helped + local dest= gate= net= flags= rest= + route -n | while read dest gate net flags rest; do + [ -z "$net" ] && continue + case "$dest" in + [0-9]*) ;; + *) continue;; + esac + local xtra= netmask="netmask $net" + case "$flags" in + U) continue;; + *H*) flags=-host; netmask=;; + *!*) flags=-net; xtra=reject;; + *) flags=-net;; + esac + route del $flags $dest $netmask $xtra + done + # Erase any default dev eth0 routes + route del default 2>/dev/null + fi + else + route -qn flush + fi +} + +runargs() +{ + dumpargs "$@" | while read -r args; do + case "$args" in + ''|"#"*) ;; + *) + ( + eval vebegin "${args#*!}" + eval "${args#*!}" + veend $? + );; + esac + done +} + +start() +{ + local cr=0 r= int= intv= cmd= args= upcmd= + + if [ -z "$domainname" -a -s /etc/defaultdomain ]; then + domainname=$(cat /etc/defaultdomain) + fi + if [ -n "$domainname" ]; then + ebegin "Setting NIS domainname: $domainname" + domainname "$domainname" + eend $? + fi + + ewarn + ewarn "The $RC_SVCNAME script is deprecated and will be" + ewarn "removed in the future." + ewarn "Please use the net.* scripts to manage your network interfaces." + ewarn + + einfo "Starting network" + routeflush + if [ "$RC_UNAME" = "Linux" ]; then + ifconfig lo 127.0.0.1 netmask 255.0.0.0 || cr=1 + route add -net 127.0.0.0 netmask 255.0.0.0 \ + gw 127.0.0.1 reject 2>/dev/null + else + ifconfig lo0 127.0.0.1 netmask 255.0.0.0 || cr=1 + route -q add -inet 127.0.0.0 -netmask 255.0.0.0 \ + 127.0.0.1 -reject || cr=1 + fi + eindent + for int in $(interfaces); do + local func= cf= + intv=$(shell_var "$int") + eval upcmd=\$ifup_$intv + for func in ip ifconfig; do + eval cmd=\$${func}_$intv + if [ -n "$cmd" -o -f /etc/"$func.$int" ]; then + cf=/etc/"$func.$int" + break + fi + done + [ -n "$cf" -o -n "$upcmd" -o \ + -f /etc/ifup."$int" -o -f "$cf" ] || continue + veinfo "$int" + case "$func" in + ip) func=runip; intup=false;; + esac + eindent + runargs /etc/ifup."$int" "$upcmd" + r=0 + dumpargs "$cf" "$cmd" | while read -r args; do + case "$args" in + ''|"#"*) ;; + "!"*) + ( + eval vebegin "${args#*!}" + eval "${args#*!}" + veend $? + );; + *) + ( + set -o noglob + eval set -- "$args" + vebegin "$@" + $func "$int" "$@" + veend $? + );; + esac + done + eoutdent + done + eoutdent + eend $cr + + # Wait for any inet6 tentative addresses + r=5 + while [ $r -gt 0 ]; do + tentative || break + [ $r = 5 ] && vebegin "Waiting for tentative addresses" + sleep 1 + : $(( r -= 1 )) + done + if [ $r != 5 ]; then + [ $r != 0 ] + veend $? + fi + + if [ -n "$defaultroute" ]; then + ebegin "Setting default route $defaultroute" + route add default $defaultroute + eend $? + elif [ -n "$defaultiproute" ]; then + ebegin "Setting default route $defaultiproute" + ip route add default $defaultiproute + eend $? + fi + + if [ -n "$defaultroute6" ]; then + ebegin "Setting default route $defaultroute6" + if [ "$RC_UNAME" = Linux ]; then + routecmd="route -A inet6 add" + else + routecmd="route -inet6 add" + fi + $routecmd default $defaultroute6 + eend $? + elif [ -n "$defaultiproute6" ]; then + ebegin "Setting default route $defaultiproute6" + ip -f inet6 route add default $defaultiproute6 + eend $? + fi + + return 0 +} + +stop() +{ + # Don't stop the network at shutdown. + # We don't use the noshutdown keyword so that we are started again + # correctly if we go back to multiuser. + yesno ${shutdown_network:-YES} && yesno $RC_GOINGDOWN && return 0 + + local int= intv= cmd= downcmd= r= + einfo "Stopping network" + routeflush + eindent + for int in $(reverse $(interfaces u)); do + intv=$(shell_var "$int") + eval downcmd=\$ifdown_$intv + eval cmd=\$ip_$intv + [ -z "$cmd" ] && eval cmd=\$ifconfig_$intv + if [ -n "$cmd" -o -f /etc/ip."$int" -o \ + -f /etc/ifconfig."$int" -o \ + -n "$downcmd" -o -f /etc/ifdown."$int" ]; + then + veinfo "$int" + runargs /etc/ifdown."$int" "$downcmd" + if [ -x /sbin/ip ] || [ -x /bin/ip ]; then + # We need to do this, otherwise we may + # fail to add things correctly on restart + ip address flush dev "$int" 2>/dev/null + fi + ifconfig "$int" down 2>/dev/null + ifconfig "$int" destroy 2>/dev/null + fi + done + eoutdent + eend 0 +} diff --git a/init.d/._cfg0000_numlock b/init.d/._cfg0000_numlock new file mode 100755 index 0000000..e354dfd --- /dev/null +++ b/init.d/._cfg0000_numlock @@ -0,0 +1,42 @@ +#!/sbin/runscript +# Copyright (c) 2007-2009 Roy Marples +# 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 -openvz -prefix -vserver -lxc +} + +_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 += 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/._cfg0000_staticroute b/init.d/._cfg0000_staticroute new file mode 100755 index 0000000..3a5d326 --- /dev/null +++ b/init.d/._cfg0000_staticroute @@ -0,0 +1,109 @@ +#!/sbin/runscript +# Copyright (c) 2009 Roy Marples +# Released under the 2-clause BSD license. + +# This script was inspired by the equivalent rc.d staticroute from NetBSD. + +description="Configures static routes." +__nl=" +" + +depend() +{ + provide net + use network + keyword -jail -prefix -vserver +} + +pre_flight_checks() +{ + route=route + [ -s /etc/route.conf ] && return 0 + + if [ -n "$staticiproute" ]; then + route="ip route" + staticroute="$staticiproute" + fi +} + +dump_args() +{ + # Route configuration file, as used by the NetBSD RC system + if [ -s /etc/route.conf ]; then + cat /etc/route.conf + return $? + fi + + case "$staticroute" in + *"$__nl"*) + echo "$staticroute" + ;; + *) + ( + set -o noglob + IFS=';'; set -- $staticroute + IFS="$__nl"; echo "$*" + ) + ;; + esac +} + +do_routes() +{ + local xtra= family= + [ "$RC_UNAME" != Linux ] && xtra=-q + + ebegin "$1 static routes" + eindent + pre_flight_checks + dump_args | while read args; do + [ -z "$args" ] && continue + case "$args" in + "#"*) + ;; + "+"*) + [ $2 = "add" ] && eval ${args#*+} + ;; + "-"*) + [ $2 = "del" -o $2 = "delete" ] && eval ${args#*-} + ;; + *) + veinfo "$args" + case "$route" in + "ip route") + ip route $2 $args + ;; + *) + # Linux route does cannot work it out ... + if [ "$RC_UNAME" = Linux ]; then + case "$args" in + *:*) family="-A inet6";; + *) family=;; + esac + fi + route $family $xtra $2 -$args + ;; + esac + veend $? + esac + done + eoutdent + eend 0 +} + +start() +{ + ewarn + ewarn "The $RC_SVCNAME script is deprecated and will be" + ewarn "removed in the future." + ewarn "Please use the net.* scripts to manage your network interfaces." + ewarn + do_routes "Adding" "add" +} + +stop() +{ + local cmd="delete" + [ "$RC_UNAME" = Linux ] && cmd="del" + do_routes "Deleting" "$cmd" +} diff --git a/init.d/._cfg0000_sysfs b/init.d/._cfg0000_sysfs new file mode 100755 index 0000000..dd3fc0e --- /dev/null +++ b/init.d/._cfg0000_sysfs @@ -0,0 +1,106 @@ +#!/sbin/runscript +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Mount the sys filesystem." + +depend() +{ + keyword -prefix -vserver +} + +mount_sys() +{ + grep -Eq "[[:space:]]+sysfs$" /proc/filesystems || return 1 + mountinfo -q /sys && return 0 + + if [ ! -d /sys ]; then + if ! mkdir -m 0755 /sys; then + ewarn "Could not create /sys!" + return 1 + fi + fi + + ebegin "Mounting /sys" + if ! fstabinfo --mount /sys; then + mount -n -t sysfs -o noexec,nosuid,nodev sysfs /sys + fi + eend $? +} + +mount_misc() +{ + # 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 -n -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 -n -t debugfs -o nodev,noexec,nosuid \ + debugfs /sys/kernel/debug + eend $? + fi + fi + + # Setup Kernel Support for configfs + if [ -d /sys/kernel/config ] && ! mountinfo -q /sys/kernel/config; then + if grep -qs configfs /proc/filesystems; then + ebegin "Mounting config filesystem" + mount -n -t configfs -o nodev,noexec,nosuid \ + configfs /sys/kernel/config + eend $? + fi + fi + + # set up kernel support for cgroups + if [ -d /sys/fs/cgroup ] && ! mountinfo -q /sys/fs/cgroup; then + if grep -qs cgroup /proc/filesystems; then + ebegin "Mounting cgroup filesystem" + local opts="nodev,noexec,nosuid,mode=755,size=${rc_cgroupsize:-10m}" + mount -n -t tmpfs -o ${opts} cgroup_root /sys/fs/cgroup + eend $? + fi + fi +} + +mount_cgroups() +{ + yesno ${rc_cgroups:-YES} || return 0 + if [ ! -e /proc/cgroups ]; then + return 0 + fi + + while read name hier groups enabled rest; do + case "${enabled}" in + 1) mkdir /sys/fs/cgroup/${name} + mount -t cgroup -o nodev,noexec,nosuid,${name} \ + ${name} /sys/fs/cgroup/${name} + ;; + esac + done < /proc/cgroups +} + +start() +{ + local retval + mount_sys + retval=$? + if [ $retval -eq 0 ]; then + mount_misc + retval=$? + fi + if [ $retval -eq 0 ]; then + mount_cgroups + retval=$? + fi + return $retval +} diff --git a/init.d/._cfg0000_termencoding b/init.d/._cfg0000_termencoding new file mode 100755 index 0000000..d7951d1 --- /dev/null +++ b/init.d/._cfg0000_termencoding @@ -0,0 +1,48 @@ +#!/sbin/runscript +# Copyright (c) 2008-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Configures terminal encoding." + +ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}} +: ${unicode:=${UNICODE}} + +depend() +{ + keyword -openvz -prefix -uml -vserver -xenu + need root + after bootmisc +} + +start() +{ + local ttydev=/dev/tty n= + [ -d /dev/vc ] && ttydev=/dev/vc/ + + # Set terminal encoding to either ASCII or UNICODE. + # See utf-8(7) for more information. + local termencoding="%@" termmsg="ASCII" + if yesno ${unicode}; then + termencoding="%G" + termmsg="UTF-8" + fi + + ebegin "Setting terminal encoding [$termmsg]" + n=1 + while [ ${n} -le "$ttyn" ]; do + printf "\033%s" "$termencoding" >$ttydev$n + : $(( n += 1 )) + done + + # Save the encoding for use immediately at boot + if [ -w "$RC_LIBEXECDIR" ]; then + mkdir -p "$RC_LIBEXECDIR"/console + if yesno ${unicode:-${UNICODE}}; then + echo "" > "$RC_LIBEXECDIR"/console/unicode + else + rm -f "$RC_LIBEXECDIR"/console/unicode + fi + fi + + eend 0 +} diff --git a/init.d/._cfg0000_urandom b/init.d/._cfg0000_urandom new file mode 100755 index 0000000..20e4325 --- /dev/null +++ b/init.d/._cfg0000_urandom @@ -0,0 +1,45 @@ +#!/sbin/runscript +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +: ${urandom_seed:=${URANDOM_SEED:-/var/lib/misc/random-seed}} +description="Initializes the random number generator." + +depend() +{ + need localmount + keyword -jail -openvz -prefix +} + +save_seed() +{ + local psz=1 + + if [ -e /proc/sys/kernel/random/poolsize ]; then + : $(( psz = $(cat /proc/sys/kernel/random/poolsize) / 4096 )) + fi + + ( # sub shell to prevent umask pollution + umask 077 + dd if=/dev/urandom of="$urandom_seed" count=${psz} 2>/dev/null + ) +} + +start() +{ + [ -c /dev/urandom ] || return + if [ -f "$urandom_seed" ]; then + ebegin "Initializing random number generator" + cat "$urandom_seed" > /dev/urandom + eend $? "Error initializing random number generator" + fi + rm -f "$urandom_seed" && save_seed + return 0 +} + +stop() +{ + ebegin "Saving random seed" + save_seed + eend $? "Failed to save random seed" +}