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