blob: c5746eba13aac5a9ce340589520bbd4d01ef66f8 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001
2# Zap the root password if debug-tweaks feature is not enabled
Andrew Geissler635e0e42020-08-21 15:58:33 -05003ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-password' ], "", "zap_empty_root_password; ",d)}'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05004
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005# Allow dropbear/openssh to accept logins from accounts with an empty password string if debug-tweaks or allow-empty-password is enabled
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'allow-empty-password' ], "ssh_allow_empty_password; ", "",d)}'
7
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08008# Allow dropbear/openssh to accept root logins if debug-tweaks or allow-root-login is enabled
9ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'allow-root-login' ], "ssh_allow_root_login; ", "",d)}'
10
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011# Enable postinst logging if debug-tweaks is enabled
12ROOTFS_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 Geissler635e0e42020-08-21 15:58:33 -050015ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp; "
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050016
17# Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled
18ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}'
19
Brad Bishopd7bf8c12018-02-25 22:55:05 -050020# 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#
24# We do this with _append because the default value might get set later with ?=
25# and we don't want to disable such a default that by setting a value here.
Patrick Williams213cb262021-08-07 19:21:33 -050026APPEND:append = '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", " ro", "", d)}'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028# Generates test data file with data store variables expanded in json format
Andrew Geissler635e0e42020-08-21 15:58:33 -050029ROOTFS_POSTPROCESS_COMMAND += "write_image_test_data; "
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050031# Write manifest
Brad Bishop00e122a2019-10-05 11:10:57 -040032IMAGE_MANIFEST = "${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.manifest"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050033ROOTFS_POSTUNINSTALL_COMMAND =+ "write_image_manifest ; "
34# Set default postinst log file
35POSTINST_LOGFILE ?= "${localstatedir}/log/postinstall.log"
36# Set default target for systemd images
Andrew Geissler95ac1b82021-03-31 14:34:31 -050037SYSTEMD_DEFAULT_TARGET ?= '${@bb.utils.contains_any("IMAGE_FEATURES", [ "x11-base", "weston" ], "graphical.target", "multi-user.target", d)}'
Patrick Williamsc0f7c042017-02-23 20:41:17 -060038ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "set_systemd_default_target; systemd_create_users;", "", d)}'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050039
40ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile;'
41
Patrick Williams0ca19cc2021-08-16 14:03:13 -050042ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "overlayfs", "overlayfs_qa_check;", "", d)}'
43
Andrew Geisslerc9f78652020-09-18 14:11:35 -050044inherit image-artifact-names
45
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046# 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
55# systemd_sysusers_create and set_user_group. Using _append is not
56# enough for that, set_user_group is added that way and would end
57# up running after us.
58SORT_PASSWD_POSTPROCESS_COMMAND ??= " sort_passwd; "
59python () {
60 d.appendVar('ROOTFS_POSTPROCESS_COMMAND', '${SORT_PASSWD_POSTPROCESS_COMMAND}')
Brad Bishop316dfdd2018-06-25 12:45:53 -040061 d.appendVar('ROOTFS_POSTPROCESS_COMMAND', 'rootfs_reproducible;')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050062}
63
Patrick Williamsc0f7c042017-02-23 20:41:17 -060064systemd_create_users () {
65 for conffile in ${IMAGE_ROOTFS}/usr/lib/sysusers.d/systemd.conf ${IMAGE_ROOTFS}/usr/lib/sysusers.d/systemd-remote.conf; do
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
81 if [ ! `grep -q "^${group}:" ${IMAGE_ROOTFS}${sysconfdir}/group` ]; then
82 eval groupadd --root ${IMAGE_ROOTFS} --system $group
83 fi
84 if [ ! `grep -q "^${name}:" ${IMAGE_ROOTFS}${sysconfdir}/passwd` ]; then
85 eval useradd --root ${IMAGE_ROOTFS} --shell /sbin/nologin --system $name
86 fi
87 eval usermod --root ${IMAGE_ROOTFS} -a -G $group $name
88 fi
89 done
90 done
91}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050092
93#
94# A hook function to support read-only-rootfs IMAGE_FEATURES
95#
96read_only_rootfs_hook () {
97 # Tweak the mount option and fs_passno for rootfs in fstab
Brad Bishopd7bf8c12018-02-25 22:55:05 -050098 if [ -f ${IMAGE_ROOTFS}/etc/fstab ]; then
99 sed -i -e '/^[#[:space:]]*\/dev\/root/{s/defaults/ro/;s/\([[:space:]]*[[:digit:]]\)\([[:space:]]*\)[[:digit:]]$/\1\20/}' ${IMAGE_ROOTFS}/etc/fstab
100 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500101
Brad Bishop79641f22019-09-10 07:20:22 -0400102 # Tweak the "mount -o remount,rw /" command in busybox-inittab inittab
103 if [ -f ${IMAGE_ROOTFS}/etc/inittab ]; then
104 sed -i 's|/bin/mount -o remount,rw /|/bin/mount -o remount,ro /|' ${IMAGE_ROOTFS}/etc/inittab
105 fi
106
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500107 # If we're using openssh and the /etc/ssh directory has no pre-generated keys,
108 # we should configure openssh to use the configuration file /etc/ssh/sshd_config_readonly
109 # and the keys under /var/run/ssh.
110 if [ -d ${IMAGE_ROOTFS}/etc/ssh ]; then
111 if [ -e ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500112 echo "SYSCONFDIR=\${SYSCONFDIR:-/etc/ssh}" >> ${IMAGE_ROOTFS}/etc/default/ssh
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500113 echo "SSHD_OPTS=" >> ${IMAGE_ROOTFS}/etc/default/ssh
114 else
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500115 echo "SYSCONFDIR=\${SYSCONFDIR:-/var/run/ssh}" >> ${IMAGE_ROOTFS}/etc/default/ssh
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500116 echo "SSHD_OPTS='-f /etc/ssh/sshd_config_readonly'" >> ${IMAGE_ROOTFS}/etc/default/ssh
117 fi
118 fi
119
120 # Also tweak the key location for dropbear in the same way.
121 if [ -d ${IMAGE_ROOTFS}/etc/dropbear ]; then
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700122 if [ ! -e ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key ]; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500123 echo "DROPBEAR_RSAKEY_DIR=/var/lib/dropbear" >> ${IMAGE_ROOTFS}/etc/default/dropbear
124 fi
125 fi
126
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500127 if ${@bb.utils.contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then
128 # Change the value of ROOTFS_READ_ONLY in /etc/default/rcS to yes
129 if [ -e ${IMAGE_ROOTFS}/etc/default/rcS ]; then
130 sed -i 's/ROOTFS_READ_ONLY=no/ROOTFS_READ_ONLY=yes/' ${IMAGE_ROOTFS}/etc/default/rcS
131 fi
132 # Run populate-volatile.sh at rootfs time to set up basic files
133 # and directories to support read-only rootfs.
134 if [ -x ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then
135 ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
136 fi
137 fi
Brad Bishopc342db32019-05-15 21:57:59 -0400138
139 if ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then
140 # Create machine-id
141 # 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
142 touch ${IMAGE_ROOTFS}${sysconfdir}/machine-id
143 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500144}
145
146#
147# This function is intended to disallow empty root password if 'debug-tweaks' is not in IMAGE_FEATURES.
148#
149zap_empty_root_password () {
150 if [ -e ${IMAGE_ROOTFS}/etc/shadow ]; then
151 sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/shadow
152 fi
153 if [ -e ${IMAGE_ROOTFS}/etc/passwd ]; then
154 sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/passwd
155 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500156}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500157
158#
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800159# allow dropbear/openssh to accept logins from accounts with an empty password string
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500160#
161ssh_allow_empty_password () {
162 for config in sshd_config sshd_config_readonly; do
163 if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/$config ]; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500164 sed -i 's/^[#[:space:]]*PermitEmptyPasswords.*/PermitEmptyPasswords yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/$config
165 fi
166 done
167
168 if [ -e ${IMAGE_ROOTFS}${sbindir}/dropbear ] ; then
169 if grep -q DROPBEAR_EXTRA_ARGS ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear 2>/dev/null ; then
170 if ! grep -q "DROPBEAR_EXTRA_ARGS=.*-B" ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear ; then
171 sed -i 's/^DROPBEAR_EXTRA_ARGS="*\([^"]*\)"*/DROPBEAR_EXTRA_ARGS="\1 -B"/' ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear
172 fi
173 else
174 printf '\nDROPBEAR_EXTRA_ARGS="-B"\n' >> ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear
175 fi
176 fi
177
178 if [ -d ${IMAGE_ROOTFS}${sysconfdir}/pam.d ] ; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500179 for f in `find ${IMAGE_ROOTFS}${sysconfdir}/pam.d/* -type f -exec test -e {} \; -print`
180 do
181 sed -i 's/nullok_secure/nullok/' $f
182 done
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500183 fi
184}
185
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800186#
187# allow dropbear/openssh to accept root logins
188#
189ssh_allow_root_login () {
190 for config in sshd_config sshd_config_readonly; do
191 if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/$config ]; then
192 sed -i 's/^[#[:space:]]*PermitRootLogin.*/PermitRootLogin yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/$config
193 fi
194 done
195
196 if [ -e ${IMAGE_ROOTFS}${sbindir}/dropbear ] ; then
197 if grep -q DROPBEAR_EXTRA_ARGS ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear 2>/dev/null ; then
198 sed -i '/^DROPBEAR_EXTRA_ARGS=/ s/-w//' ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear
199 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500200 fi
201}
202
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500203python sort_passwd () {
204 import rootfspostcommands
205 rootfspostcommands.sort_passwd(d.expand('${IMAGE_ROOTFS}${sysconfdir}'))
206}
207
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500208#
209# Enable postinst logging if debug-tweaks is enabled
210#
211postinst_enable_logging () {
212 mkdir -p ${IMAGE_ROOTFS}${sysconfdir}/default
213 echo "POSTINST_LOGGING=1" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
214 echo "LOGFILE=${POSTINST_LOGFILE}" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
215}
216
217#
218# Modify systemd default target
219#
220set_systemd_default_target () {
221 if [ -d ${IMAGE_ROOTFS}${sysconfdir}/systemd/system -a -e ${IMAGE_ROOTFS}${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ]; then
222 ln -sf ${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ${IMAGE_ROOTFS}${sysconfdir}/systemd/system/default.target
223 fi
224}
225
226# If /var/volatile is not empty, we have seen problems where programs such as the
227# journal make assumptions based on the contents of /var/volatile. The journal
228# would then write to /var/volatile before it was mounted, thus hiding the
229# items previously written.
230#
231# This change is to attempt to fix those types of issues in a way that doesn't
232# affect users that may not be using /var/volatile.
233empty_var_volatile () {
234 if [ -e ${IMAGE_ROOTFS}/etc/fstab ]; then
235 match=`awk '$1 !~ "#" && $2 ~ /\/var\/volatile/{print $2}' ${IMAGE_ROOTFS}/etc/fstab 2> /dev/null`
236 if [ -n "$match" ]; then
237 find ${IMAGE_ROOTFS}/var/volatile -mindepth 1 -delete
238 fi
239 fi
240}
241
242# Turn any symbolic /sbin/init link into a file
243remove_init_link () {
244 if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
245 LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init`
246 rm ${IMAGE_ROOTFS}/sbin/init
247 cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init
248 fi
249}
250
251make_zimage_symlink_relative () {
252 if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then
253 (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done)
254 fi
255}
256
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500257python write_image_manifest () {
258 from oe.rootfs import image_list_installed_packages
259 from oe.utils import format_pkg_list
260
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500261 deploy_dir = d.getVar('IMGDEPLOYDIR')
262 link_name = d.getVar('IMAGE_LINK_NAME')
263 manifest_name = d.getVar('IMAGE_MANIFEST')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500264
265 if not manifest_name:
266 return
267
268 pkgs = image_list_installed_packages(d)
269 with open(manifest_name, 'w+') as image_manifest:
270 image_manifest.write(format_pkg_list(pkgs, "ver"))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500271
Brad Bishop96ff1982019-08-19 13:50:42 -0400272 if os.path.exists(manifest_name) and link_name:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500273 manifest_link = deploy_dir + "/" + link_name + ".manifest"
274 if os.path.lexists(manifest_link):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500275 os.remove(manifest_link)
276 os.symlink(os.path.basename(manifest_name), manifest_link)
277}
278
Brad Bishop316dfdd2018-06-25 12:45:53 -0400279# Can be used to create /etc/timestamp during image construction to give a reasonably
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500280# sane default time setting
281rootfs_update_timestamp () {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400282 if [ "${REPRODUCIBLE_TIMESTAMP_ROOTFS}" != "" ]; then
283 # Convert UTC into %4Y%2m%2d%2H%2M%2S
284 sformatted=`date -u -d @${REPRODUCIBLE_TIMESTAMP_ROOTFS} +%4Y%2m%2d%2H%2M%2S`
285 else
286 sformatted=`date -u +%4Y%2m%2d%2H%2M%2S`
287 fi
288 echo $sformatted > ${IMAGE_ROOTFS}/etc/timestamp
289 bbnote "rootfs_update_timestamp: set /etc/timestamp to $sformatted"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500290}
291
292# Prevent X from being started
293rootfs_no_x_startup () {
294 if [ -f ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm ]; then
295 chmod a-x ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm
296 fi
297}
298
299rootfs_trim_schemas () {
300 for schema in ${IMAGE_ROOTFS}/etc/gconf/schemas/*.schemas
301 do
302 # Need this in case no files exist
303 if [ -e $schema ]; then
304 oe-trim-schemas $schema > $schema.new
305 mv $schema.new $schema
306 fi
307 done
308}
309
310rootfs_check_host_user_contaminated () {
311 contaminated="${WORKDIR}/host-user-contaminated.txt"
312 HOST_USER_UID="$(PSEUDO_UNLOAD=1 id -u)"
313 HOST_USER_GID="$(PSEUDO_UNLOAD=1 id -g)"
314
Andrew Geissler475cb722020-07-10 16:00:51 -0500315 find "${IMAGE_ROOTFS}" -path "${IMAGE_ROOTFS}/home" -prune -o \
316 -user "$HOST_USER_UID" -print -o -group "$HOST_USER_GID" -print >"$contaminated"
317
318 sed -e "s,${IMAGE_ROOTFS},," $contaminated | while read line; do
319 bbwarn "Path in the rootfs is owned by the same user or group as the user running bitbake:" $line `ls -lan ${IMAGE_ROOTFS}/$line`
320 done
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500321
322 if [ -s "$contaminated" ]; then
Andrew Geissler475cb722020-07-10 16:00:51 -0500323 bbwarn "/etc/passwd:" `cat ${IMAGE_ROOTFS}/etc/passwd`
324 bbwarn "/etc/group:" `cat ${IMAGE_ROOTFS}/etc/group`
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500325 fi
326}
327
328# Make any absolute links in a sysroot relative
329rootfs_sysroot_relativelinks () {
330 sysroot-relativelinks.py ${SDK_OUTPUT}/${SDKTARGETSYSROOT}
331}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500332
333# Generated test data json file
334python write_image_test_data() {
335 from oe.data import export2json
336
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800337 deploy_dir = d.getVar('IMGDEPLOYDIR')
338 link_name = d.getVar('IMAGE_LINK_NAME')
339 testdata_name = os.path.join(deploy_dir, "%s.testdata.json" % d.getVar('IMAGE_NAME'))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500340
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500341 searchString = "%s/"%(d.getVar("TOPDIR")).replace("//","/")
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800342 export2json(d, testdata_name, searchString=searchString, replaceString="")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500343
Brad Bishop96ff1982019-08-19 13:50:42 -0400344 if os.path.exists(testdata_name) and link_name:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800345 testdata_link = os.path.join(deploy_dir, "%s.testdata.json" % link_name)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500346 if os.path.lexists(testdata_link):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800347 os.remove(testdata_link)
348 os.symlink(os.path.basename(testdata_name), testdata_link)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500349}
350write_image_test_data[vardepsexclude] += "TOPDIR"
351
352# Check for unsatisfied recommendations (RRECOMMENDS)
353python rootfs_log_check_recommends() {
354 log_path = d.expand("${T}/log.do_rootfs")
355 with open(log_path, 'r') as log:
356 for line in log:
357 if 'log_check' in line:
358 continue
359
360 if 'unsatisfied recommendation for' in line:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500361 bb.warn('[log_check] %s: %s' % (d.getVar('PN'), line))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500362}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400363
364# Perform any additional adjustments needed to make rootf binary reproducible
365rootfs_reproducible () {
366 if [ "${REPRODUCIBLE_TIMESTAMP_ROOTFS}" != "" ]; then
367 # Convert UTC into %4Y%2m%2d%2H%2M%2S
368 sformatted=`date -u -d @${REPRODUCIBLE_TIMESTAMP_ROOTFS} +%4Y%2m%2d%2H%2M%2S`
369 echo $sformatted > ${IMAGE_ROOTFS}/etc/version
370 bbnote "rootfs_reproducible: set /etc/version to $sformatted"
371
Brad Bishopa34c0302019-09-23 22:34:48 -0400372 if [ -d ${IMAGE_ROOTFS}${sysconfdir}/gconf ]; then
373 find ${IMAGE_ROOTFS}${sysconfdir}/gconf -name '%gconf.xml' -print0 | xargs -0r \
374 sed -i -e 's@\bmtime="[0-9][0-9]*"@mtime="'${REPRODUCIBLE_TIMESTAMP_ROOTFS}'"@g'
375 fi
Brad Bishop316dfdd2018-06-25 12:45:53 -0400376 fi
377}
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500378
379python overlayfs_qa_check() {
380 from oe.overlayfs import mountUnitName
381
382 # this is a dumb check for unit existence, not its validity
383 overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT")
384 imagepath = d.getVar("IMAGE_ROOTFS")
385 searchpaths = [oe.path.join(imagepath, d.getVar("sysconfdir"), "systemd", "system"),
386 oe.path.join(imagepath, d.getVar("systemd_system_unitdir"))]
387
388 allUnitExist = True;
389 for mountPoint in overlayMountPoints:
390 path = d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint)
391 unit = mountUnitName(path)
392
393 if not any(os.path.isfile(oe.path.join(dirpath, unit))
394 for dirpath in searchpaths):
395 bb.warn('Unit name %s not found in systemd unit directories' % unit)
396 allUnitExist = False;
397
398 if not allUnitExist:
399 bb.fatal('Not all mount units are installed by the BSP')
400}