Path resolution for error templates.
[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 & "shibd.logger.in"
64   ReplaceInFile ConfigFile, "@-PKGLOGDIR-@", ConvertedDir & "/var/log/shibboleth"
65   If (NOT FileSystemObj.FileExists(ConfigDir & "shibd.logger")) then
66     FileSystemObj.CopyFile ConfigFile, ConfigDir & "shibd.logger", false
67   End If
68   If (FileSystemObj.FileExists(DistDir & "shibd.logger")) then
69     FileSystemObj.DeleteFile DistDir & "shibd.logger", true
70   End If
71   FileSystemObj.MoveFile ConfigFile, DistDir & "shibd.logger"
72
73   ConfigFile = DistDir & "native.logger.in"
74   ReplaceInFile ConfigFile, "@-SHIRELOGDIR-@", ConvertedDir & "/var/log/shibboleth"
75   If (NOT FileSystemObj.FileExists(ConfigDir & "native.logger")) then
76     FileSystemObj.CopyFile ConfigFile, ConfigDir & "native.logger", false
77   End If
78   If (FileSystemObj.FileExists(DistDir & "native.logger")) then
79     FileSystemObj.DeleteFile DistDir & "native.logger", true
80   End If
81   FileSystemObj.MoveFile ConfigFile, DistDir & "native.logger"
82
83   ConfigFile = DistDir & "apache.config.in"
84   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
85   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
86   If (NOT FileSystemObj.FileExists(ConfigDir & "apache.config")) then
87     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache.config", false
88   End If
89   If (FileSystemObj.FileExists(DistDir & "apache.config")) then
90     FileSystemObj.DeleteFile DistDir & "apache.config", true
91   End If
92   FileSystemObj.MoveFile ConfigFile, DistDir & "apache.config"
93
94   ConfigFile = DistDir & "apache2.config.in"
95   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
96   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
97   If (NOT FileSystemObj.FileExists(ConfigDir & "apache2.config")) then
98     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache2.config", false
99   End If
100   If (FileSystemObj.FileExists(DistDir & "apache2.config")) then
101     FileSystemObj.DeleteFile DistDir & "apache2.config", true
102   End If
103   FileSystemObj.MoveFile ConfigFile, DistDir & "apache2.config"
104
105   ConfigFile = DistDir & "apache22.config.in"
106   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
107   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
108   If (NOT FileSystemObj.FileExists(ConfigDir & "apache22.config")) then
109     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache22.config", false
110   End If
111   If (FileSystemObj.FileExists(DistDir & "apache22.config")) then
112     FileSystemObj.DeleteFile DistDir & "apache22.config", true
113   End If
114   FileSystemObj.MoveFile ConfigFile, DistDir & "apache22.config"
115
116   ConfigFile = DistDir & "shibboleth2.xml"
117   ReplaceInFile ConfigFile, "   <UnixListener address=""shibd.sock""/>", "<!-- <UnixListener address=""shibd.sock""/> -->"
118   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""/>"
119   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth2.xml")) then
120     FileSystemObj.CopyFile ConfigFile, ConfigDir & "shibboleth2.xml", false
121   End If
122
123   'Now just copy the other non-edited files over as well (if possible)
124
125   If (NOT FileSystemObj.FileExists(ConfigDir & "accessError.html")) then
126     FileSystemObj.CopyFile DistDir & "accessError.html", ConfigDir, false
127   End If
128
129   If (NOT FileSystemObj.FileExists(ConfigDir & "metadataError.html")) then
130     FileSystemObj.CopyFile DistDir & "metadataError.html", ConfigDir, false
131   End If
132
133   If (NOT FileSystemObj.FileExists(ConfigDir & "sessionError.html")) then
134     FileSystemObj.CopyFile DistDir & "sessionError.html", ConfigDir, false
135   End If
136
137   If (NOT FileSystemObj.FileExists(ConfigDir & "sslError.html")) then
138     FileSystemObj.CopyFile DistDir & "sslError.html", ConfigDir, false
139   End If
140
141   If (NOT FileSystemObj.FileExists(ConfigDir & "bindingTemplate.html")) then
142     FileSystemObj.CopyFile DistDir & "bindingTemplate.html", ConfigDir, false
143   End If
144
145   If (NOT FileSystemObj.FileExists(ConfigDir & "localLogout.html")) then
146     FileSystemObj.CopyFile DistDir & "localLogout.html", ConfigDir, false
147   End If
148
149   If (NOT FileSystemObj.FileExists(ConfigDir & "globalLogout.html")) then
150     FileSystemObj.CopyFile DistDir & "globalLogout.html", ConfigDir, false
151   End If
152
153   If (NOT FileSystemObj.FileExists(ConfigDir & "openssl.cnf")) then
154     FileSystemObj.CopyFile DistDir & "openssl.cnf", ConfigDir, false
155   End If
156
157   If (NOT FileSystemObj.FileExists(ConfigDir & "console.logger")) then
158     FileSystemObj.CopyFile DistDir & "console.logger", ConfigDir, false
159   End If
160
161   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth.logger")) then
162     FileSystemObj.CopyFile DistDir & "shibboleth.logger", ConfigDir, false
163   End If
164
165   If (NOT FileSystemObj.FileExists(ConfigDir & "sp-example.crt")) then
166     FileSystemObj.CopyFile DistDir & "sp-example.crt", ConfigDir, false
167   End If
168
169   If (NOT FileSystemObj.FileExists(ConfigDir & "sp-example.key")) then
170     FileSystemObj.CopyFile DistDir & "sp-example.key", ConfigDir, false
171   End If
172
173   If (NOT FileSystemObj.FileExists(ConfigDir & "example-metadata.xml")) then
174     FileSystemObj.CopyFile DistDir & "example-metadata.xml", ConfigDir, false
175   End If
176
177   If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-map.xml")) then
178     FileSystemObj.CopyFile DistDir & "attribute-map.xml", ConfigDir, false
179   End If
180
181   If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-policy.xml")) then
182     FileSystemObj.CopyFile DistDir & "attribute-policy.xml", ConfigDir, false
183   End If
184
185   ' Finally, fix up schema catalogs.
186   
187   XMLDir = InstallDir & "\share\xml\xmltooling\"
188   ConfigFile = XMLDir & "catalog.xml"
189   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
190
191   XMLDir = InstallDir & "\share\xml\opensaml\"
192   ConfigFile = XMLDir & "saml20-catalog.xml"
193   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
194   ConfigFile = XMLDir & "saml11-catalog.xml"
195   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
196   ConfigFile = XMLDir & "saml10-catalog.xml"
197   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
198
199   XMLDir = InstallDir & "\share\xml\shibboleth\"
200   ConfigFile = XMLDir & "catalog.xml"
201   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
202
203 'Last End If
204 End If