Handle the move of openSSL from \opt. Call keygen.bat during install
authorRod Widdowson <rdw@steadingsoftware.com>
Fri, 13 Apr 2012 12:55:01 +0000 (12:55 +0000)
committerRod Widdowson <rdw@steadingsoftware.com>
Fri, 13 Apr 2012 12:55:01 +0000 (12:55 +0000)
configs/keygen.bat-wix [new file with mode: 0644]
msi/WiX/ShibbolethSP-noarch.wxs
msi/WiX/testInstall.wxs
msi/scripts/shib_edit_config_files.vbs-wix [new file with mode: 0644]

diff --git a/configs/keygen.bat-wix b/configs/keygen.bat-wix
new file mode 100644 (file)
index 0000000..ca8002c
--- /dev/null
@@ -0,0 +1,98 @@
+@echo off\r
+setlocal\r
+\r
+set DAYS=\r
+set YEARS=\r
+set FQDN=\r
+set ENTITYID=\r
+set TEMP_DOMAIN_NAME=\r
+set PARAM=\r
+\r
+set PREFIX=%~dp0\r
+\r
+:opt_start\r
+set PARAM=%1\r
+if not defined PARAM goto opt_end\r
+if %1==-h goto opt_fqdn\r
+if %1==-e goto opt_entityid\r
+if %1==-y goto opt_years\r
+if %1==-f goto opt_force\r
+goto usage\r
+:opt_end\r
+\r
+if exist "%PREFIX%sp-key.pem" goto protect\r
+if exist "%PREFIX%sp-cert.pem" goto protect\r
+\r
+if not defined YEARS set YEARS=10\r
+set /a DAYS=%YEARS%*365\r
+\r
+if not defined FQDN goto guess_fqdn\r
+\r
+:generate\r
+set PATH=%PREFIX%..\..\lib;%PREFIX%..\..\bin\r
+set CNF="%PREFIX%sp-cert.cnf"\r
+echo # OpenSSL configuration file for creating sp-cert.pem    >%CNF%\r
+echo [req]                                                   >>%CNF%\r
+echo prompt=no                                               >>%CNF%\r
+echo default_bits=2048                                       >>%CNF%\r
+echo encrypt_key=no                                          >>%CNF%\r
+echo default_md=sha1                                         >>%CNF%\r
+echo distinguished_name=dn                                   >>%CNF%\r
+echo # PrintableStrings only                                 >>%CNF%\r
+echo string_mask=MASK:0002                                   >>%CNF%\r
+echo x509_extensions=ext                                     >>%CNF%\r
+echo [dn]                                                    >>%CNF%\r
+echo CN=%FQDN%                                               >>%CNF%\r
+echo [ext]                                                   >>%CNF%\r
+if defined ENTITYID (echo subjectAltName=DNS:%FQDN%,URI:%ENTITYID% >>%CNF%) else (echo subjectAltName=DNS:%FQDN% >>%CNF%)\r
+echo subjectKeyIdentifier=hash                               >>%CNF%\r
+"@-PROGRAMFILES-@Shibboleth\SP\lib\openssl.exe" req -config %PREFIX%sp-cert.cnf -new -x509 -days %DAYS% -keyout %PREFIX%sp-key.pem -out %PREFIX%sp-cert.pem\r
+del %CNF%\r
+exit /b\r
+\r
+:protect\r
+echo The files sp-key.pem and/or sp-cert.pem already exist!\r
+echo Use -f option to force recreation of keypair.\r
+exit /b\r
+\r
+:opt_force\r
+if exist "%PREFIX%sp-key.pem" del "%PREFIX%sp-key.pem"\r
+if exist "%PREFIX%sp-cert.pem" del "%PREFIX%sp-cert.pem"\r
+shift\r
+goto opt_start\r
+\r
+:opt_fqdn\r
+set FQDN=%2\r
+shift\r
+shift\r
+goto opt_start\r
+\r
+:opt_entityid\r
+set ENTITYID=%2\r
+shift\r
+shift\r
+goto opt_start\r
+\r
+:opt_years\r
+set YEARS=%2\r
+shift\r
+shift\r
+goto opt_start\r
+\r
+:usage\r
+echo usage: keygen [-h hostname for cert] [-y years to issue cert] [-e entityID to embed in cert]\r
+exit /b\r
+\r
+:guess_fqdn\r
+for /F "tokens=2 delims=:" %%i in ('"ipconfig /all | findstr /c:"Primary DNS Suffix" /c:"Primary Dns Suffix""') do set TEMP_DOMAIN_NAME=%%i\r
+if defined TEMP_DOMAIN_NAME set FQDN=%TEMP_DOMAIN_NAME: =%\r
+set TEMP_DOMAIN_NAME=\r
+if defined USERDNSDOMAIN set FQDN=%USERDNSDOMAIN%\r
+\r
+for /F %%i in ('hostname') do set HOST=%%i\r
+if defined FQDN (set FQDN=%HOST%.%FQDN%) else (set FQDN=%HOST%)\r
+\r
+echo >%FQDN%\r
+for /F %%i in ('dir /b/l %FQDN%') do set FQDN=%%i\r
+del %FQDN%\r
+goto generate\r
index 33a23c8..edc0df1 100644 (file)
@@ -54,7 +54,7 @@
             <File Name='example-shibboleth2.xml' />\r
           </Component>\r
           <Component Id='etc_shibboleth_nonperm' Guid='{A5BBCB8B-42B3-4402-B66D-66D2971F509F}'>\r
-            <File Name='keygen.bat' KeyPath='yes' />\r
+            <File Name='keygen.bat' KeyPath='yes' Source='$(var.BuildDirectory)\cvs\2.0\cpp-sp\configs\keygen.bat-wix'/>\r
             <File Name='xsltproc.js' />\r
           </Component>\r
           <Directory Id='etc_shibboleth_dist' Name='dist' \r
     <Condition Message='You must uninstall recent versions of Shibboleth before using this installer. To uninstall, use the &quot;Change&quot; option from the Add/Remove dialog and then Remove. Attempting to uninstall directly causes the installer to hang on most systems.'>SHIB_OLDVERSION = "none"</Condition>\r
 \r
     <!-- The actions to perform after the files have been copied -->\r
-    <Binary Id='EditConfigFileSrc' SourceFile='$(var.BuildDirectory)\cvs\2.0\cpp-sp\msi\scripts\shib_edit_config_files.vbs' />\r
+    <Binary Id='EditConfigFileSrc' SourceFile='$(var.BuildDirectory)\cvs\2.0\cpp-sp\msi\scripts\shib_edit_config_files.vbs-wix' />\r
+    <Binary Id='KeyGenSrc' SourceFile='$(var.BuildDirectory)\cvs\2.0\cpp-sp\msi\scripts\shib_keygen.vbs' />\r
     <CustomAction Id='EditConfigFiles' \r
                   BinaryKey='EditConfigFileSrc' VBScriptCall='' Execute='deferred' Impersonate='no' />\r
-    <CustomAction Id='SetEditConfigFiles' Property='EditConfigFiles' Value='[INSTALLDIR];@;[SHIBD_PORT]' />\r
+    <CustomAction Id='SetEditConfigFiles' Property='EditConfigFiles' Value='[INSTALLDIR];@;[SHIBD_PORT];@;[ProgramFilesFolder]' />\r
+    <CustomAction Id='KeyGen' BinaryKey='KeyGenSrc' VBScriptCall='' Execute='deferred' Impersonate='no' />\r
+    <CustomAction Id='SetKeyGen' Property='KeyGen' Value='[INSTALLDIR]' />\r
     <InstallExecuteSequence>\r
       <Custom Action='SetEditConfigFiles' Before='CostInitialize'>NOT Installed</Custom>\r
       <Custom Action='EditConfigFiles' After='InstallFiles'>NOT Installed</Custom>\r
+      <Custom Action='SetKeyGen' Before='CostInitialize'>NOT Installed</Custom>\r
+      <Custom Action='KeyGen' After='EditConfigFiles'>NOT Installed</Custom>\r
     </InstallExecuteSequence>\r
 \r
     <!-- Components\r
index d0b22ed..6b29b61 100644 (file)
@@ -21,7 +21,7 @@
            Version='1.0.0.0' Manufacturer='Shibboleth Consortium'>\r
     <Package Description='TEST Windows Installer package'\r
              Comments='Ignore Ignore Ignore Ignore'\r
-             Manufacturer='Shibboleth Consortium' InstallerVersion='200' Compressed='yes' />\r
+             Manufacturer='Shibboleth Consortium' InstallerVersion='300' Compressed='yes' />\r
 \r
     <Media Id='1' Cabinet='product.cab' EmbedCab='yes' />\r
     <!-- Files -->\r
           </Directory>\r
         </Directory>\r
       </Directory>\r
+      <Directory Id='SystemFolder' >\r
+        <!-- Note that this will cause warning at link time which can\r
+        be safely ignored\r
+        http://blogs.msdn.com/b/astebner/archive/2007/02/13/building-an-msi-using-wix-v3-0-that-includes-the-vc-8-0-runtime-merge-modules.aspx-->\r
+       <Merge Id='Microsoft_VC100_DebugCRT_x86' Language='1033' SourceFile='C:\Program Files (x86)\Common Files\Merge Modules\Microsoft_VC100_DebugCRT_x86.msm' DiskId='1' />\r
+        <Merge Id='Microsoft_VC100_CRT_x86' Language='1033' SourceFile='C:\Program Files (x86)\Common Files\Merge Modules\Microsoft_VC100_CRT_x86.msm' DiskId='1' />\r
+      </Directory>\r
     </Directory>\r
+\r
     <!-- Feature -->\r
     <Feature Id='MyFeature' Title='My 1st Feature' Level='1'>\r
       <ComponentRef Id='MyComponent' />\r
       <MergeRef Id='XercesMergeModule_x86' />\r
       <MergeRef Id='XmlSecMergeModule_x86' />\r
       <MergeRef Id='XmlToolingMergeModule_x86' />\r
+      <MergeRef Id='Microsoft_VC100_CRT_x86' />\r
+      <MergeRef Id='Microsoft_VC100_DebugCRT_x86' />\r
     </Feature>\r
   </Product>\r
 </Wix>\r
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..cbc6bd6
--- /dev/null
@@ -0,0 +1,215 @@
+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, ShibdPort\r
+\r
+on error resume next\r
+Set FileSystemObj = CreateObject("Scripting.FileSystemObject")\r
+if (Err = 0) then\r
+\r
+  'Get the INSTALLDIR and SHIBD_PORT values via CustomActionData\r
+  customData = Session.Property("CustomActionData")\r
+  msiProperties = split(customData,";@;")\r
+  InstallDir = msiProperties(0)\r
+  ShibdPort = msiProperties(1)\r
+  ProgramFiles = msiProperties(2)\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
+  '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
+  'Keygen.bat is updated in placehowever\r
+  Keygen = ConfigDir & "keygen.bat"\r
+  ReplaceInFile Keygen, "@-PROGRAMFILES-@", ProgramFiles\r
+\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 & "/lib/shibboleth"\r
+  ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/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 & "/lib/shibboleth"\r
+  ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/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 & "/lib/shibboleth"\r
+  ReplaceInFile ConfigFile, "@-PKGDOCDIR-@", ConvertedDir & "/share/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
+  '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
+  'Finally, fix up schema catalogs.\r
+  \r
+  XMLDir = InstallDir & "\share\xml\xmltooling\"\r
+  ConfigFile = XMLDir & "catalog.xml"\r
+  ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir\r
+\r
+  XMLDir = InstallDir & "\share\xml\opensaml\"\r
+  ConfigFile = XMLDir & "saml20-catalog.xml"\r
+  ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir\r
+  ConfigFile = XMLDir & "saml11-catalog.xml"\r
+  ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir\r
+  ConfigFile = XMLDir & "saml10-catalog.xml"\r
+  ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir\r
+\r
+  XMLDir = InstallDir & "\share\xml\shibboleth\"\r
+  ConfigFile = XMLDir & "catalog.xml"\r
+  ReplaceInFile ConfigFile, "@-PKGXMLDIR-@/", XMLDir\r
+\r
+'Last End If\r
+End If
\ No newline at end of file