diff options
author | Dave Reisner <dreisner@archlinux.org> | 2017-03-18 19:14:36 +0100 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2017-03-19 20:14:47 +0100 |
commit | c5ad00c2e565eaae8e8b02b92d7f193852008c80 (patch) | |
tree | 18493daa87e45e9f75a35699015917b8440a536c | |
parent | 91b212551a5066bda4eb76c83bdd9c0d0ac8e6cc (diff) | |
download | mkinitcpio-c5ad00c2e565eaae8e8b02b92d7f193852008c80.tar.gz mkinitcpio-c5ad00c2e565eaae8e8b02b92d7f193852008c80.tar.xz |
arrayize config vars in mkinitcpio.conf
allows for backwards compat by detecting and converting old-style
string-based configs.
-rw-r--r-- | functions | 23 | ||||
-rw-r--r-- | man/mkinitcpio.conf.5.txt | 20 | ||||
-rwxr-xr-x | mkinitcpio | 10 | ||||
-rw-r--r-- | mkinitcpio.conf | 22 |
4 files changed, 42 insertions, 33 deletions
@@ -198,6 +198,16 @@ map() { return $r } +arrayize_config() { + set -f + [[ ${MODULES@a} != *a* ]] && MODULES=($MODULES) + [[ ${BINARIES@a} != *a* ]] && BINARIES=($BINARIES) + [[ ${FILES@a} != *a* ]] && FILES=($FILES) + [[ ${HOOKS@a} != *a* ]] && HOOKS=($HOOKS) + [[ ${COMPRESSION_OPTIONS@a} != *a* ]] && COMPRESSION_OPTIONS=($COMPRESSION_OPTIONS) + set +f +} + in_array() { # Search for an element in an array. # $1: needle @@ -608,18 +618,15 @@ add_binary() { parse_config() { # parse key global variables set by the config file. - set -f - map add_module $MODULES - map add_binary $BINARIES - map add_file $FILES - set +f + map add_module "${MODULES[@]}" + map add_binary "${BINARIES[@]}" + map add_file "${FILES[@]}" tee "$BUILDROOT/buildconfig" < "$1" | { . /dev/stdin - # sanitize of any extra whitespace - read -ra modules <<<"${MODULES//-/_}" for mod in "${modules[@]%\?}"; do + mod=${mod//-/_} # only add real modules (2 == builtin) (( _addedmodules["$mod"] == 1 )) && add+=("$mod") done @@ -688,7 +695,7 @@ initialize_buildroot() { run_build_hook() { local hook=$1 script= realscript= - local MODULES= BINARIES= FILES= SCRIPT= + local MODULES=() BINARIES=() FILES=() SCRIPT= # find script in install dirs if ! script=$(PATH=$_d_install type -P "$hook"); then diff --git a/man/mkinitcpio.conf.5.txt b/man/mkinitcpio.conf.5.txt index da8f2ae..d272852 100644 --- a/man/mkinitcpio.conf.5.txt +++ b/man/mkinitcpio.conf.5.txt @@ -22,21 +22,21 @@ Variables --------- *MODULES*:: - Defines additional modules, space delimited, which should be added to the - image. Dependencies (including other modules and necessary firmware), will - also be added to the image. At runtime, the modules in this array which - were successfully added to the image will be explicitly loaded. + Defines an array of additional modules which should be added to the image. + Dependencies (including other modules and necessary firmware), will also be + added to the image. At runtime, the modules in this array which were + successfully added to the image will be explicitly loaded. *FILES*:: - Defines additional files, space delimited, which should be added to the image. + Defines an array of additional files which should be added to the image. Files are added as is, and parent directories will be added if needed. Files specified in this variable will override previously added files of the same path. *BINARIES*:: - Defines additional binaries, space delimited, which should be added to the + Defines an array of additional binaries which should be added to the image. These are assumed to be dynamic ELF binaries, and necessary shared library dependencies will automatically be added. However, it is not considered an error to specify a non-ELF binary in this variable. Parent @@ -45,7 +45,7 @@ Variables *HOOKS*:: - This variable defines the hooks which will be run during the build process. + Defines an array of hooks which will be run during the build process. Order is important, as it defines the order in which hooks will be run during bootup. Use mkinitcpio's '-L' flag to list all available hooks, and the '-H' flag to display the help text for a specific hook. @@ -65,9 +65,9 @@ despite being "valid". *COMPRESSION_OPTIONS*:: - Defines additional options to be passed to the compression program. This option - is generally not used. It can be potentially dangerous and may cause - invalid images to be generated without any sign of an error. + Defines an array of additional options to be passed to the compression + program. This option is generally not used. It can be potentially dangerous + and may cause invalid images to be generated without any sign of an error. See Also -------- @@ -193,7 +193,7 @@ hook_list() { compute_hookset() { local h - for h in $HOOKS "${_optaddhooks[@]}"; do + for h in "${HOOKS[@]}" "${_optaddhooks[@]}"; do in_array "$h" "${_optskiphooks[@]}" && continue _hooks+=("$h") done @@ -214,10 +214,10 @@ build_image() { unset COMPRESSION_OPTIONS ;; xz) - COMPRESSION_OPTIONS+=' --check=crc32' + COMPRESSION_OPTIONS+=(--check=crc32) ;; lz4) - COMPRESSION_OPTIONS+=' -l' + COMPRESSION_OPTIONS+=(-l) ;; esac @@ -231,7 +231,7 @@ build_image() { pushd "$BUILDROOT" >/dev/null find -mindepth 1 -printf '%P\0' | LANG=C bsdcpio "${cpio_opts[@]}" | - $compress $COMPRESSION_OPTIONS > "$out" + $compress "${COMPRESSION_OPTIONS[@]}" > "$out" pipesave=("${PIPESTATUS[@]}") # save immediately popd >/dev/null @@ -450,6 +450,8 @@ BUILDROOT=${_opttargetdir:-$_d_workdir/root} . "$_f_config" || die "Failed to read configuration \`%s'" "$_f_config" +arrayize_config + # after returning, hooks are populated into the array '_hooks' # HOOKS should not be referenced from here on compute_hookset diff --git a/mkinitcpio.conf b/mkinitcpio.conf index c4d5e06..b926b90 100644 --- a/mkinitcpio.conf +++ b/mkinitcpio.conf @@ -3,20 +3,20 @@ # The following modules are loaded before any boot hooks are # run. Advanced users may wish to specify all system modules # in this array. For instance: -# MODULES="piix ide_disk reiserfs" -MODULES="" +# MODULES=(piix ide_disk reiserfs) +MODULES=() # BINARIES # This setting includes any additional binaries a given user may # wish into the CPIO image. This is run last, so it may be used to # override the actual binaries included by a given hook # BINARIES are dependency parsed, so you may safely ignore libraries -BINARIES="" +BINARIES=() # FILES # This setting is similar to BINARIES above, however, files are added # as-is and are not parsed in any way. This is useful for config files. -FILES="" +FILES=() # HOOKS # This is the most important setting in this file. The HOOKS control the @@ -30,26 +30,26 @@ FILES="" # Examples: ## This setup specifies all modules in the MODULES setting above. ## No raid, lvm2, or encrypted root is needed. -# HOOKS="base" +# HOOKS=(base) # ## This setup will autodetect all modules for your system and should ## work as a sane default -# HOOKS="base udev autodetect block filesystems" +# HOOKS=(base udev autodetect block filesystems) # ## This setup will generate a 'full' image which supports most systems. ## No autodetection is done. -# HOOKS="base udev block filesystems" +# HOOKS=(base udev block filesystems) # ## This setup assembles a pata mdadm array with an encrypted root FS. ## Note: See 'mkinitcpio -H mdadm' for more information on raid devices. -# HOOKS="base udev block mdadm encrypt filesystems" +# HOOKS=(base udev block mdadm encrypt filesystems) # ## This setup loads an lvm2 volume group on a usb device. -# HOOKS="base udev block lvm2 filesystems" +# HOOKS=(base udev block lvm2 filesystems) # ## NOTE: If you have /usr on a separate partition, you MUST include the # usr, fsck and shutdown hooks. -HOOKS="base udev autodetect modconf block filesystems keyboard fsck" +HOOKS=(base udev autodetect modconf block filesystems keyboard fsck) # COMPRESSION # Use this to compress the initramfs image. By default, gzip compression @@ -63,4 +63,4 @@ HOOKS="base udev autodetect modconf block filesystems keyboard fsck" # COMPRESSION_OPTIONS # Additional options for the compressor -#COMPRESSION_OPTIONS="" +#COMPRESSION_OPTIONS=() |