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