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 name
RRN=rk
# Remote public source
RPS=inet
# Original source
OS=sofia
# Public source
PS=inet
# Your branch
YB=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
fi
else
echo "Default branch arguments"
fi
##########################################
# printf Original_source Public_source Your_branch Remote_repository_name
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
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.log
BRANCH=`cat branch.log`
branch_exist=0
for i in $BRANCH; do
if [ "$i" == "$OS" -o "$i" == "$PS" -o "$i" == "$YB" ]; then
((branch_exist++))
fi
done
if [ $branch_exist != 3 ]; then
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "ERROR: entry arguments invalid branch"
exit
fi
if [ -f branch.log ]; then
rm branch.log
fi
##########################################
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Check status:repo status"
repo status | tee status.log
STATUS=`cat status.log`
for i in $STATUS; do
if [ "$i" == "-m" ];then
break;
fi
done
if [ "$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
fi
else
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.log
fi