3 # System RW Update Script
5 STATUS_FILE="/opt/data/update/RW.STATUS"
6 COLOR_ERROR='\033[01;31m'
7 COLOR_DEBUG='\033[01;34m'
8 COLOR_NOTIFY='\033[01;33m'
9 COLOR_RESET='\033[00;00m'
10 PATH=/bin:/usr/bin:/sbin:/usr/sbin
13 UPDATE_SCRIPT_DIR=@TZ_SYS_UPGRADE_SCRIPTS@
14 UPDATE_DATA_DIR=/opt/data/update
15 SDB_RULE=${UPDATE_DATA_DIR}/99-sdb-switch.rules
16 HAL_SET_UPGRADE_STATUS=/usr/bin/device_board_set_upgrade_status
20 RW_MACRO=@TZ_SYS_UPGRADE@/rw-update-macro.inc
21 RW_UPDATE_FLAG=/opt/.do_rw_update
23 SCRIPT_NAME=$(basename $0)
28 echo -e "${COLOR_DEBUG}${LOG_TEXT}${COLOR_RESET}"
34 echo -e "${COLOR_ERROR}${LOG_TEXT}${COLOR_RESET}"
40 echo -e "${COLOR_NOTIFY}${LOG_TEXT}${COLOR_RESET}"
45 LOG="[$SCRIPT_NAME]$1"
47 if [ "$2" != "" ]; then
53 PROGRESS_DIR=/tmp/upgrade
56 mkdir -p ${PROGRESS_DIR}
57 echo "$1" > ${PROGRESS_DIR}/total
58 echo "0" > ${PROGRESS_DIR}/progress
59 chsmack -a _ ${PROGRESS_DIR}
60 chsmack -a _ ${PROGRESS_DIR}/total
61 chsmack -a _ ${PROGRESS_DIR}/progress
63 # if GUI is available, run the GUI
64 if [ -e "/usr/bin/rw-update-ani" ]; then
65 export XDG_RUNTIME_DIR=/run
66 export TBM_DISPLAY_SERVER=1
67 /usr/bin/rw-update-ani --wait &
73 echo "$1" > ${PROGRESS_DIR}/progress
76 # This result file will be used for Platform Update Control API to get update result.
77 UPDATE_RESULT_FILE=${UPDATE_DATA_DIR}/result
78 UPI_RW_UPDATE_ERROR_NONE=00
79 UPI_RW_UPDATE_ERROR_PREFIX=FA
80 UPI_RW_UPDATE_ERROR_FAIL=${UPI_RW_UPDATE_ERROR_PREFIX}1A
83 echo "$1" > ${UPDATE_RESULT_FILE}
88 ${HAL_SET_UPGRADE_STATUS} "$1"
90 CRITICAL_LOG "set_upgrade_status success: ${1}"
92 CRITICAL_LOG "set_upgrade_status failed: ${1}"
96 if [[ $(</proc/cmdline) =~ partition_ab= ]] && [ ! -f ${RW_UPDATE_FLAG} ]
98 NOTIFY "${RW_UPDATE_FLAG} file does not exist. Cancel RW Upgrade."
103 NOTIFY "----------------------------------------------------------------------"
104 NOTIFY "System RW update: rw update started"
107 UPDATE_PROGRESS_ERR=0
113 ERROR "FAIL: Upgrade macro does not exist"
117 if [ ! -d ${UPDATE_SCRIPT_DIR} ]
119 ERROR "FAIL: Upgrade directory does not exist"
123 # Execute update scripts
124 if [ ${UPDATE_PREPARE_ERR} = "1" ]
126 ERROR "FAIL: Update preparation was failed"
127 SET_UPDATE_RESULT ${UPI_RW_UPDATE_ERROR_FAIL}
128 SET_UPGRADE_STATUS -1
131 DEBUG "Version OLD: ${OLD_VER}, NEW: ${NEW_VER}"
133 TOTAL_TASKS=`ls -l ${UPDATE_SCRIPT_DIR} | grep -c '^-'`
134 PROGRESS_INIT ${TOTAL_TASKS}
136 UPDATE_SCRIPTS=`/bin/ls ${UPDATE_SCRIPT_DIR}`
137 NOTIFY "TOTAL TASKS: ${TOTAL_TASKS}"
138 for UPSCRIPT in ${UPDATE_SCRIPTS}; do
139 NOTIFY "CURRENT TASK: ${CURRENT_TASK} ${UPSCRIPT}"
140 ${SHELL} ${UPDATE_SCRIPT_DIR}/${UPSCRIPT}
141 if [ $? -ne 0 ]; then
142 ERROR "[FAIL] ${UPSCRIPT}"
143 UPDATE_PROGRESS_ERR=1
145 DEBUG "[DONE] ${UPSCRIPT}"
147 PROGRESS ${CURRENT_TASK}
148 SET_UPGRADE_STATUS $((HAL_PROGRESS_MIN + ((HAL_PROGRESS_MAX - HAL_PROGRESS_MIN)*CURRENT_TASK)/TOTAL_TASKS ))
149 CURRENT_TASK=$(( ${CURRENT_TASK} + 1 ))
154 if [ ${UPDATE_PROGRESS_ERR} = "1" ]
156 NOTIFY "SUCCESS: Upgrade finished, but some scripts are failed"
157 SET_UPDATE_RESULT ${UPI_RW_UPDATE_ERROR_FAIL}
159 NOTIFY "SUCCESS: Upgrade successfully finished"
160 SET_UPDATE_RESULT ${UPI_RW_UPDATE_ERROR_NONE}
164 if [ -e ${SDB_RULE} ]; then
171 NOTIFY "----------------------------------------------------------------------"
173 if [[ ! $(</proc/cmdline) =~ partition_ab= ]]
178 #Reboot by update-finalize.service