forked from episerver/foundation-mvc-cms
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.cmd
286 lines (244 loc) · 13 KB
/
setup.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
@echo off
cd /d %~dp0
openfiles > NUL 2>&1
if %ERRORLEVEL% NEQ 0 (
set "errorMessage=Build.cmd script must be run in an elevated (admin) command prompt"
goto error
)
mode con:cols=120 lines=5000
set ROOTPATH=%cd%
set ROOTDIR=%cd%
set SOURCEPATH=%ROOTPATH%\src
set APPCMD=%windir%\system32\inetsrv\appcmd.exe
if "%~1" == "" goto loop
set APPNAME=%~1
set FOUNDATIONDOMAIN=%~2
set LICENSEPATH=%~3
set SQLSERVER=%~4
set ADDITIONAL_SQLCMD=%~5
goto main
:loop
set APPNAME=
set FOUNDATIONDOMAIN=
set LICENSEPATH=
set SQLSERVER=
set ADDITIONAL_SQLCMD=
set /p APPNAME=Enter your application name (required):
set /p FOUNDATIONDOMAIN=Enter your public domain name for foundation(optional, press Enter to leave it blank):
set /p LICENSEPATH=Enter your LICENSE path (optional, press Enter to leave it blank):
set /p SQLSERVER=Enter your SQL server name (optional, press Enter for default (.) local server):
set /p ADDITIONAL_SQLCMD=Enter your sqlcmd command (optional, press Enter for default (-E) windows auth):
set check=false
if "%APPNAME%"=="" (set check=true)
if "%check%"=="true" (
echo Parameters missing, application name is required, foundation domain name, commerce manager domain name and LICENSE path are optional
pause
cls
goto loop
)
:main
if "%FOUNDATIONDOMAIN%"=="" (set FOUNDATIONDOMAIN="%APPNAME%")
if "%SQLSERVER%"=="" (set SQLSERVER=.)
if "%ADDITIONAL_SQLCMD%"=="" (set ADDITIONAL_SQLCMD=-E)
if "%LICENSEPATH%"=="" (set LICENSEPATH="")
cls
echo Your application name is: %APPNAME%
echo Your foundation domain name is: %FOUNDATIONDOMAIN%
echo Your LICENSE path is: %LICENSEPATH%
echo Your SQL server name is: %SQLSERVER%
echo Your SQLCMD command is: sqlcmd -S %SQLSERVER% %ADDITIONAL_SQLCMD%
timeout 15
set cms_db=%APPNAME%.Cms
set user=%APPNAME%User
set password=Episerver123!
set errorMessage = ""
cls
echo ######################################################################
echo # Grab a tea or coffee, this could take around 5 to 10 mins #
echo ######################################################################
echo # #
echo # ( ) ( ) ) #
echo # ) ( ) ( ( #
echo # ( ) ( ) ) #
echo # _____________ #
echo # ^|_____________^| ___ #
echo # ^| ^|/ _ \ #
echo # ^| ^| ^| ^| #
echo # ^| OPTI ^|_^| ^| #
echo # ___^| ^|\___/ #
echo # / \___________/ \ #
echo # \_____________________/ #
echo # #
echo ######################################################################
echo ## Building Foundation please check the Build\Logs directory if you receive errors
echo ## Gettting MSBuildPath ##
for /f "usebackq tokens=*" %%i in (`.\build\vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
set InstallDir=%%i
)
for %%v in (15.0, 14.0) do (
if exist "%InstallDir%\MSBuild\%%v\Bin\MSBuild.exe" (
set msBuildPath=\MSBuild\%%v\Bin\MSBuild.exe
goto :finish
)
set msBuildPath=\MSBuild\Current\Bin\MSBuild.exe
)
:finish
echo msbuild.exe path: %InstallDir%%msBuildPath%
echo ## Set folder permissions ##
md "%ROOTPATH%\Build\Logs" 2>nul
icacls "%ROOTPATH%\\" /grant *S-1-1-0:(OI)(CI)F /T > Build\Logs\Build.log
echo ## Restoring Nuget packages ##
echo ## Restoring Nuget packages ## >> Build\Logs\Build.log
.\build\nuget restore "%ROOTPATH%\Foundation.sln" >> Build\Logs\Build.log
echo ## NPM Install ##
echo ## NPM Install >> Build\Logs\Build.log
cd %SOURCEPATH%\Foundation
CALL npm ci
IF %errorlevel% NEQ 0 (
set errorMessage=%errorlevel%
goto error
)
CALL npm run dev
cd %ROOTPATH%
echo ## Clean and build ##
echo ## Clean and build ## >> Build\Logs\Build.log
"%InstallDir%%msBuildPath%" "%ROOTPATH%\Foundation.sln" /t:Clean,Build >> Build\Logs\Build.log
:: Determine package folders
for /f " tokens=*" %%i in ('dir "Packages\EPiServer.CMS.Core*" /b /o:d') do (set cms_core=%%i)
for /f " tokens=*" %%i in ('dir "Packages\EPiServer.Marketing.Testing*" /b /o:d') do (set testing_core=%%i)
for /f " tokens=*" %%i in ('dir "Packages\EPiServer.Find.Cms.1*" /b /o:d') do (set find_cms=%%i)
if "%cms_core%"=="" (
set errorMessage=CMS Core package is missing. Please build the project before running the setup
goto error
)
if "%testing_core%"=="" (
set errorMessage=EPiServer.Marketing.Testing package is missing. Please build the project before running the setup
goto error
)
if "%find_cms%"=="" (
set errorMessage=EPiServer.Find.Cms package is missing. Please build the project before running the setup
goto error
)
set sql=sqlcmd -S %SQLSERVER% %ADDITIONAL_SQLCMD%
echo ## Dropping databases ##
echo ## Dropping databases ## > Build\Logs\Database.log
%sql% -Q "EXEC msdb.dbo.sp_delete_database_backuphistory N'%cms_db%'" >> Build\Logs\Database.log
%sql% -Q "if db_id('%cms_db%') is not null ALTER DATABASE [%cms_db%] SET SINGLE_USER WITH ROLLBACK IMMEDIATE" >> Build\Logs\Database.log
%sql% -Q "if db_id('%cms_db%') is not null DROP DATABASE [%cms_db%]" >> Build\Logs\Database.log
echo ## Dropping user ##
echo ## Dropping user ## >> Build\Logs\Database.log
%sql% -Q "if exists (select loginname from master.dbo.syslogins where name = '%user%') EXEC sp_droplogin @loginame='%user%'" >> Build\Logs\Database.log
echo ## Creating databases ##
echo ## Creating databases ## >> Build\Logs\Database.log
md "%SOURCEPATH%\appdata\db" 2>nul >> Build\Logs\Database.log
%sql% -Q "CREATE DATABASE [%cms_db%] COLLATE SQL_Latin1_General_CP1_CI_AS" >> Build\Logs\Database.log
%sql% -Q "SET NOCOUNT ON; SELECT ServerProperty('Edition')" -h -1 | findstr /c:"SQL Azure" 1>nul
IF %ERRORLEVEL% EQU 0 (
echo ## Creating user in azure sql##
echo ## Creating user in azure sql## >> Build\Logs\Database.log
%sql% -d %cms_db% -Q "CREATE USER %user% WITH PASSWORD='%password%'" >> Build\Logs\Database.log
%sql% -d %cms_db% -Q "ALTER ROLE db_owner ADD MEMBER %user%" >> Build\Logs\Database.log
) else (
echo ## Creating user##
echo ## Creating user## >> Build\Logs\Database.log
%sql% -Q "EXEC sp_addlogin @loginame='%user%', @passwd='%password%', @defdb='%cms_db%'" >> Build\Logs\Database.log
%sql% -d %cms_db% -Q "EXEC sp_adduser @loginame='%user%'" >> Build\Logs\Database.log
%sql% -d %cms_db% -Q "EXEC sp_addrolemember N'db_owner', N'%user%'" >> Build\Logs\Database.log
)
echo ## Installing CMS database ##
echo ## Installing CMS database ## >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%cms_core%\tools\EPiServer.Cms.Core.sql" >> Build\Logs\Database.log
echo ## Installing EPiServer.Find.Cms schema ##
echo ## Installing EPiServer.Find.Cms schema ## >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%find_cms%\tools\epiupdates\sql\1.0.1.sql" >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%find_cms%\tools\epiupdates\sql\12.2.8.sql" >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%find_cms%\tools\epiupdates\sql\12.4.2.sql" >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%find_cms%\tools\epiupdates\sql\13.0.4.sql" >> Build\Logs\Database.log
echo ## Installing EPiServer.Marketing schema ##
echo ## Installing EPiServer.Marketing schema ## >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%testing_core%\tools\epiupdates\sql\1.0.0.1.sql" >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%testing_core%\tools\epiupdates\sql\1.0.0.2.sql" >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%testing_core%\tools\epiupdates\sql\1.0.0.3.sql" >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%testing_core%\tools\epiupdates\sql\1.0.0.4.sql" >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%testing_core%\tools\epiupdates\sql\1.0.0.5.sql" >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%testing_core%\tools\epiupdates\sql\1.0.0.6.sql" >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "packages\%testing_core%\tools\epiupdates\sql\1.0.0.7.sql" >> Build\Logs\Database.log
echo ## Installing ASP.NET Identity ##
echo ## Installing ASP.NET Identity ## >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "Build\SqlScripts\aspnet_identity.sql" >> Build\Logs\Database.log
echo ## Installing Sql Profile ##
echo ## InstallingSql Profile ## >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "Build\SqlScripts\InstallCommon.sql" >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "Build\SqlScripts\InstallProfile.sql" >> Build\Logs\Database.log
echo ## Installing Service API CMS ##
echo ## Installing Service API CMS ## >> Build\Logs\Database.log
%sql% -d %cms_db% -b -i "Build\SqlScripts\ServiceApiCms.sql" >> Build\Logs\Database.log
echo ## Cleaning packages folder ##
echo ## Cleaning packages folder ## >> Build\Logs\Build.log
echo %ROOTPATH%\packages\*.*
RD "%ROOTPATH%\packages\" /Q /S >> Build\Logs\Build.log
echo ## Set folder permissions ##
echo ## Set folder permissions ## >> Build\Logs\Build.log
icacls "%ROOTPATH%" /grant Everyone:(OI)(CI)F /T >> Build\Logs\Build.log
attrib -r "%ROOTPATH%\*.*" /s >> Build\Logs\Build.log
echo ## Creating IIS application pools ##
echo ## Creating IIS application pools ## > Build\Logs\IIS.log
%APPCMD% list site /name:"%APPNAME%"
IF "%ERRORLEVEL%" EQU "0" (
%APPCMD% delete site "%APPNAME%"
)
%APPCMD% list apppool /name:"%APPNAME%"
IF "%ERRORLEVEL%" EQU "0" (
%APPCMD% delete apppool "%APPNAME%"
)
%APPCMD% add apppool /name:%APPNAME% >> Build\Logs\IIS.log
%APPCMD% set config -section:applicationPools "/[name='%APPNAME%'].processModel.loadUserProfile:true" >> Build\Logs\IIS.log
echo ## Creating IIS applications ##
echo ## Creating IIS applications ## >> Build\Logs\IIS.log
%windir%\system32\inetsrv\appcmd add site /name:%APPNAME% /physicalPath:"%SOURCEPATH%\Foundation" /bindings:http/*:80:%APPNAME% >> Build\Logs\IIS.log
if "%FOUNDATIONDOMAIN%"=="" GOTO finish
%windir%\system32\inetsrv\appcmd set site "%APPNAME%" /+bindings.[protocol='http',bindingInformation='*:80:%FOUNDATIONDOMAIN%'] >> Build\Logs\IIS.log
:finish
echo ## Adding site to app pool ##
echo ## Adding site to app pool ## >> Build\Logs\IIS.log
%systemroot%\system32\inetsrv\APPCMD set app "%APPNAME%/" /applicationPool:%APPNAME% >> Build\Logs\IIS.log
echo ## Updating host file ##
find /C /I "%APPNAME%" %WINDIR%\system32\drivers\etc\hosts
if %ERRORLEVEL% NEQ 0 (
echo: >> %WINDIR%\System32\drivers\etc\hosts
echo 127.0.0.1 %APPNAME% >> %WINDIR%\System32\drivers\etc\hosts
)
echo ## Copying licence file ##
echo ## Copying licence file ## >> Build\Logs\IIS.log
if "%LICENSEPATH%"=="" ( echo License file not found! ) else ( xcopy "%LICENSEPATH%" "%SOURCEPATH%\Foundation" /Y >> Build\Logs\IIS.log)
echo ## Creating conectionstrings.config ##
echo ## Creating conectionstrings.config ## >> Build\Logs\Build.log
(
echo ^<connectionStrings^>
echo ^<clear /^>
echo ^<add name="EPiServerDB" connectionString="Data Source=%SQLSERVER%;Initial Catalog=%cms_db%;User Id=%user%;Password=%password%;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /^>
echo ^<!--
echo ^<add name="EPiServerAzureBlobs" connectionString="DefaultEndpointsProtocol=https;AccountName=ChangeThis;AccountKey=ChangeThis" /^>
echo ^<add name="EPiServerAzureEvents" connectionString="Endpoint=sb://ChangeThis.servicebus.windows.net/;SharedAccessKeyName=ChangeThis;SharedAccessKey=ChangeThis" /^>
echo --^>
echo ^</connectionStrings^>
) > "%SOURCEPATH%\Foundation\connectionStrings.config"
start http://%FOUNDATIONDOMAIN%/
:error
if NOT "%errorMessage%"=="" echo %errorMessage%
echo Run resetup.cmd to resetup solution
echo @echo off > resetup.cmd
echo cls >> resetup.cmd
echo echo ###################################################################### >> resetup.cmd
echo echo # Rebuid the current application from default # >> resetup.cmd
echo echo ###################################################################### >> resetup.cmd
echo echo # # >> resetup.cmd
echo echo # NOTE: This will **DROP** the existing DB # >> resetup.cmd
echo echo # and resetup so use with caution!! # >> resetup.cmd
echo echo # # >> resetup.cmd
echo echo # Crtl+C NOW if you are unsure! # >> resetup.cmd
echo echo # # >> resetup.cmd
echo echo ###################################################################### >> resetup.cmd
echo pause >> resetup.cmd
echo setup %APPNAME% %FOUNDATIONDOMAIN% %LICENSEPATH% %SQLSERVER% "%ADDITIONAL_SQLCMD%" >> resetup.cmd
pause