diff options
Diffstat (limited to 'meta/classes/rootfs-postcommands.bbclass')
-rw-r--r-- | meta/classes/rootfs-postcommands.bbclass | 75 |
1 files changed, 59 insertions, 16 deletions
diff --git a/meta/classes/rootfs-postcommands.bbclass b/meta/classes/rootfs-postcommands.bbclass index c43b9a9823..7b92df69c5 100644 --- a/meta/classes/rootfs-postcommands.bbclass +++ b/meta/classes/rootfs-postcommands.bbclass @@ -1,6 +1,6 @@ # Zap the root password if debug-tweaks feature is not enabled -ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-password' ], "", "zap_empty_root_password ; ",d)}' +ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-password' ], "", "zap_empty_root_password; ",d)}' # Allow dropbear/openssh to accept logins from accounts with an empty password string if debug-tweaks or allow-empty-password is enabled ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'allow-empty-password' ], "ssh_allow_empty_password; ", "",d)}' @@ -12,7 +12,7 @@ ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'deb ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'post-install-logging' ], "postinst_enable_logging; ", "",d)}' # Create /etc/timestamp during image construction to give a reasonably sane default time setting -ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp ; " +ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp; " # Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}' @@ -21,12 +21,12 @@ ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only # otherwise kernel or initramfs end up mounting the rootfs read/write # (the default) if supported by the underlying storage. # -# We do this with _append because the default value might get set later with ?= +# We do this with :append because the default value might get set later with ?= # and we don't want to disable such a default that by setting a value here. -APPEND_append = '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", " ro", "", d)}' +APPEND:append = '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", " ro", "", d)}' # Generates test data file with data store variables expanded in json format -ROOTFS_POSTPROCESS_COMMAND += "write_image_test_data ; " +ROOTFS_POSTPROCESS_COMMAND += "write_image_test_data; " # Write manifest IMAGE_MANIFEST = "${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.manifest" @@ -34,11 +34,15 @@ ROOTFS_POSTUNINSTALL_COMMAND =+ "write_image_manifest ; " # Set default postinst log file POSTINST_LOGFILE ?= "${localstatedir}/log/postinstall.log" # Set default target for systemd images -SYSTEMD_DEFAULT_TARGET ?= '${@bb.utils.contains("IMAGE_FEATURES", "x11-base", "graphical.target", "multi-user.target", d)}' +SYSTEMD_DEFAULT_TARGET ?= '${@bb.utils.contains_any("IMAGE_FEATURES", [ "x11-base", "weston" ], "graphical.target", "multi-user.target", d)}' ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "set_systemd_default_target; systemd_create_users;", "", d)}' ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile;' +ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "overlayfs", "overlayfs_qa_check;", "", d)}' + +inherit image-artifact-names + # Sort the user and group entries in /etc by ID in order to make the content # deterministic. Package installs are not deterministic, causing the ordering # of entries to change between builds. In case that this isn't desired, @@ -48,7 +52,7 @@ ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile;' # the numeric IDs of dynamically created entries remain stable. # # We want this to run as late as possible, in particular after -# systemd_sysusers_create and set_user_group. Using _append is not +# systemd_sysusers_create and set_user_group. Using :append is not # enough for that, set_user_group is added that way and would end # up running after us. SORT_PASSWD_POSTPROCESS_COMMAND ??= " sort_passwd; " @@ -58,7 +62,7 @@ python () { } systemd_create_users () { - for conffile in ${IMAGE_ROOTFS}/usr/lib/sysusers.d/systemd.conf ${IMAGE_ROOTFS}/usr/lib/sysusers.d/systemd-remote.conf; do + for conffile in ${IMAGE_ROOTFS}/usr/lib/sysusers.d/*.conf; do [ -e $conffile ] || continue grep -v "^#" $conffile | sed -e '/^$/d' | while read type name id comment; do if [ "$type" = "u" ]; then @@ -74,12 +78,8 @@ systemd_create_users () { eval groupadd --root ${IMAGE_ROOTFS} $groupadd_params || true elif [ "$type" = "m" ]; then group=$id - if [ ! `grep -q "^${group}:" ${IMAGE_ROOTFS}${sysconfdir}/group` ]; then - eval groupadd --root ${IMAGE_ROOTFS} --system $group - fi - if [ ! `grep -q "^${name}:" ${IMAGE_ROOTFS}${sysconfdir}/passwd` ]; then - eval useradd --root ${IMAGE_ROOTFS} --shell /sbin/nologin --system $name - fi + eval groupadd --root ${IMAGE_ROOTFS} --system $group || true + eval useradd --root ${IMAGE_ROOTFS} --shell /sbin/nologin --system $name --no-user-group || true eval usermod --root ${IMAGE_ROOTFS} -a -G $group $name fi done @@ -214,8 +214,8 @@ postinst_enable_logging () { # Modify systemd default target # set_systemd_default_target () { - if [ -d ${IMAGE_ROOTFS}${sysconfdir}/systemd/system -a -e ${IMAGE_ROOTFS}${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ]; then - ln -sf ${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ${IMAGE_ROOTFS}${sysconfdir}/systemd/system/default.target + if [ -d ${IMAGE_ROOTFS}${sysconfdir}/systemd/system -a -e ${IMAGE_ROOTFS}${systemd_system_unitdir}/${SYSTEMD_DEFAULT_TARGET} ]; then + ln -sf ${systemd_system_unitdir}/${SYSTEMD_DEFAULT_TARGET} ${IMAGE_ROOTFS}${sysconfdir}/systemd/system/default.target fi } @@ -371,3 +371,46 @@ rootfs_reproducible () { fi fi } + +# Perform a dumb check for unit existence, not its validity +python overlayfs_qa_check() { + from oe.overlayfs import mountUnitName + + overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT") or {} + imagepath = d.getVar("IMAGE_ROOTFS") + sysconfdir = d.getVar("sysconfdir") + searchpaths = [oe.path.join(imagepath, sysconfdir, "systemd", "system"), + oe.path.join(imagepath, d.getVar("systemd_system_unitdir"))] + fstabpath = oe.path.join(imagepath, sysconfdir, "fstab") + + if not any(os.path.exists(path) for path in [*searchpaths, fstabpath]): + return + + fstabDevices = [] + if os.path.isfile(fstabpath): + with open(fstabpath, 'r') as f: + for line in f: + if line[0] == '#': + continue + path = line.split(maxsplit=2) + if len(path) > 2: + fstabDevices.append(path[1]) + + allUnitExist = True; + for mountPoint in overlayMountPoints: + mountPath = d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint) + if mountPath in fstabDevices: + continue + + mountUnit = mountUnitName(mountPath) + if any(os.path.isfile(oe.path.join(dirpath, mountUnit)) + for dirpath in searchpaths): + continue + + bb.warn('Mount path %s not found in fstat and unit %s not found ' + 'in systemd unit directories' % (mountPath, mountUnit)) + allUnitExist = False; + + if not allUnitExist: + bb.fatal('Not all mount paths and units are installed in the image') +} |