summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-09-30 02:33:34 +0200
committerDave Reisner <dreisner@archlinux.org>2012-10-07 02:38:02 +0200
commitbb57d3bd3cc4af2b169f3bbdbe0984aa8e5b38dd (patch)
tree1b4fd40b88eb1c7477a1e3493792acfa061a6f36
parent367ac227f42ca9c8a7c050da0bcc04248fae29b1 (diff)
downloadmkinitcpio-bb57d3bd3cc4af2b169f3bbdbe0984aa8e5b38dd.tar.gz
mkinitcpio-bb57d3bd3cc4af2b169f3bbdbe0984aa8e5b38dd.tar.xz
mkinitcpio: check for preset file by sourcing it
Instead of using a bash test, just source the preset file. If it fails, exit. This patch is a bit ugly because it remove a level of indentation.
-rwxr-xr-xmkinitcpio86
1 files changed, 44 insertions, 42 deletions
diff --git a/mkinitcpio b/mkinitcpio
index 0300954..874d195 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -246,52 +246,54 @@ if [[ $_optpreset ]]; then
if [[ ${_optpreset:0:1} != '/' ]]; then
printf -v _optpreset '%s/%s.preset' "$_d_presets" "$_optpreset"
fi
- if [[ -f $_optpreset ]]; then
- # Use -b, -m and -v options specified earlier
- declare -a preset_mkopts preset_cmd
- (( _optquiet )) || preset_mkopts+=(-v)
- # Build all images
- . "$_optpreset"
- for p in "${PRESETS[@]}"; do
- msg "Building image from preset: '$p'"
- preset_cmd=("${preset_mkopts[@]}")
-
- preset_kver=${p}_kver
- if [[ ${!preset_kver:-$ALL_kver} ]]; then
- preset_cmd+=(-k "${!preset_kver:-$ALL_kver}")
- else
- warning "No kernel version specified. Skipping image \`%s'" "$p"
- continue
- fi
- preset_config=${p}_config
- if [[ ${!preset_config:-$ALL_config} ]]; then
- preset_cmd+=(-c "${!preset_config:-$ALL_config}")
- else
- warning "No configuration file specified. Skipping image \`%s'" "$p"
- continue
- fi
+ if ! . "$_optpreset"; then
+ die "Preset not found: \`%s'" "$_optpreset"
+ fi
- preset_image=${p}_image
- if [[ ${!preset_image} ]]; then
- preset_cmd+=(-g "${!preset_image}")
- else
- warning "No image file specified. Skipping image \`%s'" "$p"
- continue
- fi
+ # Use -m and -v options specified earlier
+ declare -a preset_mkopts preset_cmd
+ (( _optquiet )) || preset_mkopts+=(-v)
- preset_options=${p}_options
- if [[ ${!preset_options} ]]; then
- preset_cmd+=(${!preset_options}) # intentional word splitting
- fi
+ ret=0
+ for p in "${PRESETS[@]}"; do
+ msg "Building image from preset: '$p'"
+ preset_cmd=("${preset_mkopts[@]}")
- msg2 "${preset_cmd[*]}"
- "$0" "${preset_cmd[@]}"
- done
- cleanup 0
- else
- die "Preset not found: \`%s'" "$_optpreset"
- fi
+ preset_kver=${p}_kver
+ if [[ ${!preset_kver:-$ALL_kver} ]]; then
+ preset_cmd+=(-k "${!preset_kver:-$ALL_kver}")
+ else
+ warning "No kernel version specified. Skipping image \`%s'" "$p"
+ continue
+ fi
+
+ preset_config=${p}_config
+ if [[ ${!preset_config:-$ALL_config} ]]; then
+ preset_cmd+=(-c "${!preset_config:-$ALL_config}")
+ else
+ warning "No configuration file specified. Skipping image \`%s'" "$p"
+ continue
+ fi
+
+ preset_image=${p}_image
+ if [[ ${!preset_image} ]]; then
+ preset_cmd+=(-g "${!preset_image}")
+ else
+ warning "No image file specified. Skipping image \`%s'" "$p"
+ continue
+ fi
+
+ preset_options=${p}_options
+ if [[ ${!preset_options} ]]; then
+ preset_cmd+=(${!preset_options}) # intentional word splitting
+ fi
+
+ msg2 "${preset_cmd[*]}"
+ "$0" "${preset_cmd[@]}"
+ (( $? )) && ret=1
+ done
+ exit $ret
fi
KERNELVERSION=$(resolve_kernver "$_optkver") || cleanup 1