做OTA升级方面的工作零零散散的时间加起来也不短了,系统升级的流程尚未总结完毕,首先将自己的一套可以自动制作升级差分包的脚本做一段记录,以方便查阅,相关同仁需要的,可以参考借鉴。
#!/bin/bash ############################################################## # Author: XingShi <dingkongbo@747.cn> # Date : Mar. 20, 2015 ############################################################## if [ ! $1 ]; then echo echo "#########################################################" echo "# please add the product name,such as: $0 s2 #" echo "#########################################################" echo exit 0 fi echo echo "#####################################################" echo "############### FOR PRODUCT $1 ##############" echo "#####################################################" echo dirsum= DIRNAME= OLDVERSION=old-version NEWVERSION=new-version LASTVERSION=last_version DIRFLAG=0 LOCALFLAG=0 ONLINEFLAG=0 COMBASE=/home/data/upgrade/$1/source LOCALIMG=$COMBASE/daily/images/ LVBASE=$COMBASE/daily ONLINEIMG=$COMBASE/online/release/ OVBASE=$COMBASE/online LOVFILE=$LVBASE/$OLDVERSION LVBFILE=$OVBASE/$LASTVERSION LNVFILE=$LVBASE/$NEWVERSION OOVFILE=$OVBASE/$OLDVERSION ONVFILE=$OVBASE/$NEWVERSION MAKEBASE="./updatemk --platform=kitkat --product=$1 --oem=xxx" ZIPBASE=/home/data/upgrade/$1/target/ DLFILE=$ZIPBASE\daily/version RVFILE=$ZIPBASE\user_release/version LOCAL=daily ONLINE=online USRLINE=user_release MKDIR=mkdir function hourlySleep () { while (!([ "$minute" = "00" ] && [ "$second" = "00" ])) do date=`date` time=`echo $date | cut -d " " -f5` hour=`echo $time | cut -d ":" -f1` minute=`echo $time | cut -d ":" -f2` second=`echo $time | cut -d ":" -f3` done } function resultHandle () { len=0 LOGFILE=${2}"/results.txt" if [ ! -f "$1" ]; then if [ ! -f "$LOGFILE" ]; then echo $ZIPNAME >> $LOGFILE chmod a+x $LOGFILE else line=`sed -n '$=' $LOGFILE` LOGSTR=`cat $LOGFILE` for (( len = 0; len < line; len++ )) { LOGBUF[$len]=`echo $LOGSTR | cut -d " " -f$[len + 1]` } for (( index = 0; index < line; index++)) { temp=${LOGBUF[$index]} echo $ZIPNAME if [ $ZIPNAME = ${LOGBUF[$index]} ]; then index=$[line + 1] fi } # echo ================ line: $line ================== # echo ================ index: $index ================== if [ $index -eq $line ]; then echo $ZIPNAME >> $LOGFILE fi fi fi } function makeOtaZip () { # echo "============= making zip now ============" # echo $DIRFLAG SUCCESS=1 for (( i = 0; $i < ($array_size - 1); i++)) { echo "$i times" #ZIPINSTALL=$ZIPBASE${ZIPDIR[$[i+1]]}"-"${ZIPDIR[0]} ZIPINSTALL=$ZIPBASE${1} ZIPNAME=${ZIPDIR[$[i+1]]}"-"${ZIPDIR[0]}".zip" if [ ! -d "$ZIPINSTALL" ]; then $MKDIR $ZIPINSTALL fi #EXIST=`ls -a $ZIPINSTALL | wc -l` OUTPUT=$ZIPINSTALL"/"$ZIPNAME if [ ! -f $OUTPUT ]; then echo "$OUTPUT is not exist" ###########start to make update.zip########## $MAKEBASE --zipfile=${SRCDIR[0]} --incremental=${SRCDIR[$[i+1]]} --output=$ZIPINSTALL"/"$ZIPNAME ############# Add failed make log ####### RESFILE=$ZIPINSTALL"/"$ZIPNAME resultHandle $RESFILE $ZIPINSTALL fi } } function clearArray () { echo "======== clear ========" if [ $LOCALFLAG -gt $ONLINEFLAG ]; then LENGTH=$LOCALFLAG else LENGTH=$ONLINEFLAG fi for (( i = 0; i < $LENGTH; i++ )) do unset ZIPDIR[$i] done } function versionCheck () { clearArray dirsum=`du -h $1* | wc -l` # echo "dirsum :$dirsum" # echo "DIRFLAG :$DIRFLAG" DIRFLAG=$2 # if [ ! $dirsum -eq $DIRFLAG ] ; then # if [ $DIRFLAG -eq 0 ] ; then DIRFLAG=$dirsum # fi DIRNAME=`ls -t $1 | head -n $dirsum` # if [ $dirsum -lt $DIRFLAG ] ; then # array_size=${#ZIPDIR[@]} # echo "before unset array_size: $array_size" # for (( i = $dirsum; i < $DIRFLAG; i++ )) # do # unset ZIPDIR[$i] # done # array_size=${#ZIPDIR[@]} # echo "after unset array_size: $array_size" # fi DIRFLAG=$dirsum for (( i = 0 ; $i < $DIRFLAG; i++ )) { index=$[i + 1] SRCDIR[$i]=`echo $DIRNAME | cut -d " " -f$index` # ZIPDIR[$i]=`echo ${SRCDIR[$i]} | cut -d "." -f1` ZIPDIR[$i]=`echo ${SRCDIR[$i]%.*}` SRCDIR[$i]=${1}${SRCDIR[$i]} } array_size=${#ZIPDIR[@]} echo "array_size: $array_size" for (( i = 0; i < array_size ; i++ )) do for (( j = $i; j < array_size; j++ )) do temp_i=`echo ${ZIPDIR[$i]} | awk '{ print $1 }'` temp_j=`echo ${ZIPDIR[$j]} | awk '{ print $1 }'` if [ $temp_i \< $temp_j ]; then t=${ZIPDIR[$i]} ZIPDIR[$i]=${ZIPDIR[$j]} ZIPDIR[$j]=$t fi done done # # Print the sorted number # echo -e "\nSorted Numbers in Ascending Order:" for (( i=0; i < array_size; i++ )) do echo ${ZIPDIR[$i]} done # fi if [ $1 = $LOCALIMG ]; then LOCALFLAG=$DIRFLAG else ONLINEFLAG=$DIRFLAG fi echo "LOCALFLAG: $LOCALFLAG" echo "ONLINEFLAG: $ONLINEFLAG" } while true do if [ $# = 2 ]; then if [ $2 = "-h" ]; then hourlySleep else sleep 5 fi else sleep 5 fi LOV=`cat $LOVFILE` echo $LOV LNV=`cat $LNVFILE` echo $LNV OOV=`cat $OOVFILE` echo $OOV ONV=`cat $ONVFILE` echo $ONV if [ ! -f "$LVBFILE" ]; then echo $OOV > $LVBFILE chmod a+x $LVBFILE fi if [ $LNV \> $LOV ]; then versionCheck $LOCALIMG $LOCALFLAG makeOtaZip $LOCAL echo $LNV > $LOVFILE echo $LNV > $DLFILE fi if [ $ONV \> $OOV ]; then versionCheck $ONLINEIMG $ONLINEFLAG makeOtaZip $USRLINE echo $OOV > $LVBFILE echo $ONV > $OOVFILE echo $ONV > $RVFILE fi # sleep 5 done
我们的升级系统版本走两条线,一条dailybuild;一条正式发布版本。脚本默认会每隔5S扫描一次两条线的source包目录,每个源整包目录下都有记录最新版本和之前版本的文件,脚本读取最新版本文件记录,如果不同于之前版本文件的记录则开始扫描源包目录并且按时间顺序排序放至一个升级包数组中,再依次按数组元素名称,取源整包做差分升级包。其中具体做的时候用到了一个updatemk脚本,该脚本直接调用系统做升级包的工具和脚本最终生成差分包,该脚本的具体内容,后续博文会有所体现。