-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
143 lines (121 loc) · 6 KB
/
Copy pathsetup.ps1
File metadata and controls
143 lines (121 loc) · 6 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
# Quartermaster .NET - Windows Setup Interactive Installer
function Show-Header {
Clear-Host
Write-Host "#########################################" -ForegroundColor Cyan
Write-Host "# #" -ForegroundColor Cyan
Write-Host "# 🏴☠️ QUARTERMASTER .NET #" -ForegroundColor Cyan
Write-Host "# Enterprise Setup Wizard #" -ForegroundColor Cyan
Write-Host "# #" -ForegroundColor Cyan
Write-Host "#########################################" -ForegroundColor Cyan
Write-Host ""
}
function Show-Status {
param([string]$message, [string]$status = "INFO")
$color = "White"
if ($status -eq "OK") { $color = "Green" }
if ($status -eq "WARN") { $color = "Yellow" }
if ($status -eq "ERROR") { $color = "Red" }
Write-Host "[ " -NoNewline
Write-Host $status -ForegroundColor $color -NoNewline
Write-Host " ] $message"
}
Show-Header
Show-Status "Initializing environment..."
# 1. Check for .NET SDK
Show-Status "Checking for .NET SDK..."
$dotnetVersion = dotnet --version 2>$null
if ($null -eq $dotnetVersion) {
Show-Status "SDK not found. Attempting automated repair..." "WARN"
if (Get-Command winget -ErrorAction SilentlyContinue) {
$confirm = Read-Host "Would you like to install .NET 10 SDK via winget? (Y/N)"
if ($confirm -eq "Y") {
Show-Status "Installing Microsoft.DotNet.SDK.10..." "INFO"
winget install Microsoft.DotNet.SDK.10
Write-Host "`nPlease RESTART your terminal and run this script again." -ForegroundColor Yellow
exit
}
}
Show-Status "Critical failure: .NET 10 SDK is required." "ERROR"
exit 1
}
Show-Status "Detected .NET SDK: $dotnetVersion" "OK"
# 2. Build Selection
Write-Host "`nReady to build the solution."
Write-Host "1) Standard Build (Release)"
Write-Host "2) Production Publish (Optimized for Services)"
$buildChoice = Read-Host "Select build type [1-2]"
Show-Header
if ($buildChoice -eq "2") {
Show-Status "Publishing Quartermaster for production..." "INFO"
dotnet publish Quartermaster.Bot\Quartermaster.Bot.csproj --configuration Release --output ./publish
dotnet publish Quartermaster.Web\Quartermaster.Web.csproj --configuration Release --output ./publish
} else {
Show-Status "Restoring and building solution..." "INFO"
dotnet build --configuration Release
}
if ($LASTEXITCODE -ne 0) {
Show-Status "Build failed. Resolve errors above." "ERROR"
exit 1
}
Show-Status "Build successful!" "OK"
# 3. Configuration Phase
Show-Header
Write-Host "--- Configuration Phase ---" -ForegroundColor Cyan
Write-Host "You will need your Discord Application credentials."
Write-Host "Get them here: https://discord.com/developers/applications" -ForegroundColor Gray
Write-Host ""
$configPath = Resolve-Path "./appsettings.json"
$config = Get-Content $configPath | ConvertFrom-Json
$botToken = Read-Host "Enter your Discord Bot Token"
$clientId = Read-Host "Enter your Client ID (Application ID)"
$clientSecret = Read-Host "Enter your Client Secret"
$dashboardUrl = Read-Host "Enter your Dashboard URL (Default: http://localhost:3000)"
$port = Read-Host "Enter your Dashboard Port (Default: 3000)"
$dbPath = Read-Host "Enter your Database Path (Default: $($PWD.Path)\bot.db)"
if ($botToken) { $config.Bot.Token = $botToken }
if ($clientId) { $config.Discord.ClientId = $clientId }
if ($clientSecret) { $config.Discord.ClientSecret = $clientSecret }
if ($dashboardUrl) { $config.Discord.DashboardUrl = $dashboardUrl } else { $config.Discord.DashboardUrl = "http://localhost:3000" }
if ($port) { $config.Discord.Port = [int]$port } else { $config.Discord.Port = 3000 }
if ($dbPath) { $config.Bot.DatabasePath = $dbPath } else { $config.Bot.DatabasePath = "$($PWD.Path)\bot.db" }
# Ensure CallbackUrl is set based on DashboardUrl
$config.Discord.CallbackUrl = "$($config.Discord.DashboardUrl.TrimEnd('/'))/callback"
# Save updated config
$config | ConvertTo-Json -Depth 10 | Set-Content $configPath
Show-Status "Configuration saved to appsettings.json" "OK"
# 4. Deployment Mode
Write-Host "`nChoose your deployment mode:"
Write-Host "A) Manual Startup (Run via start.ps1)"
Write-Host "B) Background Service (Install as Windows Service)"
$mode = Read-Host "Selection [A/B]"
if ($mode -eq "B") {
Show-Header
Show-Status "Installing Windows Services..." "INFO"
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Show-Status "Permission Denied: Run as Administrator to install services." "ERROR"
} else {
$botExe = Resolve-Path "./publish/Quartermaster.Bot.exe"
$webExe = Resolve-Path "./publish/Quartermaster.Web.exe"
# Cleanup existing
sc.exe stop QuartermasterBot 2>$null | Out-Null
sc.exe delete QuartermasterBot 2>$null | Out-Null
sc.exe stop QuartermasterWeb 2>$null | Out-Null
sc.exe delete QuartermasterWeb 2>$null | Out-Null
# Install
New-Service -Name "QuartermasterBot" -BinaryPathName "$botExe --contentRoot $($PWD.Path)" -DisplayName "Quartermaster Discord Bot" -StartupType Automatic
New-Service -Name "QuartermasterWeb" -BinaryPathName "$webExe --contentRoot $($PWD.Path)" -DisplayName "Quartermaster Web Dashboard" -StartupType Automatic
Show-Status "Services registered successfully." "OK"
}
}
Show-Header
Show-Status "Setup Complete!" "OK"
Write-Host "-----------------------------------------"
Write-Host "Next Steps:" -ForegroundColor Cyan
Write-Host "1. Configure tokens in 'appsettings.json'"
Write-Host "2. Current database linked: " -NoNewline
Write-Host "bot.db" -ForegroundColor Green
Write-Host "-----------------------------------------"
Write-Host "Enjoy your liberated community! 🏴☠️" -ForegroundColor Cyan
Write-Host "Press any key to exit."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")