11function Invoke-Doctor {
22
3- Write-Host " Running PHOST system check..." - ForegroundColor Magenta
4- Write-Host " --------------------------------" - ForegroundColor DarkGray
3+ Clear-Host
4+ Write-Host " Running PHOST system diagnostics..." - ForegroundColor Magenta
5+ Write-Host " -----------------------------------" - ForegroundColor DarkGray
6+
7+ $ROOT = Split-Path - Parent $MyInvocation.MyCommand.Definition
8+ $errors = 0
59
610 # =========================
711 # BINARIOS
812 # =========================
13+ Write-Host " "
914 Write-Host " Checking binaries..." - ForegroundColor Cyan
1015
11- $errors = 0
12-
13- if (-Not (Test-Path " bin/nginx/nginx.exe" )) {
14- Write-Host " ✖ Nginx missing" - ForegroundColor Red
15- $errors ++
16- } else {
17- Write-Host " ✔ Nginx OK" - ForegroundColor Green
18- }
19-
20- if (-Not (Test-Path " bin/apache/bin/httpd.exe" )) {
21- Write-Host " ✖ Apache missing" - ForegroundColor Red
22- $errors ++
23- } else {
24- Write-Host " ✔ Apache OK" - ForegroundColor Green
25- }
26-
27- if (-Not (Test-Path " bin/mariadb/bin/mysqld.exe" )) {
28- Write-Host " ✖ MariaDB missing" - ForegroundColor Red
29- $errors ++
30- } else {
31- Write-Host " ✔ MariaDB OK" - ForegroundColor Green
16+ $binaries = @ {
17+ " Nginx" = " bin\nginx\nginx.exe"
18+ " Apache" = " bin\apache\bin\httpd.exe"
19+ " MariaDB" = " bin\mariadb\bin\mysqld.exe"
20+ " PHP" = " bin\php\php.exe"
3221 }
3322
34- if (-Not (Test-Path " bin/php/php.exe" )) {
35- Write-Host " ✖ PHP missing" - ForegroundColor Red
36- $errors ++
37- } else {
38- Write-Host " ✔ PHP OK" - ForegroundColor Green
23+ foreach ($bin in $binaries.GetEnumerator ()) {
24+ $path = Join-Path $ROOT $bin.Value
25+ if (-not (Test-Path $path )) {
26+ Write-Host " ✖ $ ( $bin.Key ) missing" - ForegroundColor Red
27+ $errors ++
28+ } else {
29+ Write-Host " ✔ $ ( $bin.Key ) OK" - ForegroundColor Green
30+ }
3931 }
4032
4133 # =========================
@@ -44,10 +36,11 @@ function Invoke-Doctor {
4436 Write-Host " "
4537 Write-Host " Checking ports..." - ForegroundColor Cyan
4638
47- $ports = Get-NetTCPConnection - State Listen - ErrorAction SilentlyContinue | Select-Object - ExpandProperty LocalPort
39+ $listeningPorts = Get-NetTCPConnection - State Listen - ErrorAction SilentlyContinue |
40+ Select-Object - ExpandProperty LocalPort
4841
4942 foreach ($port in @ (80 , 8080 , 3306 )) {
50- if ($ports -contains $port ) {
43+ if ($listeningPorts -contains $port ) {
5144 Write-Host " ⚠ Port $port is in use" - ForegroundColor Yellow
5245 } else {
5346 Write-Host " ✔ Port $port available" - ForegroundColor Green
@@ -61,37 +54,52 @@ function Invoke-Doctor {
6154 Write-Host " Checking updates..." - ForegroundColor Cyan
6255
6356 try {
64- $runtime = Get-Content " control/runtime.json" | ConvertFrom-Json
65- $localVersion = $runtime.version
57+ $runtimePath = Join-Path $ROOT " control\runtime.json"
58+
59+ if (-not (Test-Path $runtimePath )) {
60+ throw " runtime.json not found"
61+ }
62+
63+ $runtime = Get-Content $runtimePath - Raw | ConvertFrom-Json
64+ $localVersion = $runtime.version.Trim ()
6665
6766 $repo = " IngSystemCix/phost"
6867 $api = " https://api.github.com/repos/$repo /releases/latest"
6968
7069 $response = Invoke-RestMethod - Uri $api - Headers @ {
71- " User-Agent" = " phost"
70+ " User-Agent" = " phost-cli"
71+ }
72+
73+ if (-not $response.tag_name ) {
74+ throw " No release information available"
7275 }
7376
74- $remoteVersion = $response.tag_name.TrimStart (" v" )
77+ $remoteVersion = $response.tag_name.Trim (). TrimStart(" v" )
7578
7679 if ($remoteVersion -ne $localVersion ) {
77- Write-Host " ⚠ Update available: v$remoteVersion (installed: v$localVersion )" - ForegroundColor Yellow
78- Write-Host " 👉 Run: phost update" - ForegroundColor DarkYellow
80+ Write-Host " ⚠ Update available" - ForegroundColor Yellow
81+ Write-Host " Installed : v$localVersion " - ForegroundColor DarkYellow
82+ Write-Host " Available : v$remoteVersion " - ForegroundColor DarkYellow
83+ Write-Host " 👉 Run: phost update" - ForegroundColor Cyan
7984 } else {
8085 Write-Host " ✔ PHOST is up to date (v$localVersion )" - ForegroundColor Green
8186 }
82- } catch {
87+ }
88+ catch {
8389 Write-Host " ⚠ Unable to check updates" - ForegroundColor DarkYellow
90+ Write-Host " $ ( $_.Exception.Message ) " - ForegroundColor DarkGray
8491 }
8592
8693 # =========================
8794 # RESULTADO FINAL
8895 # =========================
8996 Write-Host " "
9097 if ($errors -gt 0 ) {
91- Write-Host " Doctor completed with issues" - ForegroundColor Red
98+ Write-Host " Doctor completed with issues ( $errors found) " - ForegroundColor Red
9299 } else {
93100 Write-Host " Doctor completed successfully" - ForegroundColor Magenta
94101 }
95102
103+ Write-Host " "
96104 Pause
97- }
105+ }
0 commit comments