用bash 写的CVS版本控制脚本

来源:互联网 发布:中国十大网络主播 编辑:程序博客网 时间:2024/05/16 05:10
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
@echooff
@REM Create tag script
@REM 2013-03-20 DD
@setlocal
@pushd%WORK_SPACE%
@goto StartScript
:Usage
@echoUsage: %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 idwho 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 filedirectory default is current directory.
@echo   help - optional. help.
@goto :eof
:errRepository
@call :Usage
@echoERROR: CVS repository name is empty.
@goto :eof
:errCheckReposit
@call :Usage
@echoERROR: CVS repository (%Repository%) does not exist.
@goto :eof
:errHome
@call :Usage
@echoERROR: CVS home is empty.
@goto :eof
:errCheckHome
@call :Usage
@echoERROR: CVS home (%cvsHome%) does not exist.
@goto :eof
:errCheckType
@call :Usage
@echoERROR: The tag typewith trunk,branch,tag.
@goto :eof
:errCheckType
@call :Usage
@echoERROR: The tag typewith trunk,branch,tag.
@goto :eof
:errSourceType
@call :Usage
@echoERROR: Source tag Type is empty
@goto :eof
:errCreateType
@call :Usage
@echoERROR:Create tag Type is empty.
@goto :eof
:errUser
@call :Usage
@echoERROR:CVS user idis empty.
@goto :eof
:errCtlFileMissing
@call :Usage
@echoERROR: There is no control file(.ctl) in current directory.
@goto :eof
:errCtlFileTooMany
@call :Usage
@echoERROR: There are morethan one control files (.ctl) incurrent directory.
@goto :eof
:errCtlFileNotFound
@call :Usage
@echoERROR: Control file(%ctlFile%) not found.
@goto :eof
:errLogDir
@call :Usage
@echoERROR: Log directory (%logDir%) does not exist.
@goto :eof
:errLogin
@echoERROR:connect to CVS (%Repository%\%cvsHome%) failed.
@echoPlease check your usrname and password.
@goto :eof
:errCreateTag
@echoERROR: created tag (%err_tag%) failed.
@goto :eof
:StartScript
@setSCRIPT_CMD=%0
@setRepository=
@setcvsHome=
@setSourceType=
@setCreateType=
@setcvsUser=
@setcvsPwd=
@setctlFile=
@setlogDir=
: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
@setRepository=%2
@shift
@shift
@goto NextParam
:setCvsHome
@setcvsHome=%2
@shift
@shift
@goto NextParam
:setSourceType
@setSourceType=%2
@shift
@shift
@goto NextParam
:setCreateType
@setCreateType=%2
@shift
@shift
@goto NextParam
:setUser
@setcvsUser=%2
@shift
@shift
@goto NextParam
:setPwd
@setcvsPwd=%2
@shift
@shift
@goto NextParam
:setCtlfile
@setctlFile=%2
@shift
@shift
@goto NextParam
:setLogDir
@setlogDir=%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
@ifnot "A%ctlFile%"== "A" goto cont_1
@set/A ASN=0
@for%%i in (*.ctl) do set /A ASN+=1
@if%ASN% == 0 goto errCtlFileMissing
@ifnot %ASN% == 1 goto errCtlFileTooMany
@for%%i in (*.ctl) do set ctlFile=%%i
  :cont_1
  @REM script root directory is the controlfile directory full path ending with \
  @for/F "tokens=*" %%i in ("%ctlFile%")do setscriptRootDir=%%~dpi
  @for/F "tokens=*" %%i in ("%ctlFile%")do setcontrolFileName=%%~nxi
  @setctlFile=%scriptRootDir%%controlFileName%
  @ifnot exist "%ctlFile%"goto errCtlFileNotFound
:cont2
@ifnot "A%logDir%" == "A" goto cont2_1
@if"A%logDir%" == "A"set logDir=.
@ifnot exist %logDir%\logs  mkdir%logDir%\logs
@setlogDir=%logDir%\logs
  :cont2_1
  @ifnot exist %logDir% goto errLogDir
  @for/F "usebackq tokens=1,2,3 delims=- "%%i in (`date /T`)do setTodayDate=%%i%%j%%k
  @for/F "usebackq tokens=1,2,3 delims=: "%%i in (`time /T`)do setTodayDate=%TodayDate%-%%i%%j
  @setlogfile=%logDir%\%TodayDate%.log
  @echologfile=%logfile% >> %logfile%
:cont3
@echoStart script at: %DATE% %TIME% > "%logfile%"
@echoPremium Technology Inc.  >>"%logFile%"
@echoCVS Repostory: %Repository% >> "%logfile%"
@echoCVS HOME: %cvsHome% >> "%logfile%"
@echoCreate tag user id: %cvsUser% >>"%logfile%"
@echoScript control file: %ctlFile% >>"%logfile%"
@echo. >>"%logfile%"
:finshLogin
@rem login CVS server.
@if"A%cvsPwd%" == "A"set /p cvsPwd=%cvsUser%'s password:
@setCVSROOT=:pserver:%cvsUser%:%cvsPwd%@192.168.3.50:/%Repository%
@echoconnect to cvs(%Repository%) ...
@cvs login >> %logfile%
@ifnot "%ERRORLEVEL%"== "0" goto errLogin
@echoLogin cvs %Repository% successfully.
@echoNew 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%
@echoCreated successful >> "%logfile%"
@echoend time >> "%logfile%"
@echoat %DATE% %TIME% >> "%logfile%"
@goto :eof
:finshTag_1
@rem create tags.
@for/f "eol=# tokens=1,2,3 delims=  "%%i in (%ctlFile%) do (
  echocreating 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 (
  echocreating 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
@echoplease check log file"%logfile%"
@goto :eof
0 0
原创粉丝点击