用bash 写的CVS版本控制脚本

cvs是一个比较老的代码版本控制软件,目前还有很多公司在使用它,这个脚本主要用于,代码的版本控制,创建branch,tag。该脚本用window是bat编写,在向脚本传输参数的时候,有比较强的逻辑判断代码如下,要有一定的bat基础,否者很难看懂哦!


@echo off
@REM Create tag script
@REM 2013-03-20 DD
@setlocal
@pushd %WORK_SPACE%
@goto StartScript
:Usage
@echo Usage: %SCRIPT_CMD% -R repository -M cvsHome -S sourceTagType -C createTagType -U userid [-P password] [-F ctlFile]  [-L logDir] [-H help]
@echo    repository - required. The CVS Repository Name.
@echo    cvsHome - required. The CVS root directory. option
@echo    SourceTagType - required. option (trunk,head,branch,tag).
@echo    createTagType - required. option (branch,tag).
@echo    userid - required. The CVS user id who can connect CVS server.
@echo    password - optional. The CVS user password.
@echo    ctlFile - optional. The script control file, default is (.ctl) in current directory.
@echo    logDir - optional. The log file directory default is current directory.
@echo    help - optional. help.
@goto :eof
:errRepository
@call :Usage
@echo ERROR: CVS repository name is empty.
@goto :eof
:errCheckReposit
@call :Usage
@echo ERROR: CVS repository (%Repository%) does not exist.
@goto :eof
:errHome
@call :Usage
@echo ERROR: CVS home is empty.
@goto :eof
:errCheckHome
@call :Usage
@echo ERROR: CVS home (%cvsHome%) does not exist.
@goto :eof
:errCheckType
@call :Usage
@echo ERROR: The tag type with trunk,branch,tag.
@goto :eof
:errCheckType
@call :Usage
@echo ERROR: The tag type with trunk,branch,tag.
@goto :eof
:errSourceType
@call :Usage
@echo ERROR: Source tag Type is empty
@goto :eof
:errCreateType
@call :Usage
@echo ERROR:Create tag Type is empty.
@goto :eof
:errUser
@call :Usage
@echo ERROR:CVS user id is empty.
@goto :eof
:errCtlFileMissing
@call :Usage
@echo ERROR: There is no control file (.ctl) in current directory.
@goto :eof
:errCtlFileTooMany
@call :Usage
@echo ERROR: There are more than one control files (.ctl) in current directory.
@goto :eof
:errCtlFileNotFound
@call :Usage
@echo ERROR: Control file (%ctlFile%) not found.
@goto :eof
:errLogDir
@call :Usage
@echo ERROR: Log directory (%logDir%) does not exist.
@goto :eof
:errLogin
@echo ERROR:connect to CVS (%Repository%\%cvsHome%) failed.
@echo Please check your usrname and password.
@goto :eof
:errCreateTag
@echo ERROR: created tag (%err_tag%) failed.
@goto :eof
:StartScript
@set SCRIPT_CMD=%0
@set Repository=
@set cvsHome=
@set SourceType=
@set CreateType=
@set cvsUser=
@set cvsPwd=
@set ctlFile=
@set logDir=
:NextParam
@if /I "A%1" == "A" goto CheckParam
@if /I "%1" == "-R" goto setRepositoy
@if /I "%1" == "-M" goto setCvsHome
@if /I "%1" == "-S" goto setSourceType
@if /I "%1" == "-C" goto setCreateType
@if /I "%1" == "-U" goto setUser
@if /I "%1" == "-P" goto setPwd
@if /I "%1" == "-F" goto setCtlfile
@if /I "%1" == "-L" goto setLogDir
@if /I "%1" == "-H" goto Usage
@if /I "%1" == "?" goto Usage
@shift
@goto NextParam
:setRepositoy
@set Repository=%2
@shift
@shift
@goto NextParam
:setCvsHome
@set cvsHome=%2
@shift
@shift
@goto NextParam
:setSourceType
@set SourceType=%2
@shift
@shift
@goto NextParam
:setCreateType
@set CreateType=%2
@shift
@shift
@goto NextParam
:setUser
@set cvsUser=%2
@shift
@shift
@goto NextParam
:setPwd
@set cvsPwd=%2
@shift
@shift
@goto NextParam
:setCtlfile
@set ctlFile=%2
@shift
@shift
@goto NextParam
:setLogDir
@set logDir=%2
@shift
@shift
@goto NextParam
:CheckParam
@if /I "A%Repository%" == "A" goto errRepository
@if /I "%Repository%" NEQ "REP1" if /I "%Repository%" NEQ "REP2" if /I "%Repository%" NEQ "REP3" if /I "%Repository%" NEQ "REP4" if /I "%Repository%" NEQ "REP5"goto errCheckReposit
@if /I "A%cvsHome%" == "A" goto errHome
@if /I "%cvsHome%" NEQ "FSCS3.0" if /I "%cvsHome%" NEQ "REP1.0" if /I "%cvsHome%" NEQ "REP2.0" if /I "%cvsHome%" NEQ "REP3.0" if /I "%cvsHome%" NEQ "REP4.0" goto errCheckHome
@if /I "A%SourceType%" == "A" goto errSourceType
@if /I "%SourceType%" NEQ "TRUNK" if /I "%SourceType%" NEQ "HEAD" if /I "%SourceType%" NEQ "TAG" if /I "%SourceType%" NEQ "BRANCH" goto errCheckType
@if /I "A%CreateType%" == "A" goto errCreateType
@if /I "%CreateType%" NEQ "TAG" if /I "%CreateType%" NEQ "BRANCH" goto errCheckType
@if /I "A%cvsUser%" == "A" goto errUser
@if /I "A%ctlFile%" == "A" goto cont1
:cont1
@REM find .ctl file in current directory
@if not "A%ctlFile%" == "A" goto cont_1
@set /A ASN=0
@for %%i in (*.ctl) do set /A ASN+=1
@if %ASN% == 0 goto errCtlFileMissing
@if not %ASN% == 1 goto errCtlFileTooMany
@for %%i in (*.ctl) do set ctlFile=%%i
  :cont_1
  @REM script root directory is the control file directory full path ending with \
  @for /F "tokens=*" %%i in ("%ctlFile%") do set scriptRootDir=%%~dpi
  @for /F "tokens=*" %%i in ("%ctlFile%") do set controlFileName=%%~nxi
  @set ctlFile=%scriptRootDir%%controlFileName%
  @if not exist "%ctlFile%" goto errCtlFileNotFound
:cont2
@if not "A%logDir%" == "A" goto cont2_1
@if "A%logDir%" == "A" set logDir=.
@if not exist %logDir%\logs  mkdir %logDir%\logs
@set logDir=%logDir%\logs
  :cont2_1
  @if not exist %logDir% goto errLogDir
  @for /F "usebackq tokens=1,2,3 delims=- " %%i in (`date /T`) do set TodayDate=%%i%%j%%k
  @for /F "usebackq tokens=1,2,3 delims=: " %%i in (`time /T`) do set TodayDate=%TodayDate%-%%i%%j
  @set logfile=%logDir%\%TodayDate%.log
  @echo logfile=%logfile% >> %logfile%
:cont3
@echo Start script at: %DATE% %TIME% > "%logfile%"
@echo Premium Technology Inc.  >>"%logFile%"
@echo CVS Repostory: %Repository% >> "%logfile%"
@echo CVS HOME: %cvsHome% >> "%logfile%"
@echo Create tag user id: %cvsUser% >> "%logfile%"
@echo Script control file: %ctlFile% >> "%logfile%"
@echo. >> "%logfile%"
:finshLogin
@rem login CVS server.
@if "A%cvsPwd%" == "A" set /p cvsPwd=%cvsUser%'s password:
@set CVSROOT=:pserver:%cvsUser%:%cvsPwd%@192.168.3.50:/%Repository%
@echo connect to cvs(%Repository%) ...
@cvs login >> %logfile%
@if not "%ERRORLEVEL%" == "0" goto errLogin
@echo Login cvs %Repository% successfully.
@echo New tag name as following: >> %logfile%
@for /F "eol=# tokens=1,2,3* delims=     " %%i in (%ctlFile%) do echo %%i %%j >> %logfile%
@echo. >> "%logfile%"
@call :finshTag %SourceType% %CreateType%
@echo Created successful >> "%logfile%"
@echo end time >> "%logfile%"
@echo at %DATE% %TIME% >> "%logfile%"
@goto :eof
:finshTag_1
@rem create tags.
@for /f "eol=# tokens=1,2,3 delims=  " %%i in (%ctlFile%) do (
  echo creating tag [%%j] please wait ...
  cvs rtag -r %%i %%j %cvsHome%/%%k
  if "%ERRORLEVEL%" == "1" set err_tag=%%j
  if "%ERRORLEVEL%" == "1" goto errCreateTag
  echo ### New tag [%%j] created. >> "%logfile%"
  echo ### New tag [%%j] created.
)
@goto logMessage
:finshBranch_1
@rem create branches.
@for /f "eol=# tokens=1,2,3 delims=  " %%i in (%ctlFile%) do (
  echo creating branch [%%j] please wait ...
  cvs rtag -r %%i -b %%j %cvsHome%/%%k
  if "%ERRORLEVEL%" == "1" set err_tag=%%j
  if "%ERRORLEVEL%" == "1" goto errCreateTag
  echo ### New branch [%%j] created. >> "%logfile%"
  echo ### New branch [%%j] created.
)
@goto logMessage
:finshTag
@if /I "%1" == "head" if /I "%2" == "tag" goto finshTag_1
@if /I "%1" == "branch" if /I "%2" == "tag" goto finshTag_1
@if /I "%1" == "tag" if /I "%2" == "tag" goto finshTag_1
@if /I "%1" == "head" if /I "%2" == "branch" goto finshBranch_1
@if /I "%1" == "branch" if /I "%2" == "branch" goto finshBranch_1
@if /I "%1" == "tag" if /I "%2" == "branch" goto finshBranch_1
:logMessage
@echo please check log file "%logfile%"
@goto :eof


本文出自 “专注于Oracle性能调优” 博客,谢绝转载!

你可能感兴趣的:(脚本,bash,cvs)