e32b307482f49c9bf6797428ce4fedee37eb513f
[shibboleth/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, ShibdPort, 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 SHIBD_PORT values via CustomActionData\r
46   customData = Session.Property("CustomActionData")\r
47   msiProperties = split(customData,";@;")\r
48   InstallDir = msiProperties(0)\r
49   ShibdPort = msiProperties(1)\r
50 \r
51   Set LogFile = FileSystemObj.OpenTextFile(InstallDir & "\var\log\shibboleth\Installer.log", 8, true)\r
52 \r
53   If (LogFile) then\r
54      LogFile.WriteLine "Edit Config Files to " & InstallDir & ", Port = " & ShibdPort\r
55   End If\r
56 \r
57   'Remove all trailing backslashes to normalize\r
58   do while (mid(InstallDir,Len(InstallDir),1) = "\")\r
59     InstallDir = mid(InstallDir,1,Len(InstallDir)-1)\r
60   loop\r
61   ConvertedDir = Replace(InstallDir, "\", "/")\r
62   ConfigDir = InstallDir & "\etc\shibboleth\"\r
63   DistDir = ConfigDir & "dist\"\r
64 \r
65   'Set ConvertedDir as the SHIBSP_PREFIX system variable.\r
66   Set WshShell = CreateObject("WScript.Shell")\r
67   WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\SHIBSP_PREFIX", ConvertedDir, "REG_SZ"\r
68 \r
69   'Perform actual Substitutions\r
70   'Afterwards, if the config file doesn't already exist, copy up to etc/shibboleth\r
71   'Also strip *.in for files in dist\r
72 \r
73   ConfigFile = DistDir & "shibd.logger.in"\r
74   ReplaceInFile ConfigFile, "@-PKGLOGDIR-@", ConvertedDir & "/var/log/shibboleth"\r
75   If (NOT FileSystemObj.FileExists(ConfigDir & "shibd.logger")) then\r
76     FileSystemObj.CopyFile ConfigFile, ConfigDir & "shibd.logger", false\r
77   End If\r
78   If (FileSystemObj.FileExists(DistDir & "shibd.logger")) then\r
79     FileSystemObj.DeleteFile DistDir & "shibd.logger", true\r
80   End If\r
81   FileSystemObj.MoveFile ConfigFile, DistDir & "shibd.logger"\r
82 \r
83   ConfigFile = DistDir & "native.logger.in"\r
84   ReplaceInFile ConfigFile, "@-SHIRELOGDIR-@", ConvertedDir & "/var/log/shibboleth"\r
85   If (NOT FileSystemObj.FileExists(ConfigDir & "native.logger")) then\r
86     FileSystemObj.CopyFile ConfigFile, ConfigDir & "native.logger", false\r
87   End If\r
88   If (FileSystemObj.FileExists(DistDir & "native.logger")) then\r
89     FileSystemObj.DeleteFile DistDir & "native.logger", true\r
90   End If\r
91   FileSystemObj.MoveFile ConfigFile, DistDir & "native.logger"\r
92 \r
93   ConfigFile = DistDir & "apache.config.in"\r
94   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"\r
95   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"\r
96   If (NOT FileSystemObj.FileExists(ConfigDir & "apache.config")) then\r
97     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache.config", false\r
98   End If\r
99   If (FileSystemObj.FileExists(DistDir & "apache.config")) then\r
100     FileSystemObj.DeleteFile DistDir & "apache.config", true\r
101   End If\r
102   FileSystemObj.MoveFile ConfigFile, DistDir & "apache.config"\r
103 \r
104   ConfigFile = DistDir & "apache2.config.in"\r
105   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"\r
106   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"\r
107   If (NOT FileSystemObj.FileExists(ConfigDir & "apache2.config")) then\r
108     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache2.config", false\r
109   End If\r
110   If (FileSystemObj.FileExists(DistDir & "apache2.config")) then\r
111     FileSystemObj.DeleteFile DistDir & "apache2.config", true\r
112   End If\r
113   FileSystemObj.MoveFile ConfigFile, DistDir & "apache2.config"\r
114 \r
115   ConfigFile = DistDir & "apache22.config.in"\r
116   ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/lib/shibboleth"\r
117   ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/doc/shibboleth"\r
118   If (NOT FileSystemObj.FileExists(ConfigDir & "apache22.config")) then\r
119     FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache22.config", false\r
120   End If\r
121   If (FileSystemObj.FileExists(DistDir & "apache22.config")) then\r
122     FileSystemObj.DeleteFile DistDir & "apache22.config", true\r
123   End If\r
124   FileSystemObj.MoveFile ConfigFile, DistDir & "apache22.config"\r
125 \r
126   'Now just copy the other non-edited files over as well (if possible)\r
127 \r
128   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth2.xml")) then\r
129     FileSystemObj.CopyFile DistDir & "shibboleth2.xml", ConfigDir, false\r
130   End If\r
131 \r
132   If (NOT FileSystemObj.FileExists(ConfigDir & "accessError.html")) then\r
133     FileSystemObj.CopyFile DistDir & "accessError.html", ConfigDir, false\r
134   End If\r
135 \r
136   If (NOT FileSystemObj.FileExists(ConfigDir & "metadataError.html")) then\r
137     FileSystemObj.CopyFile DistDir & "metadataError.html", ConfigDir, false\r
138   End If\r
139 \r
140   If (NOT FileSystemObj.FileExists(ConfigDir & "sessionError.html")) then\r
141     FileSystemObj.CopyFile DistDir & "sessionError.html", ConfigDir, false\r
142   End If\r
143 \r
144   If (NOT FileSystemObj.FileExists(ConfigDir & "sslError.html")) then\r
145     FileSystemObj.CopyFile DistDir & "sslError.html", ConfigDir, false\r
146   End If\r
147 \r
148   If (NOT FileSystemObj.FileExists(ConfigDir & "bindingTemplate.html")) then\r
149     FileSystemObj.CopyFile DistDir & "bindingTemplate.html", ConfigDir, false\r
150   End If\r
151 \r
152   If (NOT FileSystemObj.FileExists(ConfigDir & "discoveryTemplate.html")) then\r
153     FileSystemObj.CopyFile DistDir & "discoveryTemplate.html", ConfigDir, false\r
154   End If\r
155 \r
156   If (NOT FileSystemObj.FileExists(ConfigDir & "postTemplate.html")) then\r
157     FileSystemObj.CopyFile DistDir & "postTemplate.html", ConfigDir, false\r
158   End If\r
159 \r
160   If (NOT FileSystemObj.FileExists(ConfigDir & "localLogout.html")) then\r
161     FileSystemObj.CopyFile DistDir & "localLogout.html", ConfigDir, false\r
162   End If\r
163 \r
164   If (NOT FileSystemObj.FileExists(ConfigDir & "globalLogout.html")) then\r
165     FileSystemObj.CopyFile DistDir & "globalLogout.html", ConfigDir, false\r
166   End If\r
167 \r
168   If (NOT FileSystemObj.FileExists(ConfigDir & "partialLogout.html")) then\r
169     FileSystemObj.CopyFile DistDir & "partialLogout.html", ConfigDir, false\r
170   End If\r
171 \r
172   If (NOT FileSystemObj.FileExists(ConfigDir & "console.logger")) then\r
173     FileSystemObj.CopyFile DistDir & "console.logger", ConfigDir, false\r
174   End If\r
175 \r
176   If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth.logger")) then\r
177     FileSystemObj.CopyFile DistDir & "shibboleth.logger", ConfigDir, false\r
178   End If\r
179 \r
180   If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-map.xml")) then\r
181     FileSystemObj.CopyFile DistDir & "attribute-map.xml", ConfigDir, false\r
182   End If\r
183 \r
184   If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-policy.xml")) then\r
185     FileSystemObj.CopyFile DistDir & "attribute-policy.xml", ConfigDir, false\r
186   End If\r
187 \r
188   If (NOT FileSystemObj.FileExists(ConfigDir & "security-policy.xml")) then\r
189     FileSystemObj.CopyFile DistDir & "security-policy.xml", ConfigDir, false\r
190   End If\r
191 \r
192   If (NOT FileSystemObj.FileExists(ConfigDir & "protocols.xml")) then\r
193     FileSystemObj.CopyFile DistDir & "protocols.xml", ConfigDir, false\r
194   End If\r
195 \r
196   ConfigFile  = ConfigDir & "SetService64.bat"\r
197   ReplaceInFile ConfigFile, "@-INSTALLDIR-@", InstallDir\r
198 \r
199   ConfigFile  = ConfigDir & "SetService32.bat"\r
200   ReplaceInFile ConfigFile, "@-INSTALLDIR-@", InstallDir\r
201   \r
202 \r
203 'Last End If\r
204 End If