Reduce code duplication in set_bootloader_grub
authorSebastian Pipping <sebastian@pipping.org>
Sun, 8 Apr 2012 19:41:19 +0000 (21:41 +0200)
committerSebastian Pipping <sebastian@pipping.org>
Sun, 8 Apr 2012 20:47:08 +0000 (22:47 +0200)
gen_bootloader.sh

index 1debfe99bf95e5b6c889f41b1ff31ff02747229b..d14b313cec37fdb21b1cdda739e0f3677b20f8e4 100755 (executable)
@@ -33,20 +33,24 @@ set_bootloader_grub_read_device_map() {
 
 set_bootloader_grub2() {
     local GRUB_CONF
-    if [ -e "${BOOTDIR}/grub2/grub.cfg" ]
-    then
-               GRUB_CONF="${BOOTDIR}/grub2/grub.cfg"
-    elif [ -e "${BOOTDIR}/grub/grub.cfg" ]
-    then
-               GRUB_CONF="${BOOTDIR}/grub/grub.cfg"
-    else
+       for candidate in \
+                       "${BOOTDIR}/grub2/grub.cfg" \
+                       "${BOOTDIR}/grub/grub.cfg" \
+                       ; do
+               if [[ -e "${candidate}" ]]; then
+                       GRUB_CONF=${candidate}
+                       break
+               fi
+       done
+
+       if [[ -z "${GRUB_CONF}" ]]; then
                print_error 1 "Error! Grub2 configuration file does not exist, please ensure grub2 is correctly setup first."
-               return 0
+               return 0
     fi
 
     print_info 1 "You can customize Grub2 parameters in /etc/defaults/grub."
     print_info 1 "Running grub-mkconfig to create ${GRUB_CONF}..."
-    grub-mkconfig -o ${GRUB_CONF}
+    grub-mkconfig -o "${GRUB_CONF}"
 }
 
 set_bootloader_grub() {