aboutsummaryrefslogtreecommitdiff
path: root/sh/gendepends.sh.in
diff options
context:
space:
mode:
authorAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-07-19 15:41:44 +0200
committerAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-07-20 03:19:56 +0200
commit0eebf94c0d6d53d2199163a4c81232591b65da3c (patch)
tree1738e35b7806c81aea37be51cd6b33639508af12 /sh/gendepends.sh.in
parenteb4eac88ebbbae5bf4bc3457b465ed537e6fe917 (diff)
librc-depend.c: dynamically generate services for multiplexed services.dynamic-deptree
when generating back references, attempt to instantiate missing services. Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
Diffstat (limited to 'sh/gendepends.sh.in')
-rw-r--r--sh/gendepends.sh.in180
1 files changed, 102 insertions, 78 deletions
diff --git a/sh/gendepends.sh.in b/sh/gendepends.sh.in
index 8ce1c87f..85fb48c1 100644
--- a/sh/gendepends.sh.in
+++ b/sh/gendepends.sh.in
@@ -53,88 +53,112 @@ depend() {
:
}
-_dirs="
- @SYSCONFDIR@/init.d
- @PKG_PREFIX@/etc/init.d
- @LOCAL_PREFIX@/etc/init.d
-"
+gendepend() {
+ RC_SERVICE="$1"
+ [ -x "$RC_SERVICE" -a -f "$RC_SERVICE" ] || continue
+
+ # Only generate dependencies for OpenRC scripts
+ read one two three <"$RC_SERVICE"
+ case "$one" in
+ \#*/openrc-run) ;;
+ \#*/runscript) ;;
+ \#!)
+ case "$two" in
+ */openrc-run) ;;
+ */runscript) ;;
+ *)
+ continue
+ ;;
+ esac
+ ;;
+ *)
+ continue
+ ;;
+ esac
+ 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%%.*}
+ _conf_d="${RC_SYSCONF_DIR}/conf.d"
+ if [ -n "$_rc_c" -a "$_rc_c" != "$RC_SVCNAME" ]; then
+ if [ -e "$_conf_d/$_rc_c" ]; then
+ . "$_conf_d/$_rc_c"
+ fi
+ fi
+ unset _rc_c
+
+ if [ -e "$_conf_d/$RC_SVCNAME" ]; then
+ . "$_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 . "$RC_SERVICE"; then
+ echo "$RC_SVCNAME" >&3
+ _depend
+ fi
+ )
+}
-if yesno "$RC_USER_SERVICES"; then
+do_all() {
_dirs="
- @SYSCONFDIR@/user.d/init.d
- ${XDG_CONFIG_HOME:-${HOME}/.config}/openrc/init.d
+ @SYSCONFDIR@/init.d
+ @PKG_PREFIX@/etc/init.d
+ @LOCAL_PREFIX@/etc/init.d
"
-fi
-_done_dirs=
-for _dir in ${_dirs}
-do
- [ -d "$_dir" ] || continue
-
- # Don't do the same dir twice
- for _d in $_done_dirs; do
- [ "$_d" = "$_dir" ] && continue 2
+ if yesno "$RC_USER_SERVICES"; then
+ _dirs="
+ @SYSCONFDIR@/user.d/init.d
+ ${XDG_CONFIG_HOME:-${HOME}/.config}/openrc/init.d
+ "
+ fi
+
+ _done_dirs=
+ for _dir in ${_dirs}
+ 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"
+ RC_SYSCONF_DIR="$_dir"
+ for _service in *; do
+ gendepend "$_dir/$_service"
+ done
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"
- case "$one" in
- \#*/openrc-run) ;;
- \#*/runscript) ;;
- \#!)
- case "$two" in
- */openrc-run) ;;
- */runscript) ;;
- *)
- continue
- ;;
- esac
- ;;
- *)
- continue
- ;;
- esac
- 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
+ unset _dirs
+}
- if . "$_dir/$RC_SVCNAME"; then
- echo "$RC_SVCNAME" >&3
- _depend
- fi
- )
+do_svcs() {
+ for _service in $@; do
+ RC_SYSCONF_DIR="$(dirname $(realpath "$_service"))/.."
+ [ -d "${RC_SYSCONF_DIR}" ] || return 1
+ cd "${RC_SYSCONF_DIR}" || return 1
+ gendepend "$_service"
done
-done
-unset _dirs
+}
+
+if [ $# -gt 0 ]; then
+ do_svcs $@
+else
+ do_all
+fi