-
Notifications
You must be signed in to change notification settings - Fork 3
/
checkoutArchive.cmd
183 lines (168 loc) · 6.26 KB
/
checkoutArchive.cmd
1
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
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION&::(Don't pollute the global environment with the following)
::**********************************************************************
SET $NAME=%~n0
SET $DESCRIPTION=Checkout updates/install new units
SET $AUTHOR=Erik Bachmann, ClicketyClick.dk [ErikBachmann@ClicketyClick.dk]
SET $SOURCE=%~f0
::@(#)NAME
::@(-) The name of the command or function, followed by a one-line description of what it does.
::@(#) %$NAME% -- %$DESCRIPTION%
::@(#)
::@(#)SYNOPSIS
::@(-) In the case of a command, a formal description of how to run it and what command line options it takes.
::@(-) For program functions, a list of the parameters the function takes and which header file contains its definition.
::@(-)
::@(#) %$NAME% [VAR]
::@(#)
::@(#)OPTIONS
::@(-) Flags, parameters, arguments (NOT the Monty Python way)
::@(#) -h Help page
::@(#)
::@ (#)
::@(#)DESCRIPTION
::@(-) A textual description of the functioning of the command or function.
::@(#) Install any newer file from Archive directory.
::@(#)
::@(#) WILL overwrite any older file in script directory WITHOUT warning
::@(#)
::@(#)EXAMPLES
::@(-) Some examples of common usage.
::@(#)
::@ (#)EXIT STATUS
::@(-) Exit status / errorlevel is 0 if OK, otherwise 1+.
::@ (#)
::@ (#)ENVIRONMENT
::@(-) Variables affected
::@ (#)
::@ (#)
::@ (#)FILES,
::@(-) Files used, required, affected
::@ (#)
::@ (#)
::@ (#)BUGS / KNOWN PROBLEMS
::@(-) If any known
::@ (#)
::@ (#)
::@(#)REQUIRES
::@(-) Dependecies
::@(#) _Debug.cmd Setting up debug environment for batch scripts
::@(#) _GetOpt.cmd Parse command line options and create environment vars
::@(#)
::@ (#)SEE ALSO
::@(-) A list of related commands or functions.
::@(#) checkInArchive.cmd
::@ (#)
::@ (#)
::@ (#)REFERENCE
::@(-) References to inspiration, clips and other documentation
::@ (#) Author:
::@ (#) URL:
::@ (#)
::@(#)
::@(#)SOURCE
::@(-) Where to find this source
::@(#) %$Source%
::@(#)
::@ (#)AUTHOR
::@(-) Who did what
::@ (#) %$AUTHOR%
::*** HISTORY **********************************************************
::SET $VERSION=YYYY-MM-DD&SET $REVISION=hh:mm:ss&SET $COMMENT=Init Description [xx.xxx]
::SET $VERSION=2010-10-20&SET $REVISION=00:00:00&SET $COMMENT=Initial [01.000]
::SET $VERSION=2010-11-12&SET $REVISION=16:23:00&SET $COMMENT=Adding exact path to _prescript/ErikBachmann [01.010]
::SET $VERSION=2015-02-19&SET $REVISION=02:54:38&SET $COMMENT=Autoupdate / ErikBachmann
::SET $VERSION=2015-10-08&SET $REVISION=11:20:00&SET $COMMENT=GetOpt: Calling usage on -h and exit on error / ErikBachmann
::SET $VERSION=2015-11-12&SET $REVISION=15:32:00&SET $COMMENT=Adding Debug info / ErikBachmann
SET $VERSION=2016-03-14&SET $REVISION=10:00:00&SET $COMMENT=Set "%~dp0\ prefix on function calls / ErikBachmann
::**********************************************************************
::@(#)(c)%$Version:~0,4% %$Author%
::**********************************************************************
CALL "%~dp0\_DEBUG"
CALL "%~dp0\_Getopt" %*&IF ERRORLEVEL 1 EXIT /B 1
::ENDLOCAL
ECHO:%$NAME% -- %$DESCRIPTION%
ECHO:v. %$VERSION% r. %$REVISION%
ECHO:
:Init
IF NOT EXIST .ARCHIVE MKDIR .ARCHIVE
SET _FileCount=0
SET _FilesCopied=0
:Processing
FOR %%A IN (.Archive\*.cmd .Archive\*.bat) DO CALL :CheckoutFile "%%~A"
:Finalize
TITLE %$NAME% done: Tested %_FileCount%. Updates %_FilesCopied%
ECHO:
CALL "%~dp0\_Action" "Files tested"
CALL "%~dp0\_Status" "%_FileCount%"
CALL "%~dp0\_Action" "Files installed/updated"
CALL "%~dp0\_Status" "%_FilesCopied%"
ECHO:*** Done ***
GOTO :EOF
::----------------------------------------------------------------------
:CheckOutFile
SET /A _FileCount+=1
CALL SET _Source=%~1
CALL SET _target=%~n1
CALL SET _target=%_target:~0,-17%%~x1
TITLE %_target%
%_DEBUG_% Source[%_Source%]
%_DEBUG_% Target[%_target%]
:: Find source time
CALL SET _FileTime=%%~t1
CALL SET _FileTime=!_FileTime:~6,4!-!_FileTime:~3,2!-!_FileTime:~0,2!T!_FileTime:~11,5!
CALL SET _FileTime=!_FileTime::=-!
%_DEBUG_% FileTime[%_FileTime%]
CALL "%~dp0\_Action" "[%_target%] [%_fileTime%]"
:: IF target does not exist COPY
IF NOT EXIST "%_target%" (
%_DEBUG_% Target not found: Installing
CALL "%~dp0\_State" "Installing"
COPY /V "%_Source%" "%_target%">nul 2>&1
IF ErrorLevel 1 (
CALL "%~dp0\_Status" "Instal FAILED"
) ELSE (
CALL "%~dp0\_Status" "Installed OK"
SET /A _FilesCopied+=1
)
GOTO :EOF
)
:: Find target time
FOR %%a IN (%_target%) DO CALL SET _TargetTime=%%~ta
CALL SET _TargetTime=!_TargetTime:~6,4!-!_TargetTime:~3,2!-!_TargetTime:~0,2!T!_TargetTime:~11,5!
CALL SET _TargetTime=!_TargetTime::=-!
%_DEBUG_% _TargetTime[%_TargetTime%]
IF /I "%_targetTime%" LSS "%_FileTime%" (
%_DEBUG_% _TargetTime[%_targetTime%] LSS _FileTime[%_FileTime%] = Update
CALL "%~dp0\_State" "Updating..."
TITLE Updating %_target%
%_DEBUG_% "%_Source%" -^> "%_target%"
COPY /V "%_Source%" "%_target%">nul 2>&1
IF ErrorLevel 1 (
CALL "%~dp0\_Status" "Update FAILED"
) ELSE (
CALL "%~dp0\_Status" "Updated OK"
SET /A _FilesCopied+=1
)
TITLE %_target% done
)
IF /I "%_targetTime%" GTR "%_FileTime%" CALL "%~dp0\_Status" Ignore&%_DEBUG_% _TargetTime[%_targetTime%] GTR _FileTime[%_FileTime%] = Ignore
IF /I "%_targetTime%" EQU "%_FileTime%" CALL "%~dp0\_Status" Identical&%_DEBUG_% _TargetTime[%_targetTime%] EQU _FileTime[%_FileTime%] = Identical
GOTO :EOF
:ArchiveFile
%_DEBUG_% - %0 [%~1]
CALL "%~dp0\_action" "- [%~1]"
CALL SET _FileTime=%%~t1
CALL SET _FileTime=!_FileTime:~6,4!-!_FileTime:~3,2!-!_FileTime:~0,2!T!_FileTime:~11,5!
CALL SET _FileTime=!_FileTime::=-!
%_DEBUG_% _FileTime[!_FileTime!]
CALL SET _target=%~dp1\.archive\%~n1.%_FileTime%%~x1
%_DEBUG_% _target[!_target!]
IF NOT EXIST "%_target%" (
CALL "%~dp0\_status" "%_FileTime%"
%_DEBUG_% _target not found: Copying
COPY "%~1" "%_target%">nul
SET /A _FileCount+=1
) ELSE CALL "%~dp0\_status" "OK"
GOTO :EOF :ArchiveFile
::*** End of File *****************************************************