[arch-projects] [mkinitcpio] [PATCH] Add -p, --allpresets option
Dave Reisner
dreisner at archlinux.org
Mon Feb 4 17:58:11 EST 2013
As a logical extension, allow the -p option to be specified multiple
times in order to process several presets at once.
---
This is more along the lines of what I had in mind. Only lightly tested.
bash-completion | 2 +-
man/mkinitcpio.8.txt | 8 ++++++--
mkinitcpio | 28 +++++++++++++++++++---------
3 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/bash-completion b/bash-completion
index 559b2f3..e7c1db0 100644
--- a/bash-completion
+++ b/bash-completion
@@ -63,7 +63,7 @@ _files_from_dirs() {
_mkinitcpio() {
local action cur prev opts
opts=(-A --addhooks -c --config -g --generate -H --hookhelp -h --help -k --kernel
- -L --listhooks -M --automods -n --nocolor -p --preset -r --moduleroot
+ -L --listhooks -M --automods -n --nocolor -P --allpresets -p --preset -r --moduleroot
-S --skiphooks -s --save -t --builddir -V --version -v --verbose -z --compress)
_get_comp_words_by_ref cur prev
diff --git a/man/mkinitcpio.8.txt b/man/mkinitcpio.8.txt
index 2b0f524..56ac571 100644
--- a/man/mkinitcpio.8.txt
+++ b/man/mkinitcpio.8.txt
@@ -57,10 +57,14 @@ Options
*-n, \--nocolor*::
Disable color output.
+*-P, \--allpresets*::
+ Process all presets contained in '/etc/mkinitcpio.d'. See the '-p' option for
+ more detail about presets.
+
*-p, \--preset* 'preset'::
Build initramfs image(s) according to specified 'preset'. This may be a file in
/etc/mkinitcpio.d (without the .preset extension) or a full, absolute path to a
- file.
+ file. This option may be specified multiple times to process multiple presets.
*-r, \--moduleroot* 'root'::
Specifies the root directory to find modules in, defaulting to '/'.
@@ -254,7 +258,7 @@ Files
Default configuration file for mkinitcpio.
'/etc/mkinitcpio.d'::
- Folder containing mkinitcpio presets.
+ Directory containing mkinitcpio presets.
'/usr/lib/initcpio/install'::
'/lib/initcpio/install'::
diff --git a/mkinitcpio b/mkinitcpio
index 9802fd5..b19b5be 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -17,11 +17,11 @@ _d_install="$PWD/install:/usr/lib/initcpio/install:/lib/initcpio/install"
_d_presets=mkinitcpio.d
# options and runtime data
-_optmoduleroot= _optkver= _optgenimg= _optpreset=
+_optmoduleroot= _optkver= _optgenimg=
_optcompress=
_optshowautomods=0 _optsavetree=0 _optshowmods=0
_optquiet=1 _optcolor=1
-_optskiphooks=() _optaddhooks=() _hooks=()
+_optskiphooks=() _optaddhooks=() _hooks=() _optpreset=()
declare -A _runhooks _addedmodules _modpaths _autodetect_cache
# export a sane PATH
@@ -245,7 +245,10 @@ process_preset() {
printf -v preset '%s/%s.preset' "$_d_presets" "$preset"
fi
- . "$preset" || die "Preset not found: \`%s'" "$preset"
+ if ! . "$preset"; then
+ error "Preset not found: \`%s'" "$preset"
+ return 1
+ fi
# Use -m and -v options specified earlier
(( _optquiet )) || preset_mkopts+=(-v)
@@ -253,7 +256,7 @@ process_preset() {
ret=0
for p in "${PRESETS[@]}"; do
- msg "Building image from preset: '$p'"
+ msg "Building image from preset: $preset: '$p'"
preset_cmd=("${preset_mkopts[@]}")
preset_kver=${p}_kver
@@ -290,7 +293,7 @@ process_preset() {
(( $? )) && ret=1
done
- exit $ret
+ return $ret
}
install_modules() {
@@ -339,9 +342,9 @@ install_modules() {
trap 'cleanup 130' INT
trap 'cleanup 143' TERM
-_opt_short='A:c:g:H:hk:nLMp:r:S:st:Vvz:'
+_opt_short='A:c:g:H:hk:nLMPp:r:S:st:Vvz:'
_opt_long=('add:' 'addhooks:' 'config:' 'generate:' 'hookhelp:' 'help'
- 'kernel:' 'listhooks' 'automods' 'moduleroot:' 'nocolor'
+ 'kernel:' 'listhooks' 'automods' 'moduleroot:' 'nocolor' 'allpresets'
'preset:' 'skiphooks:' 'save' 'builddir:' 'version' 'verbose' 'compress:')
parseopts "$_opt_short" "${_opt_long[@]}" -- "$@" || exit 1
@@ -378,7 +381,7 @@ while :; do
cleanup 0 ;;
-p|--preset)
shift
- _optpreset=$1 ;;
+ _optpreset+=("$1") ;;
-n|--nocolor)
_optcolor=0 ;;
-v|--verbose)
@@ -397,6 +400,10 @@ while :; do
exit 0 ;;
-M|--automods)
_optshowautomods=1 ;;
+ -P|--allpresets)
+ _optpreset=("$_d_presets"/*.preset)
+ [[ -e ${_optpreset[0]} ]] || die "No presets found in $_d_presets"
+ ;;
-t|--builddir)
shift
export TMPDIR=$1 ;;
@@ -424,7 +431,10 @@ fi
[[ -e /dev/fd ]] || die "/dev must be mounted!"
# use preset $_optpreset (exits after processing)
-[[ $_optpreset ]] && process_preset "$_optpreset"
+if (( ${#_optpreset[*]} )); then
+ map process_preset "${_optpreset[@]}"
+ exit
+fi
KERNELVERSION=$(resolve_kernver "$_optkver") || cleanup 1
_d_kmoduledir=$_optmoduleroot/lib/modules/$KERNELVERSION
--
1.8.1.2
More information about the arch-projects
mailing list