postinst script: tabs are as useful as a hole in the head
authorKay Sievers <kay@vrfy.org>
Fri, 13 Jul 2012 14:41:17 +0000 (16:41 +0200)
committerKay Sievers <kay@vrfy.org>
Fri, 13 Jul 2012 14:41:17 +0000 (16:41 +0200)
gummiboot-postinst.sh

index 67b67e1..a705b2e 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 # This is a script to be called automatically by new-kernel-pkg as
-# /etc/kernel/postinst.d/gummiboot-postinst.sh
+# /etc/kernel/postinst.d/loader-postinst.sh
 
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU Lesser General Public License as published by
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 # Lesser General Public License for more details.
 #
-# Copyright (C) 2012 Kay Sievers <kay.sievers@vrfy.org>
 # Copyright (C) 2012 Harald Hoyer <harald@redhat.com>
+# Copyright (C) 2012 Kay Sievers <kay.sievers@vrfy.org>
 
 if (( $# != 2 )); then
-       echo "Usage: $0 <KERNEL_VERSION> <KERNEL_IMAGE>" >&2
-       exit 1
+        echo "Usage: $0 <KERNEL_VERSION> <KERNEL_IMAGE>" >&2
+        exit 1
 fi
 
 KERNEL_VERSION="$1"
 KERNEL_IMAGE="$2"
 
 if ! [[ -f $KERNEL_IMAGE ]]; then
-       echo "Can't find file $KERNEL_IMAGE!" >&2
-       exit 1
+        echo "Can't find file $KERNEL_IMAGE!" >&2
+        exit 1
 fi
 
 if [[ -d /boot/loader/entries ]]; then
-       EFI_DIR="/boot"
+        EFI_DIR="/boot"
 elif [[ -f /boot/efi/loader/entries ]]; then
-       EFI_DIR="/boot/efi"
+        EFI_DIR="/boot/efi"
 fi
 
 if ! [[ $EFI_DIR ]] ; then
-       echo "Can't install new kernel for loader: no directory 'loader/entries found!" >&2
-       echo "Please create the directory 'loader/entries' in your EFI partition." >&2
-       exit 1
+        echo "Can't install new kernel for loader: no directory 'loader/entries found!" >&2
+        echo "Please create the directory 'loader/entries' in your EFI partition." >&2
+        exit 1
 fi
 
 if [[ -f ${KERNEL_IMAGE/vmlinuz/initrd} ]]; then
-       INITRD_IMAGE=${KERNEL_IMAGE/vmlinuz/initrd}
+        INITRD_IMAGE=${KERNEL_IMAGE/vmlinuz/initrd}
 elif [[ -f ${KERNEL_IMAGE/vmlinuz/initrd}.img ]]; then
-       INITRD_IMAGE=${KERNEL_IMAGE/vmlinuz/initrd}.img
+        INITRD_IMAGE=${KERNEL_IMAGE/vmlinuz/initrd}.img
 elif [[ -f ${KERNEL_IMAGE/vmlinuz/initramfs}.img ]]; then
-       INITRD_IMAGE=${KERNEL_IMAGE/vmlinuz/initramfs}.img
+        INITRD_IMAGE=${KERNEL_IMAGE/vmlinuz/initramfs}.img
 fi
 
 if [[ -f /etc/kernel/cmdline ]]; then
-       while read line; do
-               BOOT_OPTIONS+="$line "
-       done < /etc/kernel/cmdline
+        while read line; do
+                BOOT_OPTIONS+="$line "
+        done < /etc/kernel/cmdline
 fi
-
 if ! [[ $BOOT_OPTIONS ]]; then
-       echo "Can't load default kernel command line parameters from /etc/kernel/cmdline!" >&2
-       echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
+        echo "Can't load default kernel command line parameters from /etc/kernel/cmdline!" >&2
+        echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
+        exit 1
 fi
 
 [[ -f /etc/os-release ]] && . /etc/os-release
-
 if ! [[ $ID ]]; then
-       echo "Can't determine the ID of your distribution. Please populate /etc/os-release!" >&2
+        echo "Can't determine the ID of your distribution. Please populate /etc/os-release!" >&2
         echo "See http://www.freedesktop.org/software/systemd/man/os-release.html" >&2
-       exit 1
+        exit 1
 fi
 
 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
-
 if ! [[ $MACHINE_ID ]]; then
-       echo "Can't determine your machine id. Please populate /etc/machine-id!" >&2
+        echo "Can't determine your machine id. Please populate /etc/machine-id!" >&2
         echo "See http://www.freedesktop.org/software/systemd/man/machine-id.html" >&2
+        exit 1
 fi
 
 ROOT_DEV=$(while read a a a a mp a a a dev a; do
-    if [[ $mp = "/" ]]; then
-        echo $dev
-        break
-    fi
-    done < /proc/self/mountinfo)
+        if [[ $mp = "/" ]]; then
+                echo $dev
+                break
+        fi
+done < /proc/self/mountinfo)
 
 if [[ $ROOT_DEV ]]; then
-       ROOT_LABEL=$(blkid -p -o udev -u filesystem $ROOT_DEV |
+        ROOT_LABEL=$(blkid -p -o udev -u filesystem $ROOT_DEV |
             while read line; do
                 if [[ $line == ID_FS_LABEL* ]]; then
                     echo ${line##ID_FS_LABEL=}
@@ -98,33 +97,29 @@ cp --preserve "$KERNEL_IMAGE" "${EFI_DIR}/${ID}/${MACHINE_ID}/"
 [[ $INITRD_IMAGE ]] && cp --preserve "$INITRD_IMAGE" "${EFI_DIR}/${ID}/${MACHINE_ID}/"
 
 {
-       echo "title $NAME $VERSION_ID ($KERNEL_VERSION) $ROOT_LABEL ${ROOT_DEV##/dev/} ${MACHINE_ID:0:8}"
-
-       echo "options $BOOT_OPTIONS"
-
-       echo "linux /$ID/$MACHINE_ID/${KERNEL_IMAGE##*/}"
-
-       [[ $INITRD_IMAGE ]] && echo "initrd /${ID}/${MACHINE_ID}/${INITRD_IMAGE##*/}"
-
+        echo "title $NAME $VERSION_ID ($KERNEL_VERSION) $ROOT_LABEL ${ROOT_DEV##/dev/} ${MACHINE_ID:0:8}"
+        echo "options $BOOT_OPTIONS"
+        echo "linux /$ID/$MACHINE_ID/${KERNEL_IMAGE##*/}"
+        [[ $INITRD_IMAGE ]] && echo "initrd /${ID}/${MACHINE_ID}/${INITRD_IMAGE##*/}"
 } > "${EFI_DIR}/loader/entries/${ID}-${KERNEL_VERSION}-${MACHINE_ID}.conf"
 
 if ! [[ -f ${EFI_DIR}/loader/loader.conf ]]; then
-    {
-        echo "default $ID-"
-    } > "${EFI_DIR}/loader/loader.conf"
+        {
+                echo "default $ID-"
+        } > "${EFI_DIR}/loader/loader.conf"
 fi
 
 # now cleanup the old entries and files, for which no /lib/modules/$KERNEL_VERSION exists
 (
-       cd ${EFI_DIR}/loader/entries
-       for conf in ${ID}-*-${MACHINE_ID}.conf; do
-               KERNEL_VERSION=${conf##$ID-}
-               KERNEL_VERSION=${KERNEL_VERSION%%-$MACHINE_ID.conf}
-               [[ $KERNEL_VERSION ]] || continue
-               [[ -d /lib/modules/${KERNEL_VERSION}/kernel ]] && continue
-               rm -f "$conf"
-               rm -f "${EFI_DIR}/${ID}/${MACHINE_ID}/*${KERNEL_VERSION}*"
-       done
+        cd ${EFI_DIR}/loader/entries
+        for conf in ${ID}-*-${MACHINE_ID}.conf; do
+                KERNEL_VERSION=${conf##$ID-}
+                KERNEL_VERSION=${KERNEL_VERSION%%-$MACHINE_ID.conf}
+                [[ $KERNEL_VERSION ]] || continue
+                [[ -d /lib/modules/${KERNEL_VERSION}/kernel ]] && continue
+                rm -f "$conf"
+                rm -f "${EFI_DIR}/${ID}/${MACHINE_ID}/*${KERNEL_VERSION}*"
+        done
 )
 
 exit 0