Skip to content

Commit

Permalink
iis express installation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanczuk committed Aug 31, 2011
1 parent 7886f9e commit 58c6f76
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/iisnode/iisnode.vcxproj
Expand Up @@ -100,6 +100,7 @@ copy /y $(OutDir)\iisnode.dll $(SolutionDir)\..\..\build\$(Configuration)\$(Plat
copy /y $(OutDir)\iisnode.pdb $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
xcopy /R /S /Y $(SolutionDir)\..\samples\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\www
copy /y $(SolutionDir)\..\scripts\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
if "$(PlatformShortName)" neq "x86" del /q $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\*iisexpress*.*
copy /y $(SolutionDir)\..\config\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
echo $(Configuration) &gt; $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\$(PlatformShortName).txt</Command>
</PostBuildEvent>
Expand Down Expand Up @@ -132,6 +133,7 @@ copy /y $(OutDir)\iisnode.dll $(SolutionDir)\..\..\build\$(Configuration)\$(Plat
copy /y $(OutDir)\iisnode.pdb $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
xcopy /R /S /Y $(SolutionDir)\..\samples\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\www
copy /y $(SolutionDir)\..\scripts\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
if "$(PlatformShortName)" neq "x86" del /q $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\*iisexpress*.*
copy /y $(SolutionDir)\..\config\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
echo $(Configuration) &gt; $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\$(PlatformShortName).txt</Command>
</PostBuildEvent>
Expand All @@ -157,6 +159,7 @@ copy /y $(OutDir)\iisnode.dll $(SolutionDir)\..\..\build\$(Configuration)\$(Plat
copy /y $(OutDir)\iisnode.pdb $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
xcopy /R /S /Y $(SolutionDir)\..\samples\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\www
copy /y $(SolutionDir)\..\scripts\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
if "$(PlatformShortName)" neq "x86" del /q $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\*iisexpress*.*
copy /y $(SolutionDir)\..\config\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
echo $(Configuration) &gt; $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\$(PlatformShortName).txt</Command>
</PostBuildEvent>
Expand All @@ -182,6 +185,7 @@ copy /y $(OutDir)\iisnode.dll $(SolutionDir)\..\..\build\$(Configuration)\$(Plat
copy /y $(OutDir)\iisnode.pdb $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
xcopy /R /S /Y $(SolutionDir)\..\samples\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\www
copy /y $(SolutionDir)\..\scripts\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
if "$(PlatformShortName)" neq "x86" del /q $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\*iisexpress*.*
copy /y $(SolutionDir)\..\config\* $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)
echo $(Configuration) &gt; $(SolutionDir)\..\..\build\$(Configuration)\$(PlatformShortName)\$(PlatformShortName).txt</Command>
</PostBuildEvent>
Expand Down Expand Up @@ -246,7 +250,10 @@ echo $(Configuration) &gt; $(SolutionDir)\..\..\build\$(Configuration)\$(Platfor
</None>
<None Include="..\samples\urlrewrite\web.config" />
<None Include="..\scripts\addiisnodesectiongroup.js" />
<None Include="..\scripts\addiisnodesectiongroup_iisexpress.js" />
<None Include="..\scripts\ensureiisexpressconfig.js" />
<None Include="..\scripts\install.bat" />
<None Include="..\scripts\install_iisexpress.bat" />
<None Include="iisnode.def" />
</ItemGroup>
<ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions src/iisnode/iisnode.vcxproj.filters
Expand Up @@ -211,5 +211,14 @@
<None Include="..\samples\express\readme.htm">
<Filter>Samples\express</Filter>
</None>
<None Include="..\scripts\install_iisexpress.bat">
<Filter>Scripts</Filter>
</None>
<None Include="..\scripts\ensureiisexpressconfig.js">
<Filter>Scripts</Filter>
</None>
<None Include="..\scripts\addiisnodesectiongroup_iisexpress.js">
<Filter>Scripts</Filter>
</None>
</ItemGroup>
</Project>
37 changes: 37 additions & 0 deletions src/scripts/addiisnodesectiongroup_iisexpress.js
@@ -0,0 +1,37 @@
// Installs iisnode configuration section into system.webServer section group in
// %userprofile%\documents\iisexpress\config\applicationHost.config

// TODO, tjanczuk, find a programmatic way of registering iisnode section in IIS Express configuration

try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
WScript.Echo("Created FileSystemObject");
var f = fso.OpenTextFile(WScript.Arguments.Item(0), 1);
WScript.Echo("Opened file " + WScript.Arguments.Item(0) + " for reading");
var config = f.ReadAll();
WScript.Echo("Read all content");
f.Close();
WScript.Echo("Closed file");

if (!config.match(/\<\s*section\s*name\s*=\s*"iisnode"\s*\/s*>/)) {
WScript.Echo("iisnode section registration not found");
config = config.replace(/(\<\s*sectionGroup\s*name\s*=\s*"system.webServer"\s*>)/, '$1<section name="iisnode"/>');
WScript.Echo("added iisnode section registration");
}
else {
WScript.Echo("existing iisnode section registration found");
WScript.Quit(0);
}

f = fso.OpenTextFile(WScript.Arguments.Item(0), 2, true);
WScript.Echo("Open file for writing");
f.Write(config);
WScript.Echo("Written file");
f.Close();
WScript.Echo("Closed file");

WScript.Quit(0);
} catch (e) {
WScript.Echo("Exception");
WScript.Quit(1);
}
17 changes: 17 additions & 0 deletions src/scripts/ensureiisexpressconfig.js
@@ -0,0 +1,17 @@
// This ensures that user-scope IIS Express applicationhost.config file is created at
// %userprofile%\documents\iisexpress\config\applicationHost.config

try {
var versionMgr = new ActiveXObject("Microsoft.IIS.VersionManager");
WScript.Echo('Obtained Microsoft.IIS.VersionManager');
var iisex = versionMgr.GetVersionObject("7.5", 2);
WScript.Echo('Obtained version object 7.5');
var userObj = iisex.GetPropertyValue("userInstanceHelper");
WScript.Echo('Obtained userInstanceHelper');
userObj.SetupIISDirectory(false);
WScript.Echo('Set up IIS directory');
WScript.Quit(0);
} catch (e) {
WScript.Echo('Exception');
WScript.Quit(1);
}
5 changes: 3 additions & 2 deletions src/scripts/install.bat
Expand Up @@ -13,6 +13,7 @@ set site="%siteName%/%path%"
set node=%systemdrive%\node\node.exe
set processor_architecture_flag=%~dp0%PROCESSOR_ARCHITECTURE%.txt
set icacls=%systemdrive%\windows\system32\icacls.exe
set wscript=%systemdrive%\windows\system32\wscript.exe

echo IIS module installer for iisnode - hosting of node.js applications in IIS.
echo This script must be run with administrative privileges.
Expand Down Expand Up @@ -65,7 +66,7 @@ if not exist "%node%" (
)

if "%1" neq "/s" (
echo This installer will perform the following tasks to provide a quick :
echo This installer will perform the following tasks:
echo * ensure that the IIS_IUSRS group has read and execute rights to %node%
echo * unregister existing "iisnode" global module from your installation of IIS if such registration exists
echo * register %iisnode% as a native module with your installation of IIS
Expand Down Expand Up @@ -112,7 +113,7 @@ if %ERRORLEVEL% neq 0 (
echo ...success

echo Registering the iisnode section within the system.webServer section group...
C:\Windows\System32\wscript.exe /B /E:jscript "%addsection%"
"%wscript%" /B /E:jscript "%addsection%"
if %ERRORLEVEL% neq 0 (
echo Installation failed. Cannot register iisnode configuration section
exit /b -1
Expand Down
126 changes: 126 additions & 0 deletions src/scripts/install_iisexpress.bat
@@ -0,0 +1,126 @@
@echo off
setlocal

set appcmd="%ProgramFiles%\IIS Express\appcmd.exe"
set schemadir="%ProgramFiles%\IIS Express\config\schema"
if "%PROCESSOR_ARCHITECTURE%" equ "AMD64" (
set appcmd="%ProgramFiles(x86)%\IIS Express\appcmd.exe"
set schemadir="%ProgramFiles(x86)%\IIS Express\config\schema"
)

set applicationhostconfig=%userprofile%\documents\IISexpress\config\applicationhost.config
set iisnode=%~dp0iisnode.dll
set www=%~dp0www
set index=%www%\index.htm
set schema=%~dp0\iisnode_schema.xml
set addsection=%~dp0\addiisnodesectiongroup_iisexpress.js
set ensureiisexpressconfig=%~dp0\ensureiisexpressconfig.js
set node=%systemdrive%\node\node.exe
set processor_architecture_flag=%~dp0x86.txt
set wscript=%systemdrive%\windows\system32\wscript.exe

echo IIS Express module installer for iisnode - hosting of node.js applications in IIS Express.
echo This script must be run individually for every user on the machine.

if not exist "%processor_architecture_flag%" (
echo Installation failed. IIS Express requires 32 bit build of iisnode. You can get it from https://github.com/tjanczuk/iisnode/archives/master or build yourself.
exit /b -1
)

if not exist %appcmd% (
echo Installation failed. The appcmd.exe IIS Express management tool was not found at %appcmd%. Make sure you have IIS Express installed.
exit /b -1
)

if not exist "%iisnode%" (
echo Installation failed. The iisnode.dll native module to install was not found at %iisnode%. Make sure you are running this script from the pre-built installation package rather than from the source tree.
exit /b -1
)

if not exist "%index%" (
echo Installation failed. The samples were not found at %www%. Make sure you are running this script from the pre-built installation package rather than from the source tree.
exit /b -1
)

if not exist "%schema%" (
echo Installation failed. The configuration schema was not found at %schema%. Make sure you are running this script from the pre-built installation package rather than from the source tree.
exit /b -1
)

if not exist "%addsection%" (
echo Installation failed. The %addsection% script required to install iisnode configuration not found. Make sure you are running this script from the pre-built installation package rather than from the source tree.
exit /b -1
)

if not exist "%ensureiisexpressconfig%" (
echo Installation failed. The %ensureiisexpressconfig% script required to install iisnode configuration not found. Make sure you are running this script from the pre-built installation package rather than from the source tree.
exit /b -1
)

if not exist "%node%" (
echo *****************************************************************************
echo ************************** ERROR *********************************
echo The node.exe is not found at %node%.
echo IIS cannot serve node.js applications without node.exe.
echo Please get the latest node.exe build from http://nodejs.org and
echo install it to %node%, then restart the installer
echo *****************************************************************************
echo *****************************************************************************
exit /b -1
)

if "%1" neq "/s" (
echo This installer will perform the following tasks:
echo * unregister existing "iisnode" global module from your installation of IIS Express if such registration exists
echo * register %iisnode% as a native module with your installation of IIS Express
echo * install configuration schema for the "iisnode" module
echo * remove existing "iisnode" section from system.webServer section group in %applicationhostconfig%
echo * add the "iisnode" section within the system.webServer section group in %applicationhostconfig%
echo This script does not provide means to revert these actions. If something fails in the middle you are on your own.
echo Press ENTER to continue or Ctrl-C to terminate.
pause
)

echo Ensuring the %applicationhostconfig% IIS Express configuration is created...
"%wscript%" /B /E:jscript "%ensureiisexpressconfig%"
if %ERRORLEVEL% neq 0 (
echo Installation failed. Cannot create %applicationhostconfig%
exit /b -1
)
echo ...success

echo Ensuring any existing registration of 'iisnode' native module is removed...
%appcmd% uninstall module iisnode /commit:apphost
if %ERRORLEVEL% neq 0 if %ERRORLEVEL% neq 1168 (
echo Installation failed. Cannot remove potentially existing registration of 'iisnode' IIS native module
exit /b -1
)
echo ...success

echo Registering the iisnode native module %iisnode%...
%appcmd% install module /name:iisnode /image:"%iisnode%" /commit:apphost
if %ERRORLEVEL% neq 0 (
echo Installation failed. Cannot register iisnode native module
exit /b -1
)
echo ...success

echo Installing the iisnode module configuration schema from %schema%...
copy /y "%schema%" %schemadir%
if %ERRORLEVEL% neq 0 (
echo Installation failed. Cannot install iisnode module configuration schema
exit /b -1
)
echo ...success

echo Registering the iisnode section within the system.webServer section group...
"%wscript%" /B /E:jscript "%addsection%" "%applicationhostconfig%"
if %ERRORLEVEL% neq 0 (
echo Installation failed. Cannot register iisnode configuration section
exit /b -1
)
echo ...success

echo INSTALLATION SUCCESSFUL. Open WebMatrix and create a new WebSite pointing to %www% to explore the samples.

endlocal

0 comments on commit 58c6f76

Please sign in to comment.