Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

busybox: init: post update script hook #7671

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/sysutils/busybox/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions packages/sysutils/busybox/scripts/init
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...
Expand Down Expand Up @@ -359,6 +374,19 @@ 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}"
sleep 10
fi
}

set_consolefont() {
local vres

Expand Down Expand Up @@ -932,6 +960,7 @@ check_update() {
umount /sysroot
update_file "System" "$UPDATE_SYSTEM" "/flash/$IMAGE_SYSTEM"
update_bootloader
post_update_tasks
do_cleanup
do_reboot
}
Expand Down
13 changes: 13 additions & 0 deletions packages/sysutils/busybox/scripts/post-update
Original file line number Diff line number Diff line change
@@ -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