initializare
This commit is contained in:
314
deployment/windows/scripts/menu.ps1
Normal file
314
deployment/windows/scripts/menu.ps1
Normal file
@@ -0,0 +1,314 @@
|
||||
#Requires -RunAsAdministrator
|
||||
<#
|
||||
.SYNOPSIS
|
||||
BTGO Telegram Bot - Main Menu Launcher
|
||||
.DESCRIPTION
|
||||
Meniu interactiv pentru toate scripturile de management
|
||||
.NOTES
|
||||
Rulare: Right-click → "Run with PowerShell" (ca Administrator)
|
||||
#>
|
||||
|
||||
$ErrorActionPreference = "Continue"
|
||||
$ScriptDir = Split-Path -Parent $PSCommandPath
|
||||
$ServiceName = "BTGOTelegramBot"
|
||||
$ProjectDir = Resolve-Path (Join-Path $ScriptDir "..\..\..") | Select-Object -ExpandProperty Path
|
||||
$LogDir = Join-Path $ProjectDir "logs"
|
||||
|
||||
function Show-MainMenu {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host " BTGO TELEGRAM BOT - MANAGEMENT MENU" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Verifică status serviciu
|
||||
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||
if ($service) {
|
||||
if ($service.Status -eq "Running") {
|
||||
Write-Host "Status: " -NoNewline
|
||||
Write-Host "[RUNNING]" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Status: " -NoNewline
|
||||
Write-Host "[STOPPED]" -ForegroundColor Yellow
|
||||
}
|
||||
} else {
|
||||
Write-Host "Status: " -NoNewline
|
||||
Write-Host "[NOT INSTALLED]" -ForegroundColor Red
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
Write-Host " [1] Deploy Complet (First Time Setup)" -ForegroundColor Cyan
|
||||
Write-Host " [2] Install Service Only" -ForegroundColor Cyan
|
||||
Write-Host " [3] Uninstall Service" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host " [4] Start Service" -ForegroundColor Green
|
||||
Write-Host " [5] Stop Service" -ForegroundColor Yellow
|
||||
Write-Host " [6] Restart Service" -ForegroundColor Magenta
|
||||
Write-Host " [7] Service Status" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host " [8] View Logs (Interactive)" -ForegroundColor White
|
||||
Write-Host " [9] Quick Log Tail (Stdout)" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host " Development & Manual Testing:" -ForegroundColor DarkCyan
|
||||
Write-Host " [S] Setup Development Environment" -ForegroundColor Cyan
|
||||
Write-Host " [R] Run Scraper (Manual)" -ForegroundColor Cyan
|
||||
Write-Host " [T] Run Telegram Bot (Manual)" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host " [A] Open Deployment README" -ForegroundColor Gray
|
||||
Write-Host " [B] Open Quick Start Guide" -ForegroundColor Gray
|
||||
Write-Host " [C] Open Project in Explorer" -ForegroundColor Gray
|
||||
Write-Host " [D] Open Logs in Explorer" -ForegroundColor Gray
|
||||
Write-Host " [U] Update Browsers (Playwright)" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host " [0] Exit" -ForegroundColor DarkGray
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
function Invoke-Deploy {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "RULARE DEPLOY COMPLET" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
& "$ScriptDir\deploy.ps1"
|
||||
Read-Host "`nApasa Enter pentru a reveni la meniu"
|
||||
}
|
||||
|
||||
function Invoke-Install {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "INSTALARE SERVICIU" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
& "$ScriptDir\install_service.ps1"
|
||||
Read-Host "`nApasa Enter pentru a reveni la meniu"
|
||||
}
|
||||
|
||||
function Invoke-Uninstall {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "DEZINSTALARE SERVICIU" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
& "$ScriptDir\uninstall_service.ps1"
|
||||
Read-Host "`nApasa Enter pentru a reveni la meniu"
|
||||
}
|
||||
|
||||
function Invoke-Start {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "START SERVICIU" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||
if (-not $service) {
|
||||
Write-Host "[EROARE] Serviciul $ServiceName nu este instalat!" -ForegroundColor Red
|
||||
Start-Sleep -Seconds 2
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "[INFO] Pornire serviciu..." -ForegroundColor Cyan
|
||||
try {
|
||||
Start-Service -Name $ServiceName
|
||||
Write-Host ""
|
||||
Write-Host "[SUCCES] Serviciu pornit!" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host ""
|
||||
Write-Host "[EROARE] Pornirea a esuat: $_" -ForegroundColor Red
|
||||
}
|
||||
Start-Sleep -Seconds 3
|
||||
}
|
||||
|
||||
function Invoke-Stop {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "STOP SERVICIU" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||
if (-not $service) {
|
||||
Write-Host "[EROARE] Serviciul $ServiceName nu este instalat!" -ForegroundColor Red
|
||||
Start-Sleep -Seconds 2
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "[INFO] Oprire serviciu..." -ForegroundColor Cyan
|
||||
try {
|
||||
Stop-Service -Name $ServiceName -Force
|
||||
Write-Host ""
|
||||
Write-Host "[SUCCES] Serviciu oprit!" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host ""
|
||||
Write-Host "[INFO] Serviciul era deja oprit" -ForegroundColor Yellow
|
||||
}
|
||||
Start-Sleep -Seconds 3
|
||||
}
|
||||
|
||||
function Invoke-Restart {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "RESTART SERVICIU" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
& "$ScriptDir\restart_service.ps1"
|
||||
Read-Host "`nApasa Enter pentru a reveni la meniu"
|
||||
}
|
||||
|
||||
function Invoke-Status {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "STATUS SERVICIU" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
& "$ScriptDir\status.ps1"
|
||||
Read-Host "`nApasa Enter pentru a reveni la meniu"
|
||||
}
|
||||
|
||||
function Invoke-ViewLogs {
|
||||
Clear-Host
|
||||
& "$ScriptDir\view_logs.ps1"
|
||||
}
|
||||
|
||||
function Invoke-TailLogs {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "LOG TAIL - STDOUT (LIVE)" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "Apasa Ctrl+C pentru a opri" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
|
||||
$stdoutLog = Join-Path $LogDir "telegram_bot_stdout.log"
|
||||
if (Test-Path $stdoutLog) {
|
||||
Get-Content $stdoutLog -Wait -Tail 30
|
||||
} else {
|
||||
Write-Host "[INFO] Log-ul nu exista inca" -ForegroundColor Yellow
|
||||
Start-Sleep -Seconds 2
|
||||
}
|
||||
}
|
||||
|
||||
function Open-ReadmeFile {
|
||||
$readme = Join-Path $ProjectDir "deployment\windows\README.md"
|
||||
if (Test-Path $readme) {
|
||||
Start-Process $readme
|
||||
}
|
||||
}
|
||||
|
||||
function Open-QuickStartFile {
|
||||
$quickstart = Join-Path $ProjectDir "deployment\windows\QUICK_START.md"
|
||||
if (Test-Path $quickstart) {
|
||||
Start-Process $quickstart
|
||||
}
|
||||
}
|
||||
|
||||
function Open-ProjectExplorer {
|
||||
Start-Process explorer $ProjectDir
|
||||
}
|
||||
|
||||
function Open-LogsExplorer {
|
||||
if (Test-Path $LogDir) {
|
||||
Start-Process explorer $LogDir
|
||||
} else {
|
||||
Write-Host "[INFO] Directorul logs nu exista inca" -ForegroundColor Yellow
|
||||
Start-Sleep -Seconds 2
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-SetupDev {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "SETUP DEVELOPMENT ENVIRONMENT" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
& "$ScriptDir\setup_dev.ps1"
|
||||
}
|
||||
|
||||
function Invoke-RunScraper {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "RUN SCRAPER (MANUAL MODE)" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
& "$ScriptDir\run_scraper.ps1"
|
||||
}
|
||||
|
||||
function Invoke-RunTelegramBotManual {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "RUN TELEGRAM BOT (MANUAL MODE)" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
& "$ScriptDir\run_telegram_bot_manual.ps1"
|
||||
}
|
||||
|
||||
function Invoke-UpdateBrowsers {
|
||||
Clear-Host
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host "UPDATE PLAYWRIGHT BROWSERS" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
& "$ScriptDir\update_browsers.ps1"
|
||||
Read-Host "`nApasa Enter pentru a reveni la meniu"
|
||||
}
|
||||
|
||||
# Main loop
|
||||
do {
|
||||
Show-MainMenu
|
||||
$choice = Read-Host "Selecteaza optiune"
|
||||
|
||||
switch ($choice) {
|
||||
"1" { Invoke-Deploy }
|
||||
"2" { Invoke-Install }
|
||||
"3" { Invoke-Uninstall }
|
||||
"4" { Invoke-Start }
|
||||
"5" { Invoke-Stop }
|
||||
"6" { Invoke-Restart }
|
||||
"7" { Invoke-Status }
|
||||
"8" { Invoke-ViewLogs }
|
||||
"9" { Invoke-TailLogs }
|
||||
"A" { Open-ReadmeFile }
|
||||
"a" { Open-ReadmeFile }
|
||||
"B" { Open-QuickStartFile }
|
||||
"b" { Open-QuickStartFile }
|
||||
"C" { Open-ProjectExplorer }
|
||||
"c" { Open-ProjectExplorer }
|
||||
"D" { Open-LogsExplorer }
|
||||
"d" { Open-LogsExplorer }
|
||||
"S" { Invoke-SetupDev }
|
||||
"s" { Invoke-SetupDev }
|
||||
"R" { Invoke-RunScraper }
|
||||
"r" { Invoke-RunScraper }
|
||||
"T" { Invoke-RunTelegramBotManual }
|
||||
"t" { Invoke-RunTelegramBotManual }
|
||||
"U" { Invoke-UpdateBrowsers }
|
||||
"u" { Invoke-UpdateBrowsers }
|
||||
"0" {
|
||||
Write-Host ""
|
||||
Write-Host "Goodbye!" -ForegroundColor Green
|
||||
exit 0
|
||||
}
|
||||
default {
|
||||
Write-Host "[EROARE] Optiune invalida!" -ForegroundColor Red
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
}
|
||||
} while ($true)
|
||||
Reference in New Issue
Block a user