Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 ghuddy 1
Option Explicit
2
'=====================================================
3
'        Name: 	pkg_archive
4
' Description:	This library contains methods required
5
'               for dpkg_archive and deploy_archive 
6
'               manipulation. 
7
'=====================================================
8
 
9
 
10
Class PkgArchive
11
	'================ Properties Declaration =============
12
	Private pRemote_Host
13
	Private pArchive_Path
14
 
15
 
16
	'==================== Properties =====================
17
	Public Property Let Remote_Host( SSrhost )
18
		pRemote_Host = SSrhost
19
	End Property
20
 
21
	Public Property Let Archive_Path( SSarch_path )
22
		pArchive_Path = UnixPath(SSarch_path)
23
	End Property
24
 
25
 
26
	'====================== Methods ======================
27
	'-----------------------------------------------------------------------------------------------------------------
28
	Private Sub Get_Archive_Telnet_Login_Details ( outUser, outPassword )
29
		outUser 		= "root"
30
		outPassword 	= "shoo7gaC"
31
	End Sub
32
	'-----------------------------------------------------------------------------------------------------------------
33
	Private Sub Get_Archive_Map_Drive_Login_Details ( outUser, outPassword )
34
		outUser 		= "erggroup\svukovic"
35
		outPassword 	= "4digimoveerg"
36
	End Sub
37
	'-----------------------------------------------------------------------------------------------------------------
38
	Function UnixPath( SSpath )
39
		If SSpath <> "" Then UnixPath = Replace( SSpath, "\", "/" )
40
	End Function
41
    '-----------------------------------------------------------------------------------------------------------------
42
	Sub Ensure_Read_Write ( SSpkg_name, SSpkg_version )
43
		Dim outMachine, outUser, outPassword
44
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
45
 
46
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
47
 
48
		' Set all folders to +RWX and all files to +RW
49
		' --- Commands to run ---
50
		command = _
51
		"cd "& pArchive_Path &" && "&_
52
		"chmod a+rwx "& SSpkg_name &"; "&_
53
		"cd "& SSpkg_name &" && "&_
54
		"find '"& SSpkg_version &"' -type d -exec chmod a+rwx {} \; ; "&_
55
		"chmod -R a+rw "& SSpkg_version &"; "
56
 
57
		WScript.Echo command
58
 
59
		' --- SSH client with login details ---
60
		login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
61
 
62
		Set sysShell = WScript.CreateObject("WScript.Shell")
63
		Set oExec = sysShell.Exec( login_details &" "& command )
64
 
65
		outStrOut = oExec.StdOut.ReadAll
66
		outStrErr = oExec.StdErr.ReadAll
67
 
68
		If outStrErr <> "" Then
69
			Call Raise_Event ( enumEVENT_ERROR, "[sub:Ensure_Read_Write]", _
70
							   "user: "& outUser & VBNewLine &_
71
							   "command: "& command , _
72
							   outStrErr, enum_RELEASE_NOTES_FAILED )
73
		End If
74
 
75
		Set oExec = Nothing
76
		Set sysShell = Nothing
77
 
78
	End Sub
79
	'-----------------------------------------------------------------------------------------------------------------	
80
	Sub All_Read_Only ( SSpkg_name, SSpkg_version )
81
		Dim outMachine, outUser, outPassword
82
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
83
 
84
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
85
 
86
		' Set all folders from version folder, to -W and all files to -W
87
		' --- Commands to run ---
88
		command = _
89
		"cd "& pArchive_Path &"/"& SSpkg_name &" && "&_
90
		"find '"& SSpkg_version &"' -type d -exec chmod a-w {} \; ; "&_
91
		"chmod -R a-w "& SSpkg_version &"; "
92
 
93
		WScript.Echo command
94
 
95
		' --- SSH client with login details ---
96
		login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
97
 
98
		Set sysShell = WScript.CreateObject("WScript.Shell")
99
		Set oExec = sysShell.Exec( login_details &" "& command )
100
 
101
		outStrOut = oExec.StdOut.ReadAll
102
		outStrErr = oExec.StdErr.ReadAll
103
 
104
		If outStrErr <> "" Then
105
			Call Raise_Event ( enumEVENT_ERROR, "[sub:All_Read_Only]", _
106
							   "user: "& outUser & VBNewLine &_
107
							   "command: "& command , _
108
							   outStrErr, enum_RELEASE_NOTES_FAILED )
109
		End If
110
 
111
		Set oExec = Nothing
112
		Set sysShell = Nothing
113
 
114
	End Sub	
115
	'-----------------------------------------------------------------------------------------------------------------	
116
	Sub Create_Doc_Folder ( SSpkg_name, SSpkg_version, docFolder )
117
		Dim outMachine, outDpkg_root, outUser, outPassword
118
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
119
 
120
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
121
 
122
		' --- Commands to run ---
123
		' Creates doc folder if required with rwx permissions for all
124
		command = _
125
		"cd "& pArchive_Path &"/"& SSpkg_name &"/"& SSpkg_version &" && "&_
126
		"mkdir -p -m a+rwx "& docFolder &"; "
127
 
128
		WScript.Echo command
129
 
130
		' --- SSH client with login details ---
131
		login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
132
 
133
		Set sysShell = WScript.CreateObject("WScript.Shell")
134
		Set oExec = sysShell.Exec( login_details &" "& command )
135
 
136
		outStrOut = oExec.StdOut.ReadAll
137
		outStrErr = oExec.StdErr.ReadAll
138
 
139
		If outStrErr <> "" Then
140
			Call Raise_Event ( enumEVENT_ERROR, "[sub:Create_Doc_Folder]", _
141
							   "user: "& outUser & VBNewLine &_
142
							   "command: "& command , _
143
							   outStrErr, enum_RELEASE_NOTES_FAILED )
144
		End If
145
 
146
		Set oExec = Nothing
147
		Set sysShell = Nothing
148
	End Sub
149
    '-----------------------------------------------------------------------------------------------------------------	
150
	Sub Create_Pkg_Folder ( SSpkg_name, SSpkg_version )
151
		Dim outMachine, outDpkg_root, outUser, outPassword
152
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
153
 
154
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
155
 
156
		' --- Commands to run ---
157
		' Creates pkg_name and pkg_version folder if required with rwx permissions for all
158
		command = _
159
		"cd "& pArchive_Path &" && "&_
160
		"mkdir -p -m a+rwx "& SSpkg_name &"; "&_
161
		"cd "& pArchive_Path &"/"& SSpkg_name &" && "&_
162
		"mkdir -p -m a+rwx "& SSpkg_version &"; "
163
 
164
		WScript.Echo command
165
 
166
		' --- SSH client with login details ---
167
		login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
168
 
169
		Set sysShell = WScript.CreateObject("WScript.Shell")
170
		Set oExec = sysShell.Exec( login_details &" "& command )
171
 
172
		outStrOut = oExec.StdOut.ReadAll
173
		outStrErr = oExec.StdErr.ReadAll
174
 
175
		If outStrErr <> "" Then
176
			Call Raise_Event ( enumEVENT_ERROR, "[sub:Create_Pkg_Folder]", _
177
							   "user: "& outUser & VBNewLine &_
178
							   "command: "& command , _
179
							   outStrErr, enum_RELEASE_NOTES_FAILED )
180
		End If
181
 
182
		Set oExec = Nothing
183
		Set sysShell = Nothing
184
	End Sub
185
	'-----------------------------------------------------------------------------------------------------------------
186
	Sub Map_Network_Drive ( SSunc, outMappedDrive )
187
		Dim outUser, outPassword
188
		Dim ValidDrivesARR, validDrive, UsedDrives
189
		Dim i, WshNetwork, oDrives, oFilesys, drv
190
		WScript.Echo "Mapping drive..."
191
 
192
		Call Get_Archive_Map_Drive_Login_Details ( outUser, outPassword )
193
 
194
		ValidDrivesARR = Array("B:","E:","F:","G:","H:","I:","J:","K:","L:","M:","N:","O:","P:","Q:","R:","S:","T:","U:","V:","W:","X:","Y:","Z:")
195
		Set WshNetwork = WScript.CreateObject("WScript.Network")
196
		Set oDrives = WshNetwork.EnumNetworkDrives
197
 
198
		' Check for existing map
199
		outMappedDrive = ""			
200
		For i = 0 to oDrives.Count - 1 Step 2
201
        	If UCase(oDrives.Item(i+1)) = UCase(SSunc) Then
202
				outMappedDrive = oDrives.Item(i)
203
				Exit For
204
			End If
205
        Next
206
 
207
 
208
		If outMappedDrive = "" Then
209
			' Drive need to be mapped, hence map one.
210
 
211
			' Get all drive used drive letters.
212
			' NOTE: It will not display a drive if mapped but not connected.
213
			Set oFilesys = CreateObject("Scripting.FileSystemObject")
214
			Set oDrives = oFilesys.Drives
215
			For Each drv in oDrives
216
				UsedDrives = UsedDrives &"|"& drv.DriveLetter &":|"
217
			Next
218
 
219
			For Each validDrive In ValidDrivesARR
220
				If NOT InStr( UCase(UsedDrives), "|"& UCase(validDrive) &"|") > 0 Then
221
					' used this unused drive
222
					On Error Resume Next
223
 
224
					WshNetwork.MapNetworkDrive validDrive, SSunc, FALSE, outUser, outPassword
225
 
226
					Call ErrorCheck ( "[sub:Map_Network_Drive]", _
227
							   		  "used drives: "& UsedDrives & VBNewLine &_
228
							   		  "valid letters to pick from: "& Join( ValidDrivesARR, ",") & VBNewLine &_
229
							   		  "attempting to map: "& validDrive & VBNewLine &_
230
							   		  "UNC: "& SSunc )
231
 
232
					outMappedDrive = validDrive
233
					Exit For
234
				End If
235
			Next
236
 
237
		End If
238
 
239
		If outMappedDrive = "" Then
240
			Call Raise_Event ( enumEVENT_ERROR, "[sub:Map_Network_Drive]", _
241
							   "used drives: "& UsedDrives & VBNewLine &_
242
							   "valid drives to pick from: "& Join( ValidDrivesARR, ",") , _
243
							   "Network drive is not mapped!", enum_RELEASE_NOTES_FAILED )
244
		End If
245
 
246
		WScript.Echo "Using network drive: "& outMappedDrive
247
 
248
		Set oDrives = Nothing
249
		Set WshNetwork = Nothing
250
	End Sub
251
    '-----------------------------------------------------------------------------------------------------------------
252
 
253
End Class