busybox: init: less mount/umount for update process

This commit is contained in:
sky42 2019-09-13 22:07:23 +02:00
parent f44f964127
commit 4ba4ba6df2

View File

@ -261,14 +261,10 @@ mount_sysroot() {
# mount the specified SYSTEM file and output arch from /etc/os-release # mount the specified SYSTEM file and output arch from /etc/os-release
get_project_arch() { get_project_arch() {
mount_part "$1" "/update" "ro,loop" || return if [ -f ${1}/etc/os-release ]; then
. ${1}/etc/os-release
if [ -f /update/etc/os-release ]; then
. /update/etc/os-release
echo "${LIBREELEC_ARCH:-${OPENELEC_ARCH}}" echo "${LIBREELEC_ARCH:-${OPENELEC_ARCH}}"
fi fi
umount /update
} }
# If the project/arch of current matches the upgrade, then it is considered compatible. # If the project/arch of current matches the upgrade, then it is considered compatible.
@ -278,16 +274,12 @@ get_project_arch() {
is_compatible() { is_compatible() {
local result=1 local result=1
if [ "${2}" = "${3}" ]; then if [ "${1}" = "${2}" ]; then
result=0 result=0
else else
mount_part "$1" "/update" "ro,loop"
if [ -f /update/usr/share/bootloader/canupdate.sh ]; then if [ -f /update/usr/share/bootloader/canupdate.sh ]; then
sh /update/usr/share/bootloader/canupdate.sh "${2}" "${3}" && result=0 sh /update/usr/share/bootloader/canupdate.sh "${1}" "${2}" && result=0
fi fi
umount /update
fi fi
return ${result} return ${result}
@ -296,17 +288,15 @@ is_compatible() {
# determine if the new SYSTEM file is compatible with the current SYSTEM file # determine if the new SYSTEM file is compatible with the current SYSTEM file
check_is_compatible() { check_is_compatible() {
local update_filename="${1}" local update_filename="${1}"
local old_system="${2}"
local new_system="${3}"
local old_project_arch new_project_arch local old_project_arch new_project_arch
old_project_arch="$(get_project_arch "${old_system}")" || return old_project_arch="$(get_project_arch "/sysroot")" || return
new_project_arch="$(get_project_arch "${new_system}")" || return new_project_arch="$(get_project_arch "/update")" || return
# If old or new project/arch isn't available then could be very old (pre-/etc/os-release) build - have to trust it # 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 [ -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... # If the old project/arch is not compatible with the new project/arch then abort...
if ! is_compatible "${new_system}" "${old_project_arch}" "${new_project_arch}"; then if ! is_compatible "${old_project_arch}" "${new_project_arch}"; then
echo "" echo ""
echo "ERROR: $(basename "${update_filename}") is not compatible with ${old_project_arch} hardware - update cancelled." echo "ERROR: $(basename "${update_filename}") is not compatible with ${old_project_arch} hardware - update cancelled."
echo "" echo ""
@ -359,8 +349,6 @@ update_bootloader() {
export BOOT_ROOT="/flash" export BOOT_ROOT="/flash"
export SYSTEM_ROOT="/update" export SYSTEM_ROOT="/update"
mount_part "/flash/$IMAGE_SYSTEM" "$SYSTEM_ROOT" "ro,loop"
if [ -f $SYSTEM_ROOT/usr/share/bootloader/update.sh ]; then if [ -f $SYSTEM_ROOT/usr/share/bootloader/update.sh ]; then
StartProgress spinner "Updating Boot Files... " StartProgress spinner "Updating Boot Files... "
result="$(sh $SYSTEM_ROOT/usr/share/bootloader/update.sh 2>&1)" result="$(sh $SYSTEM_ROOT/usr/share/bootloader/update.sh 2>&1)"
@ -368,8 +356,6 @@ update_bootloader() {
StopProgress "done" StopProgress "done"
[ -n "${result}" ] && echo "${result}" [ -n "${result}" ] && echo "${result}"
fi fi
umount $SYSTEM_ROOT
} }
load_modules() { load_modules() {
@ -875,10 +861,12 @@ check_update() {
fi fi
fi fi
mount_part "$UPDATE_DIR/$UPDATE_SYSTEM" "/update" "ro,loop"
# Verify that the new upgrade is compatible with the current system - this should avoid creating # Verify that the new upgrade is compatible with the current system - this should avoid creating
# non-booting systems after (for example) an RPi tar is incorrectly applied to an RPi2 system. # non-booting systems after (for example) an RPi tar is incorrectly applied to an RPi2 system.
if [ ! -f "$UPDATE_ROOT/.nocompat" ]; then if [ ! -f "$UPDATE_ROOT/.nocompat" ]; then
if ! check_is_compatible "$UPDATE_FILENAME" "/flash/$IMAGE_SYSTEM" "$UPDATE_DIR/$UPDATE_SYSTEM"; then if ! check_is_compatible "$UPDATE_FILENAME"; then
do_cleanup do_cleanup
StartProgress countdown "Normal startup in 60s... " 60 "NOW" StartProgress countdown "Normal startup in 60s... " 60 "NOW"
return 0 return 0
@ -932,6 +920,7 @@ check_update() {
umount /sysroot umount /sysroot
update_file "System" "$UPDATE_SYSTEM" "/flash/$IMAGE_SYSTEM" update_file "System" "$UPDATE_SYSTEM" "/flash/$IMAGE_SYSTEM"
update_bootloader update_bootloader
umount /update
do_cleanup do_cleanup
do_reboot do_reboot
} }
@ -1093,10 +1082,10 @@ for BOOT_STEP in \
set_consolefont \ set_consolefont \
check_disks \ check_disks \
mount_flash \ mount_flash \
mount_sysroot \
cleanup_flash \ cleanup_flash \
update_bootmenu \ update_bootmenu \
load_splash \ load_splash \
mount_sysroot \
mount_storage \ mount_storage \
check_update \ check_update \
prepare_sysroot; do prepare_sysroot; do