https://issues.shibboleth.net/jira/browse/SSPCPP-463
[shibboleth/cpp-sp.git] / msi / scripts / shib_edit_config_files.vbs-wix
1 Function ReadFile( filePath )\r
2    Dim theFile\r
3 \r
4    'OpenTextFile args: <path>, 1 = ForReading\r
5    'If you read an empty file, VBScript throws an error for some reason\r
6    if (FileSystemObj.FileExists(filePath)) then\r
7      Set theFile = FileSystemObj.GetFile(filePath)\r
8      if (theFile.size > 0) then\r
9        Set theFile = FileSystemObj.OpenTextFile(filePath, 1)\r
10        ReadFile = theFile.ReadAll\r
11      else\r
12        ReadFile = ""\r
13      end if\r
14    else\r
15      ReadFile = ""\r
16    end if\r
17 End Function\r
18 \r
19 Sub WriteFile( filePath, contents )\r
20    Dim theFile\r
21 \r
22    'OpenTextFile args: <path>, 2 = ForWriting, True = create if not exist\r
23    Set theFile = FileSystemObj.OpenTextFile(filePath, 2, True)\r
24    theFile.Write contents\r
25 End Sub\r
26 \r
27 Sub ReplaceInFile( filePath, lookForStr, replaceWithStr )\r
28   Dim buffer\r
29 \r
30   buffer = ReadFile(filePath)\r
31   if (buffer <> "") then\r
32     buffer = Replace(buffer, lookForStr, replaceWithStr)\r
33     WriteFile filePath, buffer\r
34   end if\r
35 End Sub\r
36 \r
37 \r
38 Dim FileSystemObj, ConvertedDir, ConfigFile, XMLDir, WshShell\r
39 Dim customData, msiProperties, InstallDir, LibDir, Is64Bit, Install32, LogFile\r
40 \r
41 on error resume next\r
42 Set FileSystemObj = CreateObject("Scripting.FileSystemObject")\r
43 if (Err = 0) then\r
44 \r
45   'Get the INSTALLDIR and 64/32 values via CustomActionData\r
46   customData = Session.Property("CustomActionData")\r
47   msiProperties = split(customData,";@;")\r
48   InstallDir = msiProperties(0)\r
49   Is64Bit = msiProperties(1)\r
50   Install32 = msiProperties(2)\r
51 \r
52   LibDir = "lib"\r
53   If (Is64Bit = "TRUE") then\r
54       If (Install32 <> "TRUE") then\r
55           LibDir = "lib64"\r
56       End If\r
57   End If\r
58 \r
59   Set LogFile = FileSystemObj.OpenTextFile(InstallDir & "\var\log\shibboleth\Installer.log", 8, true)\r
60 \r
61   If (LogFile) then\r
62      LogFile.WriteLine "Edit Config Files to " & InstallDir & ", 64Bit = " & Is64Bit & ", 32Bit = " & Install32\r
63   End If\r
64 \r
65   'Remove all trailing backslashes to normalize\r
66   do while (mid(InstallDir,Len(InstallDir),1) = "\")\r
67     InstallDir = mid(InstallDir,1,Len(InstallDir)-1)\r
68   loop\r
69   ConvertedDir = Replace(InstallDir, "\", "/")\r
70   ConfigDir = InstallDir & "\etc\shibboleth\"\r
71   DistDir = ConfigDir & "dist\"\r
72 \r
73   'Set ConvertedDir as the SHIBSP_PREFIX system variable.\r
74   Set WshShell = CreateObject("WScript.Shell")\r
75   WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\SHIBSP_PREFIX", ConvertedDir, "REG_SZ"\r
76 \r
77   'Perform actual Substitutions\r
78   'Afterwards, if the config file doesn't already exist, copy up to etc/shibboleth\r
79   'Also strip *.in for files in dist\r
80 \r
81   ConfigFile = DistDir & "shibd.logger.in"\r
82   ReplaceInFile ConfigFile, "@-PKGLOGDIR-@", ConvertedDir & "/var/log/shibboleth"\r
83   If (NOT FileSystemObj.FileExists(ConfigDir & "shibd.logger")) then\r
84     FileSystemObj.CopyFile ConfigFile, ConfigDir & "shibd.logger", false\r
85   End If\r
86   If (FileSystemObj.FileExists(DistDir & "shibd.logger")) then\r
87     FileSystemObj.DeleteFile DistDir & "shibd.logger", true\r
88   End If\r
89   FileSystemObj.MoveFile ConfigFile, DistDir & "shibd.logger"\r
90 \r
91   ConfigFile = DistDir & "native.logger.in"\r
92   ReplaceInFile ConfigFile, "@-SHIRELOGDIR-@", ConvertedDir & "/var/log/shibboleth"\r
93   If (NOT FileSystemObj.FileExists(ConfigDir & "native.logger")) then\r
94     FileSystemObj.CopyFile ConfigFile, ConfigDir & "native.logger", false\r
95   End If\r
96   If (FileSystemObj.FileExists(DistDir & "native.logger")) then\r
97     FileSystemObj.DeleteFile DistDir & "native.logger", true\r
98   End If\r
99   FileSystemObj.MoveFile ConfigFile, DistDir & "native.logger"\r
100 \r
101   ConfigFile = DistDir & "apache.config.in"\r
102   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/" & LibDir & "/shibboleth"\r
103   ReplaceInFile ConfigFile, "@-PKGWEBDIR-@", ConvertedDir & "/doc/shibboleth"\r
104   If (NOT FileSystemObj.FileExists(ConfigDir & "apache.config")) then\r
105     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache.config", false\r
106   End If\r
107   If (FileSystemObj.FileExists(DistDir & "apache.config")) then\r
108     FileSystemObj.DeleteFile DistDir & "apache.config", true\r
109   End If\r
110   FileSystemObj.MoveFile ConfigFile, DistDir & "apache.config"\r
111 \r
112   ConfigFile = DistDir & "apache2.config.in"\r
113   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/" & LibDir & "/shibboleth"\r
114   ReplaceInFile ConfigFile, "@-PKGWEBDIR-@", ConvertedDir & "/doc/shibboleth"\r
115   If (NOT FileSystemObj.FileExists(ConfigDir & "apache2.config")) then\r
116     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache2.config", false\r
117   End If\r
118   If (FileSystemObj.FileExists(DistDir & "apache2.config")) then\r
119     FileSystemObj.DeleteFile DistDir & "apache2.config", true\r
120   End If\r
121   FileSystemObj.MoveFile ConfigFile, DistDir & "apache2.config"\r
122 \r
123   ConfigFile = DistDir & "apache22.config.in"\r
124   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/" & LibDir & "/shibboleth"\r
125   ReplaceInFile ConfigFile, "@-PKGWEBDIR-@", ConvertedDir & "/doc/shibboleth"\r
126   If (NOT FileSystemObj.FileExists(ConfigDir & "apache22.config")) then\r
127     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache22.config", false\r
128   End If\r
129   If (FileSystemObj.FileExists(DistDir & "apache22.config")) then\r
130     FileSystemObj.DeleteFile DistDir & "apache22.config", true\r
131   End If\r
132   FileSystemObj.MoveFile ConfigFile, DistDir & "apache22.config"\r
133 \r
134   ConfigFile = DistDir & "apache24.config.in"\r
135   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/" & LibDir & "/shibboleth"\r
136   ReplaceInFile ConfigFile, "@-PKGWEBDIR-@", ConvertedDir & "/doc/shibboleth"\r
137   If (NOT FileSystemObj.FileExists(ConfigDir & "apache24.config")) then\r
138     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache24.config", false\r
139   End If\r
140   If (FileSystemObj.FileExists(DistDir & "apache24.config")) then\r
141     FileSystemObj.DeleteFile DistDir & "apache24.config", true\r
142   End If\r
143   FileSystemObj.MoveFile ConfigFile, DistDir & "apache24.config"\r
144 \r
145   'Now just copy the other non-edited files over as well (if possible)\r
146 \r
147   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth2.xml")) then\r
148     FileSystemObj.CopyFile DistDir & "shibboleth2.xml", ConfigDir, false\r
149   End If\r
150 \r
151   If (NOT FileSystemObj.FileExists(ConfigDir & "accessError.html")) then\r
152     FileSystemObj.CopyFile DistDir & "accessError.html", ConfigDir, false\r
153   End If\r
154 \r
155   If (NOT FileSystemObj.FileExists(ConfigDir & "metadataError.html")) then\r
156     FileSystemObj.CopyFile DistDir & "metadataError.html", ConfigDir, false\r
157   End If\r
158 \r
159   If (NOT FileSystemObj.FileExists(ConfigDir & "sessionError.html")) then\r
160     FileSystemObj.CopyFile DistDir & "sessionError.html", ConfigDir, false\r
161   End If\r
162 \r
163   If (NOT FileSystemObj.FileExists(ConfigDir & "sslError.html")) then\r
164     FileSystemObj.CopyFile DistDir & "sslError.html", ConfigDir, false\r
165   End If\r
166 \r
167   If (NOT FileSystemObj.FileExists(ConfigDir & "bindingTemplate.html")) then\r
168     FileSystemObj.CopyFile DistDir & "bindingTemplate.html", ConfigDir, false\r
169   End If\r
170 \r
171   If (NOT FileSystemObj.FileExists(ConfigDir & "discoveryTemplate.html")) then\r
172     FileSystemObj.CopyFile DistDir & "discoveryTemplate.html", ConfigDir, false\r
173   End If\r
174 \r
175   If (NOT FileSystemObj.FileExists(ConfigDir & "postTemplate.html")) then\r
176     FileSystemObj.CopyFile DistDir & "postTemplate.html", ConfigDir, false\r
177   End If\r
178 \r
179   If (NOT FileSystemObj.FileExists(ConfigDir & "localLogout.html")) then\r
180     FileSystemObj.CopyFile DistDir & "localLogout.html", ConfigDir, false\r
181   End If\r
182 \r
183   If (NOT FileSystemObj.FileExists(ConfigDir & "globalLogout.html")) then\r
184     FileSystemObj.CopyFile DistDir & "globalLogout.html", ConfigDir, false\r
185   End If\r
186 \r
187   If (NOT FileSystemObj.FileExists(ConfigDir & "partialLogout.html")) then\r
188     FileSystemObj.CopyFile DistDir & "partialLogout.html", ConfigDir, false\r
189   End If\r
190 \r
191   If (NOT FileSystemObj.FileExists(ConfigDir & "console.logger")) then\r
192     FileSystemObj.CopyFile DistDir & "console.logger", ConfigDir, false\r
193   End If\r
194 \r
195   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth.logger")) then\r
196     FileSystemObj.CopyFile DistDir & "shibboleth.logger", ConfigDir, false\r
197   End If\r
198 \r
199   If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-map.xml")) then\r
200     FileSystemObj.CopyFile DistDir & "attribute-map.xml", ConfigDir, false\r
201   End If\r
202 \r
203   If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-policy.xml")) then\r
204     FileSystemObj.CopyFile DistDir & "attribute-policy.xml", ConfigDir, false\r
205   End If\r
206 \r
207   If (NOT FileSystemObj.FileExists(ConfigDir & "security-policy.xml")) then\r
208     FileSystemObj.CopyFile DistDir & "security-policy.xml", ConfigDir, false\r
209   End If\r
210 \r
211   If (NOT FileSystemObj.FileExists(ConfigDir & "protocols.xml")) then\r
212     FileSystemObj.CopyFile DistDir & "protocols.xml", ConfigDir, false\r
213   End If\r
214 \r
215   ConfigFile  = ConfigDir & "SetService64.bat"\r
216   ReplaceInFile ConfigFile, "@-INSTALLDIR-@", InstallDir\r
217 \r
218   ConfigFile  = ConfigDir & "SetService32.bat"\r
219   ReplaceInFile ConfigFile, "@-INSTALLDIR-@", InstallDir\r
220   \r
221 \r
222 'Last End If\r
223 End If