diff options
author | Gatis Paeglis <gatis.paeglis@qt.io> | 2016-07-27 15:22:05 +0200 |
---|---|---|
committer | Gatis Paeglis <gatis.paeglis@qt.io> | 2016-08-24 12:59:15 +0000 |
commit | 86f3a9562229c4e3f5a10cf12db0aa33bc6b5d38 (patch) | |
tree | f2939303bbffc800f64569b1d17ac1836956e447 /qt-ostree | |
parent | f48ab751dd43906d5b9492e3f124b94f189b9971 (diff) |
Extract kernel version from filename or binary
This is a preperation for initramfs-less booting. This
means that initramfs won't be mandatory anymore, therefore
we can't assume that initramfs will be there for extracting
the kernel version.
Task-number: QTBUG-52758
Change-Id: I397a0fa4925b4ae8a3725921a318542c6132f025
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'qt-ostree')
-rwxr-xr-x | qt-ostree/qt-ostree | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/qt-ostree/qt-ostree b/qt-ostree/qt-ostree index defa94e..caeda03 100755 --- a/qt-ostree/qt-ostree +++ b/qt-ostree/qt-ostree @@ -290,13 +290,6 @@ validate_arg() validation_error "--gpg-trusted-keyring expects gpg keyring file with the .gpg extension, but ${GPG_TRUSTED_KEYRING} was provided." fi ;; - --initramfs) - if [[ "$(basename ${INITRAMFS})" != initramfs-* ]] ; then - error="The provided initramfs image ${INITRAMFS} doesn't seem to be generated by the bundled 'generate-initramfs' script." - error+=" The required naming pattern is initramfs-\${device}-\${release} or initramfs-\${release}." - validation_error "${error}" - fi - ;; --sysroot-image-path) INPUT_SYSROOT_ARG_COUNTER=$(( $INPUT_SYSROOT_ARG_COUNTER + 1 )) if [ -d "${SYSROOT_IMAGE_PATH}" ] ; then @@ -527,34 +520,56 @@ path_in_sysroot() echo ${target_path} } -organize_boot_files() +get_kernel_info() { - if [ $(ls ${GENERATED_TREE}/boot/ | wc -l) != 0 ]; then - mv -f ${GENERATED_TREE}/boot/* ${BOOT_FILE_PATH}/ - fi - # Find kernel image. + # Note: It might be a good idea to expose KERNEL as command line argument, when + # the existing search algorithm is not sufficient. cd ${BOOT_FILE_PATH}/ for boot_file in *; do if file -b ${boot_file} | grep -qi "kernel"; then - kernel=${BOOT_FILE_PATH}/${boot_file} - qt_ostree_info "Found kernel image ${kernel}" + KERNEL=${BOOT_FILE_PATH}/${boot_file} break fi done - if [ -z "${kernel}" ] ; then + if [ -z "${KERNEL}" ] ; then qt_ostree_error "Failed to find kernel image in ${BOOT_FILE_PATH}" fi + # Extract kernel version from a file name. + KERNEL_VERSION=$(basename "${KERNEL}" | grep -o -E "[1-4]\.[0-9][0-9]*\.[0-9][0-9]*" || true) + if [ -z "${KERNEL_VERSION}" ] ; then + # Otherwise look for a string in the kernel binary that looks like a kernel version. + # Note: This is fragile, it might be a good idea to expose KERNEL_VERSION via command line argument. + if file -b "${KERNEL}" | grep -qi "u-boot"; then + KERNEL_VERSION=$(strings "${KERNEL}" | grep -o -E "[1-4]\.[0-9][0-9]*\.[0-9][0-9]*" | head -1) + else + KERNEL_VERSION=$(strings "${KERNEL}" | grep -o -E "^[1-4]\.[0-9][0-9]*\.[0-9][0-9]*" | head -1) + fi + fi + if [ -z "${KERNEL_VERSION}" ] ; then + qt_ostree_error "Failed to extract kernel version information from ${KERNEL}". + fi + + qt_ostree_info "Using kernel image ${KERNEL} (extracted version: ${KERNEL_VERSION})" +} + +organize_boot_files() +{ + if [ $(ls ${GENERATED_TREE}/boot/ | wc -l) != 0 ]; then + mv -f ${GENERATED_TREE}/boot/* ${BOOT_FILE_PATH}/ + fi + + get_kernel_info + # Clean up from unnecessary files and broken symbolic links. rm -rf initramfs find -L ${BOOT_FILE_PATH}/ -type l -delete # OSTree deploy requires vmlinuz-*. - release=$(basename ${INITRAMFS} | cut -f2- -d'-') - bootcsum=$(cat ${kernel} ${INITRAMFS} | sha256sum | cut -f 1 -d ' ') - mv ${kernel} ${BOOT_FILE_PATH}/vmlinuz-${release}-${bootcsum} - cp ${INITRAMFS} ${BOOT_FILE_PATH}/initramfs-${release}-${bootcsum} + bootcsum=$(cat ${KERNEL} ${INITRAMFS} | sha256sum | cut -f 1 -d ' ') + mv ${KERNEL} ${BOOT_FILE_PATH}/vmlinuz-${KERNEL_VERSION}-${bootcsum} + cp ${INITRAMFS} ${BOOT_FILE_PATH}/initramfs-${KERNEL_VERSION}-${bootcsum} # Boot loader companions. if [[ "${BOOTLOADER}" = "u-boot" && -n "${UBOOT_ENV_FILE}" ]] ; then |