From aa93cd90acae16f720dc8ba60925bdc43447db82 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Wed, 1 Jun 2022 15:45:10 +0200 Subject: [PATCH] upgrade scripts: Improve check exectuion This change is to prevent bash from exiting a script with an error when a command returns a code other than 0, which is expected. E.g.: SOME_VAR=$(grep some_value /some/file) as the "errexit" flag is set, if "some_value" is not found grep will return exit code 1 and the script will abort. This behavior also varies with different versions of bash, so it is better in such cases to avoid invoking commands that may return non-zero code. Change-Id: I3f9eefc51a37d9762a9b47cc716805957461891f --- scripts/upgrade-common.inc | 6 ++++-- scripts/upgrade-trigger.sh | 14 ++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/upgrade-common.inc b/scripts/upgrade-common.inc index c313ad8..da9357e 100644 --- a/scripts/upgrade-common.inc +++ b/scripts/upgrade-common.inc @@ -5,6 +5,8 @@ HAL_PART_MAP_FILE="label_map.list" HAL_PART_LIST_FILE="background_copy.list" CONFIG_FILE="update.cfg" SET_UPGRADE_STATUS="/usr/bin/device_board_set_upgrade_status" +TRUE=0 +FALSE=1 #------------------------------------------------ # critical_log msg [file] @@ -121,7 +123,7 @@ background_copy() { } load_background_copy_list() { - PARTITION_LIST=$(grep -v -e "^#" -e "^$" ${HAL_UPGRADE_CFG_DIR}/${HAL_PART_LIST_FILE}) + PARTITION_LIST=$(sed -e '/^#/d' -e '/^$/d' "${HAL_UPGRADE_CFG_DIR}/${HAL_PART_LIST_FILE}") } upgrade_images() { @@ -131,7 +133,7 @@ upgrade_images() { LABEL_MAP_PATH=${HAL_UPGRADE_CFG_DIR}/${HAL_} while read LABEL PARTLABEL; do declare "LABEL_MAP_${LABEL}=${PARTLABEL}" - done < <(grep -v -e "^#" -e "^#" ${LABEL_MAP_PATH}/${HAL_PART_MAP_FILE}) + done < <(sed -e '/^#/d' -e '/^$/d' "${LABEL_MAP_PATH}/${HAL_PART_MAP_FILE}") # _OFFSET _SIZE _HASH1 _HASH2 while read -r LABEL_NAME DELTA_NAME TYPE DEV OFFSET OLD_SIZE NEW_SIZE OLD_SHA NEW_SHA diff --git a/scripts/upgrade-trigger.sh b/scripts/upgrade-trigger.sh index 777cd5f..af51fd3 100755 --- a/scripts/upgrade-trigger.sh +++ b/scripts/upgrade-trigger.sh @@ -53,13 +53,19 @@ log() { } is_full_upgrade() { - NON_PRE_UA_IMAGES=$(tar Oxf "$DOWNLOAD_DELTA" update.cfg | awk '{print $3}' | grep -v PRE_UA) - [ -z "${NON_PRE_UA_IMAGES}" ] + # Check if update.cfg contains any entry with type other than PRE_UA. If so, + # it is not full upgrade + if tar Oxf "$DOWNLOAD_DELTA" update.cfg | awk '{print $3}' | grep -q -v PRE_UA; then + return $FALSE + fi + return $TRUE } is_ab_upgrade() { - AB_SLOT=$(grep partition_ab= /proc/cmdline) - [ ! -z "${AB_SLOT}" ] + if grep -q partition_ab= /proc/cmdline; then + return $TRUE + fi + return $FALSE } do_update() { -- 2.7.4