# overrides meta-updater/classes/image_types_ostree.bbclass # - add do_image_ostree flags: # - dirs, cleandirs: to avoid mktemp, rm, cd, and to also remove at clean # - subimages, imgsuffix: to use automatic link creation # - override of IMAGE_CMD_ostree # - use the added flags # - IMGDEPLOYDIR, instead of DEPLOY_DIR_IMAGE OSTREE_ROOTFS="${WORKDIR}/ostree-root" do_image_ostree[dirs] = "${OSTREE_ROOTFS}" do_image_ostree[cleandirs] = "${OSTREE_ROOTFS}" do_image_ostree[subimages] = "rootfs.ostree.tar.bz2" do_image_ostree[imgsuffix] = "." export OSTREE_ROOTFS IMAGE_CMD_ostree () { if [ -z "$OSTREE_REPO" ]; then bbfatal "OSTREE_REPO should be set in your local.conf" fi if [ -z "$OSTREE_BRANCHNAME" ]; then bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" fi cp -a ${IMAGE_ROOTFS}/* ${OSTREE_ROOTFS} chmod a+rx ${OSTREE_ROOTFS} sync for d in var/*; do if [ "${d}" != "var/local" ]; then rm -rf ${d} fi done # Create sysroot directory to which physical sysroot will be mounted mkdir sysroot ln -sf sysroot/ostree ostree rm -rf tmp/* ln -sf sysroot/tmp tmp mkdir -p usr/rootdirs mv etc usr/ # Implement UsrMove dirs="bin sbin lib" for dir in ${dirs} ; do if [ -d ${dir} ] && [ ! -L ${dir} ] ; then mv ${dir} usr/rootdirs/ rm -rf ${dir} ln -sf usr/rootdirs/${dir} ${dir} fi done if [ -n "$SYSTEMD_USED" ]; then mkdir -p usr/etc/tmpfiles.d tmpfiles_conf=usr/etc/tmpfiles.d/00ostree-tmpfiles.conf echo "d /var/rootdirs 0755 root root -" >>${tmpfiles_conf} echo "L /var/rootdirs/home - - - - /sysroot/home" >>${tmpfiles_conf} else mkdir -p usr/etc/init.d tmpfiles_conf=usr/etc/init.d/tmpfiles.sh echo '#!/bin/sh' > ${tmpfiles_conf} echo "mkdir -p /var/rootdirs; chmod 755 /var/rootdirs" >> ${tmpfiles_conf} echo "ln -sf /sysroot/home /var/rootdirs/home" >> ${tmpfiles_conf} ln -s ../init.d/tmpfiles.sh usr/etc/rcS.d/S20tmpfiles.sh fi # Preserve OSTREE_BRANCHNAME for future information mkdir -p usr/share/sota/ echo -n "${OSTREE_BRANCHNAME}" > usr/share/sota/branchname # Preserve data in /home to be later copied to /sysroot/home by sysroot # generating procedure mkdir -p usr/homedirs if [ -d "home" ] && [ ! -L "home" ]; then mv home usr/homedirs/home ln -sf var/rootdirs/home home fi # Move persistent directories to /var dirs="opt mnt media srv" for dir in ${dirs}; do if [ -d ${dir} ] && [ ! -L ${dir} ]; then if [ "$(ls -A $dir)" ]; then bbwarn "Data in /$dir directory is not preserved by OSTree. Consider moving it under /usr" fi if [ -n "$SYSTEMD_USED" ]; then echo "d /var/rootdirs/${dir} 0755 root root -" >>${tmpfiles_conf} else echo "mkdir -p /var/rootdirs/${dir}; chown 755 /var/rootdirs/${dir}" >>${tmpfiles_conf} fi rm -rf ${dir} ln -sf var/rootdirs/${dir} ${dir} fi done if [ -d root ] && [ ! -L root ]; then if [ "$(ls -A root)" ]; then bberror "Data in /root directory is not preserved by OSTree." exit 1 fi if [ -n "$SYSTEMD_USED" ]; then echo "d /var/roothome 0755 root root -" >>${tmpfiles_conf} else echo "mkdir -p /var/roothome; chown 755 /var/roothome" >>${tmpfiles_conf} fi rm -rf root ln -sf var/roothome root fi if [ -n "${SOTA_SECONDARY_ECUS}" ]; then mkdir -p var/sota/ecus cp ${SOTA_SECONDARY_ECUS} var/sota/ecus fi # Creating boot directories is required for "ostree admin deploy" mkdir -p boot/loader.0 mkdir -p boot/loader.1 ln -sf loader.0 boot/loader checksum=`sha256sum ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} | cut -f 1 -d " "` # Copy kernel and initramfs and their signature files cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} boot/vmlinuz-${checksum} cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL}.p7b boot/vmlinuz-${checksum}.p7b cp ${DEPLOY_DIR_IMAGE}/${OSTREE_INITRAMFS_IMAGE}-${MACHINE}${RAMDISK_EXT} boot/initramfs-${checksum} cp ${DEPLOY_DIR_IMAGE}/${OSTREE_INITRAMFS_IMAGE}-${MACHINE}${RAMDISK_EXT}.p7b boot/initramfs-${checksum}.p7b # Copy image manifest cat ${IMAGE_MANIFEST} | cut -d " " -f1,3 > usr/package.manifest # Create a tarball that can be then commited to OSTree repo OSTREE_TAR=${IMGDEPLOYDIR}/${IMAGE_NAME}.rootfs.ostree.tar.bz2 tar -C ${OSTREE_ROOTFS} --xattrs --xattrs-include='*' -cjf ${OSTREE_TAR} . sync if ! ostree --repo=${OSTREE_REPO} refs 2>&1 > /dev/null; then ostree --repo=${OSTREE_REPO} init --mode=archive-z2 fi # Commit the result ostree --repo=${OSTREE_REPO} commit \ --tree=dir=${OSTREE_ROOTFS} \ --skip-if-unchanged \ --branch=${OSTREE_BRANCHNAME} \ --subject="Commit-id: ${IMAGE_NAME}" }