From 0065da791fd15325d6ddbfbf922e641a67d12d99 Mon Sep 17 00:00:00 2001 From: Ian Leonard Date: Fri, 10 Mar 2023 20:26:25 +0000 Subject: [PATCH 1/2] busybox: init: add post update command hook Signed-off-by: Ian Leonard --- packages/sysutils/busybox/package.mk | 1 + packages/sysutils/busybox/scripts/init | 28 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/sysutils/busybox/package.mk b/packages/sysutils/busybox/package.mk index c993b98c04d..80752ae5d40 100644 --- a/packages/sysutils/busybox/package.mk +++ b/packages/sysutils/busybox/package.mk @@ -130,6 +130,7 @@ makeinstall_target() { cp ${PKG_DIR}/scripts/fs-resize ${INSTALL}/usr/lib/libreelec sed -e "s/@DISTRONAME@/${DISTRONAME}/g" \ -i ${INSTALL}/usr/lib/libreelec/fs-resize + find_file_path config/post-update ${PKG_DIR}/scripts/post-update && cp -PRv ${FOUND_PATH} ${INSTALL}/usr/lib/libreelec if listcontains "${FIRMWARE}" "rpi-eeprom"; then cp ${PKG_DIR}/scripts/rpi-flash-firmware ${INSTALL}/usr/lib/libreelec diff --git a/packages/sysutils/busybox/scripts/init b/packages/sysutils/busybox/scripts/init index 7d7ad04bae4..8a20e4366ec 100755 --- a/packages/sysutils/busybox/scripts/init +++ b/packages/sysutils/busybox/scripts/init @@ -267,6 +267,13 @@ get_project_arch() { fi } +get_distro_version() { + if [ -f ${1}/etc/os-release ]; then + . ${1}/etc/os-release + echo "${VERSION_ID}" + fi +} + # If the project/arch of current matches the update, then it is considered compatible. # Otherwise, mount the update SYSTEM partition and, if canupdate.sh is available, # call the script to determine if the current update file can be applied on to the @@ -293,6 +300,14 @@ check_is_compatible() { old_project_arch="$(get_project_arch "/sysroot")" || return new_project_arch="$(get_project_arch "/update")" || return + # old image will be gone by the time post-update runs + if [ -f "/update/usr/lib/libreelec/post-update" ]; then + export OLD_PROJECT_ARCH=$old_project_arch + export NEW_PROJECT_ARCH=$new_project_arch + export OLD_DISTRO_VERSION="$(get_distro_version "/sysroot")" + export NEW_DISTRO_VERSION="$(get_distro_version "/update")" + fi + # If old or new project/arch isn't available then could be very old (pre-/etc/os-release) build - have to trust it if [ -n "${old_project_arch}" -a -n "${new_project_arch}" ]; then # If the old project/arch is not compatible with the new project/arch then abort... @@ -359,6 +374,18 @@ update_bootloader() { fi } +post_update_tasks() { + if [ -f "${SYSTEM_ROOT}/usr/lib/libreelec/post-update" ]; then + local result + + StartProgress spinner "Running post update tasks... " + result="$(sh ${SYSTEM_ROOT}/usr/lib/libreelec/post-update 2>&1)" + sync + StopProgress "done" + [ -n "${result}" ] && echo "${result}" + fi +} + set_consolefont() { local vres @@ -932,6 +959,7 @@ check_update() { umount /sysroot update_file "System" "$UPDATE_SYSTEM" "/flash/$IMAGE_SYSTEM" update_bootloader + post_update_tasks do_cleanup do_reboot } From 79d8a6e96d4d665497b83996471859e52d2e6c15 Mon Sep 17 00:00:00 2001 From: Ian Leonard Date: Fri, 10 Mar 2023 20:48:20 +0000 Subject: [PATCH 2/2] temp: test post-update Signed-off-by: Ian Leonard --- packages/sysutils/busybox/scripts/init | 1 + packages/sysutils/busybox/scripts/post-update | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100755 packages/sysutils/busybox/scripts/post-update diff --git a/packages/sysutils/busybox/scripts/init b/packages/sysutils/busybox/scripts/init index 8a20e4366ec..622dcccf99a 100755 --- a/packages/sysutils/busybox/scripts/init +++ b/packages/sysutils/busybox/scripts/init @@ -383,6 +383,7 @@ post_update_tasks() { sync StopProgress "done" [ -n "${result}" ] && echo "${result}" + sleep 10 fi } diff --git a/packages/sysutils/busybox/scripts/post-update b/packages/sysutils/busybox/scripts/post-update new file mode 100755 index 00000000000..e01d58af833 --- /dev/null +++ b/packages/sysutils/busybox/scripts/post-update @@ -0,0 +1,13 @@ +#!/bin/sh +# Copyright (C) 2023-present Team LibreELEC (https://libreelec.tv) + +# post-update script demo + +echo "BOOT_ROOT=${BOOT_ROOT}" +echo "SYSTEM_ROOT=${SYSTEM_ROOT}" +echo "OLD_PROJECT_ARCH=${OLD_PROJECT_ARCH}" +echo "NEW_PROJECT_ARCH=${NEW_PROJECT_ARCH}" +echo "OLD_DISTRO_VERSION=${OLD_DISTRO_VERSION}" +echo "NEW_DISTRO_VERSION=${NEW_DISTRO_VERSION}" + +exit