Stale replace rule.
[shibboleth/sp.git] / msi / scripts / shib_edit_config_files.vbs
1 Function ReadFile( filePath )
2    Dim theFile
3
4    'OpenTextFile args: <path>, 1 = ForReading
5    'If you read an empty file, VBScript throws an error for some reason
6    if (FileSystemObj.FileExists(filePath)) then
7      Set theFile = FileSystemObj.GetFile(filePath)
8      if (theFile.size > 0) then
9        Set theFile = FileSystemObj.OpenTextFile(filePath, 1)
10        ReadFile = theFile.ReadAll
11      else
12        ReadFile = ""
13      end if
14    else
15      ReadFile = ""
16    end if
17 End Function
18
19 Sub WriteFile( filePath, contents )
20    Dim theFile
21
22    'OpenTextFile args: <path>, 2 = ForWriting, True = create if not exist
23    Set theFile = FileSystemObj.OpenTextFile(filePath, 2, True)
24    theFile.Write contents
25 End Sub
26
27 Sub ReplaceInFile( filePath, lookForStr, replaceWithStr )
28   Dim buffer
29
30   buffer = ReadFile(filePath)
31   if (buffer <> "") then
32     buffer = Replace(buffer, lookForStr, replaceWithStr)
33     WriteFile filePath, buffer
34   end if
35 End Sub
36
37
38 Dim FileSystemObj, ConvertedDir, ConfigFile, XMLDir
39 Dim customData, msiProperties, InstallDir, ShibdPort
40
41 on error resume next
42 Set FileSystemObj = CreateObject("Scripting.FileSystemObject")
43 if (Err = 0) then
44
45   'Get the INSTALLDIR and SHIBD_PORT values via CustomActionData
46   customData = Session.Property("CustomActionData")
47   msiProperties = split(customData,";@;")
48   InstallDir = msiProperties(0)
49   ShibdPort = msiProperties(1)
50
51   'Remove all trailing backslashes to normalize
52   do while (mid(InstallDir,Len(InstallDir),1) = "\")
53     InstallDir = mid(InstallDir,1,Len(InstallDir)-1)
54   loop
55   ConvertedDir = Replace(InstallDir, "\", "/")
56   ConfigDir = InstallDir & "\etc\shibboleth\"
57   DistDir = ConfigDir & "dist\"
58
59   'Perform actual Substitutions
60   'Afterwards, if the config file doesn't already exist, copy up to etc/shibboleth
61   'Also strip *.in for files in dist
62
63   ConfigFile = DistDir & "attribute-map.xml.in"
64   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@", ConvertedDir & "/share/xml/shibboleth"
65   If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-map.xml")) then
66     FileSystemObj.CopyFile ConfigFile, ConfigDir & "attribute-map.xml", false
67   End If
68   If (FileSystemObj.FileExists(DistDir & "attribute-map.xml")) then
69     FileSystemObj.DeleteFile DistDir & "attribute-map.xml", true
70   End If
71   FileSystemObj.MoveFile ConfigFile, DistDir & "attribute-map.xml"
72
73   ConfigFile = DistDir & "attribute-policy.xml.in"
74   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@", ConvertedDir & "/share/xml/shibboleth"
75   If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-policy.xml")) then
76     FileSystemObj.CopyFile ConfigFile, ConfigDir & "attribute-policy.xml", false
77   End If
78   If (FileSystemObj.FileExists(DistDir & "attribute-policy.xml")) then
79     FileSystemObj.DeleteFile DistDir & "attribute-policy.xml", true
80   End If
81   FileSystemObj.MoveFile ConfigFile, DistDir & "attribute-policy.xml"
82   
83   ConfigFile = DistDir & "shibboleth2.xml.in"
84   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@", ConvertedDir & "/share/xml/shibboleth"
85   ReplaceInFile ConfigFile, "@-PKGSYSCONFDIR-@", ConvertedDir & "/etc/shibboleth"
86   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
87   ReplaceInFile ConfigFile, "   <UnixListener address=""@-PKGRUNDIR-@/shibd.sock""/>", "<!-- <UnixListener address=""@-PKGRUNDIR-@/shibd.sock""/> -->"
88   ReplaceInFile ConfigFile, "<!-- <TCPListener address=""127.0.0.1"" port=""12345"" acl=""127.0.0.1""/> -->", "<TCPListener address=""127.0.0.1"" port=""" & ShibdPort & """ acl=""127.0.0.1""/>"
89   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth2.xml")) then
90     FileSystemObj.CopyFile ConfigFile, ConfigDir & "shibboleth2.xml", false
91   End If
92   If (FileSystemObj.FileExists(DistDir & "shibboleth2.xml")) then
93     FileSystemObj.DeleteFile DistDir & "shibboleth2.xml", true
94   End If
95   FileSystemObj.MoveFile ConfigFile, DistDir & "shibboleth2.xml"
96
97   ConfigFile = DistDir & "shibd.logger.in"
98   ReplaceInFile ConfigFile, "@-PKGLOGDIR-@", ConvertedDir & "/var/log/shibboleth"
99   If (NOT FileSystemObj.FileExists(ConfigDir & "shibd.logger")) then
100     FileSystemObj.CopyFile ConfigFile, ConfigDir & "shibd.logger", false
101   End If
102   If (FileSystemObj.FileExists(DistDir & "shibd.logger")) then
103     FileSystemObj.DeleteFile DistDir & "shibd.logger", true
104   End If
105   FileSystemObj.MoveFile ConfigFile, DistDir & "shibd.logger"
106
107   ConfigFile = DistDir & "native.logger.in"
108   ReplaceInFile ConfigFile, "@-SHIRELOGDIR-@", ConvertedDir & "/var/log/shibboleth"
109   If (NOT FileSystemObj.FileExists(ConfigDir & "native.logger")) then
110     FileSystemObj.CopyFile ConfigFile, ConfigDir & "native.logger", false
111   End If
112   If (FileSystemObj.FileExists(DistDir & "native.logger")) then
113     FileSystemObj.DeleteFile DistDir & "native.logger", true
114   End If
115   FileSystemObj.MoveFile ConfigFile, DistDir & "native.logger"
116
117   ConfigFile = DistDir & "apache.config.in"
118   ReplaceInFile ConfigFile, "@-XMLTOOLINGXMLDIR-@", ConvertedDir & "/share/xml/xmltooling"
119   ReplaceInFile ConfigFile, "@-OPENSAMLXMLDIR-@", ConvertedDir & "/share/xml/opensaml"
120   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@", ConvertedDir & "/share/xml/shibboleth"
121   ReplaceInFile ConfigFile, "catalog.xml:", "catalog.xml;"
122   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
123   ReplaceInFile ConfigFile, "@-PKGSYSCONFDIR-@", ConvertedDir & "/etc/shibboleth"
124   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
125   If (NOT FileSystemObj.FileExists(ConfigDir & "apache.config")) then
126     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache.config", false
127   End If
128   If (FileSystemObj.FileExists(DistDir & "apache.config")) then
129     FileSystemObj.DeleteFile DistDir & "apache.config", true
130   End If
131   FileSystemObj.MoveFile ConfigFile, DistDir & "apache.config"
132
133   ConfigFile = DistDir & "apache2.config.in"
134   ReplaceInFile ConfigFile, "@-XMLTOOLINGXMLDIR-@", ConvertedDir & "/share/xml/xmltooling"
135   ReplaceInFile ConfigFile, "@-OPENSAMLXMLDIR-@", ConvertedDir & "/share/xml/opensaml"
136   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@", ConvertedDir & "/share/xml/shibboleth"
137   ReplaceInFile ConfigFile, "catalog.xml:", "catalog.xml;"
138   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
139   ReplaceInFile ConfigFile, "@-PKGSYSCONFDIR-@", ConvertedDir & "/etc/shibboleth"
140   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
141   If (NOT FileSystemObj.FileExists(ConfigDir & "apache2.config")) then
142     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache2.config", false
143   End If
144   If (FileSystemObj.FileExists(DistDir & "apache2.config")) then
145     FileSystemObj.DeleteFile DistDir & "apache2.config", true
146   End If
147   FileSystemObj.MoveFile ConfigFile, DistDir & "apache2.config"
148
149   ConfigFile = DistDir & "apache22.config.in"
150   ReplaceInFile ConfigFile, "@-XMLTOOLINGXMLDIR-@", ConvertedDir & "/share/xml/xmltooling"
151   ReplaceInFile ConfigFile, "@-OPENSAMLXMLDIR-@", ConvertedDir & "/share/xml/opensaml"
152   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@", ConvertedDir & "/share/xml/shibboleth"
153   ReplaceInFile ConfigFile, "catalog.xml:", "catalog.xml;"
154   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
155   ReplaceInFile ConfigFile, "@-PKGSYSCONFDIR-@", ConvertedDir & "/etc/shibboleth"
156   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
157   If (NOT FileSystemObj.FileExists(ConfigDir & "apache22.config")) then
158     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache22.config", false
159   End If
160   If (FileSystemObj.FileExists(DistDir & "apache22.config")) then
161     FileSystemObj.DeleteFile DistDir & "apache22.config", true
162   End If
163   FileSystemObj.MoveFile ConfigFile, DistDir & "apache22.config"
164
165   'Now just copy the other non-edited files over as well (if possible)
166
167   If (NOT FileSystemObj.FileExists(ConfigDir & "accessError.html")) then
168     FileSystemObj.CopyFile DistDir & "accessError.html", ConfigDir, false
169   End If
170
171   If (NOT FileSystemObj.FileExists(ConfigDir & "metadataError.html")) then
172     FileSystemObj.CopyFile DistDir & "metadataError.html", ConfigDir, false
173   End If
174
175   If (NOT FileSystemObj.FileExists(ConfigDir & "sessionError.html")) then
176     FileSystemObj.CopyFile DistDir & "sessionError.html", ConfigDir, false
177   End If
178
179   If (NOT FileSystemObj.FileExists(ConfigDir & "sslError.html")) then
180     FileSystemObj.CopyFile DistDir & "sslError.html", ConfigDir, false
181   End If
182
183   If (NOT FileSystemObj.FileExists(ConfigDir & "bindingTemplate.html")) then
184     FileSystemObj.CopyFile DistDir & "bindingTemplate.html", ConfigDir, false
185   End If
186
187   If (NOT FileSystemObj.FileExists(ConfigDir & "localLogout.html")) then
188     FileSystemObj.CopyFile DistDir & "localLogout.html", ConfigDir, false
189   End If
190
191   If (NOT FileSystemObj.FileExists(ConfigDir & "globalLogout.html")) then
192     FileSystemObj.CopyFile DistDir & "globalLogout.html", ConfigDir, false
193   End If
194
195   If (NOT FileSystemObj.FileExists(ConfigDir & "openssl.cnf")) then
196     FileSystemObj.CopyFile DistDir & "openssl.cnf", ConfigDir, false
197   End If
198
199   If (NOT FileSystemObj.FileExists(ConfigDir & "console.logger")) then
200     FileSystemObj.CopyFile DistDir & "console.logger", ConfigDir, false
201   End If
202
203   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth.logger")) then
204     FileSystemObj.CopyFile DistDir & "shibboleth.logger", ConfigDir, false
205   End If
206
207   If (NOT FileSystemObj.FileExists(ConfigDir & "sp-example.crt")) then
208     FileSystemObj.CopyFile DistDir & "sp-example.crt", ConfigDir, false
209   End If
210
211   If (NOT FileSystemObj.FileExists(ConfigDir & "sp-example.key")) then
212     FileSystemObj.CopyFile DistDir & "sp-example.key", ConfigDir, false
213   End If
214
215   If (NOT FileSystemObj.FileExists(ConfigDir & "example-metadata.xml")) then
216     FileSystemObj.CopyFile DistDir & "example-metadata.xml", ConfigDir, false
217   End If
218
219   ' Finally, fix up schema catalogs.
220   
221   XMLDir = InstallDir & "\share\xml\xmltooling\"
222   ConfigFile = XMLDir & "catalog.xml"
223   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
224
225   XMLDir = InstallDir & "\share\xml\opensaml\"
226   ConfigFile = XMLDir & "saml20-catalog.xml"
227   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
228   ConfigFile = XMLDir & "saml11-catalog.xml"
229   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
230   ConfigFile = XMLDir & "saml10-catalog.xml"
231   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
232
233   XMLDir = InstallDir & "\share\xml\shibboleth\"
234   ConfigFile = XMLDir & "catalog.xml"
235   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
236
237 'Last End If
238 End If