#!/bin/bash ############################################################################# ## ## Copyright (C) 2016 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the Qt OTA Update module of the Qt Toolkit. ## ## $QT_BEGIN_LICENSE:GPL$ ## Commercial License Usage ## Licensees holding valid commercial Qt licenses may use this file in ## accordance with the commercial license agreement provided with the ## Software or, alternatively, in accordance with the terms contained in ## a written agreement between you and The Qt Company. For licensing terms ## and conditions see https://www.qt.io/terms-conditions. For further ## information use the contact form at https://www.qt.io/contact-us. ## ## GNU General Public License Usage ## Alternatively, this file may be used under the terms of the GNU ## General Public License version 3 or (at your option) any later version ## approved by the KDE Free Qt Foundation. The licenses are as published by ## the Free Software Foundation and appearing in the file LICENSE.GPL3 ## included in the packaging of this file. Please review the following ## information to ensure the GNU General Public License requirements will ## be met: https://www.gnu.org/licenses/gpl-3.0.html. ## ## $QT_END_LICENSE$ ## ############################################################################# set -e ROOT=$(dirname $(readlink -f $0)) ADB=$(which adb) || true if [ ! -x "${ADB}" ] ; then # No system adb found. Try the one from Qt SDK. ADB="${ROOT}"/../../../b2qt/adb if [ ! -x "${ADB}" ] ; then echo "Needed command 'adb' not found in PATH." exit 1 fi fi ADB=$(readlink -e "${ADB}") echo "Using adb from ${ADB}" BOOTLOADER="u-boot" detect_target_device() { "${ADB}" pull /etc/hostname DEVICE=$(cat hostname) rm -f hostname if [ -z "${DEVICE}" ] ; then echo "error: no hostname specified in /etc/hostname on a device." exit 1 fi case "${DEVICE}" in *intel-corei7*|*nuc*) # Intel NUC BOOTLOADER="grub2" ;; esac echo "Detected ${DEVICE} device with ${BOOTLOADER} boot loader." } generate_initramfs() { MODULE_PATH=/usr/lib/dracut/modules.d/ init_system=$(basename $("${ADB}" shell readlink -f /sbin/init) | tr -d '\r') if [ "$init_system" != "systemd" ] ; then echo "error: Failed to detected systemd init support on the image" exit 1 fi options='/boot/initramfs.img --host-only --add ostree --omit i18n --stdlog 3 --force' # OSTree ships with a dracut module for systemd based images. echo "Generating initramfs for systemd based image ..." "${ADB}" push "${ROOT}"/systemd/01-qt.conf /etc/dracut.conf.d/ "${ADB}" push "${ROOT}"/systemd/e2fsck.conf /etc/ custom_options="--add systemd --install /etc/e2fsck.conf" # Recovery module parts #"${ADB}" push "${ROOT}"/recovery/ "${MODULE_PATH}"/98recovery/ #custom_options="${custom_options} --add recovery" # Terminate when the explicitly required modules could not be found or installed. "${ADB}" shell dracut ${options} ${custom_options} | tee dracut.log errors=$(cat dracut.log | grep -i "cannot be found or installed" | wc -l) if [ ${errors} -gt 0 ] ; then echo "error: Failed to include the required modules into the initramfs image." exit 1 fi rm -f initramfs.img "${ADB}" pull /boot/initramfs.img device=$("${ADB}" shell uname -n | tr -d '\r') release=$("${ADB}" shell uname -r | tr -d '\r' | cut -d'-' -f1) INITRAMFS=initramfs-${device}-${release} rm -rf ${INITRAMFS} detect_target_device if [ "${BOOTLOADER}" = "u-boot" ] ; then # Add u-boot header. SOURCE_DATE_EPOCH=1 mkimage -A arm -O linux -T ramdisk -a 0 -e 0 -d initramfs.img ${INITRAMFS} rm -f initramfs.img else mv initramfs.img ${INITRAMFS} fi } main() { generate_initramfs echo echo "Done, generated OSTree boot compatible initramfs:" echo echo ${INITRAMFS} echo } main