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 | # Zap the root password if debug-tweaks and empty-root-password features are not enabled |
| 8 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-password' ], "", "zap_empty_root_password; ",d)}' |
| 9 | |
| 10 | # Allow dropbear/openssh to accept logins from accounts with an empty password string if debug-tweaks or allow-empty-password is enabled |
| 11 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'allow-empty-password' ], "ssh_allow_empty_password; ", "",d)}' |
| 12 | |
| 13 | # Allow dropbear/openssh to accept root logins if debug-tweaks or allow-root-login is enabled |
| 14 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'allow-root-login' ], "ssh_allow_root_login; ", "",d)}' |
| 15 | |
| 16 | # Autologin the root user on the serial console, if empty-root-password and serial-autologin-root are active |
| 17 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", [ 'empty-root-password', 'serial-autologin-root' ], "serial_autologin_root; ", "",d)}' |
| 18 | |
| 19 | # Enable postinst logging if debug-tweaks or post-install-logging is enabled |
| 20 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'post-install-logging' ], "postinst_enable_logging; ", "",d)}' |
| 21 | |
| 22 | # Create /etc/timestamp during image construction to give a reasonably sane default time setting |
| 23 | ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp; " |
| 24 | |
| 25 | # Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled |
| 26 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}' |
| 27 | |
| 28 | # We also need to do the same for the kernel boot parameters, |
| 29 | # otherwise kernel or initramfs end up mounting the rootfs read/write |
| 30 | # (the default) if supported by the underlying storage. |
| 31 | # |
| 32 | # We do this with :append because the default value might get set later with ?= |
| 33 | # and we don't want to disable such a default that by setting a value here. |
| 34 | APPEND:append = '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", " ro", "", d)}' |
| 35 | |
| 36 | # Generates test data file with data store variables expanded in json format |
| 37 | ROOTFS_POSTPROCESS_COMMAND += "write_image_test_data; " |
| 38 | |
| 39 | # Write manifest |
| 40 | IMAGE_MANIFEST = "${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.manifest" |
| 41 | ROOTFS_POSTUNINSTALL_COMMAND =+ "write_image_manifest ; " |
| 42 | # Set default postinst log file |
| 43 | POSTINST_LOGFILE ?= "${localstatedir}/log/postinstall.log" |
| 44 | # Set default target for systemd images |
| 45 | SYSTEMD_DEFAULT_TARGET ?= '${@bb.utils.contains_any("IMAGE_FEATURES", [ "x11-base", "weston" ], "graphical.target", "multi-user.target", d)}' |
| 46 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "set_systemd_default_target; systemd_create_users;", "", d)}' |
| 47 | |
| 48 | ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile;' |
| 49 | |
| 50 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "overlayfs", "overlayfs_qa_check; overlayfs_postprocess;", "", d)}' |
| 51 | |
| 52 | inherit image-artifact-names |
| 53 | |
| 54 | # Sort the user and group entries in /etc by ID in order to make the content |
| 55 | # deterministic. Package installs are not deterministic, causing the ordering |
| 56 | # of entries to change between builds. In case that this isn't desired, |
| 57 | # the command can be overridden. |
| 58 | # |
| 59 | # Note that useradd-staticids.bbclass has to be used to ensure that |
| 60 | # the numeric IDs of dynamically created entries remain stable. |
| 61 | # |
| 62 | # We want this to run as late as possible, in particular after |
| 63 | # systemd_sysusers_create and set_user_group. Using :append is not |
| 64 | # enough for that, set_user_group is added that way and would end |
| 65 | # up running after us. |
| 66 | SORT_PASSWD_POSTPROCESS_COMMAND ??= " tidy_shadowutils_files; " |
| 67 | python () { |
| 68 | d.appendVar('ROOTFS_POSTPROCESS_COMMAND', '${SORT_PASSWD_POSTPROCESS_COMMAND}') |
| 69 | d.appendVar('ROOTFS_POSTPROCESS_COMMAND', 'rootfs_reproducible;') |
| 70 | } |
| 71 | |
| 72 | systemd_create_users () { |
| 73 | for conffile in ${IMAGE_ROOTFS}/usr/lib/sysusers.d/*.conf; do |
| 74 | [ -e $conffile ] || continue |
| 75 | grep -v "^#" $conffile | sed -e '/^$/d' | while read type name id comment; do |
| 76 | if [ "$type" = "u" ]; then |
| 77 | useradd_params="--shell /sbin/nologin" |
| 78 | [ "$id" != "-" ] && useradd_params="$useradd_params --uid $id" |
| 79 | [ "$comment" != "-" ] && useradd_params="$useradd_params --comment $comment" |
| 80 | useradd_params="$useradd_params --system $name" |
| 81 | eval useradd --root ${IMAGE_ROOTFS} $useradd_params || true |
| 82 | elif [ "$type" = "g" ]; then |
| 83 | groupadd_params="" |
| 84 | [ "$id" != "-" ] && groupadd_params="$groupadd_params --gid $id" |
| 85 | groupadd_params="$groupadd_params --system $name" |
| 86 | eval groupadd --root ${IMAGE_ROOTFS} $groupadd_params || true |
| 87 | elif [ "$type" = "m" ]; then |
| 88 | group=$id |
| 89 | eval groupadd --root ${IMAGE_ROOTFS} --system $group || true |
| 90 | eval useradd --root ${IMAGE_ROOTFS} --shell /sbin/nologin --system $name --no-user-group || true |
| 91 | eval usermod --root ${IMAGE_ROOTFS} -a -G $group $name |
| 92 | fi |
| 93 | done |
| 94 | done |
| 95 | } |
| 96 | |
| 97 | # |
| 98 | # A hook function to support read-only-rootfs IMAGE_FEATURES |
| 99 | # |
| 100 | read_only_rootfs_hook () { |
| 101 | # Tweak the mount option and fs_passno for rootfs in fstab |
| 102 | if [ -f ${IMAGE_ROOTFS}/etc/fstab ]; then |
| 103 | sed -i -e '/^[#[:space:]]*\/dev\/root/{s/defaults/ro/;s/\([[:space:]]*[[:digit:]]\)\([[:space:]]*\)[[:digit:]]$/\1\20/}' ${IMAGE_ROOTFS}/etc/fstab |
| 104 | fi |
| 105 | |
| 106 | # Tweak the "mount -o remount,rw /" command in busybox-inittab inittab |
| 107 | if [ -f ${IMAGE_ROOTFS}/etc/inittab ]; then |
| 108 | sed -i 's|/bin/mount -o remount,rw /|/bin/mount -o remount,ro /|' ${IMAGE_ROOTFS}/etc/inittab |
| 109 | fi |
| 110 | |
| 111 | # If we're using openssh and the /etc/ssh directory has no pre-generated keys, |
| 112 | # we should configure openssh to use the configuration file /etc/ssh/sshd_config_readonly |
| 113 | # and the keys under /var/run/ssh. |
| 114 | if [ -d ${IMAGE_ROOTFS}/etc/ssh ]; then |
| 115 | if [ -e ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key ]; then |
| 116 | echo "SYSCONFDIR=\${SYSCONFDIR:-/etc/ssh}" >> ${IMAGE_ROOTFS}/etc/default/ssh |
| 117 | echo "SSHD_OPTS=" >> ${IMAGE_ROOTFS}/etc/default/ssh |
| 118 | else |
| 119 | echo "SYSCONFDIR=\${SYSCONFDIR:-/var/run/ssh}" >> ${IMAGE_ROOTFS}/etc/default/ssh |
| 120 | echo "SSHD_OPTS='-f /etc/ssh/sshd_config_readonly'" >> ${IMAGE_ROOTFS}/etc/default/ssh |
| 121 | fi |
| 122 | fi |
| 123 | |
| 124 | # Also tweak the key location for dropbear in the same way. |
| 125 | if [ -d ${IMAGE_ROOTFS}/etc/dropbear ]; then |
| 126 | if [ ! -e ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key ]; then |
| 127 | echo "DROPBEAR_RSAKEY_DIR=/var/lib/dropbear" >> ${IMAGE_ROOTFS}/etc/default/dropbear |
| 128 | fi |
| 129 | fi |
| 130 | |
| 131 | if ${@bb.utils.contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then |
| 132 | # Change the value of ROOTFS_READ_ONLY in /etc/default/rcS to yes |
| 133 | if [ -e ${IMAGE_ROOTFS}/etc/default/rcS ]; then |
| 134 | sed -i 's/ROOTFS_READ_ONLY=no/ROOTFS_READ_ONLY=yes/' ${IMAGE_ROOTFS}/etc/default/rcS |
| 135 | fi |
| 136 | # Run populate-volatile.sh at rootfs time to set up basic files |
| 137 | # and directories to support read-only rootfs. |
| 138 | if [ -x ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then |
| 139 | ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh |
| 140 | fi |
| 141 | fi |
| 142 | |
| 143 | if ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then |
| 144 | # Create machine-id |
| 145 | # 20:12 < mezcalero> koen: you have three options: a) run systemd-machine-id-setup at install time, b) have / read-only and an empty file there (for stateless) and c) boot with / writable |
| 146 | touch ${IMAGE_ROOTFS}${sysconfdir}/machine-id |
| 147 | fi |
| 148 | } |
| 149 | |
| 150 | # |
| 151 | # This function disallows empty root passwords |
| 152 | # |
| 153 | zap_empty_root_password () { |
| 154 | if [ -e ${IMAGE_ROOTFS}/etc/shadow ]; then |
| 155 | sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/shadow |
| 156 | fi |
| 157 | if [ -e ${IMAGE_ROOTFS}/etc/passwd ]; then |
| 158 | sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/passwd |
| 159 | fi |
| 160 | } |
| 161 | |
| 162 | # |
| 163 | # allow dropbear/openssh to accept logins from accounts with an empty password string |
| 164 | # |
| 165 | ssh_allow_empty_password () { |
| 166 | for config in sshd_config sshd_config_readonly; do |
| 167 | if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/$config ]; then |
| 168 | sed -i 's/^[#[:space:]]*PermitEmptyPasswords.*/PermitEmptyPasswords yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/$config |
| 169 | fi |
| 170 | done |
| 171 | |
| 172 | if [ -e ${IMAGE_ROOTFS}${sbindir}/dropbear ] ; then |
| 173 | if grep -q DROPBEAR_EXTRA_ARGS ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear 2>/dev/null ; then |
| 174 | if ! grep -q "DROPBEAR_EXTRA_ARGS=.*-B" ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear ; then |
| 175 | sed -i 's/^DROPBEAR_EXTRA_ARGS="*\([^"]*\)"*/DROPBEAR_EXTRA_ARGS="\1 -B"/' ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear |
| 176 | fi |
| 177 | else |
| 178 | printf '\nDROPBEAR_EXTRA_ARGS="-B"\n' >> ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear |
| 179 | fi |
| 180 | fi |
| 181 | |
| 182 | if [ -d ${IMAGE_ROOTFS}${sysconfdir}/pam.d ] ; then |
| 183 | for f in `find ${IMAGE_ROOTFS}${sysconfdir}/pam.d/* -type f -exec test -e {} \; -print` |
| 184 | do |
| 185 | sed -i 's/nullok_secure/nullok/' $f |
| 186 | done |
| 187 | fi |
| 188 | } |
| 189 | |
| 190 | # |
| 191 | # allow dropbear/openssh to accept root logins |
| 192 | # |
| 193 | ssh_allow_root_login () { |
| 194 | for config in sshd_config sshd_config_readonly; do |
| 195 | if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/$config ]; then |
| 196 | sed -i 's/^[#[:space:]]*PermitRootLogin.*/PermitRootLogin yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/$config |
| 197 | fi |
| 198 | done |
| 199 | |
| 200 | if [ -e ${IMAGE_ROOTFS}${sbindir}/dropbear ] ; then |
| 201 | if grep -q DROPBEAR_EXTRA_ARGS ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear 2>/dev/null ; then |
| 202 | sed -i '/^DROPBEAR_EXTRA_ARGS=/ s/-w//' ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear |
| 203 | fi |
| 204 | fi |
| 205 | } |
| 206 | |
| 207 | # |
| 208 | # Autologin the 'root' user on the serial terminal, |
| 209 | # if empty-root-password' AND 'serial-autologin-root are enabled |
| 210 | # |
| 211 | serial_autologin_root () { |
| 212 | if ${@bb.utils.contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then |
| 213 | # add autologin option to util-linux getty only |
| 214 | sed -i 's/options="/&--autologin root /' \ |
| 215 | "${IMAGE_ROOTFS}${base_bindir}/start_getty" |
| 216 | elif ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then |
| 217 | if [ -e ${IMAGE_ROOTFS}${systemd_system_unitdir}/serial-getty@.service ]; then |
| 218 | sed -i '/^\s*ExecStart\b/ s/getty /&--autologin root /' \ |
| 219 | "${IMAGE_ROOTFS}${systemd_system_unitdir}/serial-getty@.service" |
| 220 | fi |
| 221 | fi |
| 222 | } |
| 223 | |
| 224 | python tidy_shadowutils_files () { |
| 225 | import rootfspostcommands |
| 226 | rootfspostcommands.tidy_shadowutils_files(d.expand('${IMAGE_ROOTFS}${sysconfdir}')) |
| 227 | } |
| 228 | |
| 229 | python sort_passwd () { |
| 230 | """ |
| 231 | Deprecated in the favour of tidy_shadowutils_files. |
| 232 | """ |
| 233 | import rootfspostcommands |
| 234 | bb.warn('[sort_passwd] You are using a deprecated function for ' |
| 235 | 'SORT_PASSWD_POSTPROCESS_COMMAND. The default one is now called ' |
| 236 | '"tidy_shadowutils_files".') |
| 237 | rootfspostcommands.tidy_shadowutils_files(d.expand('${IMAGE_ROOTFS}${sysconfdir}')) |
| 238 | } |
| 239 | |
| 240 | # |
| 241 | # Enable postinst logging |
| 242 | # |
| 243 | postinst_enable_logging () { |
| 244 | mkdir -p ${IMAGE_ROOTFS}${sysconfdir}/default |
| 245 | echo "POSTINST_LOGGING=1" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst |
| 246 | echo "LOGFILE=${POSTINST_LOGFILE}" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst |
| 247 | } |
| 248 | |
| 249 | # |
| 250 | # Modify systemd default target |
| 251 | # |
| 252 | set_systemd_default_target () { |
| 253 | if [ -d ${IMAGE_ROOTFS}${sysconfdir}/systemd/system -a -e ${IMAGE_ROOTFS}${systemd_system_unitdir}/${SYSTEMD_DEFAULT_TARGET} ]; then |
| 254 | ln -sf ${systemd_system_unitdir}/${SYSTEMD_DEFAULT_TARGET} ${IMAGE_ROOTFS}${sysconfdir}/systemd/system/default.target |
| 255 | fi |
| 256 | } |
| 257 | |
| 258 | # If /var/volatile is not empty, we have seen problems where programs such as the |
| 259 | # journal make assumptions based on the contents of /var/volatile. The journal |
| 260 | # would then write to /var/volatile before it was mounted, thus hiding the |
| 261 | # items previously written. |
| 262 | # |
| 263 | # This change is to attempt to fix those types of issues in a way that doesn't |
| 264 | # affect users that may not be using /var/volatile. |
| 265 | empty_var_volatile () { |
| 266 | if [ -e ${IMAGE_ROOTFS}/etc/fstab ]; then |
| 267 | match=`awk '$1 !~ "#" && $2 ~ /\/var\/volatile/{print $2}' ${IMAGE_ROOTFS}/etc/fstab 2> /dev/null` |
| 268 | if [ -n "$match" ]; then |
| 269 | find ${IMAGE_ROOTFS}/var/volatile -mindepth 1 -delete |
| 270 | fi |
| 271 | fi |
| 272 | } |
| 273 | |
| 274 | # Turn any symbolic /sbin/init link into a file |
| 275 | remove_init_link () { |
| 276 | if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then |
| 277 | LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init` |
| 278 | rm ${IMAGE_ROOTFS}/sbin/init |
| 279 | cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init |
| 280 | fi |
| 281 | } |
| 282 | |
| 283 | make_zimage_symlink_relative () { |
| 284 | if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then |
| 285 | (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done) |
| 286 | fi |
| 287 | } |
| 288 | |
| 289 | python write_image_manifest () { |
| 290 | from oe.rootfs import image_list_installed_packages |
| 291 | from oe.utils import format_pkg_list |
| 292 | |
| 293 | deploy_dir = d.getVar('IMGDEPLOYDIR') |
| 294 | link_name = d.getVar('IMAGE_LINK_NAME') |
| 295 | manifest_name = d.getVar('IMAGE_MANIFEST') |
| 296 | |
| 297 | if not manifest_name: |
| 298 | return |
| 299 | |
| 300 | pkgs = image_list_installed_packages(d) |
| 301 | with open(manifest_name, 'w+') as image_manifest: |
| 302 | image_manifest.write(format_pkg_list(pkgs, "ver")) |
| 303 | |
| 304 | if os.path.exists(manifest_name) and link_name: |
| 305 | manifest_link = deploy_dir + "/" + link_name + ".manifest" |
| 306 | if manifest_link != manifest_name: |
| 307 | if os.path.lexists(manifest_link): |
| 308 | os.remove(manifest_link) |
| 309 | os.symlink(os.path.basename(manifest_name), manifest_link) |
| 310 | } |
| 311 | |
| 312 | # Can be used to create /etc/timestamp during image construction to give a reasonably |
| 313 | # sane default time setting |
| 314 | rootfs_update_timestamp () { |
| 315 | if [ "${REPRODUCIBLE_TIMESTAMP_ROOTFS}" != "" ]; then |
| 316 | # Convert UTC into %4Y%2m%2d%2H%2M%2S |
| 317 | sformatted=`date -u -d @${REPRODUCIBLE_TIMESTAMP_ROOTFS} +%4Y%2m%2d%2H%2M%2S` |
| 318 | else |
| 319 | sformatted=`date -u +%4Y%2m%2d%2H%2M%2S` |
| 320 | fi |
| 321 | echo $sformatted > ${IMAGE_ROOTFS}/etc/timestamp |
| 322 | bbnote "rootfs_update_timestamp: set /etc/timestamp to $sformatted" |
| 323 | } |
| 324 | |
| 325 | # Prevent X from being started |
| 326 | rootfs_no_x_startup () { |
| 327 | if [ -f ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm ]; then |
| 328 | chmod a-x ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm |
| 329 | fi |
| 330 | } |
| 331 | |
| 332 | rootfs_trim_schemas () { |
| 333 | for schema in ${IMAGE_ROOTFS}/etc/gconf/schemas/*.schemas |
| 334 | do |
| 335 | # Need this in case no files exist |
| 336 | if [ -e $schema ]; then |
| 337 | oe-trim-schemas $schema > $schema.new |
| 338 | mv $schema.new $schema |
| 339 | fi |
| 340 | done |
| 341 | } |
| 342 | |
| 343 | rootfs_check_host_user_contaminated () { |
| 344 | contaminated="${S}/host-user-contaminated.txt" |
| 345 | HOST_USER_UID="$(PSEUDO_UNLOAD=1 id -u)" |
| 346 | HOST_USER_GID="$(PSEUDO_UNLOAD=1 id -g)" |
| 347 | |
| 348 | find "${IMAGE_ROOTFS}" -path "${IMAGE_ROOTFS}/home" -prune -o \ |
| 349 | -user "$HOST_USER_UID" -print -o -group "$HOST_USER_GID" -print >"$contaminated" |
| 350 | |
| 351 | sed -e "s,${IMAGE_ROOTFS},," $contaminated | while read line; do |
| 352 | bbwarn "Path in the rootfs is owned by the same user or group as the user running bitbake:" $line `ls -lan ${IMAGE_ROOTFS}/$line` |
| 353 | done |
| 354 | |
| 355 | if [ -s "$contaminated" ]; then |
| 356 | bbwarn "/etc/passwd:" `cat ${IMAGE_ROOTFS}/etc/passwd` |
| 357 | bbwarn "/etc/group:" `cat ${IMAGE_ROOTFS}/etc/group` |
| 358 | fi |
| 359 | } |
| 360 | |
| 361 | # Make any absolute links in a sysroot relative |
| 362 | rootfs_sysroot_relativelinks () { |
| 363 | sysroot-relativelinks.py ${SDK_OUTPUT}/${SDKTARGETSYSROOT} |
| 364 | } |
| 365 | |
| 366 | # Generated test data json file |
| 367 | python write_image_test_data() { |
| 368 | from oe.data import export2json |
| 369 | |
| 370 | deploy_dir = d.getVar('IMGDEPLOYDIR') |
| 371 | link_name = d.getVar('IMAGE_LINK_NAME') |
| 372 | testdata_name = os.path.join(deploy_dir, "%s.testdata.json" % d.getVar('IMAGE_NAME')) |
| 373 | |
| 374 | searchString = "%s/"%(d.getVar("TOPDIR")).replace("//","/") |
| 375 | export2json(d, testdata_name, searchString=searchString, replaceString="") |
| 376 | |
| 377 | if os.path.exists(testdata_name) and link_name: |
| 378 | testdata_link = os.path.join(deploy_dir, "%s.testdata.json" % link_name) |
| 379 | if testdata_link != testdata_name: |
| 380 | if os.path.lexists(testdata_link): |
| 381 | os.remove(testdata_link) |
| 382 | os.symlink(os.path.basename(testdata_name), testdata_link) |
| 383 | } |
| 384 | write_image_test_data[vardepsexclude] += "TOPDIR" |
| 385 | |
| 386 | # Check for unsatisfied recommendations (RRECOMMENDS) |
| 387 | python rootfs_log_check_recommends() { |
| 388 | log_path = d.expand("${T}/log.do_rootfs") |
| 389 | with open(log_path, 'r') as log: |
| 390 | for line in log: |
| 391 | if 'log_check' in line: |
| 392 | continue |
| 393 | |
| 394 | if 'unsatisfied recommendation for' in line: |
| 395 | bb.warn('[log_check] %s: %s' % (d.getVar('PN'), line)) |
| 396 | } |
| 397 | |
| 398 | # Perform any additional adjustments needed to make rootf binary reproducible |
| 399 | rootfs_reproducible () { |
| 400 | if [ "${REPRODUCIBLE_TIMESTAMP_ROOTFS}" != "" ]; then |
| 401 | # Convert UTC into %4Y%2m%2d%2H%2M%2S |
| 402 | sformatted=`date -u -d @${REPRODUCIBLE_TIMESTAMP_ROOTFS} +%4Y%2m%2d%2H%2M%2S` |
| 403 | echo $sformatted > ${IMAGE_ROOTFS}/etc/version |
| 404 | bbnote "rootfs_reproducible: set /etc/version to $sformatted" |
| 405 | |
| 406 | if [ -d ${IMAGE_ROOTFS}${sysconfdir}/gconf ]; then |
| 407 | find ${IMAGE_ROOTFS}${sysconfdir}/gconf -name '%gconf.xml' -print0 | xargs -0r \ |
| 408 | sed -i -e 's@\bmtime="[0-9][0-9]*"@mtime="'${REPRODUCIBLE_TIMESTAMP_ROOTFS}'"@g' |
| 409 | fi |
| 410 | fi |
| 411 | } |
| 412 | |
| 413 | # Perform a dumb check for unit existence, not its validity |
| 414 | python overlayfs_qa_check() { |
| 415 | from oe.overlayfs import mountUnitName |
| 416 | |
| 417 | overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT") or {} |
| 418 | imagepath = d.getVar("IMAGE_ROOTFS") |
| 419 | sysconfdir = d.getVar("sysconfdir") |
| 420 | searchpaths = [oe.path.join(imagepath, sysconfdir, "systemd", "system"), |
| 421 | oe.path.join(imagepath, d.getVar("systemd_system_unitdir"))] |
| 422 | fstabpath = oe.path.join(imagepath, sysconfdir, "fstab") |
| 423 | |
| 424 | if not any(os.path.exists(path) for path in [*searchpaths, fstabpath]): |
| 425 | return |
| 426 | |
| 427 | fstabDevices = [] |
| 428 | if os.path.isfile(fstabpath): |
| 429 | with open(fstabpath, 'r') as f: |
| 430 | for line in f: |
| 431 | if line[0] == '#': |
| 432 | continue |
| 433 | path = line.split(maxsplit=2) |
| 434 | if len(path) > 2: |
| 435 | fstabDevices.append(path[1]) |
| 436 | |
| 437 | allUnitExist = True; |
| 438 | for mountPoint in overlayMountPoints: |
| 439 | qaSkip = (d.getVarFlag("OVERLAYFS_QA_SKIP", mountPoint) or "").split() |
| 440 | if "mount-configured" in qaSkip: |
| 441 | continue |
| 442 | |
| 443 | mountPath = d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint) |
| 444 | if mountPath in fstabDevices: |
| 445 | continue |
| 446 | |
| 447 | mountUnit = mountUnitName(mountPath) |
| 448 | if any(os.path.isfile(oe.path.join(dirpath, mountUnit)) |
| 449 | for dirpath in searchpaths): |
| 450 | continue |
| 451 | |
| 452 | bb.warn(f'Mount path {mountPath} not found in fstab and unit ' |
| 453 | f'{mountUnit} not found in systemd unit directories.') |
| 454 | bb.warn(f'Skip this check by setting OVERLAYFS_QA_SKIP[{mountPoint}] = ' |
| 455 | '"mount-configured"') |
| 456 | allUnitExist = False; |
| 457 | |
| 458 | if not allUnitExist: |
| 459 | bb.fatal('Not all mount paths and units are installed in the image') |
| 460 | } |
| 461 | |
| 462 | python overlayfs_postprocess() { |
| 463 | import shutil |
| 464 | |
| 465 | # install helper script |
| 466 | helperScriptName = "overlayfs-create-dirs.sh" |
| 467 | helperScriptSource = oe.path.join(d.getVar("COREBASE"), "meta/files", helperScriptName) |
| 468 | helperScriptDest = oe.path.join(d.getVar("IMAGE_ROOTFS"), "/usr/sbin/", helperScriptName) |
| 469 | shutil.copyfile(helperScriptSource, helperScriptDest) |
| 470 | os.chmod(helperScriptDest, 0o755) |
| 471 | } |