现在开始了新的工作,工作中使用到的代码管理工具是clearcase。但是它在提交多级目录时很是麻烦,所以自己写了个脚本。
放在这里,给需要的用户。
使用方法是:
./add_source.sh dir
需要注意的是 需要提交的目录下的东西都是自己新建的,否则会出错直接退出
#!/bin/bash
#list result analyzer added but not check in java file
TMPFILE="/tmp/tmp_file"
TMPFILE2="/tmp/tmp_file2"
CT="/usr/atria/bin/cleartool "
CTCO="/usr/atria/bin/cleartool co -nc "
CTCI="/usr/atria/bin/cleartool ci -nc "
CTMKELEM="/usr/atria/bin/cleartool mkelem -mkpath -nc "
WORKSAPCE=""
CURRENTPATH=""
function cleantmpfile()
{
rm -rf $TMPFILE $TMPFILE2
}
if [ $# -ne 1 ]
then
echo "usage: ./add_source.sh dir"
echo "for example, ./add_source.sh /tmp/ab"
echo "/tmp path must be under VOBs, your created directory ab, ab/cd, etc"
echo "then this shell will check in all the directory and file to clearcase."
exit
fi
function checkexitcode()
{
if [ "$?" -ne "0" ]; then
echo "##############################"
echo "Sorry, command executed error."
echo "##############################"
exit 1
fi
}
cleantmpfile
#backup current path
CURRENTPATH=$(pwd)
cd $1
WORKSAPCE=$(pwd)
echo -n "Your parameter is: "
echo $WORKSAPCE
#check out current path's parent
cd ..
$CTCO .
#find all dirctories/files in user input
find $WORKSAPCE -type d -print > $TMPFILE
find $WORKSAPCE -type f -print > $TMPFILE2
#add all dir to clearcase
echo "mkelem all directories"
while read LINE
do
echo $LINE
$CTMKELEM $LINE
checkexitcode
done < $TMPFILE
#make sure file under directory is add to clearcase
echo "check in all files"
path=""
while read FILE
do
echo $FILE
#path=$(dirname $FILE)
#cd $path
$CTMKELEM $FILE
checkexitcode
#check in file
$CTCI $FILE
checkexitcode
done < $TMPFILE2
#check all dir
echo "check out all directories"
while read LINE
do
$CTCI $LINE
checkexitcode
done < $TMPFILE
$CTCI .
#restore path
cd $CURRENTPATH