summaryrefslogtreecommitdiffstats
path: root/meta/classes/image.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-05 17:52:06 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-06 15:27:33 +0000
commit0051510ae3e8f5d4dcd1f074bba1bd9c7e2362d9 (patch)
treeb0b2de5246440fe2552e45b172741b010d06c467 /meta/classes/image.bbclass
parent3428eddcd1c433c52f1886598479c5970dd400d5 (diff)
downloadpoky-0051510ae3e8f5d4dcd1f074bba1bd9c7e2362d9.tar.gz
image/rootfs-postcommands: Separate out post rootfs commands to separate class
Reading image.bbclass is a little difficult as it has many post rootfs helper functions and its hard to separate those from the core contents of the rootfs/image code. Moving it to a separate class would be one way of making it clearer what these functions are. There are some comment layout improvements but no code changes. (From OE-Core rev: df4cb51c8e60fa46d4d15be8da3d84287ff08ae7) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/image.bbclass')
-rw-r--r--meta/classes/image.bbclass240
1 files changed, 1 insertions, 239 deletions
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 8242c568a8..da64cadd3a 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -191,31 +191,7 @@ inherit ${IMAGE_CLASSES}
191 191
192IMAGE_POSTPROCESS_COMMAND ?= "" 192IMAGE_POSTPROCESS_COMMAND ?= ""
193 193
194# Zap the root password if debug-tweaks feature is not enabled
195ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-password' ], "", "zap_empty_root_password ; ",d)}'
196 194
197# Allow dropbear/openssh to accept logins from accounts with an empty password string if debug-tweaks is enabled
198ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'allow-empty-password' ], "ssh_allow_empty_password; ", "",d)}'
199
200# Enable postinst logging if debug-tweaks is enabled
201ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'post-install-logging' ], "postinst_enable_logging; ", "",d)}'
202
203# Create /etc/timestamp during image construction to give a reasonably sane default time setting
204ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp ; "
205
206# Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled
207ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}'
208
209# Write manifest
210IMAGE_MANIFEST = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.manifest"
211ROOTFS_POSTUNINSTALL_COMMAND =+ "write_image_manifest ; "
212# Set default postinst log file
213POSTINST_LOGFILE ?= "${localstatedir}/log/postinstall.log"
214# Set default target for systemd images
215SYSTEMD_DEFAULT_TARGET ?= '${@bb.utils.contains("IMAGE_FEATURES", "x11-base", "graphical.target", "multi-user.target", d)}'
216ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "set_systemd_default_target; ", "", d)}'
217
218ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile;'
219 195
220# some default locales 196# some default locales
221IMAGE_LINGUAS ?= "de-de fr-fr en-gb" 197IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
@@ -233,67 +209,7 @@ do_rootfs[cleandirs] += "${S}"
233# task, so that we have a single fakeroot context for the whole process. 209# task, so that we have a single fakeroot context for the whole process.
234do_rootfs[umask] = "022" 210do_rootfs[umask] = "022"
235 211
236# A hook function to support read-only-rootfs IMAGE_FEATURES 212inherit rootfs-postcommands
237read_only_rootfs_hook () {
238 # Tweak the mount option and fs_passno for rootfs in fstab
239 sed -i -e '/^[#[:space:]]*\/dev\/root/{s/defaults/ro/;s/\([[:space:]]*[[:digit:]]\)\([[:space:]]*\)[[:digit:]]$/\1\20/}' ${IMAGE_ROOTFS}/etc/fstab
240
241 # If we're using openssh and the /etc/ssh directory has no pre-generated keys,
242 # we should configure openssh to use the configuration file /etc/ssh/sshd_config_readonly
243 # and the keys under /var/run/ssh.
244 if [ -d ${IMAGE_ROOTFS}/etc/ssh ]; then
245 if [ -e ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key ]; then
246 echo "SYSCONFDIR=/etc/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh
247 echo "SSHD_OPTS=" >> ${IMAGE_ROOTFS}/etc/default/ssh
248 else
249 echo "SYSCONFDIR=/var/run/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh
250 echo "SSHD_OPTS='-f /etc/ssh/sshd_config_readonly'" >> ${IMAGE_ROOTFS}/etc/default/ssh
251 fi
252 fi
253
254 # Also tweak the key location for dropbear in the same way.
255 if [ -d ${IMAGE_ROOTFS}/etc/dropbear ]; then
256 if [ -e ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key ]; then
257 echo "DROPBEAR_RSAKEY_DIR=/etc/dropbear" >> ${IMAGE_ROOTFS}/etc/default/dropbear
258 else
259 echo "DROPBEAR_RSAKEY_DIR=/var/lib/dropbear" >> ${IMAGE_ROOTFS}/etc/default/dropbear
260 fi
261 fi
262
263
264 if ${@bb.utils.contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then
265 # Change the value of ROOTFS_READ_ONLY in /etc/default/rcS to yes
266 if [ -e ${IMAGE_ROOTFS}/etc/default/rcS ]; then
267 sed -i 's/ROOTFS_READ_ONLY=no/ROOTFS_READ_ONLY=yes/' ${IMAGE_ROOTFS}/etc/default/rcS
268 fi
269 # Run populate-volatile.sh at rootfs time to set up basic files
270 # and directories to support read-only rootfs.
271 if [ -x ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then
272 ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
273 fi
274 fi
275
276 if ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then
277 # Update user database files so that services don't fail for a read-only systemd system
278 for conffile in ${IMAGE_ROOTFS}/usr/lib/sysusers.d/systemd.conf ${IMAGE_ROOTFS}/usr/lib/sysusers.d/systemd-remote.conf; do
279 [ -e $conffile ] || continue
280 grep -v "^#" $conffile | sed -e '/^$/d' | while read type name id comment; do
281 if [ "$type" = "u" ]; then
282 useradd_params=""
283 [ "$id" != "-" ] && useradd_params="$useradd_params --uid $id"
284 [ "$comment" != "-" ] && useradd_params="$useradd_params --comment $comment"
285 useradd_params="$useradd_params --system $name"
286 eval useradd --root ${IMAGE_ROOTFS} $useradd_params || true
287 elif [ "$type" = "g" ]; then
288 groupadd_params=""
289 [ "$id" != "-" ] && groupadd_params="$groupadd_params --gid $id"
290 groupadd_params="$groupadd_params --system $name"
291 eval groupadd --root ${IMAGE_ROOTFS} $groupadd_params || true
292 fi
293 done
294 done
295 fi
296}
297 213
298PACKAGE_EXCLUDE ??= "" 214PACKAGE_EXCLUDE ??= ""
299PACKAGE_EXCLUDE[type] = "list" 215PACKAGE_EXCLUDE[type] = "list"
@@ -346,164 +262,10 @@ fakeroot python do_rootfs () {
346 create_image(d) 262 create_image(d)
347} 263}
348 264
349insert_feed_uris () {
350
351 echo "Building feeds for [${DISTRO}].."
352
353 for line in ${FEED_URIS}
354 do
355 # strip leading and trailing spaces/tabs, then split into name and uri
356 line_clean="`echo "$line"|sed 's/^[ \t]*//;s/[ \t]*$//'`"
357 feed_name="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\1/p'`"
358 feed_uri="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\2/p'`"
359
360 echo "Added $feed_name feed with URL $feed_uri"
361
362 # insert new feed-sources
363 echo "src/gz $feed_name $feed_uri" >> ${IMAGE_ROOTFS}/etc/opkg/${feed_name}-feed.conf
364 done
365}
366
367MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|" 265MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|"
368MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py" 266MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py"
369MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib" 267MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib"
370 268
371# This function is intended to disallow empty root password if 'debug-tweaks' is not in IMAGE_FEATURES.
372zap_empty_root_password () {
373 if [ -e ${IMAGE_ROOTFS}/etc/shadow ]; then
374 sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/shadow
375 fi
376 if [ -e ${IMAGE_ROOTFS}/etc/passwd ]; then
377 sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/passwd
378 fi
379}
380
381# allow dropbear/openssh to accept root logins and logins from accounts with an empty password string
382ssh_allow_empty_password () {
383 if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
384 sed -i 's/^[#[:space:]]*PermitRootLogin.*/PermitRootLogin yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config
385 sed -i 's/^[#[:space:]]*PermitEmptyPasswords.*/PermitEmptyPasswords yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config
386 fi
387
388 if [ -e ${IMAGE_ROOTFS}${sbindir}/dropbear ] ; then
389 if grep -q DROPBEAR_EXTRA_ARGS ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear 2>/dev/null ; then
390 if ! grep -q "DROPBEAR_EXTRA_ARGS=.*-B" ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear ; then
391 sed -i 's/^DROPBEAR_EXTRA_ARGS="*\([^"]*\)"*/DROPBEAR_EXTRA_ARGS="\1 -B"/' ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear
392 fi
393 else
394 printf '\nDROPBEAR_EXTRA_ARGS="-B"\n' >> ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear
395 fi
396 fi
397
398 if [ -d ${IMAGE_ROOTFS}${sysconfdir}/pam.d ] ; then
399 sed -i 's/nullok_secure/nullok/' ${IMAGE_ROOTFS}${sysconfdir}/pam.d/*
400 fi
401}
402
403# Disable DNS lookups, the SSH_DISABLE_DNS_LOOKUP can be overridden to allow
404# distros to choose not to take this change
405SSH_DISABLE_DNS_LOOKUP ?= " ssh_disable_dns_lookup ; "
406ROOTFS_POSTPROCESS_COMMAND_append_qemuall = "${SSH_DISABLE_DNS_LOOKUP}"
407ssh_disable_dns_lookup () {
408 if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
409 sed -i -e 's:#UseDNS yes:UseDNS no:' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config
410 fi
411}
412
413# Enable postinst logging if debug-tweaks is enabled
414postinst_enable_logging () {
415 mkdir -p ${IMAGE_ROOTFS}${sysconfdir}/default
416 echo "POSTINST_LOGGING=1" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
417 echo "LOGFILE=${POSTINST_LOGFILE}" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
418}
419
420# Modify systemd default target
421set_systemd_default_target () {
422 if [ -d ${IMAGE_ROOTFS}${sysconfdir}/systemd/system -a -e ${IMAGE_ROOTFS}${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ]; then
423 ln -sf ${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ${IMAGE_ROOTFS}${sysconfdir}/systemd/system/default.target
424 fi
425}
426
427# If /var/volatile is not empty, we have seen problems where programs such as the
428# journal make assumptions based on the contents of /var/volatile. The journal
429# would then write to /var/volatile before it was mounted, thus hiding the
430# items previously written.
431#
432# This change is to attempt to fix those types of issues in a way that doesn't
433# affect users that may not be using /var/volatile.
434empty_var_volatile () {
435 if [ -e ${IMAGE_ROOTFS}/etc/fstab ]; then
436 match=`awk '$1 !~ "#" && $2 ~ /\/var\/volatile/{print $2}' ${IMAGE_ROOTFS}/etc/fstab 2> /dev/null`
437 if [ -n "$match" ]; then
438 find ${IMAGE_ROOTFS}/var/volatile -mindepth 1 -delete
439 fi
440 fi
441}
442
443# Turn any symbolic /sbin/init link into a file
444remove_init_link () {
445 if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
446 LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init`
447 rm ${IMAGE_ROOTFS}/sbin/init
448 cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init
449 fi
450}
451
452make_zimage_symlink_relative () {
453 if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then
454 (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done)
455 fi
456}
457
458python write_image_manifest () {
459 from oe.rootfs import image_list_installed_packages
460 with open(d.getVar('IMAGE_MANIFEST', True), 'w+') as image_manifest:
461 image_manifest.write(image_list_installed_packages(d, 'ver'))
462 image_manifest.write("\n")
463}
464
465# Can be use to create /etc/timestamp during image construction to give a reasonably
466# sane default time setting
467rootfs_update_timestamp () {
468 date -u +%4Y%2m%2d%2H%2M%2S >${IMAGE_ROOTFS}/etc/timestamp
469}
470
471# Prevent X from being started
472rootfs_no_x_startup () {
473 if [ -f ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm ]; then
474 chmod a-x ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm
475 fi
476}
477
478rootfs_trim_schemas () {
479 for schema in ${IMAGE_ROOTFS}/etc/gconf/schemas/*.schemas
480 do
481 # Need this in case no files exist
482 if [ -e $schema ]; then
483 oe-trim-schemas $schema > $schema.new
484 mv $schema.new $schema
485 fi
486 done
487}
488
489rootfs_check_host_user_contaminated () {
490 contaminated="${WORKDIR}/host-user-contaminated.txt"
491 HOST_USER_UID="$(PSEUDO_UNLOAD=1 id -u)"
492 HOST_USER_GID="$(PSEUDO_UNLOAD=1 id -g)"
493
494 find "${IMAGE_ROOTFS}" -wholename "${IMAGE_ROOTFS}/home" -prune \
495 -user "$HOST_USER_UID" -o -group "$HOST_USER_GID" >"$contaminated"
496
497 if [ -s "$contaminated" ]; then
498 echo "WARNING: Paths in the rootfs are owned by the same user or group as the user running bitbake. See the logfile for the specific paths."
499 cat "$contaminated" | sed "s,^, ,"
500 fi
501}
502
503# Make any absolute links in a sysroot relative
504rootfs_sysroot_relativelinks () {
505 sysroot-relativelinks.py ${SDK_OUTPUT}/${SDKTARGETSYSROOT}
506}
507 269
508do_fetch[noexec] = "1" 270do_fetch[noexec] = "1"
509do_unpack[noexec] = "1" 271do_unpack[noexec] = "1"