summaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
Diffstat (limited to 'sh')
-rw-r--r--sh/.gitignore10
-rw-r--r--sh/Makefile34
-rw-r--r--sh/cgroup-release-agent.sh.in10
-rw-r--r--sh/functions.sh.in117
-rw-r--r--sh/gendepends.sh.in92
-rw-r--r--sh/init-early.sh.Linux.in50
-rw-r--r--sh/init.sh.BSD.in53
-rw-r--r--sh/init.sh.GNU-kFreeBSD.in35
-rw-r--r--sh/init.sh.GNU.in38
-rw-r--r--sh/init.sh.Linux.in88
-rw-r--r--sh/migrate-to-run.sh.in29
-rw-r--r--sh/rc-cgroup.sh.in134
-rw-r--r--sh/rc-functions.sh.in113
-rw-r--r--sh/rc-mount.sh80
-rw-r--r--sh/runscript.sh.in351
-rwxr-xr-xsh/runtests.sh25
-rwxr-xr-xsh/tmpfiles.sh.in378
17 files changed, 0 insertions, 1637 deletions
diff --git a/sh/.gitignore b/sh/.gitignore
deleted file mode 100644
index d5cb215a..00000000
--- a/sh/.gitignore
+++ /dev/null
@@ -1,10 +0,0 @@
-functions.sh
-gendepends.sh
-rc-functions.sh
-runscript.sh
-cgroup-release-agent.sh
-init.sh
-init-early.sh
-rc-cgroup.sh
-tmpfiles.sh
-migrate-to-run.sh
diff --git a/sh/Makefile b/sh/Makefile
deleted file mode 100644
index c1953f31..00000000
--- a/sh/Makefile
+++ /dev/null
@@ -1,34 +0,0 @@
-DIR= ${LIBEXECDIR}/sh
-SRCS= init.sh.in functions.sh.in gendepends.sh.in \
- rc-functions.sh.in runscript.sh.in tmpfiles.sh.in ${SRCS-${OS}}
-INC= rc-mount.sh functions.sh rc-functions.sh
-BIN= gendepends.sh init.sh runscript.sh tmpfiles.sh ${BIN-${OS}}
-
-INSTALLAFTER= _installafter
-
-MK= ../mk
-include ${MK}/os.mk
-
-SRCS-FreeBSD=
-BIN-FreeBSD=
-
-SRCS-Linux= cgroup-release-agent.sh.in init-early.sh.in migrate-to-run.sh.in \
- rc-cgroup.sh.in
-BIN-Linux= cgroup-release-agent.sh init-early.sh migrate-to-run.sh \
- rc-cgroup.sh
-
-SRCS-NetBSD=
-BIN-NetBSD=
-
-include ${MK}/scripts.mk
-
-%.sh: %.sh${SFX}
- ${SED} ${SED_REPLACE} ${SED_EXTRA} $< > $@
-
-_installafter:
- ${INSTALL} -d ${DESTDIR}/${INITDIR}
- @# Put functions.sh into init for backwards compat
- ln -snf ${LIBEXECDIR}/sh/functions.sh ${DESTDIR}/${INITDIR} || exit $$?
-
-check test::
- ./runtests.sh
diff --git a/sh/cgroup-release-agent.sh.in b/sh/cgroup-release-agent.sh.in
deleted file mode 100644
index d6dd1e1e..00000000
--- a/sh/cgroup-release-agent.sh.in
+++ /dev/null
@@ -1,10 +0,0 @@
-#!@SHELL@
-#
-# This is run by the kernel after the last task is removed from a
-# control group in the openrc hierarchy.
-
-cgroup=/sys/fs/cgroup/openrc
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
-if [ -d ${cgroup}/"$1" ]; then
- rmdir ${cgroup}/"$1"
-fi
diff --git a/sh/functions.sh.in b/sh/functions.sh.in
deleted file mode 100644
index e4e69eb7..00000000
--- a/sh/functions.sh.in
+++ /dev/null
@@ -1,117 +0,0 @@
-# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
-# Released under the 2-clause BSD license.
-
-# Allow any sh script to work with einfo functions and friends
-# We also provide a few helpful functions for other programs to use
-
-RC_GOT_FUNCTIONS="yes"
-
-eindent()
-{
- : $(( EINFO_INDENT = ${EINFO_INDENT:-0} + 2 ))
- [ "$EINFO_INDENT" -gt 40 ] && EINFO_INDENT=40
- export EINFO_INDENT
-}
-
-eoutdent()
-{
- : $(( EINFO_INDENT = ${EINFO_INDENT:-0} - 2 ))
- [ "$EINFO_INDENT" -lt 0 ] && EINFO_INDENT=0
- return 0
-}
-
-yesno()
-{
- [ -z "$1" ] && return 1
-
- # Check the value directly so people can do:
- # yesno ${VAR}
- case "$1" in
- [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
- [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
- esac
-
- # Check the value of the var so people can do:
- # yesno VAR
- # Note: this breaks when the var contains a double quote.
- local value=
- eval value=\"\$$1\"
- case "$value" in
- [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
- [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
- *) vewarn "\$$1 is not set properly"; return 1;;
- esac
-}
-
-rc_runlevel()
-{
- rc-status --runlevel
-}
-
-_sanitize_path()
-{
- local IFS=":" p= path=
- for p in $PATH; do
- case "$p" in
- @LIBEXECDIR@/bin|@LIBEXECDIR@/sbin);;
- @BINDIR@|@SBINDIR@|/usr/bin|/usr/sbin);;
- @PKG_PREFIX@/bin|@PKG_PREFIX@/sbin);;
- @LOCAL_PREFIX@/bin|@LOCAL_PREFIX@/sbin);;
- *) path="$path${path:+:}$p";;
- esac
- done
- echo "$path"
-}
-
-# Allow our scripts to support zsh
-if [ -n "$ZSH_VERSION" ]; then
- emulate sh
- NULLCMD=:
- alias -g '${1+"$@"}'='"$@"'
- setopt NO_GLOB_SUBST
-fi
-
-# Make a sane PATH
-_PREFIX=@PREFIX@
-_PKG_PREFIX=@PKG_PREFIX@
-_LOCAL_PREFIX=@LOCAL_PREFIX@
-_LOCAL_PREFIX=${_LOCAL_PREFIX:-/usr/local}
-_PATH=@LIBEXECDIR@/bin
-case "$_PREFIX" in
- "$_PKG_PREFIX"|"$_LOCAL_PREFIX") ;;
- *) _PATH="$_PATH:$_PREFIX/bin:$_PREFIX/sbin";;
-esac
-_PATH="$_PATH":/bin:/sbin:/usr/bin:/usr/sbin
-
-if [ -n "$_PKG_PREFIX" ]; then
- _PATH="$_PATH:$_PKG_PREFIX/bin:$_PKG_PREFIX/sbin"
-fi
-if [ -n "$_LOCAL_PREFIX" ]; then
- _PATH="$_PATH:$_LOCAL_PREFIX/bin:$_LOCAL_PREFIX/sbin"
-fi
-_path="$(_sanitize_path "$PATH")"
-PATH="$_PATH${_path:+:}$_path" ; export PATH
-unset _sanitize_path _PREFIX _PKG_PREFIX _LOCAL_PREFIX _PATH _path
-
-for arg; do
- case "$arg" in
- --nocolor|--nocolour|-C)
- EINFO_COLOR="NO" ; export EINFO_COLOR
- ;;
- esac
-done
-
-if [ -t 1 ] && yesno "${EINFO_COLOR:-YES}"; then
- if [ -z "$GOOD" ]; then
- eval $(eval_ecolors)
- fi
-else
- # We need to have shell stub functions so our init scripts can remember
- # the last ecmd
- for _e in ebegin eend error errorn einfo einfon ewarn ewarnn ewend \
- vebegin veend veinfo vewarn vewend; do
- eval "$_e() { local _r; command $_e \"\$@\"; _r=\$?; \
- EINFO_LASTCMD=$_e; export EINFO_LASTCMD ; return \$_r; }"
- done
- unset _e
-fi
diff --git a/sh/gendepends.sh.in b/sh/gendepends.sh.in
deleted file mode 100644
index dfe7444b..00000000
--- a/sh/gendepends.sh.in
+++ /dev/null
@@ -1,92 +0,0 @@
-#!@SHELL@
-# Shell wrapper to list our dependencies
-
-# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
-# Released under the 2-clause BSD license.
-
-. @LIBEXECDIR@/sh/functions.sh
-. @LIBEXECDIR@/sh/rc-functions.sh
-
-config() {
- [ -n "$*" ] && echo "$RC_SVCNAME config $*" >&3
-}
-need() {
- [ -n "$*" ] && echo "$RC_SVCNAME ineed $*" >&3
-}
-use() {
- [ -n "$*" ] && echo "$RC_SVCNAME iuse $*" >&3
-}
-before() {
- [ -n "$*" ] && echo "$RC_SVCNAME ibefore $*" >&3
-}
-after() {
- [ -n "$*" ] && echo "$RC_SVCNAME iafter $*" >&3
-}
-provide() {
- [ -n "$*" ] && echo "$RC_SVCNAME iprovide $*" >&3
-}
-keyword() {
- [ -n "$*" ] && echo "$RC_SVCNAME keyword $*" >&3
-}
-depend() {
- :
-}
-
-_done_dirs=
-for _dir in \
-@SYSCONFDIR@/init.d \
-@PKG_PREFIX@/etc/init.d \
-@LOCAL_PREFIX@/etc/init.d
-do
- [ -d "$_dir" ] || continue
-
- # Don't do the same dir twice
- for _d in $_done_dirs; do
- [ "$_d" = "$_dir" ] && continue 2
- done
- unset _d
- _done_dirs="$_done_dirs $_dir"
-
- cd "$_dir"
- for RC_SERVICE in *; do
- [ -x "$RC_SERVICE" -a -f "$RC_SERVICE" ] || continue
-
- # Only generate dependencies for OpenRC scripts
- read one two three <"$RC_SERVICE"
- [ "$one" = "#!@SBINDIR@/runscript" ] || \
- [ "$one" = "#!@SBINDIR@/openrc-run" ] || \
- [ "$one" = "#!" -a "$two" = "@SBINDIR@/runscript" ] || \
- [ "$one" = "#!" -a "$two" = "@SBINDIR@/openrc-run" ] || \
- continue
- unset one two three
-
- RC_SVCNAME=${RC_SERVICE##*/} ; export RC_SVCNAME
-
- # Compat
- SVCNAME=$RC_SVCNAME ; export SVCNAME
-
- (
- # Save stdout in fd3, then remap it to stderr
- exec 3>&1 1>&2
-
- _rc_c=${RC_SVCNAME%%.*}
- if [ -n "$_rc_c" -a "$_rc_c" != "$RC_SVCNAME" ]; then
- if [ -e "$_dir/../conf.d/$_rc_c" ]; then
- . "$_dir/../conf.d/$_rc_c"
- fi
- fi
- unset _rc_c
-
- if [ -e "$_dir/../conf.d/$RC_SVCNAME" ]; then
- . "$_dir/../conf.d/$RC_SVCNAME"
- fi
-
- [ -e @SYSCONFDIR@/rc.conf ] && . @SYSCONFDIR@/rc.conf
-
- if . "$_dir/$RC_SVCNAME"; then
- echo "$RC_SVCNAME" >&3
- _depend
- fi
- )
- done
-done
diff --git a/sh/init-early.sh.Linux.in b/sh/init-early.sh.Linux.in
deleted file mode 100644
index a4116fc8..00000000
--- a/sh/init-early.sh.Linux.in
+++ /dev/null
@@ -1,50 +0,0 @@
-#!@SHELL@
-# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
-# Released under the 2-clause BSD license.
-
-: ${CONSOLE:=/dev/console}
-: ${RC_LIBEXECDIR:=@LIBEXECDIR@}
-
-service_present()
-{
- local p="@SYSCONFDIR@/runlevels/$1/$2"
- # fail if the file doesn't exist
- [ ! -e "$p" ] && return 1
- # succeed if $RC_SYS empty, can't check further, assume script will run
- [ -z "$RC_SYS" ] && return 0
- # fail if file contains "-$RC_SYS", because then it won't run
- egrep -qi "^[[:space:]]*keyword[[:space:]].*-$RC_SYS\>" "$p" && return 1
- # succeed otherwise
- return 0
-}
-
-if [ -e "$RC_LIBEXECDIR"/console/unicode ]; then
- termencoding="%G"
- kmode="-u"
-else
- termencoding="(K"
- kmode="-a"
-fi
-
-# Try and set a font and as early as we can
-if service_present "$RC_DEFAULTLEVEL" consolefont ||
- service_present "$RC_BOOTLEVEL" consolefont; then
- printf "\033%s" "$termencoding" >"$CONSOLE" 2>/dev/null
- if [ -r "$RC_LIBEXECDIR"/console/font ] && \
- command -v setfont > /dev/null 2>&1; then
- [ -c "$CONSOLE" ] && cons="-C $CONSOLE"
- setfont $cons "$RC_LIBEXECDIR"/console/font 2>/dev/null
- fi
-fi
-
-# Try and set a keyboard map as early as possible
-if service_present "$RC_DEFAULTLEVEL" keymaps ||
- service_present "$RC_BOOTLEVEL" keymaps; then
- kbd_mode $kmode -C "$CONSOLE" 2>/dev/null
- if [ -r "$RC_LIBEXECDIR"/console/keymap ]; then
- loadkeys -q "$RC_LIBEXECDIR"/console/keymap 2>/dev/null
- fi
-fi
-
-# Ensure we exit 0 so the boot continues
-exit 0
diff --git a/sh/init.sh.BSD.in b/sh/init.sh.BSD.in
deleted file mode 100644
index 2a53dcd8..00000000
--- a/sh/init.sh.BSD.in
+++ /dev/null
@@ -1,53 +0,0 @@
-#!@SHELL@
-# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
-# Released under the 2-clause BSD license.
-
-# This basically mounts $svcdir as a ramdisk, but preserving its content
-# which allows us to run depscan.sh
-# FreeBSD has a nice ramdisk - we don't set a size as we should always
-# be fairly small and we unmount them after the boot level is done anyway
-# NOTE we don't set a size for Linux either
-# FreeBSD-7 supports tmpfs now :)
-mount_svcdir()
-{
- if ! fstabinfo --mount "$RC_SVCDIR"; then
- if ! mount -t tmpfs -o rw,noexec,nosuid none \
- "$RC_SVCDIR" 2>/dev/null
- then
- mdconfig -a -t malloc -s "${rc_svcsize:-1024}"k -u 0
- newfs -b 4096 -i 1024 -n /dev/md0
- mount -o rw,noexec,nosuid /dev/md0 "$RC_SVCDIR"
- fi
- fi
-}
-
-. "$RC_LIBEXECDIR"/sh/functions.sh
-[ -r "@SYSCONFDIR@/rc.conf" ] && . "@SYSCONFDIR@/rc.conf"
-
-# Disable devd until we need it
-if [ -z "$RC_SYS" -a "$RC_UNAME" = "FreeBSD" ]; then
- sysctl hw.bus.devctl_disable=1 >/dev/null
-fi
-
-# mount $RC_SVCDIR as something we can write to if it's not rw
-# On vservers, / is always rw at this point, so we need to clean out
-# the old service state data
-: ${RC_LIBEXECDIR:=@LIBEXECDIR@}
-: ${RC_SVCDIR:=@LIBEXECDIR@/init.d}
-case "$(openrc --sys)" in
- OPENVZ|VSERVER) rm -rf "$RC_SVCDIR"/*;;
- *) if mountinfo --quiet "$RC_SVCDIR"; then
- rm -rf "$RC_SVCDIR"/*
- else
- mount_svcdir
- fi
- ;;
-esac
-retval=$?
-
-if [ -e "$RC_LIBEXECDIR"/cache/deptree ]; then
- cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
-fi
-
-echo sysinit >"$RC_SVCDIR"/softlevel
-exit $retval
diff --git a/sh/init.sh.GNU-kFreeBSD.in b/sh/init.sh.GNU-kFreeBSD.in
deleted file mode 100644
index d1a04e15..00000000
--- a/sh/init.sh.GNU-kFreeBSD.in
+++ /dev/null
@@ -1,35 +0,0 @@
-#!@SHELL@
-# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
-# Released under the 2-clause BSD license.
-
-if [ ! -d /run ]; then
- ebegin "Creating /run"
- mkdir -p /run
- eend $?
-fi
-
-if [ -L $RC_SVCDIR ]; then
- rm $RC_SVCDIR
-fi
-
-ebegin "Mounting /run"
-if ! fstabinfo --mount /run; then
- mount -t tmpfs -o mode=0755,noexec,nosuid,size=10% tmpfs /run
- if [ $? != 0 ]; then
- eerror "Unable to mount tmpfs on /run."
- eerror "Can't continue."
- exit 1
- fi
-fi
-eend
-
-ebegin "Creating $RC_SVCDIR"
-mkdir -p $RC_SVCDIR
-eend $?
-
-if [ -e "$RC_LIBEXECDIR"/cache/deptree ]; then
- cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
-fi
-
-echo sysinit >"$RC_SVCDIR"/softlevel
-exit 0
diff --git a/sh/init.sh.GNU.in b/sh/init.sh.GNU.in
deleted file mode 100644
index 5ba051d9..00000000
--- a/sh/init.sh.GNU.in
+++ /dev/null
@@ -1,38 +0,0 @@
-#!@SHELL@
-# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
-# Copyright (c) 2014 Svante Signell <svante.signell@gmail.com>
-# Released under the 2-clause BSD license.
-
-if [ ! -d /run ]; then
- ebegin "Creating /run"
- mkdir -p /run
- eend $?
-fi
-
-if [ -L $RC_SVCDIR ]; then
- rm $RC_SVCDIR
-fi
-
-if ! mountinfo -q /run; then
- ebegin "Mounting /run"
- if ! fstabinfo --mount /run; then
- mount -t tmpfs -o mode=0755,no-suid,size=10% tmpfs /run
- if [ $? != 0 ]; then
- eerror "Unable to mount tmpfs on /run."
- eerror "Can't continue."
- exit 1
- fi
- fi
- eend
-fi
-
-ebegin "Creating $RC_SVCDIR"
-mkdir -p $RC_SVCDIR
-eend $?
-
-if [ -e "$RC_LIBEXECDIR"/cache/deptree ]; then
- cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
-fi
-
-echo sysinit >"$RC_SVCDIR"/softlevel
-exit 0
diff --git a/sh/init.sh.Linux.in b/sh/init.sh.Linux.in
deleted file mode 100644
index a8ee69ea..00000000
--- a/sh/init.sh.Linux.in
+++ /dev/null
@@ -1,88 +0,0 @@
-#!@SHELL@
-# Copyright (c) 1999-2007 Gentoo Foundation
-# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
-# Released under the 2-clause BSD license.
-
-. "$RC_LIBEXECDIR"/sh/functions.sh
-[ -r "@SYSCONFDIR@/rc.conf" ] && . "@SYSCONFDIR@/rc.conf"
-
-# By default VServer already has /proc mounted, but OpenVZ does not!
-# However, some of our users have an old proc image in /proc
-# NFC how they managed that, but the end result means we have to test if
-# /proc actually works or not. We do this by comparing two reads of
-# /proc/self/environ for which we have set the variable VAR to two
-# different values. If the comparison comes back equal, we know that
-# /proc is not working.
-mountproc=true
-f=/proc/self/environ
-if [ -e $f ]; then
- if [ "$(VAR=a cat $f)" = "$(VAR=b cat $f)" ]; then
- eerror "You have cruft in /proc that should be deleted"
- else
- einfo "/proc is already mounted"
- mountproc=false
- fi
-fi
-unset f
-
-if $mountproc; then
- procfs="proc"
- [ "$RC_UNAME" = "GNU/kFreeBSD" ] && proc="linprocfs"
- ebegin "Mounting /proc"
- if ! fstabinfo --mount /proc; then
- mount -n -t "$procfs" -o noexec,nosuid,nodev proc /proc
- fi
- eend $?
-fi
-
-# /run is a new directory for storing volatile runtime data.
-# Read more about /run at https://lwn.net/Articles/436012
-sys="$(openrc --sys)"
-
-if [ ! -d /run ]; then
- if [ "$sys" = VSERVER ]; then
- if [ -e /run ]; then
- rm -rf /run
- fi
- mkdir /run
- else
- eerror "The /run directory does not exist. Unable to continue."
- return 1
- fi
-fi
-
-if [ "$sys" = VSERVER ]; then
- rm -rf /run/*
-elif ! mountinfo -q /run; then
- ebegin "Mounting /run"
- rc=0
- if ! fstabinfo --mount /run; then
- mount -t tmpfs -o mode=0755,nodev,size=10% tmpfs /run
- rc=$?
- fi
- if [ $rc != 0 ]; then
- eerror "Unable to mount tmpfs on /run."
- eerror "Can't continue."
- exit 1
- fi
-fi
-
-checkpath -d $RC_SVCDIR
-checkpath -d -m 0775 -o root:uucp /run/lock
-
-# Try to mount xenfs as early as possible, otherwise rc_sys() will always
-# return RC_SYS_XENU and will think that we are in a domU while it's not.
-if grep -Eq "[[:space:]]+xenfs$" /proc/filesystems; then
- ebegin "Mounting xenfs"
- if ! fstabinfo --mount /proc/xen; then
- mount -n -t xenfs xenfs /proc/xen -o nosuid,nodev,noexec
- fi
- eend $?
-fi
-
-if [ -e "$RC_LIBEXECDIR"/cache/deptree ]; then
- cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
-fi
-
-echo sysinit >"$RC_SVCDIR"/softlevel
-exit 0
diff --git a/sh/migrate-to-run.sh.in b/sh/migrate-to-run.sh.in
deleted file mode 100644
index 91f49fa9..00000000
--- a/sh/migrate-to-run.sh.in
+++ /dev/null
@@ -1,29 +0,0 @@
-#!@SHELL@
-# Copyright (c) 2012 William Hubbs <w.d.hubbs@gmail.com>
-# Released under the 2-clause BSD license.
-
-. "@LIBEXECDIR@/sh/functions.sh"
-
-if [ -e /run/openrc/softlevel ]; then
- einfo "The OpenRC dependency data has already been migrated."
- exit 0
-fi
-
-if [ ! -d /run ]; then
- eerror "/run is not a directory."
- eerror "moving /run to /run.pre-openrc"
- mv /run /run.pre-openrc
- mkdir /run
-fi
-
-rm -rf /run/openrc
-
-if ! mountinfo -q -f tmpfs /run; then
- ln -s "@LIBEXECDIR@"/init.d /run/openrc
-else
- cp -a "@LIBEXECDIR@/init.d" /run/openrc
- rc-update -u
-fi
-
-einfo "The OpenRC dependency data was migrated successfully."
-exit 0
diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
deleted file mode 100644
index b635340a..00000000
--- a/sh/rc-cgroup.sh.in
+++ /dev/null
@@ -1,134 +0,0 @@
-#!@SHELL@
-# Copyright (c) 2012 Alexander Vershilov <qnikst@gentoo.org>
-# Released under the 2-clause BSD license.
-extra_stopped_commands="${extra_stopped_commands} cgroup_cleanup"
-
-cgroup_find_path()
-{
- local OIFS n name dir result
- [ -n "$1" ] || return 0
- OIFS="$IFS"
- IFS=":"
- while read n name dir; do
- [ "$name" = "$1" ] && result="$dir"
- done < /proc/1/cgroup
- IFS="$OIFS"
- echo $result
-}
-
-cgroup_get_pids()
-{
- local p
- pids=
- while read p; do
- [ $p -eq $$ ] || pids="${pids} ${p}"
- done < /sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks
- [ -n "$pids" ]
-}
-
-cgroup_running()
-{
- [ -d "/sys/fs/cgroup/openrc/${RC_SVCNAME}" ]
-}
-
-cgroup_set_values()
-{
- [ -n "$1" -a -n "$2" -a -d "/sys/fs/cgroup/$1" ] || return 0
-
- local controller="$1" h=$(cgroup_find_path "$1")
- cgroup="/sys/fs/cgroup/${1}${h}openrc_${RC_SVCNAME}"
- [ -d "$cgroup" ] || mkdir -p "$cgroup"
-
- set -- $2
- local name val
- while [ -n "$1" -a "$controller" != "cpuacct" ]; do
- case "$1" in
- $controller.*)
- if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then
- veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
- echo $val > "$cgroup/$name"
- fi
- name=$1
- val=
- ;;
- *)
- val="$val $1"
- ;;
- esac
- shift
- done
- if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then
- veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
- echo $val > "$cgroup/$name"
- fi
-
- if [ -f "$cgroup/tasks" ]; then
- veinfo "$RC_SVCNAME: adding to $cgroup/tasks"
- echo 0 > "$cgroup/tasks"
- fi
-
- return 0
-}
-
-cgroup_add_service()
-{
- # relocate starting process to the top of the cgroup
- # it prevents from unwanted inheriting of the user
- # cgroups. But may lead to a problems where that inheriting
- # is needed.
- for d in /sys/fs/cgroup/* ; do
- [ -f "${d}"/tasks ] && echo 0 > "${d}"/tasks
- done
-
- openrc_cgroup=/sys/fs/cgroup/openrc
- if [ -d "$openrc_cgroup" ]; then
- cgroup="$openrc_cgroup/$RC_SVCNAME"
- mkdir -p "$cgroup"
- [ -f "$cgroup/tasks" ] && echo 0 > "$cgroup/tasks"
- fi
-}
-
-cgroup_set_limits()
-{
- local blkio="${rc_cgroup_blkio:-$RC_CGROUP_BLKIO}"
- [ -n "$blkio" ] && cgroup_set_values blkio "$blkio"
-
- local cpu="${rc_cgroup_cpu:-$RC_CGROUP_CPU}"
- [ -n "$cpu" ] && cgroup_set_values cpu "$cpu"
-
- local cpuacct="${rc_cgroup_cpuacct:-$RC_CGROUP_CPUACCT}"
- [ -n "$cpuacct" ] && cgroup_set_values cpuacct "$cpuacct"
-
- local cpuset="${rc_cgroup_cpuset:-$RC_CGROUP_cpuset}"
- [ -n "$cpuset" ] && cgroup_set_values cpuset "$cpuset"
-
- local devices="${rc_cgroup_devices:-$RC_CGROUP_DEVICES}"
- [ -n "$devices" ] && cgroup_set_values devices "$devices"
-
- local memory="${rc_cgroup_memory:-$RC_CGROUP_MEMORY}"
- [ -n "$memory" ] && cgroup_set_values memory "$memory"
-
- local net_prio="${rc_cgroup_net_prio:-$RC_CGROUP_NET_PRIO}"
- [ -n "$net_prio" ] && cgroup_set_values net_prio "$net_prio"
-
- return 0
-}
-
-cgroup_cleanup()
-{
- cgroup_running || return 0
- ebegin "starting cgroups cleanup"
- for sig in TERM QUIT INT; do
- cgroup_get_pids || { eend 0 "finished" ; return 0 ; }
- for i in 0 1; do
- kill -s $sig $pids
- for j in 0 1 2; do
- cgroup_get_pids || { eend 0 "finished" ; return 0 ; }
- sleep 1
- done
- done 2>/dev/null
- done
- cgroup_get_pids || { eend 0 "finished" ; return 0; }
- kill -9 $pids
- eend $(cgroup_running && echo 1 || echo 0) "fail to stop all processes"
-}
diff --git a/sh/rc-functions.sh.in b/sh/rc-functions.sh.in
deleted file mode 100644
index d52b82e1..00000000
--- a/sh/rc-functions.sh.in
+++ /dev/null
@@ -1,113 +0,0 @@
-# Copyright (c) 2007 Gentoo Foundation
-# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
-# Released under the 2-clause BSD license.
-
-has_addon()
-{
- [ -e /@LIB@/rc/addons/"$1".sh -o -e /@LIB@/rcscripts/addons/"$1".sh ]
-}
-
-_addon_warn()
-{
- eindent
- ewarn "$RC_SVCNAME uses addon code which is deprecated"
- ewarn "and may not be available in the future."
- eoutdent
-}
-
-import_addon()
-{
- if [ -e /@LIB@/rc/addons/"$1".sh ]; then
- _addon_warn
- . /@LIB@/rc/addons/"$1".sh
- elif [ -e /@LIB@/rcscripts/addons/"$1".sh ]; then
- _addon_warn
- . /@LIB@/rcscripts/addons/"$1".sh
- else
- return 1
- fi
-}
-
-start_addon()
-{
- ( import_addon "$1-start" )
-}
-
-stop_addon()
-{
- ( import_addon "$1-stop" )
-}
-
-net_fs_list="afs ceph cifs coda davfs fuse fuse.sshfs gfs glusterfs lustre
-ncpfs nfs nfs4 ocfs2 shfs smbfs"
-is_net_fs()
-{
- [ -z "$1" ] && return 1
-
- # Check OS specific flags to see if we're local or net mounted
- mountinfo --quiet --netdev "$1" && return 0
- mountinfo --quiet --nonetdev "$1" && return 1
-
- # Fall back on fs types
- local t=$(mountinfo --fstype "$1")
- for x in $net_fs_list $extra_net_fs_list; do
- [ "$x" = "$t" ] && return 0
- done
- return 1
-}
-
-is_union_fs()
-{
- [ ! -x /sbin/unionctl ] && return 1
- unionctl "$1" --list >/dev/null 2>&1
-}
-
-get_bootparam()
-{
- local match="$1"
- [ -z "$match" -o ! -r /proc/cmdline ] && return 1
-
- set -- $(cat /proc/cmdline)
- while [ -n "$1" ]; do
- [ "$1" = "$match" ] && return 0
- case "$1" in
- gentoo=*)
- local params="${1##*=}"
- local IFS=, x=
- for x in $params; do
- [ "$x" = "$match" ] && return 0
- done
- ;;
- esac
- shift
- done
-
- return 1
-}
-
-# Called from runscript.sh or gendepends.sh
-_depend() {
- depend
- local _rc_svcname=$(shell_var "$RC_SVCNAME") _deptype= _depends=
-
- # Add any user defined depends
- for _deptype in config:CONFIG need:NEED use:USE \
- after:AFTER before:BEFORE \
- provide:PROVIDE keyword:KEYWORD; do
- IFS=:
- set -- $_deptype
- unset IFS
- eval _depends=\$rc_${_rc_svcname}_$1
- [ -z "$_depends" ] && eval _depends=\$rc_$1
- [ -z "$_depends" ] && eval _depends=\$RC_${_rc_svcname}_$2
- [ -z "$_depends" ] && eval _depends=\$RC_$2
-
- $1 $_depends
- done
-}
-
-# Add our sbin to $PATH
-case "$PATH" in
- "$RC_LIBEXECDIR"/sbin|"$RC_LIBEXECDIR"/sbin:*);;
- *) PATH="$RC_LIBEXECDIR/sbin:$PATH" ; export PATH ;;
-esac
diff --git a/sh/rc-mount.sh b/sh/rc-mount.sh
deleted file mode 100644
index cd5d0f78..00000000
--- a/sh/rc-mount.sh
+++ /dev/null
@@ -1,80 +0,0 @@
-# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
-# Released under the 2-clause BSD license.
-
-# Declare this here so that no formatting doesn't affect the embedded newline
-__IFS="
-"
-
-# Handy function to handle all our unmounting needs
-# mountinfo is a C program to actually find our mounts on our supported OS's
-# We rely on fuser being present, so if it's not then don't unmount anything.
-# This isn't a real issue for the BSD's, but it is for Linux.
-do_unmount()
-{
- local cmd="$1" retval=0 retry= pids=-
- local f_opts="-m -c" f_kill="-s " mnt=
- if [ "$RC_UNAME" = "Linux" ]; then
- f_opts="-m"
- f_kill="-"
- fi
-
- shift
- local IFS="$__IFS"
- set -- $(mountinfo "$@")
- unset IFS
- for mnt; do
- # Unmounting a shared mount can unmount other mounts, so
- # we need to check the mount is still valid
- mountinfo --quiet "$mnt" || continue
- # Ensure we interpret all characters properly.
- mnt=$(printf "$mnt")
-
- case "$cmd" in
- umount)
- ebegin "Unmounting $mnt"
- ;;
- *)
- ebegin "Remounting $mnt read only"
- ;;
- esac
-
- retry=4 # Effectively TERM, sleep 1, TERM, sleep 1, KILL, sleep 1
- while ! LC_ALL=C $cmd "$mnt" 2>/dev/null; do
- if command -v fuser >/dev/null 2>&1; then
- pids="$(timeout -k 10 -s KILL "${rc_fuser_timeout:-60}" \
- fuser $f_opts "$mnt" 2>/dev/null)"
- fi
- case " $pids " in
- *" $$ "*)
- eend 1 "failed because we are using" \
- "$mnt"
- retry=0;;
- " - ")
- eend 1
- retry=0;;
- " ")
- eend 1 "in use but fuser finds nothing"
- retry=0;;
- *)
- if [ $retry -le 0 ]; then
- eend 1
- else
- local sig="TERM"
- : $(( retry -= 1 ))
- [ $retry = 1 ] && sig="KILL"
- fuser $f_kill$sig -k $f_opts \
- "$mnt" >/dev/null 2>&1
- sleep 1
- fi
- ;;
- esac
- [ $retry -le 0 ] && break
- done
- if [ $retry -le 0 ]; then
- retval=1
- else
- eend 0
- fi
- done
- return $retval
-}
diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
deleted file mode 100644
index 06d51d07..00000000
--- a/sh/runscript.sh.in
+++ /dev/null
@@ -1,351 +0,0 @@
-#!@SHELL@
-# Shell wrapper for runscript
-
-# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
-# Released under the 2-clause BSD license.
-
-verify_boot()
-{
- if [ ! -e ${RC_SVCDIR}/softlevel ]; then
- eerror "You are attempting to run an openrc service on a"
- eerror "system which openrc did not boot."
- eerror "You may be inside a chroot or you may have used"
- eerror "another initialization system to boot this system."
- eerror "In this situation, you will get unpredictable results!"
- eerror
- eerror "If you really want to do this, issue the following command:"
- eerror "touch ${RC_SVCDIR}/softlevel"
- exit 1
- fi
- return 0
-}
-
-sourcex()
-{
- if [ "$1" = "-e" ]; then
- shift
- [ -e "$1" ] || return 1
- fi
- if ! . "$1"; then
- eerror "$RC_SVCNAME: error loading $1"
- exit 1
- fi
-}
-
-sourcex "@LIBEXECDIR@/sh/functions.sh"
-sourcex "@LIBEXECDIR@/sh/rc-functions.sh"
-[ "$RC_SYS" != "PREFIX" ] && sourcex -e "@LIBEXECDIR@/sh/rc-cgroup.sh"
-
-# Support LiveCD foo
-if sourcex -e "/sbin/livecd-functions.sh"; then
- livecd_read_commandline
-fi
-
-if [ -z "$1" -o -z "$2" ]; then
- eerror "$RC_SVCNAME: not enough arguments"
- exit 1
-fi
-
-# So daemons know where to recall us if needed
-RC_SERVICE="$1" ; export RC_SERVICE
-shift
-
-# Compat
-SVCNAME=$RC_SVCNAME ; export SVCNAME
-
-# Dependency function
-config() {
- [ -n "$*" ] && echo "config $*"
-}
-need() {
- [ -n "$*" ] && echo "need $*"
-}
-use() {
- [ -n "$*" ] && echo "use $*"
-}
-before() {
- [ -n "$*" ] && echo "before $*"
-}
-after() {
- [ -n "$*" ] && echo "after $*"
-}
-provide() {
- [ -n "$*" ] && echo "provide $*"
-}
-keyword() {
- [ -n "$*" ] && echo "keyword $*"
-}
-
-# Describe the init script to the user
-describe()
-{
- if [ -n "$description" ]; then
- einfo "$description"
- else
- ewarn "No description for $RC_SVCNAME"
- fi
-
- local svc= desc=
- for svc in ${extra_commands:-$opts} $extra_started_commands \
- $extra_stopped_commands; do
- eval desc=\$description_$svc
- if [ -n "$desc" ]; then
- einfo "$HILITE$svc$NORMAL: $desc"
- else
- ewarn "$HILITE$svc$NORMAL: no description"
- fi
- done
-}
-
-# Report status
-_status()
-{
- if service_stopping; then
- ewarn "status: stopping"
- return 4
- elif service_starting; then
- ewarn "status: starting"
- return 8
- elif service_inactive; then
- ewarn "status: inactive"
- return 16
- elif service_started; then
- if service_crashed; then
- eerror "status: crashed"
- return 32
- fi
- einfo "status: started"
- return 0
- else
- einfo "status: stopped"
- return 3
- fi
-}
-
-# Template start / stop / status functions
-start()
-{
- [ -n "$command" ] || return 0
- local _background=
- ebegin "Starting ${name:-$RC_SVCNAME}"
- if yesno "${command_background}"; then
- if [ -z "${pidfile}" ]; then
- eend 1 "command_background option used but no pidfile specified"
- return 1
- fi
- _background="--background --make-pidfile"
- fi
- if yesno "$start_inactive"; then
- local _inactive=false
- service_inactive && _inactive=true
- mark_service_inactive
- fi
- eval start-stop-daemon --start \
- --exec $command \
- ${chroot:+--chroot} $chroot \
- ${procname:+--name} $procname \
- ${pidfile:+--pidfile} $pidfile \
- $_background $start_stop_daemon_args \
- -- $command_args
- if eend $? "Failed to start $RC_SVCNAME"; then
- service_set_value "command" "${command}"
- [ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
- [ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
- [ -n "${procname}" ] && service_set_value "procname" "${procname}"
- return 0
- fi
- if yesno "$start_inactive"; then
- if ! $_inactive; then
- mark_service_stopped
- fi
- fi
- return 1
-}
-
-stop()
-{
- local startcommand="$(service_get_value "command")"
- local startchroot="$(service_get_value "chroot")"
- local startpidfile="$(service_get_value "pidfile")"
- local startprocname="$(service_get_value "procname")"
- command="${startcommand:-$command}"
- chroot="${startchroot:-$chroot}"
- pidfile="${startpidfile:-$pidfile}"
- procname="${startprocname:-$procname}"
- [ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
- ebegin "Stopping ${name:-$RC_SVCNAME}"
- start-stop-daemon --stop \
- ${retry:+--retry} $retry \
- ${command:+--exec} $command \
- ${procname:+--name} $procname \
- ${pidfile:+--pidfile} $chroot$pidfile \
- ${stopsig:+--signal} $stopsig
- eend $? "Failed to stop $RC_SVCNAME"
-}
-
-status()
-{
- _status
-}
-
-yesno $RC_DEBUG && set -x
-if yesno "${rc_verbose:-$RC_VERBOSE}"; then
- EINFO_VERBOSE=yes
- export EINFO_VERBOSE
-fi
-
-_conf_d=${RC_SERVICE%/*}/../conf.d
-# If we're net.eth0 or openvpn.work then load net or openvpn config
-_c=${RC_SVCNAME%%.*}
-if [ -n "$_c" -a "$_c" != "$RC_SVCNAME" ]; then
- if ! sourcex -e "$_conf_d/$_c.$RC_RUNLEVEL"; then
- sourcex -e "$_conf_d/$_c"
- fi
-fi
-unset _c
-
-# Overlay with our specific config
-if ! sourcex -e "$_conf_d/$RC_SVCNAME.$RC_RUNLEVEL"; then
- sourcex -e "$_conf_d/$RC_SVCNAME"
-fi
-unset _conf_d
-
-# Load any system overrides
-sourcex -e "@SYSCONFDIR@/rc.conf"
-
-for _cmd; do
- if [ "$_cmd" != status -a "$_cmd" != describe ]; then
- # Apply any ulimit defined
- [ -n "${rc_ulimit:-$RC_ULIMIT}" ] && \
- ulimit ${rc_ulimit:-$RC_ULIMIT}
- # Apply cgroups settings if defined
- if [ "$(command -v cgroup_add_service)" = \
- "cgroup_add_service" ]
- then
- if [ -d /sys/fs/cgroup -a ! -w /sys/fs/cgroup ]; then
- eerror "No permission to apply cgroup settings"
- break
- fi
- cgroup_add_service /sys/fs/cgroup/openrc
- cgroup_add_service /sys/fs/cgroup/systemd/system
- fi
- [ "$(command -v cgroup_set_limits)" = \
- "cgroup_set_limits" ] && \
- cgroup_set_limits
- break
- fi
-done
-
-# Load our script
-sourcex "$RC_SERVICE"
-
-for _d in $required_dirs; do
- if [ ! -d $_d ]; then
- eerror "$RC_SVCNAME: \`$_d' is not a directory"
- exit 1
- fi
-done
-unset _d
-
-for _f in $required_files; do
- if [ ! -r $_f ]; then
- eerror "$RC_SVCNAME: \`$_f' is not readable"
- exit 1
- fi
-done
-unset _f
-
-if [ -n "$opts" ]; then
- ewarn "Use of the opts variable is deprecated and will be"
- ewarn "removed in the future."
- ewarn "Please use extra_commands, extra_started_commands or extra_stopped_commands."
-fi
-
-while [ -n "$1" ]; do
- # Special case depend
- if [ "$1" = depend ]; then
- shift
-
- # Enter the dir of the init script to fix the globbing
- # bug 412677
- cd ${RC_SERVICE%/*}
- _depend
- cd /
- continue
- fi
- # See if we have the required function and run it
- for _cmd in describe start stop status ${extra_commands:-$opts} \
- $extra_started_commands $extra_stopped_commands
- do
- if [ "$_cmd" = "$1" ]; then
- if [ "$(command -v "$1")" = "$1" ]; then
- # If we're in the background, we may wish to
- # fake some commands. We do this so we can
- # "start" ourselves from inactive which then
- # triggers other services to start which
- # depend on us.
- # A good example of this is openvpn.
- if yesno $IN_BACKGROUND; then
- for _cmd in $in_background_fake; do
- if [ "$_cmd" = "$1" ]; then
- shift
- continue 3
- fi
- done
- fi
- # Check to see if we need to be started before
- # we can run this command
- for _cmd in $extra_started_commands; do
- if [ "$_cmd" = "$1" ]; then
- if verify_boot && ! service_started; then
- eerror "$RC_SVCNAME: cannot \`$1' as it has not been started"
- exit 1
- fi
- fi
- done
- # Check to see if we need to be stopped before
- # we can run this command
- for _cmd in $extra_stopped_commands; do
- if [ "$_cmd" = "$1" ]; then
- if verify_boot && ! service_stopped; then
- eerror "$RC_SVCNAME: cannot \`$1' as it has not been stopped"
- exit 1
- fi
- fi
- done
- unset _cmd
- case $1 in
- start|stop|status) verify_boot;;
- esac
- if [ "$(command -v "$1_pre")" = "$1_pre" ]
- then
- "$1"_pre || exit $?
- fi
- "$1" || exit $?
- if [ "$(command -v "$1_post")" = "$1_post" ]
- then
- "$1"_post || exit $?
- fi
- [ "$(command -v cgroup_cleanup)" = "cgroup_cleanup" -a \
- "$1" = "stop" ] && \
- yesno "${rc_cgroup_cleanup}" && \
- cgroup_cleanup
- shift
- continue 2
- else
- if [ "$_cmd" = "start" -o "$_cmd" = "stop" ]
- then
- shift
- continue 2
- else
- eerror "$RC_SVCNAME: function \`$1' defined but does not exist"
- exit 1
- fi
- fi
- fi
- done
- eerror "$RC_SVCNAME: unknown function \`$1'"
- exit 1
-done
-
-exit 0
diff --git a/sh/runtests.sh b/sh/runtests.sh
deleted file mode 100755
index f083ff46..00000000
--- a/sh/runtests.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/sh
-
-: ${top_srcdir:=..}
-. $top_srcdir/test/setup_env.sh
-
-ret=0
-
-tret=0
-ebegin "Testing yesno()"
-for f in yes YES Yes true TRUE True 1 ; do
- if ! yesno $f; then
- : $(( tret += 1 ))
- echo "!$f!"
- fi
-done
-for f in no NO No false FALSE False 0 ; do
- if yesno $f; then
- : $(( tret += 1 ))
- echo "!$f!"
- fi
-done
-eend $tret
-: $(( ret += $tret ))
-
-exit $ret
diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
deleted file mode 100755
index 6e7be420..00000000
--- a/sh/tmpfiles.sh.in
+++ /dev/null
@@ -1,378 +0,0 @@
-#!/bin/sh
-# This is a reimplementation of the systemd tmpfiles.d code
-# Control creation, deletion, and cleaning of volatile and temporary files
-#
-# Copyright (c) 2012 Gentoo Foundation
-# Released under the 2-clause BSD license.
-#
-# This instance is a pure-POSIX sh version, written by Robin H Johnson
-# <robbat2@gentoo.org>, based on the Arch Linux version as of 2012/01/01:
-# http://projects.archlinux.org/initscripts.git/tree/arch-tmpfiles
-#
-# See the tmpfiles.d manpage as well:
-# http://0pointer.de/public/systemd-man/tmpfiles.d.html
-# This script should match the manpage as of 2012/03/12
-#
-
-DRYRUN=0
-CHECKPATH="@LIBEXECDIR@/bin/checkpath"
-
-checkprefix() {
- n=$1
- shift
- for x in $@; do
- case $n in
- ${x}*) return 0 ;;
- esac
- done
- return 1
-}
-
-warninvalid() {
- printf "tmpfiles: ignoring invalid entry on line %d of \`%s'\n" "$LINENUM" "$FILE"
- error=$(( error+1 ))
-} >&2
-
-dryrun_or_real() {
- local dryrun=
- [ $DRYRUN -eq 1 ] && dryrun=echo
- $dryrun "$@"
-}
-
-relabel() {
- local path
- local paths=$1 mode=$2 uid=$3 gid=$4
-
- for path in ${paths}; do
- if [ -e "$path" ]; then
- [ -x /sbin/restorecon ] && dryrun_or_real restorecon $CHOPTS "$path"
- [ $uid != '-' ] && dryrun_or_real chown $CHOPTS "$uid" "$path"
- [ $gid != '-' ] && dryrun_or_real chgrp $CHOPTS "$gid" "$path"
- [ $mode != '-' ] && dryrun_or_real chmod $CHOPTS "$mode" "$path"
- fi
- done
-}
-
-_restorecon() {
- local path=$1
- if [ -x /sbin/restorecon ]; then
- dryrun_or_real restorecon -F "$path"
- fi
-}
-
-_b() {
- # Create a block device node if it doesn't exist yet
- local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
- if [ ! -e "$path" ]; then
- dryrun_or_real mknod -m $mode $path b ${arg%:*} ${arg#*:}
- _restorecon "$path"
- dryrun_or_real chown $uid:$gid $path
- fi
-}
-
-_c() {
- # Create a character device node if it doesn't exist yet
- local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
- if [ ! -e "$path" ]; then
- dryrun_or_real mknod -m $mode $path c ${arg%:*} ${arg#*:}
- _restorecon "$path"
- dryrun_or_real chown $uid:$gid $path
- fi
-}
-
-_C() {
- # recursively copy a file or directory
- local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
- if [ ! -e "$path" ]; then
- dryrun_or_real cp -r "$arg" "$path"
- _restorecon "$path"
- [ $uid != '-' ] && dryrun_or_real chown "$uid" "$path"
- [ $gid != '-' ] && dryrun_or_real chgrp "$gid" "$path"
- [ $mode != '-' ] && dryrun_or_real chmod "$mode" "$path"
- fi
-}
-
-_f() {
- # Create a file if it doesn't exist yet
- local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
-
- [ $CREATE -gt 0 ] || return 0
-
- if [ ! -e "$path" ]; then
- dryrun_or_real $CHECKPATH -fq -m "$mode" -o "$uid:$gid" "$path"
- [ -z "$arg" ] || _w "$@"
- fi
-}
-
-_F() {
- # Create or truncate a file
- local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
-
- [ $CREATE -gt 0 ] || return 0
-
- dryrun_or_real $CHECKPATH -Fq -m "$mode" -o "$uid:$gid" "$path"
- [ -z "$arg" ] || _w "$@"
-}
-
-_d() {
- # Create a directory if it doesn't exist yet
- local path=$1 mode=$2 uid=$3 gid=$4
-
- [ $CREATE -gt 0 ] || return 0
-
- if [ ! -d "$path" ]; then
- dryrun_or_real mkdir -p "$path" 2>/dev/null
- dryrun_or_real $CHECKPATH -dq -m "$mode" -o "$uid:$gid" "$path"
- fi
-}
-
-_D() {
- # Create or empty a directory
- local path=$1 mode=$2 uid=$3 gid=$4
-
- if [ -d "$path" ] && [ $REMOVE -gt 0 ]; then
- dryrun_or_real find "$path" -mindepth 1 -maxdepth 1 -xdev -exec rm -rf {} +
- _restorecon "$path"
- fi
-
- if [ $CREATE -gt 0 ]; then
- dryrun_or_real mkdir -p "$path" 2>/dev/null
- dryrun_or_real $CHECKPATH -Dq -m "$mode" -o "$uid:$gid" "$path"
- fi
-}
-
-_L() {
- # Create a symlink if it doesn't exist yet
- local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
- [ ! -e "$path" ] && dryrun_or_real ln -s "$arg" "$path"
- _restorecon "$path"
-}
-
-_p() {
- # Create a named pipe (FIFO) if it doesn't exist yet
- local path=$1 mode=$2 uid=$3 gid=$4
-
- [ $CREATE -gt 0 ] || return 0
-
- if [ ! -p "$path" ]; then
- dryrun_or_real $CHECKPATH -pq -m $mode -o "$uid:$gid" "$path"
- fi
-}
-
-_x() {
- # Ignore a path during cleaning. Use this type to exclude paths from clean-up as
- # controlled with the Age parameter. Note that lines of this type do not
- # influence the effect of r or R lines. Lines of this type accept shell-style
- # globs in place of of normal path names.
- :
- # XXX: we don't implement this
-}
-
-_X() {
- # Ignore a path during cleanup. Use this type to prevent path
- # removal as controled with the age parameter. Note that if path is
- # a directory, the content of the directory is not excluded from
- # clean-up, only the directory itself.
- # Lines of this type accept shell-style globs in place of normal path names.
- :
- # XXX: we don't implement this
-}
-
-_r() {
- # Remove a file or directory if it exists. This may not be used to remove
- # non-empty directories, use R for that. Lines of this type accept shell-style
- # globs in place of normal path names.
- local path
- local paths=$1
-
- [ $REMOVE -gt 0 ] || return 0
-
- for path in ${paths}; do
- if [ -f "$path" ]; then
- dryrun_or_real rm -f "$path"
- elif [ -d "$path" ]; then
- dryrun_or_real rmdir "$path"
- fi
- done
-}
-
-_R() {
- # Recursively remove a path and all its subdirectories (if it is a directory).
- # Lines of this type accept shell-style globs in place of normal path names.
- local path
- local paths=$1
-
- [ $REMOVE -gt 0 ] || return 0
-
- for path in ${paths}; do
- [ -d "$path" ] && dryrun_or_real rm -rf --one-file-system "$path"
- done
-}
-
-_w() {
- # Write the argument parameter to a file, if it exists.
- local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
- if [ -f "$path" ]; then
- if [ $DRYRUN -eq 1 ]; then
- echo "echo \"$arg\" >>\"$path\""
- else
- echo "$arg" >>"$path"
- fi
- fi
-}
-
-_z() {
- # Set ownership, access mode and relabel security context of a file or
- # directory if it exists. Lines of this type accept shell-style globs in
- # place of normal path names.
- [ $CREATE -gt 0 ] || return 0
-
- relabel "$@"
-}
-
-_Z() {
- # Recursively set ownership, access mode and relabel security context of a
- # path and all its subdirectories (if it is a directory). Lines of this type
- # accept shell-style globs in place of normal path names.
- [ $CREATE -gt 0 ] || return 0
-
- CHOPTS=-R relabel "$@"
-}
-
-BOOT=0 CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
-EXCLUDE=
-PREFIX=
-FILE=
-fragments=
-# XXX: The harcoding of /usr/lib/ is an explicit choice by upstream
-tmpfiles_dirs='/usr/lib/tmpfiles.d/ /etc/tmpfiles.d/ /run/tmpfiles.d/'
-tmpfiles_basenames=''
-tmpfiles_d=''
-# Build a list of sorted unique basenames
-# directories declared later in the tmpfiles_d array will override earlier
-# directories, on a per file basename basis.
-# `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'.
-# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
-for d in ${tmpfiles_dirs} ; do
- [ -d $d ] && for f in ${d}/*.conf ; do
- case "${f##*/}" in
- systemd.conf|systemd-*.conf) continue;;
- esac
- [ -f $f ] && tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
- done # for f in ${d}
-done # for d in ${tmpfiles_dirs}
-tmpfiles_basenames="$(printf "${tmpfiles_basenames}\n" | sort -u )"
-
-for b in $tmpfiles_basenames ; do
- real_f=''
- for d in $tmpfiles_dirs ; do
- f=${d}/${b}
- [ -f "${f}" ] && real_f=$f
- done
- [ -f "${real_f}" ] && tmpfiles_d="${tmpfiles_d} ${real_f}"
-done
-
-while [ $# -gt 0 ]; do
- case $1 in
- --boot) BOOT=1 ;;
- --create) CREATE=1 ;;
- --remove) REMOVE=1 ;;
- --clean) CLEAN=1 ;; # TODO: Not implemented
- --verbose) VERBOSE=1 ;;
- --dryrun|--dry-run) DRYRUN=1 ;;
- --exclude-prefix=*) EXCLUDE="${EXCLUDE}${1##--exclude-prefix=} " ;;
- --prefix=*) PREFIX="${PREFIX}${1##--prefix=} " ;;
- esac
- shift
-done
-
-if [ $(( CLEAN )) -eq 1 ] ; then
- printf '%s clean mode is not implemented\n' "${0##*/}"
- exit 1
-fi
-
-if [ "$CREATE$REMOVE" = '00' ]; then
- printf 'usage: %s [--exclude-prefix=path] [--prefix=path] [--boot] [--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}"
- exit 1
-fi
-
-error=0
-
-# loop through the gathered fragments, sorted globally by filename.
-# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
-for FILE in $tmpfiles_d ; do
- LINENUM=0
-
- ### FILE FORMAT ###
- # XXX: We ignore the 'Age' parameter
- # 1 2 3 4 5 6 7
- # Cmd Path Mode UID GID Age Argument
- # d /run/user 0755 root root 10d -
- # Mode, UID, GID, Age, Argument may be omitted!
- # If Cmd ends with !, the line is only processed if --boot is passed
-
- # XXX: Upstream says whitespace is NOT permitted in the Path argument.
- # But IS allowed when globs are expanded for the x/r/R/z/Z types.
- while read cmd path mode uid gid age arg; do
- LINENUM=$(( LINENUM+1 ))
- FORCE=0
-
- # Unless we have both command and path, skip this line.
- if [ -z "$cmd" -o -z "$path" ]; then
- continue
- fi
-
- case $cmd in
- \#*) continue ;;
- esac
-
- while [ ${#cmd} -gt 1 ]; do
- case $cmd in
- *!) cmd=${cmd%!}; [ "$BOOT" -eq "1" ] || continue 2 ;;
- *+) cmd=${cmd%+}; FORCE=1; ;;
- *) warninvalid ; continue 2 ;;
- esac
- done
-
- # whine about invalid entries
- case $cmd in
- f|F|w|d|D|p|L|c|C|b|x|X|r|R|z|Z) ;;
- *) warninvalid ; continue ;;
- esac
-
- # fall back on defaults when parameters are passed as '-'
- if [ "$mode" = '-' -o "$mode" = '' ]; then
- case "$cmd" in
- p|f|F) mode=0644 ;;
- d|D) mode=0755 ;;
- C|z|Z|x|r|R|L) ;;
- esac
- fi
-
- [ "$uid" = '-' -o "$uid" = '' ] && uid=0
- [ "$gid" = '-' -o "$gid" = '' ] && gid=0
- [ "$age" = '-' -o "$age" = '' ] && age=0
- [ "$arg" = '-' -o "$arg" = '' ] && arg=''
- set -- "$path" "$mode" "$uid" "$gid" "$age" "$arg"
-
- [ -n "$EXCLUDE" ] && checkprefix $path $EXCLUDE && continue
- [ -n "$PREFIX" ] && ! checkprefix $path $PREFIX && continue
-
- if [ $FORCE -gt 0 ]; then
- case $cmd in
- p|L|c|b) [ -f "$path" ] && dryrun_or_real rm -f "$path"
- esac
- fi
-
- [ "$VERBOSE" -eq "1" ] && echo _$cmd "$@"
- _$cmd "$@"
- rc=$?
- if [ "${DRYRUN}" -eq "0" ]; then
- [ $rc -ne 0 ] && error=$((error + 1))
- fi
- done <$FILE
-done
-
-exit $error
-
-# vim: set ts=2 sw=2 sts=2 noet ft=sh: