Android系统代码本地更新Linux shell脚本2

来源:互联网 发布:大数据可视化展示系统 编辑:程序博客网 时间:2024/06/06 00:01

Android系统代码本地更新Linux shell脚本2相当于Android系统代码本地更新(Linux系统)原理差不多、修改和使用方法更简单。可以带参数(脚本运行方法:./sync.sh Remote_repository_name Remote_Public_source Original_source Public_source Your_branch ),也可以到脚本中修改默认一些变量(RRN(Remote repository name) RPS(Remote public source) OS(Original source) PS(Public source) YB(Your branch))。脚本如下:sync.sh

#!/bin/bash########################################### User modified RRN RPS OS PS YB # Remote repository nameRRN=rk# Remote public sourceRPS=inet# Original sourceOS=sofia# Public sourcePS=inet# Your branchYB=weitf########################################### entry arguments: Remote_repository_name Remote_Public_source Original_source Public_source Your_branch if [ $# != 0 ]; then    if [ $# \> 5 ]; then        echo "ERROR: too many arguments"        exit    elif [ $# == 5 ]; then        # Remote repository name        RRN=$1        # Remote public source        PS=$2        # Original source        OS=$3        # Public source        RPS=$4        # Your branch        YB=$5    else        if [ $# \< 5 ]; then            echo "ERROR: missing arguments 5 --> your branch"        fi        if [ $# \< 4 ]; then            echo "ERROR: missing arguments 4 --> Public branch"        fi        if [ $# \< 3 ]; then            echo "ERROR: missing arguments 3 --> original branch"        fi        if [ $# \< 2 ]; then            echo "ERROR: missing arguments 2 --> remote public branch"        fi        if [ $# \< 1 ]; then            echo "ERROR: missing arguments 1 --> remote repository name"        fi        exit    fielse    echo "Default branch arguments"     fi########################################### printf Original_source Public_source Your_branch Remote_repository_nameecho ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"echo "Remote repository name: $RRN"echo "Remote public source: $RPS"echo "Original source: $OS"echo "Public source: $PS"echo "Your branch: $YB"##########################################echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"echo "Check branch:repo branch"repo branch | tee branch.logBRANCH=`cat branch.log`branch_exist=0for i in $BRANCH; do    if [ "$i" == "$OS" -o "$i" == "$PS" -o "$i" == "$YB" ]; then        ((branch_exist++))    fidoneif [ $branch_exist != 3 ]; then    echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"    echo "ERROR: entry arguments invalid branch"    exitfiif [ -f branch.log ]; then    rm branch.logfi##########################################echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"echo "Check status:repo status"repo status | tee status.logSTATUS=`cat status.log`for i in $STATUS; do    if [ "$i" == "-m" ];then        break;    fidoneif [ "$i" != "-m" ];then    echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"    echo "checkout $OS:repo checkout $OS"    repo checkout $OS    if [ $? -eq 0 ]; then        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"        echo "Update project files:repo sync"        repo sync        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"        echo "checkout $PS:repo checkout $PS"        repo checkout $PS        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"        echo "Pull code:repo forall -c git pull $RRN $RPS"        repo forall -c git pull $RRN $RPS        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"        echo "checkout $YB:repo checkout $YB"        repo checkout $YB        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"        echo "Merge code:repo forall -c git merge $PS"        repo forall -c git merge $PS        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"        echo "Check status:repo status"        repo status | tee status.log        STATUS=`cat status.log`        for j in $STATUS        do            # echo $j            # modified by weitf @20150802            # if [ "$j" == "-m" ];then            if [ "$j" == "Um" ];then                echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"                echo "Merge error: CONFLICT!!!!($(date -d "today" +"%Y.%m.%d %H:%M:%S"))" | tee -a sync.log                exit            fi        done        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"        echo "Push code:repo forall -c git push $RRN $YB:$RPS"          # repo forall -c git push $RRN $YB:$RPS        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"        echo "Push code:push finish!!!"        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"        echo "sync finish($(date -d "today" +"%Y.%m.%d %H:%M:%S"))!!!" | tee -a sync.log    fielse    echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"    echo "checkout $YB:repo checkout $YB"    repo checkout $YB    echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"    echo "Check status:repo status"    repo status    echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"    echo "Commit error:no commit($(date -d "today" +"%Y.%m.%d %H:%M:%S"))"| tee -a sync.logfi
0 0