Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | # This class installs additional files found on the build host |
| 8 | # directly into the rootfs. |
| 9 | # |
| 10 | # One use case is to install a constant ssh host key in |
| 11 | # an image that gets created for just one machine. This |
| 12 | # solves two issues: |
| 13 | # - host key generation on the device can stall when the |
| 14 | # kernel has not gathered enough entropy yet (seen in practice |
| 15 | # under qemu) |
| 16 | # - ssh complains by default when the host key changes |
| 17 | # |
| 18 | # For dropbear, with the ssh host key store along side the local.conf: |
| 19 | # 1. Extend local.conf: |
| 20 | # INHERIT += "rootfsdebugfiles" |
| 21 | # ROOTFS_DEBUG_FILES += "${TOPDIR}/conf/dropbear_rsa_host_key ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key ;" |
| 22 | # 2. Boot the image once, copy the dropbear_rsa_host_key from |
| 23 | # the device into your build conf directory. |
| 24 | # 3. A optional parameter can be used to set file mode |
| 25 | # of the copied target, for instance: |
| 26 | # ROOTFS_DEBUG_FILES += "${TOPDIR}/conf/dropbear_rsa_host_key ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key 0600;" |
| 27 | # in case they might be required to have a specific mode. (Shoundn't be too open, for example) |
| 28 | # |
| 29 | # Do not use for production images! It bypasses several |
| 30 | # core build mechanisms (updating the image when one |
| 31 | # of the files changes, license tracking in the image |
| 32 | # manifest, ...). |
| 33 | |
| 34 | ROOTFS_DEBUG_FILES ?= "" |
| 35 | ROOTFS_DEBUG_FILES[doc] = "Lists additional files or directories to be installed with 'cp -a' in the format 'source1 target1;source2 target2;...'" |
| 36 | |
| 37 | ROOTFS_POSTPROCESS_COMMAND += "rootfs_debug_files;" |
| 38 | rootfs_debug_files () { |
| 39 | #!/bin/sh -e |
| 40 | echo "${ROOTFS_DEBUG_FILES}" | sed -e 's/;/\n/g' | while read source target mode; do |
| 41 | if [ -e "$source" ]; then |
| 42 | mkdir -p $(dirname $target) |
| 43 | cp -a $source $target |
| 44 | [ -n "$mode" ] && chmod $mode $target |
| 45 | fi |
| 46 | done |
| 47 | } |