diskimage-builder/elements/fedora-minimal/install.d/99-ramdisk
Martin André d8a0e13261 Fix uniqueness check of initrd in fedora-minimal
The check suffered from various flaws.

First, due to missing quotes around $initrd, 'wc -l' would always see
1 line no matter how many results the find returned.

Second, echo adds a line break making 'wc -l' count 1 even for empty
string. We need to add a check for empty string.

Change-Id: Ib2c67960f566dbdc471d9585a4cef1beb1cc38ab
Closes-Bug: #1506692
2015-11-04 06:23:17 +11:00

18 lines
402 B
Bash
Executable File

#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
initrd=$(find /boot -name initrd)
kernel_version=$(rpm -qa | grep kernel | sort | head -n 1 | cut -d '-' -f 2,3)
if [ -n "$initrd" -a $(echo "$initrd" | wc -l) -eq 1 ]; then
cp $initrd /boot/initrd-$kernel_version.img
else
echo "Zero or multiple initrds found. This should not happen."
exit 1
fi