Use shibboleth-sp as package name for compatibility.
[shibboleth/cpp-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, WshShell
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   'Set ConvertedDir as the SHIBSP_PREFIX system variable.
60   Set WshShell = CreateObject("WScript.Shell")
61   WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\SHIBSP_PREFIX", ConvertedDir, "REG_SZ"
62
63   'Perform actual Substitutions
64   'Afterwards, if the config file doesn't already exist, copy up to etc/shibboleth
65   'Also strip *.in for files in dist
66
67   ConfigFile = DistDir & "shibd.logger.in"
68   ReplaceInFile ConfigFile, "@-PKGLOGDIR-@", ConvertedDir & "/var/log/shibboleth"
69   If (NOT FileSystemObj.FileExists(ConfigDir & "shibd.logger")) then
70     FileSystemObj.CopyFile ConfigFile, ConfigDir & "shibd.logger", false
71   End If
72   If (FileSystemObj.FileExists(DistDir & "shibd.logger")) then
73     FileSystemObj.DeleteFile DistDir & "shibd.logger", true
74   End If
75   FileSystemObj.MoveFile ConfigFile, DistDir & "shibd.logger"
76
77   ConfigFile = DistDir & "native.logger.in"
78   ReplaceInFile ConfigFile, "@-SHIRELOGDIR-@", ConvertedDir & "/var/log/shibboleth"
79   If (NOT FileSystemObj.FileExists(ConfigDir & "native.logger")) then
80     FileSystemObj.CopyFile ConfigFile, ConfigDir & "native.logger", false
81   End If
82   If (FileSystemObj.FileExists(DistDir & "native.logger")) then
83     FileSystemObj.DeleteFile DistDir & "native.logger", true
84   End If
85   FileSystemObj.MoveFile ConfigFile, DistDir & "native.logger"
86
87   ConfigFile = DistDir & "apache.config.in"
88   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
89   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
90   If (NOT FileSystemObj.FileExists(ConfigDir & "apache.config")) then
91     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache.config", false
92   End If
93   If (FileSystemObj.FileExists(DistDir & "apache.config")) then
94     FileSystemObj.DeleteFile DistDir & "apache.config", true
95   End If
96   FileSystemObj.MoveFile ConfigFile, DistDir & "apache.config"
97
98   ConfigFile = DistDir & "apache2.config.in"
99   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
100   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
101   If (NOT FileSystemObj.FileExists(ConfigDir & "apache2.config")) then
102     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache2.config", false
103   End If
104   If (FileSystemObj.FileExists(DistDir & "apache2.config")) then
105     FileSystemObj.DeleteFile DistDir & "apache2.config", true
106   End If
107   FileSystemObj.MoveFile ConfigFile, DistDir & "apache2.config"
108
109   ConfigFile = DistDir & "apache22.config.in"
110   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"
111   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"
112   If (NOT FileSystemObj.FileExists(ConfigDir & "apache22.config")) then
113     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache22.config", false
114   End If
115   If (FileSystemObj.FileExists(DistDir & "apache22.config")) then
116     FileSystemObj.DeleteFile DistDir & "apache22.config", true
117   End If
118   FileSystemObj.MoveFile ConfigFile, DistDir & "apache22.config"
119
120   'Now just copy the other non-edited files over as well (if possible)
121
122   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth2.xml")) then
123     FileSystemObj.CopyFile DistDir & "shibboleth2.xml", ConfigDir, false
124   End If
125
126   If (NOT FileSystemObj.FileExists(ConfigDir & "accessError.html")) then
127     FileSystemObj.CopyFile DistDir & "accessError.html", ConfigDir, false
128   End If
129
130   If (NOT FileSystemObj.FileExists(ConfigDir & "metadataError.html")) then
131     FileSystemObj.CopyFile DistDir & "metadataError.html", ConfigDir, false
132   End If
133
134   If (NOT FileSystemObj.FileExists(ConfigDir & "sessionError.html")) then
135     FileSystemObj.CopyFile DistDir & "sessionError.html", ConfigDir, false
136   End If
137
138   If (NOT FileSystemObj.FileExists(ConfigDir & "sslError.html")) then
139     FileSystemObj.CopyFile DistDir & "sslError.html", ConfigDir, false
140   End If
141
142   If (NOT FileSystemObj.FileExists(ConfigDir & "bindingTemplate.html")) then
143     FileSystemObj.CopyFile DistDir & "bindingTemplate.html", ConfigDir, false
144   End If
145
146   If (NOT FileSystemObj.FileExists(ConfigDir & "discoveryTemplate.html")) then
147     FileSystemObj.CopyFile DistDir & "discoveryTemplate.html", ConfigDir, false
148   End If
149
150   If (NOT FileSystemObj.FileExists(ConfigDir & "postTemplate.html")) then
151     FileSystemObj.CopyFile DistDir & "postTemplate.html", ConfigDir, false
152   End If
153
154   If (NOT FileSystemObj.FileExists(ConfigDir & "localLogout.html")) then
155     FileSystemObj.CopyFile DistDir & "localLogout.html", ConfigDir, false
156   End If
157
158   If (NOT FileSystemObj.FileExists(ConfigDir & "globalLogout.html")) then
159     FileSystemObj.CopyFile DistDir & "globalLogout.html", ConfigDir, false
160   End If
161
162   If (NOT FileSystemObj.FileExists(ConfigDir & "partialLogout.html")) then
163     FileSystemObj.CopyFile DistDir & "partialLogout.html", ConfigDir, false
164   End If
165
166   If (NOT FileSystemObj.FileExists(ConfigDir & "console.logger")) then
167     FileSystemObj.CopyFile DistDir & "console.logger", ConfigDir, false
168   End If
169
170   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth.logger")) then
171     FileSystemObj.CopyFile DistDir & "shibboleth.logger", ConfigDir, false
172   End If
173
174   If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-map.xml")) then
175     FileSystemObj.CopyFile DistDir & "attribute-map.xml", ConfigDir, false
176   End If
177
178   If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-policy.xml")) then
179     FileSystemObj.CopyFile DistDir & "attribute-policy.xml", ConfigDir, false
180   End If
181
182   If (NOT FileSystemObj.FileExists(ConfigDir & "security-policy.xml")) then
183     FileSystemObj.CopyFile DistDir & "security-policy.xml", ConfigDir, false
184   End If
185
186   If (NOT FileSystemObj.FileExists(ConfigDir & "protocols.xml")) then
187     FileSystemObj.CopyFile DistDir & "protocols.xml", ConfigDir, false
188   End If
189   
190   'Finally, fix up schema catalogs.
191   
192   XMLDir = InstallDir & "\share\xml\xmltooling\"
193   ConfigFile = XMLDir & "catalog.xml"
194   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
195
196   XMLDir = InstallDir & "\share\xml\opensaml\"
197   ConfigFile = XMLDir & "saml20-catalog.xml"
198   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
199   ConfigFile = XMLDir & "saml11-catalog.xml"
200   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
201   ConfigFile = XMLDir & "saml10-catalog.xml"
202   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
203
204   XMLDir = InstallDir & "\share\xml\shibboleth\"
205   ConfigFile = XMLDir & "catalog.xml"
206   ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir
207
208 'Last End If
209 End If