fwupdate: add an error status

This commit is contained in:
Calin Crisan 2019-11-18 00:00:21 +02:00
parent 16a17ec158
commit 875c05ac1a

View File

@ -60,6 +60,7 @@ EXTRACT_DONE_FILE=${FW_DIR}/extract_done
FLASH_BOOT_STARTED_FILE=${FW_DIR}/flash_boot_started FLASH_BOOT_STARTED_FILE=${FW_DIR}/flash_boot_started
FLASH_BOOT_DONE_FILE=${FW_DIR}/flash_boot_done FLASH_BOOT_DONE_FILE=${FW_DIR}/flash_boot_done
FLASH_REBOOT_STARTED_FILE=${FW_DIR}/flash_reboot_started FLASH_REBOOT_STARTED_FILE=${FW_DIR}/flash_reboot_started
ERROR_FILE=${FW_DIR}/error
TMP_BOOT_DIR=/tmp/fwupdate_boot TMP_BOOT_DIR=/tmp/fwupdate_boot
TMP_ROOT_DIR=/tmp/fwupdate_root TMP_ROOT_DIR=/tmp/fwupdate_root
@ -255,6 +256,7 @@ function do_download() {
rm -f ${FLASH_BOOT_STARTED_FILE} rm -f ${FLASH_BOOT_STARTED_FILE}
rm -f ${FLASH_BOOT_DONE_FILE} rm -f ${FLASH_BOOT_DONE_FILE}
rm -f ${FLASH_REBOOT_STARTED_FILE} rm -f ${FLASH_REBOOT_STARTED_FILE}
rm -f ${ERROR_FILE}
touch ${DOWNLOAD_STARTED_FILE} touch ${DOWNLOAD_STARTED_FILE}
echo "downloading..." echo "downloading..."
@ -288,14 +290,14 @@ function do_download() {
fi fi
if [[ -z "${url}" ]]; then if [[ -z "${url}" ]]; then
echo "no such version" 1>&2 echo "no such version" | tee 1>&2 ${ERROR_FILE}
rm ${DOWNLOAD_STARTED_FILE} rm ${DOWNLOAD_STARTED_FILE}
exit 1 exit 1
fi fi
free_disk=$(df /data | tail -n 1 | tr -s ' ' | cut -d ' ' -f 4) free_disk=$(df /data | tail -n 1 | tr -s ' ' | cut -d ' ' -f 4)
if [[ "${free_disk}" -lt $((MIN_FREE_DISK * 1024)) ]]; then if [[ "${free_disk}" -lt $((MIN_FREE_DISK * 1024)) ]]; then
echo "not enough disk space" 1>&2 echo "not enough disk space" | tee 1>&2 ${ERROR_FILE}
rm ${DOWNLOAD_STARTED_FILE} rm ${DOWNLOAD_STARTED_FILE}
exit 1 exit 1
fi fi
@ -321,7 +323,7 @@ function do_download() {
wait ${pid} wait ${pid}
if [[ "$?" != 0 ]]; then if [[ "$?" != 0 ]]; then
cat ${CURL_LOG_FILE} echo "download failed" | tee 1>&2 ${ERROR_FILE}
rm ${DOWNLOAD_STARTED_FILE} rm ${DOWNLOAD_STARTED_FILE}
exit 1 exit 1
fi fi
@ -354,7 +356,7 @@ function run_pre_upgrade() {
# non-zero exit status of pre-upgrade script indicates that # non-zero exit status of pre-upgrade script indicates that
# the upgrade process must not be continued # the upgrade process must not be continued
echo "aborted by pre-upgrade script" echo "aborted by pre-upgrade script" | tee 1>&2 ${ERROR_FILE}
return 1 return 1
fi fi
done done
@ -368,7 +370,7 @@ function run_pre_upgrade() {
function do_extract() { function do_extract() {
if ! [[ -f ${FW_FILE_GZ} || -f ${FW_FILE_XZ} ]] || ! [[ -f ${DOWNLOAD_DONE_FILE} ]]; then if ! [[ -f ${FW_FILE_GZ} || -f ${FW_FILE_XZ} ]] || ! [[ -f ${DOWNLOAD_DONE_FILE} ]]; then
echo "firmware file not downloaded" 1>&2 echo "firmware file not downloaded" | tee 1>&2 ${ERROR_FILE}
exit 1 exit 1
fi fi
@ -376,6 +378,7 @@ function do_extract() {
rm -f ${FLASH_BOOT_STARTED_FILE} rm -f ${FLASH_BOOT_STARTED_FILE}
rm -f ${FLASH_BOOT_DONE_FILE} rm -f ${FLASH_BOOT_DONE_FILE}
rm -f ${FLASH_REBOOT_STARTED_FILE} rm -f ${FLASH_REBOOT_STARTED_FILE}
rm -f ${ERROR_FILE}
rm -f ${FW_FILE_EXTR} rm -f ${FW_FILE_EXTR}
touch ${EXTRACT_STARTED_FILE} touch ${EXTRACT_STARTED_FILE}
@ -400,7 +403,7 @@ function do_extract() {
DECOMPRESS_PID_FILE=${GUNZIP_PID_FILE} DECOMPRESS_PID_FILE=${GUNZIP_PID_FILE}
gunzip -k -c ${FW_FILE_GZ} > ${FW_FILE_EXTR} 2>${GUNZIP_LOG_FILE} & gunzip -k -c ${FW_FILE_GZ} > ${FW_FILE_EXTR} 2>${GUNZIP_LOG_FILE} &
else else
echo "firmware compression format ${format} not supported" 1>&2 echo "firmware compression format ${format} not supported" 1>&2 | tee 1>&2 ${ERROR_FILE}
exit 1 exit 1
fi fi
@ -440,12 +443,13 @@ function do_extract() {
function do_flash_boot() { function do_flash_boot() {
if ! [[ -f ${FW_FILE_EXTR} ]] || ! [[ -f ${EXTRACT_DONE_FILE} ]]; then if ! [[ -f ${FW_FILE_EXTR} ]] || ! [[ -f ${EXTRACT_DONE_FILE} ]]; then
echo "extracted firmware not present" echo "extracted firmware not present" | tee 1>&2 ${ERROR_FILE}
return 1 return 1
fi fi
rm -f ${FLASH_BOOT_DONE_FILE} rm -f ${FLASH_BOOT_DONE_FILE}
rm -f ${FLASH_REBOOT_STARTED_FILE} rm -f ${FLASH_REBOOT_STARTED_FILE}
rm -f ${ERROR_FILE}
touch ${FLASH_BOOT_STARTED_FILE} touch ${FLASH_BOOT_STARTED_FILE}
echo "flashing boot..." echo "flashing boot..."
@ -490,10 +494,11 @@ function do_flash_boot() {
function do_flash_reboot() { function do_flash_reboot() {
if ! [[ -f ${ROOT_INFO_FILE} ]] || ! [[ -f ${FLASH_BOOT_DONE_FILE} ]]; then if ! [[ -f ${ROOT_INFO_FILE} ]] || ! [[ -f ${FLASH_BOOT_DONE_FILE} ]]; then
echo "root partition info file not present" echo "root partition info file not present" | tee 1>&2 ${ERROR_FILE}
return 1 return 1
fi fi
rm -f ${ERROR_FILE}
touch ${FLASH_REBOOT_STARTED_FILE} touch ${FLASH_REBOOT_STARTED_FILE}
echo "preparing for reboot..." echo "preparing for reboot..."
@ -528,7 +533,10 @@ function show_status() {
new_version=$(cat ${VER_FILE}) new_version=$(cat ${VER_FILE})
fi fi
if [[ -f ${FLASH_REBOOT_STARTED_FILE} ]]; then if [[ -f ${ERROR_FILE} ]]; then
echo -n "error: "
cat ${ERROR_FILE}
elif [[ -f ${FLASH_REBOOT_STARTED_FILE} ]]; then
echo "rebooting [${new_version}]" echo "rebooting [${new_version}]"
elif [[ -f ${FLASH_BOOT_DONE_FILE} ]]; then elif [[ -f ${FLASH_BOOT_DONE_FILE} ]]; then
echo "boot flashed [${new_version}]" echo "boot flashed [${new_version}]"