Port fastcgi code to trunk.
[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 & "example-metadata.xml.in"
84   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@", ConvertedDir & "/share/xml/shibboleth"
85   If (NOT FileSystemObj.FileExists(ConfigDir & "example-metadata.xml")) then
86     FileSystemObj.CopyFile ConfigFile, ConfigDir & "example-metadata.xml", false
87   End If
88   If (FileSystemObj.FileExists(DistDir & "example-metadata.xml")) then
89     FileSystemObj.DeleteFile DistDir & "example-metadata.xml", true
90   End If
91   FileSystemObj.MoveFile ConfigFile, DistDir & "example-metadata.xml"
92
93   ConfigFile = DistDir & "shibboleth2.xml.in"
94   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@", ConvertedDir & "/share/xml/shibboleth"
95   ReplaceInFile ConfigFile, "@-PKGSYSCONFDIR-@", ConvertedDir & "/etc/shibboleth"
96   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
97   ReplaceInFile ConfigFile, "@-LOGDIR-@", ConvertedDir & "/var/log/shibboleth"
98   ReplaceInFile ConfigFile, "@-PREFIX-@", ConvertedDir
99   ReplaceInFile ConfigFile, "   <UnixListener address=""@-PKGRUNDIR-@/shibd.sock""/>", "<!-- <UnixListener address=""@-PKGRUNDIR-@/shibd.sock""/> -->"
100   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""/>"
101   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth2.xml")) then
102     FileSystemObj.CopyFile ConfigFile, ConfigDir & "shibboleth2.xml", false
103   End If
104   If (FileSystemObj.FileExists(DistDir & "shibboleth2.xml")) then
105     FileSystemObj.DeleteFile DistDir & "shibboleth2.xml", true
106   End If
107   FileSystemObj.MoveFile ConfigFile, DistDir & "shibboleth2.xml"
108
109   ConfigFile = DistDir & "shibd.logger.in"
110   ReplaceInFile ConfigFile, "@-PKGLOGDIR-@", ConvertedDir & "/var/log/shibboleth"
111   If (NOT FileSystemObj.FileExists(ConfigDir & "shibd.logger")) then
112     FileSystemObj.CopyFile ConfigFile, ConfigDir & "shibd.logger", false
113   End If
114   If (FileSystemObj.FileExists(DistDir & "shibd.logger")) then
115     FileSystemObj.DeleteFile DistDir & "shibd.logger", true
116   End If
117   FileSystemObj.MoveFile ConfigFile, DistDir & "shibd.logger"
118
119   ConfigFile = DistDir & "native.logger.in"
120   ReplaceInFile ConfigFile, "@-SHIRELOGDIR-@", ConvertedDir & "/var/log/shibboleth"
121   If (NOT FileSystemObj.FileExists(ConfigDir & "native.logger")) then
122     FileSystemObj.CopyFile ConfigFile, ConfigDir & "native.logger", false
123   End If
124   If (FileSystemObj.FileExists(DistDir & "native.logger")) then
125     FileSystemObj.DeleteFile DistDir & "native.logger", true
126   End If
127   FileSystemObj.MoveFile ConfigFile, DistDir & "native.logger"
128
129   ConfigFile = DistDir & "apache.config.in"
130   ReplaceInFile ConfigFile, "@-XMLDIR-@", ConvertedDir & "/share/xml"
131   ReplaceInFile ConfigFile, "catalog.xml:", "catalog.xml;"
132   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
133   ReplaceInFile ConfigFile, "@-PKGSYSCONFDIR-@", ConvertedDir & "/etc/shibboleth"
134   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
135   If (NOT FileSystemObj.FileExists(ConfigDir & "apache.config")) then
136     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache.config", false
137   End If
138   If (FileSystemObj.FileExists(DistDir & "apache.config")) then
139     FileSystemObj.DeleteFile DistDir & "apache.config", true
140   End If
141   FileSystemObj.MoveFile ConfigFile, DistDir & "apache.config"
142
143   ConfigFile = DistDir & "apache2.config.in"
144   ReplaceInFile ConfigFile, "@-XMLDIR-@", ConvertedDir & "/share/xml"
145   ReplaceInFile ConfigFile, "catalog.xml:", "catalog.xml;"
146   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
147   ReplaceInFile ConfigFile, "@-PKGSYSCONFDIR-@", ConvertedDir & "/etc/shibboleth"
148   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
149   If (NOT FileSystemObj.FileExists(ConfigDir & "apache2.config")) then
150     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache2.config", false
151   End If
152   If (FileSystemObj.FileExists(DistDir & "apache2.config")) then
153     FileSystemObj.DeleteFile DistDir & "apache2.config", true
154   End If
155   FileSystemObj.MoveFile ConfigFile, DistDir & "apache2.config"
156
157   ConfigFile = DistDir & "apache22.config.in"
158   ReplaceInFile ConfigFile, "@-XMLDIR-@", ConvertedDir & "/share/xml"
159   ReplaceInFile ConfigFile, "catalog.xml:", "catalog.xml;"
160   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
161   ReplaceInFile ConfigFile, "@-PKGSYSCONFDIR-@", ConvertedDir & "/etc/shibboleth"
162   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
163   If (NOT FileSystemObj.FileExists(ConfigDir & "apache22.config")) then
164     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache22.config", false
165   End If
166   If (FileSystemObj.FileExists(DistDir & "apache22.config")) then
167     FileSystemObj.DeleteFile DistDir & "apache22.config", true
168   End If
169   FileSystemObj.MoveFile ConfigFile, DistDir & "apache22.config"
170
171   'Now just copy the other non-edited files over as well (if possible)
172
173   If (NOT FileSystemObj.FileExists(ConfigDir & "accessError.html")) then
174     FileSystemObj.CopyFile DistDir & "accessError.html", ConfigDir, false
175   End If
176
177   If (NOT FileSystemObj.FileExists(ConfigDir & "metadataError.html")) then
178     FileSystemObj.CopyFile DistDir & "metadataError.html", ConfigDir, false
179   End If
180
181   If (NOT FileSystemObj.FileExists(ConfigDir & "sessionError.html")) then
182     FileSystemObj.CopyFile DistDir & "sessionError.html", ConfigDir, false
183   End If
184
185   If (NOT FileSystemObj.FileExists(ConfigDir & "sslError.html")) then
186     FileSystemObj.CopyFile DistDir & "sslError.html", ConfigDir, false
187   End If
188
189   If (NOT FileSystemObj.FileExists(ConfigDir & "bindingTemplate.html")) then
190     FileSystemObj.CopyFile DistDir & "bindingTemplate.html", ConfigDir, false
191   End If
192
193   If (NOT FileSystemObj.FileExists(ConfigDir & "localLogout.html")) then
194     FileSystemObj.CopyFile DistDir & "localLogout.html", ConfigDir, false
195   End If
196
197   If (NOT FileSystemObj.FileExists(ConfigDir & "globalLogout.html")) then
198     FileSystemObj.CopyFile DistDir & "globalLogout.html", ConfigDir, false
199   End If
200
201   If (NOT FileSystemObj.FileExists(ConfigDir & "openssl.cnf")) then
202     FileSystemObj.CopyFile DistDir & "openssl.cnf", ConfigDir, false
203   End If
204
205   If (NOT FileSystemObj.FileExists(ConfigDir & "console.logger")) then
206     FileSystemObj.CopyFile DistDir & "console.logger", ConfigDir, false
207   End If
208
209   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth.logger")) then
210     FileSystemObj.CopyFile DistDir & "shibboleth.logger", ConfigDir, false
211   End If
212
213   If (NOT FileSystemObj.FileExists(ConfigDir & "sp-example.crt")) then
214     FileSystemObj.CopyFile DistDir & "sp-example.crt", ConfigDir, false
215   End If
216
217   If (NOT FileSystemObj.FileExists(ConfigDir & "sp-example.key")) then
218     FileSystemObj.CopyFile DistDir & "sp-example.key", ConfigDir, false
219   End If
220
221   ' Finally, fix up schema catalogs.
222   
223   XMLDir = InstallDir & "\share\xml\xmltooling\"
224   ConfigFile = XMLDir & "catalog.xml"
225   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
226
227   XMLDir = InstallDir & "\share\xml\opensaml\"
228   ConfigFile = XMLDir & "saml20-catalog.xml"
229   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
230   ConfigFile = XMLDir & "saml11-catalog.xml"
231   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
232   ConfigFile = XMLDir & "saml10-catalog.xml"
233   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
234
235   XMLDir = InstallDir & "\share\xml\shibboleth\"
236   ConfigFile = XMLDir & "catalog.xml"
237   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
238
239 'Last End If
240 End If