Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1637955
  • 博文数量: 126
  • 博客积分: 1541
  • 博客等级: 上尉
  • 技术积分: 1914
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-20 11:14
文章分类

全部博文(126)

文章存档

2014年(21)

2013年(42)

2012年(63)

分类: LINUX

2013-03-13 21:15:01

#!/bin/bash


cd_to_zprojects()
{
     ls .repo >/dev/null
     result=$?
     
     while [[ "$result" -ne 0 ]]
     do     
             cd ../
             ls .repo   >/dev/null
             result=$?
     done
     
     cd zprojects/
}


cd_to_zprojects


sync_code()
{
     local PROJECT=$(pwd | awk -F "/" '{print $4}')
     local XML=$(ls -l $HOME/$PROJECT/.repo/manifest.xml|awk -F'/' '{print $NF}')
     local BRANCH=${XML%.*}
     BRANCH=${BRANCH/8x25*/8x25}
     echo "git fetch caf"
         git fetch caf
     echo "git reset --hard m/$BRANCH"
          git reset --hard m/$BRANCH


     temp=$(cat .git/HEAD | awk -F "/" '{print $3}')
     echo $temp
     str=$(ls .git/refs/heads/$BRANCH|awk -F'/' '{print $NF}' )
     echo $str
     if [ $str"yes" == "yes" ];then
         git checkout -b $BRANCH m/$BRANCH
     elif [ "$temp" == "$BARANCH" ];then
         echo "Already on $BRANCH"
     else
         git checkout $BRANCH
     fi
}
echo -e  '\e[33mdo you want Synchronization code and switch branches [y/n]  \e[m'
read ch
if [ $ch"yes" == "yyes" -o $ch"yes" == "Yyes" -o $ch"yes" == "yes" ];then
     sync_code
fi
projects=($(ls -d */ | grep -v "\(common\|public-binary\)"))
project=''


print_projects()
{


if [[ ${#projects[@]} > 0 ]]; then
local index=1
local project
for project in ${projects[@]}; do
printf "%4s %s\n" "[$index]" ${project%/}
index=$(($index + 1))
done
fi
}




read -p "new project name:" project


if [ -d $project ]; then
echo "$project is exits"
read -p "continue anyway[Y]" answer
if [ ! -z "$answer" -a "${answer:0:1}" != "Y" -a "${answer:0:1}" != "y" ];then
echo "abort"
exit 1
fi
fi


print_projects
echo -n "$project is base on:"
read choice
if [ -d $choice ];then
base=$choice
elif [[ $choice -gt ${#projects[@]} || $choice -lt 1 ]]; then 
echo "bad choice"
exit 1
else
base=${projects[$(($choice-1))]}
fi


proj=${project%%-*}
proj=$(echo "$proj" |tr '[a-z]' "[A-Z]")




base=${base%/}
echo "copy files..."
[ -d $project ] && rm -rf $project
cp -r $base $project 


echo "rename files..."
(cd $project && rename -f "s/$base/$project/g" *.*;sed -i "s/$base/$project/" *.ini *.cfg;
BASE=$(sed "s/-/_/" <<<$base|tr '[a-z]' '[A-Z]');PROJECT=$(sed "s/-/_/" <<<$project|tr '[a-z]' '[A-Z]');
sed -i "s/$BASE/$PROJECT/g" *.ini;
sed -i '/PRJ_PRODUCT_MODEL/ s/".*"/""/' *.ini;
sed -i '/PRODUCT_MANUFACTURER/ s/".*"/""/' *.ini;
sed -i -r "s/E[0-9]{3}/$proj/" *.h;
)


sleep 1


submit_gerrit()
{
echo "git add $project ..."
git add $project
echo "git commit $project ..."
git commit $project
echo  "repo upload . ..."
repo upload .
}


echo -e  '\e[33mdo you want to submitted to gerrit [y/n]  \e[m'
read ch
if [ $ch"yes" == "yyes" -o $ch"yes" == "Yyes" -o $ch"yes" == "yes" ];then
    submit_gerrit
fi
#editor $project/env_$project.ini

阅读(564) | 评论(0) | 转发(0) |
0

上一篇:shell 项目

下一篇:shell 练习 随笔

给主人留下些什么吧!~~