1 | "This script will work fine for a few cases 'by default':" |
---|
2 | " - completely CLEAN WS2012R2 host" |
---|
3 | " - python 2.7 installed in the default path" |
---|
4 | " - wfasctgi installed on the default path" |
---|
5 | "It'll install web2py under the default website " |
---|
6 | " You can use it as a boilerplate to automate your deployments" |
---|
7 | " but it still is released AS IT IS. " |
---|
8 | "BIG FAT WARNING: It will install a bunch of dependecies |
---|
9 | Inspect the source before executing it" |
---|
10 | "" |
---|
11 | "" |
---|
12 | $ErrorActionPreference = 'stop' |
---|
13 | |
---|
14 | $REALLY_SURE = Read-Host "Do you want to start with web2py deployment? [y/N]" |
---|
15 | if (!@('y', 'Y') -contains $REALLY_SURE) { |
---|
16 | "Ok, Exiting without doing anything" |
---|
17 | exit 1 |
---|
18 | } |
---|
19 | #setting root folder |
---|
20 | $rootfolder = $pwd |
---|
21 | |
---|
22 | ### utilities - start |
---|
23 | function ask_a_question($question) { |
---|
24 | $response = Read-Host "$question [Y/n]" |
---|
25 | if (@('Y', 'y', '', $null) -contains $response) { |
---|
26 | return $true |
---|
27 | } else { |
---|
28 | return $false |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | function unzip_me { |
---|
33 | #Load the assembly |
---|
34 | [System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null |
---|
35 | #Unzip the file |
---|
36 | [System.IO.Compression.ZipFile]::ExtractToDirectory($pathToZip, $targetDir) |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | ### utilities - end |
---|
41 | |
---|
42 | #install 4.5 that is needed for a bunch of things anyway |
---|
43 | Install-WindowsFeature Net-Framework-45-Core |
---|
44 | |
---|
45 | #fetch web2py |
---|
46 | $web2py_url = 'http://www.web2py.com/examples/static/web2py_src.zip' |
---|
47 | $web2py_file = "$pwd\web2py_src.zip" |
---|
48 | if (!(Test-Path $web2py_file)) { |
---|
49 | (new-object net.webclient).DownloadFile($web2py_url, $web2py_file) |
---|
50 | } |
---|
51 | #Load the assembly |
---|
52 | [System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null |
---|
53 | #Unzip the file |
---|
54 | [System.IO.Compression.ZipFile]::ExtractToDirectory($web2py_file, $pwd) |
---|
55 | |
---|
56 | #features installation (IIS, needed modules, python, chocolatey, etc) |
---|
57 | $installfeatures = ask_a_question('Do you want to install needed features?') |
---|
58 | |
---|
59 | if ($installfeatures) { |
---|
60 | Install-WindowsFeature Web-Server,Web-Default-Doc,Web-Static-Content,Web-Http-Redirect,Web-Http-Logging,Web-Request-Monitor,` |
---|
61 | Web-Http-Tracing,Web-Stat-Compression,Web-Dyn-Compression,Web-Filtering,Web-Basic-Auth,Web-Windows-Auth,Web-AppInit,` |
---|
62 | Web-CGI,Web-WebSockets,Web-Mgmt-Console,Web-Net-Ext45 |
---|
63 | } |
---|
64 | |
---|
65 | $copy_web2py = ask_a_question("Copy web2py to the default website root?") |
---|
66 | if ($copy_web2py) { |
---|
67 | Import-Module WebAdministration |
---|
68 | $available_websites = Get-Website |
---|
69 | if ($available_websites[0] -eq $null) { |
---|
70 | $default_one = $available_websites |
---|
71 | } else { |
---|
72 | $default_one = $available_websites[0] |
---|
73 | } |
---|
74 | $iis_root = [System.Environment]::ExpandEnvironmentVariables($default_one.PhysicalPath) |
---|
75 | Copy-Item "$rootfolder\web2py\*" $iis_root -Recurse |
---|
76 | $rootfolder = $iis_root |
---|
77 | $acl = (Get-Item $rootfolder).GetAccessControl('Access') |
---|
78 | $identity = "BUILTIN\IIS_IUSRS" |
---|
79 | $fileSystemRights = "Modify" |
---|
80 | $inheritanceFlags = "ContainerInherit, ObjectInherit" |
---|
81 | $propagationFlags = "None" |
---|
82 | $accessControlType = "Allow" |
---|
83 | $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($identity, $fileSystemRights, $inheritanceFlags, $propagationFlags, $accessControlType) |
---|
84 | $acl.SetAccessRule($rule) |
---|
85 | Set-Acl $rootfolder $acl |
---|
86 | } |
---|
87 | |
---|
88 | $create_cert = ask_a_question("Do you want to create a self-signed SSL cert?") |
---|
89 | if ($create_cert) { |
---|
90 | $cert = New-SelfSignedCertificate -DnsName ("localtest.me","*.localtest.me") -CertStoreLocation cert:\LocalMachine\My |
---|
91 | $rootStore = Get-Item cert:\LocalMachine\Root |
---|
92 | $rootStore.Open("ReadWrite") |
---|
93 | $rootStore.Add($cert) |
---|
94 | $rootStore.Close(); |
---|
95 | Import-Module WebAdministration |
---|
96 | Set-Location IIS:\SslBindings |
---|
97 | New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https |
---|
98 | $cert | New-Item 0.0.0.0!443 |
---|
99 | Set-Location $pwd |
---|
100 | } |
---|
101 | |
---|
102 | "checking for chocolatey" |
---|
103 | if (Get-Command "choco.exe" -ErrorAction SilentlyContinue) |
---|
104 | { |
---|
105 | "chocolatey found" |
---|
106 | } else { |
---|
107 | "installing chocolatey" |
---|
108 | (new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1') | iex |
---|
109 | } |
---|
110 | "installing url-rewrite" |
---|
111 | choco install UrlRewrite |
---|
112 | $pythonexe = Read-Host 'Python.exe path [C:\Python27\python.exe]' |
---|
113 | if (($pythonexe -eq '') -or ($pythonexe -eq $null)) { |
---|
114 | $pythonexe = 'C:\Python27\python.exe' |
---|
115 | } |
---|
116 | if (!(Test-Path $pythonexe)) { |
---|
117 | "ERROR: python executable not found" |
---|
118 | $pythonwanted = ask_a_question("do you want to install it automatically?") |
---|
119 | |
---|
120 | if ($pythonwanted) { |
---|
121 | choco install webpicmd |
---|
122 | WebpiCmd.exe /Install /Products:WFastCgi_21_279 |
---|
123 | $pythonexe = 'C:\Python27\python.exe' |
---|
124 | } |
---|
125 | else { |
---|
126 | exit 1 |
---|
127 | } |
---|
128 | |
---|
129 | } |
---|
130 | $wfastcgipath = Read-Host 'wfastcgi.py path [C:\Python27\Scripts\wfastcgi.py]' |
---|
131 | if (($wfastcgipath -eq '') -or ($wfastcgipath -eq $null)) { |
---|
132 | $wfastcgipath = 'C:\Python27\Scripts\wfastcgi.py' |
---|
133 | } |
---|
134 | |
---|
135 | if (-not (Test-Path $wfastcgipath)) { |
---|
136 | "ERROR: wfastcgi.py not found" |
---|
137 | |
---|
138 | $wfastcgiwanted = ask_a_question("do you want to install it automatically?") |
---|
139 | if ($wfastcgiwanted) { |
---|
140 | choco install webpicmd |
---|
141 | WebpiCmd.exe /Install /Products:WFastCgi_21_279 |
---|
142 | } else { |
---|
143 | exit 1 |
---|
144 | } |
---|
145 | } |
---|
146 | $pythondir = Split-Path c:\python27\python.exe |
---|
147 | #installing dependencies |
---|
148 | $env:Path = $env:Path + ";$pythondir;$pythondir\Scripts" |
---|
149 | |
---|
150 | pip install pypiwin32 |
---|
151 | |
---|
152 | $PW = Read-Host 'Web2py Admin Password' |
---|
153 | |
---|
154 | $appcmdpath = "$env:windir\system32\inetsrv\appcmd.exe" |
---|
155 | |
---|
156 | & $appcmdpath set config /section:system.webServer/fastCGI "/+[fullPath='$pythonexe', arguments='$wfastcgipath']" |
---|
157 | & $appcmdpath unlock config -section:system.webServer/handlers |
---|
158 | |
---|
159 | & cd $rootfolder |
---|
160 | & $pythonexe -c "from gluon.main import save_password; save_password('$PW',443)" |
---|
161 | |
---|
162 | $webconfig_template = Join-Path $rootfolder "examples\web.config" |
---|
163 | $destination = Join-Path $rootfolder "web.config" |
---|
164 | $scriptprocessor = 'scriptProcessor="{0}|{1}"' -f $pythonexe, $wfastcgipath |
---|
165 | |
---|
166 | (Get-Content $webconfig_template) | Foreach-Object {$_ -replace 'scriptProcessor="SCRIPT_PROCESSOR"', $scriptprocessor} | where {$_ -ne ""} | Set-Content $destination |
---|
167 | "" |
---|
168 | "Installation finished. Web2py is available either on http://localhost/ or at https://localtest.me/" |
---|
169 | "" |
---|