openrc/sh/gendepends.sh.in
William Hubbs cc9c23c848 Complete support for rc.conf.d
- gendepends.sh needs to read this directory to allow dependencies to be
  overridden
  - init.sh for Linux and Bsd need to read it to allow config settings
    they use to be overridden.
2015-12-09 12:38:10 -06:00

112 lines
2.3 KiB
Bash

#!@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
}
want() {
[ -n "$*" ] && echo "$RC_SVCNAME iwant $*" >&3
}
before() {
[ -n "$*" ] && echo "$RC_SVCNAME ibefore $*" >&3
}
after() {
[ -n "$*" ] && echo "$RC_SVCNAME iafter $*" >&3
}
provide() {
[ -n "$*" ] && echo "$RC_SVCNAME iprovide $*" >&3
}
keyword() {
local c x
set -- $*
while [ -n "$*" ]; do
case "$1" in
-containers) x="$(_get_containers)" ;;
!-containers) x="$(_get_containers_remove)" ;;
*) x=$1 ;;
esac
c="${c}${x} "
shift
done
[ -n "$c" ] && echo "$RC_SVCNAME keyword $c" >&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 [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
[ -e "$_f" ] && . "$_f"
done
fi
if . "$_dir/$RC_SVCNAME"; then
echo "$RC_SVCNAME" >&3
_depend
fi
)
done
done