Skip to content

Commit

Permalink
librc-depend: Split deptree generation into three functions
Browse files Browse the repository at this point in the history
rc_deptree_generate does the generation of the deptree,
rc_deptree_backref does back references and sanity checks, lastly
rc_deptree_save write it to disk.
  • Loading branch information
navi-desu committed Oct 26, 2024
1 parent 9fc02ee commit c09cdd4
Show file tree
Hide file tree
Showing 2 changed files with 307 additions and 235 deletions.
123 changes: 67 additions & 56 deletions sh/gendepends.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,71 @@ keyword() {
depend() {
:
}
gendepend() {
[ -x "$RC_SERVICE" -a -f "$RC_SERVICE" ] || return

# Only generate dependencies for OpenRC scripts
read one two three <"$RC_SERVICE"
case "$one" in
\#*/openrc-run) ;;
\#*/runscript) ;;
\#!)
case "$two" in
*/openrc-run) ;;
*/runscript) ;;
*)
return
;;
esac
;;
*)
return
;;
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

if . "$RC_SERVICE"; then
echo "$RC_SVCNAME" >&3
_depend
fi
)
}

if [ $# -gt 0 ]; then
_dir="$RC_SCRIPTDIR"
cd "$_dir"
for RC_SERVICE in "$@"; do
gendepend
done
fi

_done_dirs=
for _dir in $RC_SCRIPTDIRS
Expand All @@ -67,61 +132,7 @@ do
_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

if . "$_dir/$RC_SVCNAME"; then
echo "$RC_SVCNAME" >&3
_depend
fi
)
for RC_SERVICE in "$_dir"/*; do
gendepend
done
done
Loading

0 comments on commit c09cdd4

Please sign in to comment.