我有以下问题。我需要组织自动上传以从svn存储库部署服务器,但有一些特色。 我是怎么写的:
# $1 - project; $2 - version (optional)
# rm -rf $projectDir
if [ "$2" == '' ]; then
svn export $trunk $projectDir --force >> $log
version=`svn info $trunk | grep Revision | awk '{print$2}'`
svn copy $trunk $tags/$version -m "created while uploading last version of $1"
echo "New stable version #$version of $1 is created
Uploading to last version is completed successfully"
else
version=$2
svn export $tags/$version/ $projectDir --force >> $log
echo "Revert to version #$version is completed successfully"
fi
echo $version > $projectDir/version
chown -R $1:$1 $projectDir
但是svn export不会删除通过svn文件删除的内容,所以我需要在每次导出之前清理目录。这不好。 在此之前,我使用checkout进行部署,如下所示:
svn co $trunk >> $log
cp -ruf trunk/* $projectDir
svn info $trunk | grep Revision > $projectDir/version
chown -R $project:$project $projectDir
echo "uploading finished"
这项工作非常好且非常快(它只更改了更改的文件)而不是导出,但是:
在我的上一个脚本中co不起作用,因为它试图从不同的存储库目录(trunk / some tag)检出一个目录,这不是真的。
所以,问:
提前致谢。
答案 0 :(得分:1)
您评估过Capistrano了吗?它可以做很多你想要实现的目标。
答案 1 :(得分:0)
以下代码为解决方案的基础:
它更简单,完全解决了我的问题。
if [ "$2" == '' ]; then
version=`svn info ${trunk} | grep Revision | awk '{print$2}'`
if [ `cat ${projectWWW}/version` == "${version}" ]; then
resultMessage="Project is up to date"
else
svn co ${trunk} ${projectRoot}/co >> ${log}
cp -ruf ${projectRoot}/co/ ${projectRoot}/releases/${version}
chown -R $1:$1 ${projectRoot}/releases/${version}
resultMessage="New stable version #$version of $1 is created
Uploading to last version is completed successfully"
fi
else
version=$2
resultMessage="Revert to version #$version is completed successfully"
fi
ln -s ${projectRoot}/releases/${version} ${projectWWW}
echo ${version} > ${projectWWW}/version
echo ${resultMessage} >> ${log}