aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-core/swupd-client
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-core/swupd-client')
-rw-r--r--recipes-core/swupd-client/oe-swupd-helpers.bb39
-rw-r--r--recipes-core/swupd-client/oe-swupd-helpers/catalog-trigger.service8
-rwxr-xr-xrecipes-core/swupd-client/oe-swupd-helpers/clr_pre_update.sh16
-rwxr-xr-xrecipes-core/swupd-client/oe-swupd-helpers/kernel_updater.sh9
-rwxr-xr-xrecipes-core/swupd-client/oe-swupd-helpers/kernel_updater.sh~395
-rw-r--r--recipes-core/swupd-client/oe-swupd-helpers/ldconfig-trigger.service8
-rwxr-xr-xrecipes-core/swupd-client/oe-swupd-helpers/systemdboot_updater.sh10
-rwxr-xr-xrecipes-core/swupd-client/oe-swupd-helpers/systemdboot_updater.sh~267
-rw-r--r--recipes-core/swupd-client/oe-swupd-helpers/tmpfiles-trigger.service8
-rw-r--r--recipes-core/swupd-client/oe-swupd-helpers/update-triggers.target5
-rw-r--r--recipes-core/swupd-client/oe-swupd-helpers/update-triggers.target~9
-rw-r--r--recipes-core/swupd-client/swupd-client/0001-Tolerate-quotes-in-os-release-files.patch59
-rw-r--r--recipes-core/swupd-client/swupd-client/Change-systemctl-path-to-OE-systemctl-path.patch31
-rw-r--r--recipes-core/swupd-client/swupd-client/Fix-build-failure-on-Yocto.patch36
-rw-r--r--recipes-core/swupd-client/swupd-client/Right-usage-of-AC_ARG_ENABLE-on-bzip2.patch38
-rw-r--r--recipes-core/swupd-client/swupd-client_2.87.bb49
16 files changed, 987 insertions, 0 deletions
diff --git a/recipes-core/swupd-client/oe-swupd-helpers.bb b/recipes-core/swupd-client/oe-swupd-helpers.bb
new file mode 100644
index 0000000..4690f21
--- /dev/null
+++ b/recipes-core/swupd-client/oe-swupd-helpers.bb
@@ -0,0 +1,39 @@
+SUMMARY = "OE swupd helper files"
+DESCRIPTION = "swupd-client assumes the presence of various helpers, this is a minimal OE \
+implementation of the required scripts and systemd units. \
+Scripts are modified versions of those in clr-specialized-updaters and units are modified \
+versions of those in clr-systemd-config"
+LICENSE = "GPL-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6"
+
+SRC_URI = "file://update-triggers.target \
+ file://catalog-trigger.service \
+ file://ldconfig-trigger.service \
+ file://tmpfiles-trigger.service \
+ file://clr_pre_update.sh \
+ file://kernel_updater.sh \
+ file://systemdboot_updater.sh \
+ "
+
+inherit allarch distro_features_check systemd
+
+REQUIRED_DISTRO_FEATURES = "systemd"
+
+do_install () {
+ install -d ${D}${systemd_system_unitdir}
+ for svc in `find ${WORKDIR} -maxdepth 1 -name *.target -o -name *.service`; do
+ install -m 0644 $svc ${D}${systemd_system_unitdir}/
+ sed -i -e s#/bin#${base_bindir}# ${D}${systemd_system_unitdir}/`basename $svc`
+ sed -i -e s#/sbin#${base_sbindir}# ${D}${systemd_system_unitdir}/`basename $svc`
+ sed -i -e s#/lib#${base_libdir}# ${D}${systemd_system_unitdir}/`basename $svc`
+ done
+
+ # NOTE: swupd-client hard-codes /usr/bin
+ install -d ${D}/usr/bin
+ for helper in `find ${WORKDIR} -maxdepth 1 -name *.sh`; do
+ install $helper ${D}/usr/bin/
+ done
+}
+
+RDEPENDS_${PN} += "bash"
+FILES_${PN} += "${systemd_system_unitdir}" \ No newline at end of file
diff --git a/recipes-core/swupd-client/oe-swupd-helpers/catalog-trigger.service b/recipes-core/swupd-client/oe-swupd-helpers/catalog-trigger.service
new file mode 100644
index 0000000..8266174
--- /dev/null
+++ b/recipes-core/swupd-client/oe-swupd-helpers/catalog-trigger.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Rebuild journal catalog
+Documentation=man:journalctl(1)
+BindsTo=update-triggers.target
+
+[Service]
+Type=oneshot
+ExecStart=/bin/journalctl --update-catalog
diff --git a/recipes-core/swupd-client/oe-swupd-helpers/clr_pre_update.sh b/recipes-core/swupd-client/oe-swupd-helpers/clr_pre_update.sh
new file mode 100755
index 0000000..6302090
--- /dev/null
+++ b/recipes-core/swupd-client/oe-swupd-helpers/clr_pre_update.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+set -u
+
+#######################################
+# Clear Linux General Purpose Pre-update helper script
+# This is a script meant to update state information external to what swupd updates.
+# The specific content of this script will vary over time, according to the state
+# change needed
+#######################################
+
+UPDATE_NAME="Pre-update"
+VERSION="3.60"
+
+### Enter your script here
+echo "Running script '$UPDATE_NAME'"
+exit 0
diff --git a/recipes-core/swupd-client/oe-swupd-helpers/kernel_updater.sh b/recipes-core/swupd-client/oe-swupd-helpers/kernel_updater.sh
new file mode 100755
index 0000000..b0d5335
--- /dev/null
+++ b/recipes-core/swupd-client/oe-swupd-helpers/kernel_updater.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+#######################################
+# This script will be called after an updated kernel has been installed
+#######################################
+
+### Enter your script here
+echo "Running script 'kernel_updater.sh'"
+exit 0
diff --git a/recipes-core/swupd-client/oe-swupd-helpers/kernel_updater.sh~ b/recipes-core/swupd-client/oe-swupd-helpers/kernel_updater.sh~
new file mode 100755
index 0000000..0060be0
--- /dev/null
+++ b/recipes-core/swupd-client/oe-swupd-helpers/kernel_updater.sh~
@@ -0,0 +1,395 @@
+#!/bin/bash
+
+#######################################
+# Clear Linux Kernel update script
+# Author Brad Peters <brad.t.peters@intel.com>
+# kernel_updater.sh: Provides a minimal-copy wrapper which finesses
+# the VFAT /boot fs to minimize writes, while implementing Clear Linux
+# update/install and fix policies
+#######################################
+
+VERSION=3.60
+HASH="/usr/bin/sha256sum"
+
+function printUsage()
+{
+ echo "kernel_updater.sh [--path <path to chroot>]"
+ echo " -v | --version : Prints version of kernel_updater.sh"
+ echo " -h | --help : Prints usage"
+ echo " -p | --path : Optional. Used when creating new image "
+ echo " in a subdir. Should be absolute path"
+}
+
+function cleanDuplicates()
+{
+ # Move duplicate kernels out of the way in /boot, if necessary.
+ # Kernels in /usr are considered 'correct'
+ SRCFILES=org.clearlinux.*
+
+ for f in $SRCFILES
+ do
+ destfile="$SUBDIR/boot/$f"
+ if [ ! -f $destfile ]
+ then
+ continue
+ fi
+
+ srcsha=$(sha1sum $f)
+ destsha=$(sha1sum $destfile)
+
+ srcsha=$(echo $srcsha | awk '{print $1}')
+ destsha=$(echo $destsha | awk '{print $1}')
+
+ if [ "$srcsha" != "$destsha" ]
+ then
+ newname="${destfile/clearlinux/clearTMP}"
+# echo "Renaming $destfile to $newname prior to replacement"
+ mv $destfile $newname
+ fi
+ done
+}
+
+function cleanDuplicatesEFI()
+{
+ # Move duplicate kernels out of the way in /boot, if necessary.
+ # Kernels in /usr are considered 'correct'
+ SRCFILES=*.efi
+
+ for f in $SRCFILES
+ do
+ destfile="$SUBDIR/boot/EFI/Linux/$f"
+ if [ ! -f $destfile ]
+ then
+ continue
+ fi
+
+ srcsha=$(sha1sum $f)
+ destsha=$(sha1sum $destfile)
+
+ srcsha=$(echo $srcsha | awk '{print $1}')
+ destsha=$(echo $destsha | awk '{print $1}')
+
+ if [ "$srcsha" != "$destsha" ]
+ then
+ newname="${destfile/clearlinux/clearTMP}"
+# echo "Renaming $destfile to $newname prior to replacement"
+ mv $destfile $newname
+ fi
+ done
+}
+
+
+function cleanOldEFI()
+{
+ # Clean up old kernels
+
+ # Get list of all kernels in reverse sorted order (based only on release ID)
+ LS_KERNELS_SORTED=$(ls org.clearlinux*.efi | sort --field-separator=- -n -k3 -r)
+
+ i=0
+ for k in $LS_KERNELS_SORTED
+ do
+ if [[ "$i" -ge 3 ]]
+ then
+ cur_kernel=$(uname -r | cut -f1,2,3 -d.)
+ ls_kernel=$(echo $k | cut -f4,5,6 -d.)
+
+ #Do not clean up currently running kernel
+ if [[ $ls_kernel = $cur_kernel ]]
+ then
+ echo "Keeping $k. Is currently running kernel"
+ continue;
+ fi
+
+ echo "Clean up old kernel: $k"
+ echo "Clean up modules $SUBDIR/lib/modules/$ls_kernel"
+ rm "$k"
+ rm -Rf "$SUBDIR/lib/modules/$ls_kernel"
+ fi
+ i=$((i + 1))
+ done
+}
+
+function cleanOld()
+{
+ # Clean up old kernels
+
+ # Get list of all kernels in reverse sorted order (based only on release ID)
+ LS_KERNELS_SORTED=($(ls org.clearlinux.* | sort --field-separator=- -n -k3 -r))
+
+ i=0
+ for k in $LS_KERNELS_SORTED[*]
+ do
+ if [[ "$i" -ge 3 ]]
+ then
+ cur_kernel=$(uname -r | cut -f1,2,3 -d.)
+ ls_kernel=$(echo $k | cut -f4,5,6 -d.)
+
+ #Do not clean up currently running kernel
+ if [[ $ls_kernel = $cur_kernel ]]
+ then
+ echo "Keeping $k. Is currently running kernel"
+ continue;
+ fi
+
+ echo "Clean up old kernel: $k"
+ if [[ -z "${SUBDIR}" ]]; then
+ ${KINSTALL} remove "${ls_kernel}"
+ else
+ ${KINSTALL} --root "${SUBDIR}" remove "${ls_kernel}"
+ fi
+ fi
+ i=$((i + 1))
+ done
+}
+
+#Set the "default" entry option in file /boot/loader/loader.conf
+#requires /boot partition mounted
+function updateDefaultEntry()
+{
+ LOADER_CONF_FILE="/boot/loader/loader.conf"
+ if [ ! -f "$SUBDIR""$LOADER_CONF_FILE" ]; then
+ mkdir -p "$(dirname "$SUBDIR""$LOADER_CONF_FILE" )"
+ touch "$SUBDIR""$LOADER_CONF_FILE"
+ fi
+
+ for typename in "native" "kvm" "container" ; do
+ TPATH="${SUBDIR}/usr/lib/kernel/default-${typename}"
+ if [[ -e "${TPATH}" ]] ; then
+ kfile="$(basename $(readlink ${TPATH}))"
+
+ ktype="$(echo $kfile|cut -d. -f 3)"
+ kversion="$(echo $kfile|cut -f4,5,6 -d.|cut -d - -f 1)"
+ krelease="$(echo $kfile|cut -d - -f 2)"
+ defaultConf="Clear-linux-${ktype}-${kversion}-${krelease}"
+ break
+ fi
+ done
+
+ if [[ -z "${defaultConf}" ]]; then
+ echo "Default loader cannot be found"
+ return
+ fi
+
+ configFile="$SUBDIR""$LOADER_CONF_FILE"
+ hashFile="${configFile}.sha256sum"
+
+ sync
+ echo "default ${defaultConf}" > "${configFile}"
+ sync
+
+ echo "Updated default to: ${defaultConf}"
+
+ if [[ -e "${hashFile}" ]]; then
+ echo "Removing legacy file: ${hashFile}"
+ rm -v "${hashFile}"
+ sync
+ fi
+}
+
+# Copies kernel from /usr to /boot. Checks each kernel to
+# ensure modules are installed, and only copies if so
+function copyKernelBlobs()
+{
+ pushd "$SUBDIR/usr/lib/kernel" > /dev/null
+ LS_KERNELS_SORTED=$(ls org.clearlinux.* | sort --field-separator=- -n -k3 -r)
+ popd > /dev/null
+
+ for k in $LS_KERNELS_SORTED
+ do
+ kernel_version=$(echo "$k" | cut -f4,5,6 -d.)
+ kernel_file="${SUBDIR}/usr/lib/kernel/$(basename ${k})"
+ kernel_blob=$(echo "$k" | cut -f5 -d/)
+ echo "Kernel version = $kernel_version , blob = $kernel_blob"
+ kmods=$(ls $SUBDIR/lib/modules | sed -n "/$kernel_version/p")
+ kmods_len=${#kmods}
+
+ # Proceed with cp if kernel modules are present and kernel is not
+ # already installed
+ if [ $kmods_len -gt 0 ] && [ ! -e "$SUBDIR/boot/$kernel_blob" ]
+ then
+ echo " Installing $k to $SUBDIR/boot/"
+ if [[ -z "${SUBDIR}" ]]; then
+ ${KINSTALL} add "${kernel_version}" "${kernel_file}"
+ else
+ ${KINSTALL} --root "${SUBDIR}" add "${kernel_version}" "${kernel_file}"
+ fi
+
+ if [[ $? -eq 0 ]]; then
+ echo "Installed $k to /boot/"
+ else
+ echo "Failed to copy $k to /boot"
+ fi
+
+ else
+ if [ ! $kmods_len -gt 0 ]
+ then
+ echo "Skipping kernel $kernel_version - No modules found."
+ fi
+ if [ -e "$SUBDIR/boot/$kernel_blob" ]
+ then
+ echo "Skipping kernel $kernel_version - Already installed."
+ fi
+ fi
+
+ done
+}
+
+##################### Main #####################
+if [[ $# > 2 ]]
+then
+ printUsage
+fi
+
+# Parse cmdline
+if [[ $# > 0 ]]
+then
+ case "$1" in
+ -h|--help)
+ printUsage
+ exit 0
+ ;;
+ -v|--version)
+ echo "kernel_updater.sh version $VERSION"
+ exit 0
+ ;;
+ -p|--path)
+ if [[ $# = 1 ]]
+ then
+ echo "Invalid arguments. --path requires a second argument."
+ exit 1
+ fi
+ SUBDIR="$2"
+ ;;
+ *)
+ echo "Unrecognized argument ($1). Try again"
+ printUsage
+ exit 1
+ ;;
+ esac
+fi
+
+if [[ $EUID -ne 0 ]]; then
+ echo "Must be root to execute kernel_updater.sh"
+ exit 1
+fi
+
+KINSTALL="${SUBDIR}/usr/bin/kernel-install"
+
+# Clean up /usr/lib/kernel to the minimal 3 kernels we want to install
+pushd "$SUBDIR/usr/lib/kernel/" > /dev/null
+
+have_blobs=0
+have_legacy=0
+for test in org.clearlinux.*; do
+ have_blobs=1
+ if [[ "${test}" == *.efi ]] ; then
+ have_legacy=1
+ fi
+ break;
+done
+if [[ "$have_blobs" -eq 1 ]]; then
+ cleanOld
+ if [[ "$have_legacy" -eq 1 ]]; then
+ cleanOldEFI
+ fi
+else
+ echo "No kernel blobs found."
+ echo "kernel update complete."
+ exit 0
+fi
+
+# Note that if we are given a --SUBDIR or if there are no org.clearlinux blobs
+# in /usr/lib/kernel, we do not attempt a mount of /boot
+if [ -z "${SUBDIR}" ]; then
+ # Get boot partition UUID
+ BOOTUUIDENTRY=$(ls /sys/firmware/efi/efivars/LoaderDevicePartUUID*)
+ if [[ -e $BOOTUUIDENTRY ]]; then
+ UUID=$(cat $BOOTUUIDENTRY | tr -cd '[[:alnum:]]._-' | tr '[:upper:]' '[:lower:]')
+ fi
+
+ strlen=${#UUID}
+
+ IS_MOUNTED=$(mount | sed -n '/boot/p' | sed -n '/vfat/p')
+ if [[ -z "$IS_MOUNTED" ]];
+ then
+ if [ "$strlen" -gt 0 ]
+ then
+ echo "Mounting boot partition with UUID=$UUID"
+ mount /dev/disk/by-partuuid/$UUID /boot -o rw -t vfat
+ else
+ echo "Failed to identify boot partition using /sys/firmware/efi/efivars."
+ echo " Attempting to mount by-partlabel"
+ mount /dev/disk/by-partlabel/ESP /boot -o rw -t vfat
+ fi
+ else
+ if [ "$strlen" -gt 0 ]
+ then
+ echo "Mounting boot partition with UUID=$UUID"
+ mount -o remount,rw /dev/disk/by-partuuid/$UUID /boot -t vfat
+ else
+ echo "Failed to identify boot partition using /sys/firmware/efi/efivars."
+ echo " Attempting to remount by-partlabel"
+ mount -o remount,rw /dev/disk/by-partlabel/ESP /boot -t vfat
+ fi
+ fi
+
+ IS_MOUNTED=$(mount | sed -n '/boot/p' | sed -n '/vfat/p')
+ if [[ -z "$IS_MOUNTED" ]];
+ then
+ echo "/boot partition was not found. Unable to continue"
+ exit 1
+ fi
+fi
+
+echo "Updating kernel... please wait..."
+# Identify kernels in /boot/EFI/Linux which are different from those
+# in /usr. Assume /usr is 'correct', and remove those in /boot
+cleanDuplicates
+cleanDuplicatesEFI
+
+# Sync after cleanup to protect against VFAT corruption
+pushd "$SUBDIR/boot" > /dev/null
+sync
+popd > /dev/null
+
+# Copy new kernels from /usr/lib/kernel into /boot/
+copyKernelBlobs
+
+# Step 3 - Cleanup kernels which were repaired, then sync
+if [[ -e "$SUBDIR/boot/EFI/Linux/" ]]; then
+ pushd "$SUBDIR/boot/EFI/Linux/" > /dev/null
+ rm -f *clearTMP* 2>/dev/null
+ sync
+ popd > /dev/null
+fi
+
+pushd "$SUBDIR/boot/" > /dev/null
+rm -f *clearTMP* 2>/dev/null
+sync
+popd > /dev/null
+
+# Clean up legacy EFI blobs which are no longer needed
+if [[ -e "$SUBDIR/boot/EFI/Linux" ]]; then
+ pushd "$SUBDIR/boot/EFI/Linux" > /dev/null
+ cleanOldEFI
+ sync
+ popd > /dev/null
+fi
+
+# Finally, clean up kernels which are no longer needed
+pushd "$SUBDIR/boot" > /dev/null
+cleanOld
+sync
+popd > /dev/null
+
+#Update default kernel with the latest version
+updateDefaultEntry
+
+if [ -z "${SUBDIR}" ]; then
+ umount /boot
+fi
+
+popd > /dev/null
+
+echo "kernel update complete."
diff --git a/recipes-core/swupd-client/oe-swupd-helpers/ldconfig-trigger.service b/recipes-core/swupd-client/oe-swupd-helpers/ldconfig-trigger.service
new file mode 100644
index 0000000..224ac7a
--- /dev/null
+++ b/recipes-core/swupd-client/oe-swupd-helpers/ldconfig-trigger.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Rebuild Dynamic Linker Cache
+Documentation=man:ldconfig(8)
+BindsTo=update-triggers.target
+
+[Service]
+Type=oneshot
+ExecStart=/sbin/ldconfig -X
diff --git a/recipes-core/swupd-client/oe-swupd-helpers/systemdboot_updater.sh b/recipes-core/swupd-client/oe-swupd-helpers/systemdboot_updater.sh
new file mode 100755
index 0000000..470cd6e
--- /dev/null
+++ b/recipes-core/swupd-client/oe-swupd-helpers/systemdboot_updater.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+#######################################
+# systemd bootloader installer
+# This script will be called after an updated bootloader has been installed
+#######################################
+
+### Enter your script here
+echo "Running script 'systemdboot_updater.sh'"
+exit 0
diff --git a/recipes-core/swupd-client/oe-swupd-helpers/systemdboot_updater.sh~ b/recipes-core/swupd-client/oe-swupd-helpers/systemdboot_updater.sh~
new file mode 100755
index 0000000..d8cdc7e
--- /dev/null
+++ b/recipes-core/swupd-client/oe-swupd-helpers/systemdboot_updater.sh~
@@ -0,0 +1,267 @@
+#!/bin/bash
+
+#######################################
+# Clear Linux systemd bootloader installer
+# Author Brad Peters <brad.t.peters@intel.com>
+# systemdboot_updater.sh provides a minimal-copy wrapper which finesses
+# the VFAT /boot fs to minimize writes, while implementing Clear Linux
+# update/install and fix policies
+#######################################
+
+
+VERSION=3.60
+
+mountedBoot=0
+
+function printUsage()
+{
+ echo "systemdboot_updater.sh [--path <path to chroot>]"
+ echo " -v | --version : Prints version of bootloader_updater.sh"
+ echo " -h | --help : Prints usage"
+ echo " -p | --path : Optional. Used when creating new image "
+ echo " in a subdir. Should be absolute path"
+}
+
+# Compares the sha1_sum of two files
+# Sets $sha1_cmp_res to 0 if equal, 1 if not
+function sha1_cmp()
+{
+ src=$1
+ dest=$2
+
+ if [[ ! -e $src ]]; then
+ echo "In sha1_cmp - $src File not found"
+ exit 1
+ fi
+
+ if [[ ! -e $dest ]]; then
+ # dest file does not exist, therefore we know the
+ # sha1_sum is different
+ sha1_cmp_res=1
+ return 1
+ fi
+
+ srcsha=$(sha1sum $src)
+ destsha=$(sha1sum $dest)
+
+ srcsha=$(echo $srcsha | awk '{print $1}')
+ destsha=$(echo $destsha | awk '{print $1}')
+
+ if [ $srcsha == $destsha ]
+ then
+ sha1_cmp_res=0
+ else
+ sha1_cmp_res=1
+ fi
+}
+
+
+
+#Checks if there is enough space to copy 2 files to /boot
+# Sets enoughSpace_res to 0 if not enough space to do the copy,
+# 1 if can saftely proceed
+function enoughSpace()
+{
+ src1=$1
+ src2=$2
+
+ fileSize1=$(ls -la $src1 | cut -f5 -d" ")
+ fileSize2=$(ls -la $src2 | cut -f5 -d" ")
+ # Add a buffer to space requirements to ensure we don't fill up boot
+ fileSize=$(($fileSize1 + $fileSize2 + 4096))
+ freeSpace=$(df --output=avail $SUBDIR/boot | sed -n '1!p')
+ # Get free space in bytes
+ freeBytes=$(expr $freeSpace \* 1000)
+
+ if [ $fileSize -lt $freeBytes ]; then
+ enoughSpace_res=1
+ else
+ enoughSpace_res=0
+ fi
+}
+
+# Compares sha1_sum's of srcfile and destfile, creates backup of destfile
+# if the two differ
+# This backup will then be available for restoration via UEFI command line
+# if the new binary fails to boot
+function preCopyBackup()
+{
+ srcfile=$1
+ destfile=$2
+
+ if [ ! -f $srcfile ]
+ then
+ echo " $srcfile not found. Nothing to do."
+ exit 1;
+ fi
+
+ if [ ! -f $destfile ]
+ then
+ return 0
+ fi
+
+ sha1_cmp $srcfile $destfile
+ if [ $sha1_cmp_res ]
+ then
+ newname="${destfile}.old"
+ cp $destfile $newname
+ fi
+
+ return 0
+}
+
+
+##################### Main #####################
+if [[ $# > 2 ]]
+then
+ printUsage
+fi
+
+# Parse cmdline
+if [[ $# > 0 ]]
+then
+ case $1 in
+ -h|--help)
+ printUsage
+ exit 0
+ ;;
+ -v|--version)
+ echo "bootloader_updater.sh version $VERSION"
+ exit 0
+ ;;
+ -p|--path)
+ if [[ $# = 1 ]]
+ then
+ echo "Invalid arguments. --path requires a second argument."
+ exit 1
+ fi
+ SUBDIR="$2"
+ ;;
+ *)
+ echo "Unrecognized argument ($1). Try again"
+ printUsage
+ exit 1
+ ;;
+ esac
+fi
+
+if [[ $EUID -ne 0 ]]; then
+ echo "Must be root to execute bootloader_updater.sh"
+ exit 1
+fi
+
+##### Mount /boot ######
+if [ -z "${SUBDIR}" ]; then
+ # Get boot partition UUID
+ BOOTUUIDENTRY=$(ls /sys/firmware/efi/efivars/LoaderDevicePartUUID*)
+ if [[ -e $BOOTUUIDENTRY ]]; then
+ UUID=$(cat $BOOTUUIDENTRY | tr -cd '[[:alnum:]]._-' | tr '[:upper:]' '[:lower:]')
+ fi
+
+ strlen=${#UUID}
+
+ IS_MOUNTED=$(mount | sed -n '/boot/p' | sed -n '/vfat/p')
+ if [[ -z "$IS_MOUNTED" ]];
+ then
+ if [ "$strlen" -gt 0 ]
+ then
+ echo "Mounting boot partition with UUID=$UUID"
+ mount /dev/disk/by-partuuid/$UUID /boot -o rw -t vfat
+ else
+ echo "Failed to identify boot partition using /sys/firmware/efi/efivars."
+ echo " Attempting to mount by-partlabel"
+ mount /dev/disk/by-partlabel/ESP /boot -o rw -t vfat
+ fi
+ mountedBoot=1
+ fi
+
+ IS_MOUNTED=$(mount | sed -n '/boot/p' | sed -n '/vfat/p')
+ if [[ -z "$IS_MOUNTED" ]];
+ then
+ echo "/boot partition was not found. Unable to continue with systemd bootloader install"
+ exit 1
+ fi
+fi
+
+
+echo "Installing new systemd bootx binary... please wait..."
+src1="$SUBDIR/usr/lib/systemd/boot/efi/systemd-bootx64.efi"
+dest1="$SUBDIR/boot/EFI/systemd/systemd-bootx64.efi"
+preCopyBackup $src1 $dest1
+src2="$SUBDIR/usr/lib/systemd/boot/efi/systemd-bootx64.efi"
+dest2="$SUBDIR/boot/EFI/Boot/BOOTX64.EFI"
+preCopyBackup $src2 $dest2
+
+
+if [ ! -d "$SUBDIR/boot/EFI/systemd/" ]; then
+ mkdir -p "$SUBDIR/boot/EFI/systemd"
+fi
+
+if [ ! -d "$SUBDIR/boot/EFI/Boot/" ]; then
+ mkdir -p "$SUBDIR/boot/EFI/Boot"
+fi
+
+function fail_msg()
+{
+ echo "$* - Aborting"
+ exit 1
+}
+
+# use clear's bootctl only.
+function installSystemd()
+{
+ if [[ -z "${SUBDIR}" ]]; then
+ /usr/bin/bootctl install || fail_msg "Installing systemd bootloader failed"
+ else
+ # HACK
+ chroot "${SUBDIR}" /usr/bin/bootctl install --no-variables --force || fail_msg "Installing systemd bootloader failed"
+ fi
+}
+
+function updateSystemd()
+{
+ if [[ -z "${SUBDIR}" ]]; then
+ /usr/bin/bootctl update || fail_msg "Updating systemd bootloader failed"
+ else
+ chroot "${SUBDIR}" /usr/bin/bootctl update --no-variables --force || fail_msg "Updating systemd bootloader failed"
+ fi
+}
+
+# Space check before copy
+enoughSpace $src1 $src2
+if [ $enoughSpace_res -eq 1 ]; then
+ if [[ ! -e "${dest1}" ]] || [[ ! -e "${dest2}" ]]; then
+ # absolutely require an install
+ installSystemd
+ fi
+ sha1_cmp "$src1" "$dest1"
+ if [ $sha1_cmp_res -eq 1 ]; then
+ updateSystemd
+ fi
+else
+ echo "Insufficient space on /boot to install new bootloader binary"
+ exit 1
+fi
+
+
+# Sync after copy to protect against VFAT corruption
+pushd "$SUBDIR/boot" > /dev/null
+sync
+popd > /dev/null
+
+# Ensure older bootloader binary is not present
+# Note this will only occur if the new systemd bootloader was installed
+rm -Rf "$SUBDIR/boot/EFI/gummiboot"
+
+# Sync after cleanup to protect against VFAT corruption
+pushd "$SUBDIR/boot" > /dev/null
+sync
+popd > /dev/null
+
+if [ -z "${SUBDIR}" ]; then
+ if [[ "${mountedBoot}" -eq 1 ]]; then
+ umount /boot
+ fi
+fi
+
+echo "systemd bootloader update sucessful."
diff --git a/recipes-core/swupd-client/oe-swupd-helpers/tmpfiles-trigger.service b/recipes-core/swupd-client/oe-swupd-helpers/tmpfiles-trigger.service
new file mode 100644
index 0000000..71009fe
--- /dev/null
+++ b/recipes-core/swupd-client/oe-swupd-helpers/tmpfiles-trigger.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Create tmpfiles
+Documentation=man:systemd-tmpfiles(8)
+BindsTo=update-triggers.target
+
+[Service]
+Type=oneshot
+ExecStart=/bin/systemd-tmpfiles --create
diff --git a/recipes-core/swupd-client/oe-swupd-helpers/update-triggers.target b/recipes-core/swupd-client/oe-swupd-helpers/update-triggers.target
new file mode 100644
index 0000000..d104b00
--- /dev/null
+++ b/recipes-core/swupd-client/oe-swupd-helpers/update-triggers.target
@@ -0,0 +1,5 @@
+[Unit]
+Description=Post system update triggers
+Wants=ldconfig-trigger.service
+Wants=catalog-trigger.service
+Wants=tmpfiles-trigger.service
diff --git a/recipes-core/swupd-client/oe-swupd-helpers/update-triggers.target~ b/recipes-core/swupd-client/oe-swupd-helpers/update-triggers.target~
new file mode 100644
index 0000000..3c2e394
--- /dev/null
+++ b/recipes-core/swupd-client/oe-swupd-helpers/update-triggers.target~
@@ -0,0 +1,9 @@
+[Unit]
+Description=Post system update triggers
+Wants=ldconfig-trigger.service
+#Wants=mandb-trigger.service
+#Wants=python-trigger.service
+Wants=catalog-trigger.service
+Wants=tmpfiles-trigger.service
+#Wants=locale-archive-trigger.service
+Wants=systemd-modules-trigger.service
diff --git a/recipes-core/swupd-client/swupd-client/0001-Tolerate-quotes-in-os-release-files.patch b/recipes-core/swupd-client/swupd-client/0001-Tolerate-quotes-in-os-release-files.patch
new file mode 100644
index 0000000..49c71ae
--- /dev/null
+++ b/recipes-core/swupd-client/swupd-client/0001-Tolerate-quotes-in-os-release-files.patch
@@ -0,0 +1,59 @@
+From 586e7b927461f6604ee3a3159cd7a6d4ac22ef30 Mon Sep 17 00:00:00 2001
+From: Dmitry Rozhkov <dmitry.rozhkov@intel.com>
+Date: Thu, 11 Feb 2016 13:29:57 +0200
+Subject: [PATCH 1/2] Tolerate quotes in os-release files
+
+Some systems like Yocto or OpenSUSE prefer to wrap values in
+/etc/os-release file with quotes always and that still conforms
+to the format defined in systemd.
+
+This patch removes quotes from the values before trying to
+transform them into integer version id.
+
+Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@intel.com>
+
+Upstream-Status: Backport (v3.0.0+)
+
+---
+ src/version.c | 18 +++++++++++++++++-
+ 1 file changed, 17 insertions(+), 1 deletion(-)
+
+diff --git a/src/version.c b/src/version.c
+index 0e09cd9..83d6ad4 100644
+--- a/src/version.c
++++ b/src/version.c
+@@ -88,6 +88,7 @@ int read_version_from_subvol_file(char *path_prefix)
+ FILE *file;
+ int v = -1;
+ char *buildstamp;
++ char *src, *dest;
+
+ string_or_die(&buildstamp, "%s/usr/lib/os-release", path_prefix);
+ file = fopen(buildstamp, "rm");
+@@ -106,7 +107,22 @@ int read_version_from_subvol_file(char *path_prefix)
+ break;
+ }
+
+- if (strncmp(line,"VERSION_ID=", 11) == 0) {
++ if (strncmp(line, "VERSION_ID=", 11) == 0) {
++ src = &line[11];
++
++ /* Drop quotes and newline in value */
++ dest = src;
++ while (*src) {
++ if (*src == '\'' || *src == '"' || *src == '\n') {
++ ++src;
++ } else {
++ *dest = *src;
++ ++dest;
++ ++src;
++ }
++ }
++ *dest = 0;
++
+ v = strtoull(&line[11], NULL, 10);
+ break;
+ }
+--
+2.5.0
+
diff --git a/recipes-core/swupd-client/swupd-client/Change-systemctl-path-to-OE-systemctl-path.patch b/recipes-core/swupd-client/swupd-client/Change-systemctl-path-to-OE-systemctl-path.patch
new file mode 100644
index 0000000..5ca6373
--- /dev/null
+++ b/recipes-core/swupd-client/swupd-client/Change-systemctl-path-to-OE-systemctl-path.patch
@@ -0,0 +1,31 @@
+From 259d86e64146c3156eccfcce0351a9cdc4714766 Mon Sep 17 00:00:00 2001
+From: Jaska Uimonen <jaska.uimonen@intel.com>
+Date: Thu, 14 Jan 2016 10:17:43 +0200
+Subject: [PATCH] change systemctl path to OE systemctl path
+
+Upstream-Status: Inappropriate
+
+---
+ src/scripts.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/scripts.c b/src/scripts.c
+index e426272..9bec0f5 100644
+--- a/src/scripts.c
++++ b/src/scripts.c
+@@ -84,10 +84,10 @@ static void update_triggers(void)
+ int ret;
+ LOG_INFO(NULL, "calling systemd trigger", class_scripts, "");
+
+- ret = system("/usr/bin/systemctl daemon-reload");
++ ret = system("/bin/systemctl daemon-reload");
+ if (ret != 0)
+ LOG_ERROR(NULL, "systemd daemon reload failed", class_scripts, "%d", ret);
+- ret = system("/usr/bin/systemctl restart update-triggers.target");
++ ret = system("/bin/systemctl restart update-triggers.target");
+ if (ret != 0)
+ LOG_ERROR(NULL, "systemd update triggers failed", class_scripts, "%d", ret);
+ }
+--
+2.5.0
+
diff --git a/recipes-core/swupd-client/swupd-client/Fix-build-failure-on-Yocto.patch b/recipes-core/swupd-client/swupd-client/Fix-build-failure-on-Yocto.patch
new file mode 100644
index 0000000..73f1728
--- /dev/null
+++ b/recipes-core/swupd-client/swupd-client/Fix-build-failure-on-Yocto.patch
@@ -0,0 +1,36 @@
+From ccce73a2d703e6789ded87ca5aa9f3b7c506892a Mon Sep 17 00:00:00 2001
+From: Amarnath Valluri <amarnath.valluri@intel.com>
+Date: Thu, 7 Jan 2016 16:19:34 +0200
+Subject: [PATCH] Fix build failure on Yocto
+
+On install phase certificate files are being installed twice as included in
+_DATA twice. We can use EXTRA_DIST than dist_.
+
+Upstream-Status: Inappropriate
+
+Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
+---
+ Makefile.am | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/Makefile.am b/Makefile.am
+index 1e65d3d..4d15c55 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -111,11 +111,11 @@ SWUPD_CERTS = certs/157753a5.0 \
+ certs/d6325660.0 \
+ certs/d6325660.1
+ swupdcerts_DATA = $(SWUPD_CERTS)
+-dist_swupdcerts_DATA = $(SWUPD_CERTS)
+
+ EXTRA_DIST += \
+ data/check-update.service \
+- data/check-update.timer
++ data/check-update.timer \
++ $(SWUPD_CERTS)
+
+ DISTCHECK_CONFIGURE_FLAGS = \
+ --with-systemdsystemunitdir=$$dc_install_base/$(systemdunitdir)
+--
+2.1.4
+
diff --git a/recipes-core/swupd-client/swupd-client/Right-usage-of-AC_ARG_ENABLE-on-bzip2.patch b/recipes-core/swupd-client/swupd-client/Right-usage-of-AC_ARG_ENABLE-on-bzip2.patch
new file mode 100644
index 0000000..e5b53ef
--- /dev/null
+++ b/recipes-core/swupd-client/swupd-client/Right-usage-of-AC_ARG_ENABLE-on-bzip2.patch
@@ -0,0 +1,38 @@
+From d80ae9954c5e5b720766274249dbf5309b7c70a9 Mon Sep 17 00:00:00 2001
+From: Amarnath Valluri <amarnath.valluri@intel.com>
+Date: Wed, 13 Jan 2016 15:46:19 +0200
+Subject: [PATCH] Right usage of AC_ARG_ENABLE on bzip2
+
+Upstream-Status: Pending[Not submitted]
+
+Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
+---
+ configure.ac | 12 +++++++-----
+ 1 file changed, 7 insertions(+), 5 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index f94a17d..b11ef0a 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -20,11 +20,13 @@ AC_CONFIG_HEADERS([config.h])
+ PKG_CHECK_MODULES([lzma], [liblzma])
+ PKG_CHECK_MODULES([zlib], [zlib])
+ AC_ARG_ENABLE(
+- bzip2,
+- AS_HELP_STRING([--disable-bzip2],[Do not use bzip2 compression (uses bzip2 by default)]),
+- AC_DEFINE(SWUPD_WITHOUT_BZIP2,1,[Do not use bzip2 compression]) ,
+- AC_DEFINE(SWUPD_WITH_BZIP2,1,[Use bzip2 compression])
+- AC_CHECK_LIB([bz2], [BZ2_bzBuffToBuffCompress], [], [AC_MSG_ERROR([the libbz2 library is missing])])
++ [bzip2],
++ AS_HELP_STRING([--disable-bzip2],[Do not use bzip2 compression (uses bzip2 by default)])
++)
++AS_IF([test "x$enable_bzip2" = "xyes" ],
++ [AC_DEFINE(SWUPD_WITH_BZIP2,1,[Use bzip2 compression])
++ AC_CHECK_LIB([bz2], [BZ2_bzBuffToBuffCompress], [], [AC_MSG_ERROR([the libbz2 library is missing])])],
++ [AC_DEFINE(SWUPD_WITHOUT_BZIP2,1,[Do not use bzip2 compression])]
+ )
+
+ AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR],
+--
+2.1.4
+
diff --git a/recipes-core/swupd-client/swupd-client_2.87.bb b/recipes-core/swupd-client/swupd-client_2.87.bb
new file mode 100644
index 0000000..8226624
--- /dev/null
+++ b/recipes-core/swupd-client/swupd-client_2.87.bb
@@ -0,0 +1,49 @@
+SUMMARY = "swupd sofware update from Clear Linux - client component"
+LICENSE = "GPL-2.0"
+LIC_FILES_CHKSUM = "file://COPYING;md5=04d0b48662817042d80393e7511fa41b \
+ file://bsdiff/LICENSE;md5=0dbe7a50f028269750631fcbded3846a"
+
+SRC_URI = "\
+ https://download.clearlinux.org/releases/5700/clear/source/SRPMS/${BPN}-${PV}-105.src.rpm;extract=${BP}.tar.gz \
+ file://Fix-build-failure-on-Yocto.patch \
+ file://Right-usage-of-AC_ARG_ENABLE-on-bzip2.patch \
+ file://Change-systemctl-path-to-OE-systemctl-path.patch \
+ file://0001-Tolerate-quotes-in-os-release-files.patch \
+"
+
+SRC_URI[md5sum] = "5d272c62edb8a9c576005ac5e1182ea3"
+SRC_URI[sha256sum] = "45df259a7dc2fed985ee9961e112120fc46670dd75476c3262fc6804b1c66fb8"
+
+DEPENDS = "glib-2.0 curl zlib bzip2 xz openssl"
+RDEPENDS_${PN} = "gzip bzip2 tar xz"
+RDEPENDS_${PN}_class-target = "oe-swupd-helpers"
+# We check /etc/os-release for the current OS version number
+RRECOMMENDS_${PN}_class-target = "os-release"
+
+inherit pkgconfig autotools-brokensep systemd
+
+EXTRA_OECONF = "--with-systemdsystemunitdir=${systemd_system_unitdir}"
+
+#TODO: create and install /var/lib/swupd/{delta,staged/download}
+do_install_append () {
+ # swupd-client 2.87 doesn't (succesfully) create these and fails to update
+ # should they not exist. This is due to a bash-specific shell command
+ # called to create the directories 'mkdir -p /var/lib/{delta,staged,download}'
+ install -d ${D}/var/lib/swupd/delta
+ install -d ${D}/var/lib/swupd/download
+ install -d ${D}/var/lib/swupd/staged
+
+ # TODO: This should be a less os-specific directory and not hard-code datadir
+ install -d ${D}/usr/share/clear/bundles
+}
+
+FILES_${PN} += "\
+ /usr/share/clear \
+ ${systemd_system_unitdir}/multi-user.target.wants* \
+ /var/lib/swupd \
+"
+
+SYSTEMD_SERVICE_${PN} = "check-update.timer check-update.service"
+SYSTEMD_AUTO_ENABLE_${PN} = "disable"
+
+BBCLASSEXTEND = "native"