Skip to content

Commit

Permalink
feat(dracut.sh): support multiple config dirs
Browse files Browse the repository at this point in the history
Configuration can come from many places, users should not be restricted
to keep all configuration files in one directory.

Signed-off-by: Shreenidhi Shedi <[email protected]>
  • Loading branch information
sshedi committed Mar 8, 2023
1 parent e9b4774 commit d5491c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
30 changes: 19 additions & 11 deletions dracut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ Creates initial ramdisk images for preloading modules
-q, --quiet Decrease verbosity level.
-c, --conf [FILE] Specify configuration file to use.
Default: /etc/dracut.conf
--confdir [DIR] Specify configuration directory to use *.conf files
from. Default: /etc/dracut.conf.d
--confdir [LIST] Specify a space separated list of configuration
directories to use *.conf files from.
Default: /etc/dracut.conf.d
--tmpdir [DIR] Temporary directory to be used instead of default
${TMPDIR:-/var/tmp}.
-r, --sysroot [DIR] Specify sysroot directory to collect files from.
Expand Down Expand Up @@ -668,7 +669,7 @@ while :; do
shift
;;
--confdir)
confdir="$2"
confdirs_l=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
Expand Down Expand Up @@ -911,15 +912,21 @@ elif [[ ! -e $conffile ]]; then
exit 1
fi

if [[ -z $confdir ]]; then
if [ ${#confdirs_l[@]} -eq 0 ]; then
if [[ $allowlocal ]]; then
confdir="$dracutbasedir/dracut.conf.d"
confdirs="$dracutbasedir/dracut.conf.d"
else
confdir="$dracutsysrootdir/etc/dracut.conf.d"
confdirs="$dracutsysrootdir/etc/dracut.conf.d"
fi
elif [[ ! -d $confdir ]]; then
printf "%s\n" "dracut[F]: Configuration directory '$confdir' not found." >&2
exit 1
else
# shellcheck disable=SC2068
for d in ${confdirs_l[@]}; do
if [[ ! -d $d ]]; then
printf "%s\n" "dracut[F]: Configuration directory '$d' not found." >&2
exit 1
fi
confdirs+=" $d"
done
fi

# source our config file
Expand All @@ -929,8 +936,9 @@ if [[ -f $conffile ]]; then
. "$conffile"
fi

# source our config dir
for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
# source config files from all config dirs
# shellcheck disable=SC2086
for f in $(dropindirs_sort ".conf" $confdirs "$dracutbasedir/dracut.conf.d"); do
check_conf_file "$f"
# shellcheck disable=SC1090
[[ -e $f ]] && . "$f"
Expand Down
4 changes: 2 additions & 2 deletions man/dracut.8.asc
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ example:
Default:
_/etc/dracut.conf_
**--confdir** _<configuration directory>_::
Specify configuration directory to use.
**--confdir** _<list of dracut configuration directories>_::
Specify a space-separated list of dracut configuration directories to use.
+
Default:
_/etc/dracut.conf.d_
Expand Down

0 comments on commit d5491c9

Please sign in to comment.