-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall.ps1
More file actions
209 lines (178 loc) · 6.56 KB
/
install.ps1
File metadata and controls
209 lines (178 loc) · 6.56 KB
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
# PowerShell script for installing the project on Windows using Chocolatey
# Define variables
$NODE_VERSION = "22.16.0"
$POSTGRES_VERSION = "17"
$PHP_VERSION = "8.5"
$COMPOSER_VERSION = "6.3.0"
$LOG_FILE = "install.log"
# Function to log messages
function Log-Message {
param([string]$message)
Write-Host $message
Add-Content -Path $LOG_FILE -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): $message"
}
# Function to run commands with logging
function Run-Command {
param([string]$command)
Log-Message "Running: $command"
try {
Invoke-Expression $command *>&1 | Tee-Object -Append -FilePath $LOG_FILE
if ($LASTEXITCODE -ne 0) {
throw "Command failed with exit code $LASTEXITCODE"
}
}
catch {
Log-Message "Error executing command: $_"
throw
}
}
# Function to check Windows version and compatibility
function Check-SystemCompatibility {
$os = Get-WmiObject -Class Win32_OperatingSystem
if (-not $os.Caption.Contains("Windows")) {
Log-Message "This script is only compatible with Windows operating systems."
exit 1
}
Log-Message "Running on: $($os.Caption)"
}
# Function to check for admin permissions
function Check-Admin {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Log-Message "This script requires administrator permissions. Please run PowerShell as an administrator."
exit 1
}
}
# Function to update system
function Update-System {
Log-Message "Updating system packages..."
Run-Command "choco upgrade all -y"
}
# Function to install Chocolatey
function Install-Chocolatey {
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
Log-Message "Installing Chocolatey..."
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
} else {
Log-Message "Chocolatey is already installed"
}
}
# Function to install and setup PostgreSQL
function Install-Postgres {
Log-Message "Installing PostgreSQL $POSTGRES_VERSION..."
Run-Command "choco install postgresql$POSTGRES_VERSION --params '/Password:password' -y"
Log-Message "Starting PostgreSQL..."
Run-Command "net start postgresql-x64-$POSTGRES_VERSION"
Log-Message "Creating users and databases..."
$env:PGPASSWORD = "password"
# Create users and databases matching install.sh
$queries = @"
CREATE USER "mysql" WITH PASSWORD 'password' IF NOT EXISTS;
CREATE DATABASE "mush" WITH OWNER "mysql" IF NOT EXISTS;
GRANT ALL PRIVILEGES ON DATABASE "mush" TO "mysql";
CREATE USER "etwin.dev" WITH PASSWORD 'password' IF NOT EXISTS;
CREATE DATABASE "etwin.dev" WITH OWNER "etwin.dev" IF NOT EXISTS;
GRANT ALL PRIVILEGES ON DATABASE "etwin.dev" TO "etwin.dev";
\c etwin.dev
ALTER SCHEMA public OWNER TO "etwin.dev";
GRANT ALL ON SCHEMA public TO "etwin.dev";
"@
$queries -split "`n" | ForEach-Object {
if ($_.Trim()) {
Run-Command "psql -U postgres -c `"$_`""
}
}
}
# Function to install front-end dependencies
function Install-Frontend {
Log-Message "Installing Node.js $NODE_VERSION..."
Run-Command "choco install nodejs --version=$NODE_VERSION -y"
Log-Message "Installing Yarn..."
Run-Command "choco install yarn -y"
Log-Message "Setup front-end env variables..."
Run-Command "Copy-Item -Path App\.env.bare-metal -Destination App\.env -Force"
Log-Message "Installing front-end dependencies..."
Set-Location App
Run-Command "yarn install"
Set-Location ..
}
# Function to install Eternaltwin server
function Install-Eternaltwin {
Log-Message "Setup Eternaltwin env variables..."
Run-Command "Copy-Item -Path Eternaltwin\eternaltwin.bare-metal.toml -Destination Eternaltwin\eternaltwin.local.toml -Force"
Log-Message "Installing Eternaltwin server dependencies..."
Set-Location Eternaltwin
Run-Command "yarn set version latest"
Run-Command "yarn install"
Log-Message "Installing Eternaltwin server..."
Run-Command "yarn etwin db reset"
Run-Command "yarn etwin db sync"
Set-Location ..
}
# Function to install back-end dependencies
function Install-Backend {
Log-Message "Installing PHP $PHP_VERSION and extensions..."
Run-Command "choco install php --version=$PHP_VERSION -y"
# Install PHP extensions
$extensions = @(
"php-pgsql",
"php-curl",
"php-opcache",
"php-intl",
"php-xml",
"php-dom",
"php-zip",
"php-mbstring"
)
foreach ($ext in $extensions) {
Run-Command "choco install $ext -y"
}
Log-Message "Installing Composer..."
Run-Command "choco install composer --version=$COMPOSER_VERSION -y"
Log-Message "Creating JWT certificates..."
Set-Location Api
if (-not (Test-Path config\jwt\private.pem)) {
Run-Command "openssl genpkey -pass pass:mush -out config/jwt/private.pem -aes256 -algorithm rsa -pkeyopt rsa_keygen_bits:4096"
}
if (-not (Test-Path config\jwt\public.pem)) {
Run-Command "openssl pkey -passin pass:mush -in config/jwt/private.pem -out config/jwt/public.pem -pubout"
}
Run-Command "icacls config\jwt\private.pem /grant Everyone:R"
Log-Message "Setup back-end env variables..."
Run-Command "Copy-Item -Path .env.bare-metal -Destination .env.local -Force"
Run-Command "Copy-Item -Path .env.bare-metal.test -Destination .env.test.local -Force"
Log-Message "Installing back-end dependencies..."
Run-Command "composer install"
Run-Command "composer reset"
Set-Location ..
}
# Function to launch the project
function Launch-Project {
Log-Message "Project installed successfully! You can access it by running make start."
Log-Message "Use the following credentials to login:"
Log-Message "Username: chun"
Log-Message "Password: 1234567891"
}
# Main installation process
function Main {
try {
Check-Admin
Check-SystemCompatibility
Install-Chocolatey
Update-System
Install-Postgres
Install-Frontend
Install-Eternaltwin
Install-Backend
Launch-Project
}
catch {
Log-Message "Installation failed: $_"
exit 1
}
}
# Run the main installation process
Main