Merge commit '2.5.0' into moonshot-packaging-fixes
[shibboleth/sp.git] / msi / scripts / shib_edit_config_files.vbs-wix
diff --git a/msi/scripts/shib_edit_config_files.vbs-wix b/msi/scripts/shib_edit_config_files.vbs-wix
new file mode 100644 (file)
index 0000000..0aacd1c
--- /dev/null
@@ -0,0 +1,226 @@
+Function ReadFile( filePath )\r
+   Dim theFile\r
+\r
+   'OpenTextFile args: <path>, 1 = ForReading\r
+   'If you read an empty file, VBScript throws an error for some reason\r
+   if (FileSystemObj.FileExists(filePath)) then\r
+     Set theFile = FileSystemObj.GetFile(filePath)\r
+     if (theFile.size > 0) then\r
+       Set theFile = FileSystemObj.OpenTextFile(filePath, 1)\r
+       ReadFile = theFile.ReadAll\r
+     else\r
+       ReadFile = ""\r
+     end if\r
+   else\r
+     ReadFile = ""\r
+   end if\r
+End Function\r
+\r
+Sub WriteFile( filePath, contents )\r
+   Dim theFile\r
+\r
+   'OpenTextFile args: <path>, 2 = ForWriting, True = create if not exist\r
+   Set theFile = FileSystemObj.OpenTextFile(filePath, 2, True)\r
+   theFile.Write contents\r
+End Sub\r
+\r
+Sub ReplaceInFile( filePath, lookForStr, replaceWithStr )\r
+  Dim buffer\r
+\r
+  buffer = ReadFile(filePath)\r
+  if (buffer <> "") then\r
+    buffer = Replace(buffer, lookForStr, replaceWithStr)\r
+    WriteFile filePath, buffer\r
+  end if\r
+End Sub\r
+\r
+\r
+Dim FileSystemObj, ConvertedDir, ConfigFile, XMLDir, WshShell\r
+Dim customData, msiProperties, InstallDir, LibDir, Is64Bit, Install32, LogFile\r
+\r
+on error resume next\r
+Set FileSystemObj = CreateObject("Scripting.FileSystemObject")\r
+if (Err = 0) then\r
+\r
+  'Get the INSTALLDIR and 64/32 values via CustomActionData\r
+  customData = Session.Property("CustomActionData")\r
+  msiProperties = split(customData,";@;")\r
+  InstallDir = msiProperties(0)\r
+  Is64Bit = msiProperties(1)\r
+  Install32 = msiProperties(2)\r
+\r
+  LibDir = "lib"\r
+  If (Is64Bit = "TRUE") then\r
+      If (Install32 <> "TRUE") then\r
+          LibDir = "lib64"\r
+      End If\r
+  End If\r
+\r
+  Set LogFile = FileSystemObj.OpenTextFile(InstallDir & "\var\log\shibboleth\Installer.log", 8, true)\r
+\r
+  If (LogFile) then\r
+     LogFile.WriteLine "Edit Config Files to " & InstallDir & ", 64Bit = " & Is64Bit & ", 32Bit = " & Install32\r
+  End If\r
+\r
+  'Remove all trailing backslashes to normalize\r
+  do while (mid(InstallDir,Len(InstallDir),1) = "\")\r
+    InstallDir = mid(InstallDir,1,Len(InstallDir)-1)\r
+  loop\r
+  ConvertedDir = Replace(InstallDir, "\", "/")\r
+  ConfigDir = InstallDir & "\etc\shibboleth\"\r
+  DistDir = ConfigDir & "dist\"\r
+\r
+  'Set ConvertedDir as the SHIBSP_PREFIX system variable.\r
+  Set WshShell = CreateObject("WScript.Shell")\r
+  WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\SHIBSP_PREFIX", ConvertedDir, "REG_SZ"\r
+\r
+  'Blow away any old SHIBSPP_SCHEMAS variable we find\r
+  WshShell.RegDelete "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\SHIBSP_SCHEMAS"\r
+\r
+  'Perform actual Substitutions\r
+  'Afterwards, if the config file doesn't already exist, copy up to etc/shibboleth\r
+  'Also strip *.in for files in dist\r
+\r
+  ConfigFile = DistDir & "shibd.logger.in"\r
+  ReplaceInFile ConfigFile, "@-PKGLOGDIR-@", ConvertedDir & "/var/log/shibboleth"\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "shibd.logger")) then\r
+    FileSystemObj.CopyFile ConfigFile, ConfigDir & "shibd.logger", false\r
+  End If\r
+  If (FileSystemObj.FileExists(DistDir & "shibd.logger")) then\r
+    FileSystemObj.DeleteFile DistDir & "shibd.logger", true\r
+  End If\r
+  FileSystemObj.MoveFile ConfigFile, DistDir & "shibd.logger"\r
+\r
+  ConfigFile = DistDir & "native.logger.in"\r
+  ReplaceInFile ConfigFile, "@-SHIRELOGDIR-@", ConvertedDir & "/var/log/shibboleth"\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "native.logger")) then\r
+    FileSystemObj.CopyFile ConfigFile, ConfigDir & "native.logger", false\r
+  End If\r
+  If (FileSystemObj.FileExists(DistDir & "native.logger")) then\r
+    FileSystemObj.DeleteFile DistDir & "native.logger", true\r
+  End If\r
+  FileSystemObj.MoveFile ConfigFile, DistDir & "native.logger"\r
+\r
+  ConfigFile = DistDir & "apache.config.in"\r
+  ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/" & LibDir & "/shibboleth"\r
+  ReplaceInFile ConfigFile, "@-PKGWEBDIR-@", ConvertedDir & "/doc/shibboleth"\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "apache.config")) then\r
+    FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache.config", false\r
+  End If\r
+  If (FileSystemObj.FileExists(DistDir & "apache.config")) then\r
+    FileSystemObj.DeleteFile DistDir & "apache.config", true\r
+  End If\r
+  FileSystemObj.MoveFile ConfigFile, DistDir & "apache.config"\r
+\r
+  ConfigFile = DistDir & "apache2.config.in"\r
+  ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/" & LibDir & "/shibboleth"\r
+  ReplaceInFile ConfigFile, "@-PKGWEBDIR-@", ConvertedDir & "/doc/shibboleth"\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "apache2.config")) then\r
+    FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache2.config", false\r
+  End If\r
+  If (FileSystemObj.FileExists(DistDir & "apache2.config")) then\r
+    FileSystemObj.DeleteFile DistDir & "apache2.config", true\r
+  End If\r
+  FileSystemObj.MoveFile ConfigFile, DistDir & "apache2.config"\r
+\r
+  ConfigFile = DistDir & "apache22.config.in"\r
+  ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/" & LibDir & "/shibboleth"\r
+  ReplaceInFile ConfigFile, "@-PKGWEBDIR-@", ConvertedDir & "/doc/shibboleth"\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "apache22.config")) then\r
+    FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache22.config", false\r
+  End If\r
+  If (FileSystemObj.FileExists(DistDir & "apache22.config")) then\r
+    FileSystemObj.DeleteFile DistDir & "apache22.config", true\r
+  End If\r
+  FileSystemObj.MoveFile ConfigFile, DistDir & "apache22.config"\r
+\r
+  ConfigFile = DistDir & "apache24.config.in"\r
+  ReplaceInFile ConfigFile, "@-PKGLIBDIR-@", ConvertedDir & "/" & LibDir & "/shibboleth"\r
+  ReplaceInFile ConfigFile, "@-PKGWEBDIR-@", ConvertedDir & "/doc/shibboleth"\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "apache24.config")) then\r
+    FileSystemObj.CopyFile ConfigFile, ConfigDir & "apache24.config", false\r
+  End If\r
+  If (FileSystemObj.FileExists(DistDir & "apache24.config")) then\r
+    FileSystemObj.DeleteFile DistDir & "apache24.config", true\r
+  End If\r
+  FileSystemObj.MoveFile ConfigFile, DistDir & "apache24.config"\r
+\r
+  'Now just copy the other non-edited files over as well (if possible)\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth2.xml")) then\r
+    FileSystemObj.CopyFile DistDir & "shibboleth2.xml", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "accessError.html")) then\r
+    FileSystemObj.CopyFile DistDir & "accessError.html", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "metadataError.html")) then\r
+    FileSystemObj.CopyFile DistDir & "metadataError.html", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "sessionError.html")) then\r
+    FileSystemObj.CopyFile DistDir & "sessionError.html", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "sslError.html")) then\r
+    FileSystemObj.CopyFile DistDir & "sslError.html", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "bindingTemplate.html")) then\r
+    FileSystemObj.CopyFile DistDir & "bindingTemplate.html", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "discoveryTemplate.html")) then\r
+    FileSystemObj.CopyFile DistDir & "discoveryTemplate.html", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "postTemplate.html")) then\r
+    FileSystemObj.CopyFile DistDir & "postTemplate.html", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "localLogout.html")) then\r
+    FileSystemObj.CopyFile DistDir & "localLogout.html", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "globalLogout.html")) then\r
+    FileSystemObj.CopyFile DistDir & "globalLogout.html", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "partialLogout.html")) then\r
+    FileSystemObj.CopyFile DistDir & "partialLogout.html", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "console.logger")) then\r
+    FileSystemObj.CopyFile DistDir & "console.logger", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "shibboleth.logger")) then\r
+    FileSystemObj.CopyFile DistDir & "shibboleth.logger", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-map.xml")) then\r
+    FileSystemObj.CopyFile DistDir & "attribute-map.xml", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "attribute-policy.xml")) then\r
+    FileSystemObj.CopyFile DistDir & "attribute-policy.xml", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "security-policy.xml")) then\r
+    FileSystemObj.CopyFile DistDir & "security-policy.xml", ConfigDir, false\r
+  End If\r
+\r
+  If (NOT FileSystemObj.FileExists(ConfigDir & "protocols.xml")) then\r
+    FileSystemObj.CopyFile DistDir & "protocols.xml", ConfigDir, false\r
+  End If\r
+\r
+  ConfigFile  = ConfigDir & "SetService64.bat"\r
+  ReplaceInFile ConfigFile, "@-INSTALLDIR-@", InstallDir\r
+\r
+  ConfigFile  = ConfigDir & "SetService32.bat"\r
+  ReplaceInFile ConfigFile, "@-INSTALLDIR-@", InstallDir\r
+  \r
+\r
+'Last End If\r
+End If
\ No newline at end of file