ITADN

Assistant.ps1

#346Pull Requestbadman576 创建于 2025-03-28
B
badman576commented
<# .SYNOPSIS Ultimate Assistant Secure Deployment Script .DESCRIPTION Installs with military-grade security and automatic error recovery #> # ===== CONFIGURATION ===== $RepoUrl = "https://github.com/badman576/UltimateAssistant" $BackupRepo = "https://gitlab.com/badman576/UltimateAssistant-Mirror" $ConfigDir = "$env:APPDATA\UltimateAssistant" $ConfigPath = "$ConfigDir\github_config.json" # ===== SECURE INSTALLER ===== function Install-UltimateAssistant { [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [SecureString]$GitHubToken, # Now accepts SecureString directly [string[]]$LinkedRepos = @("badman576/peter", "badman576/a-bot"), [switch]$EnableCopilot, [switch]$EnableActions, [switch]$EnablePages ) # 1. VALIDATE ENVIRONMENT try { if (-not (Test-Path $ConfigDir)) { New-Item -ItemType Directory -Path $ConfigDir -Force | Out-Null } # 2. SECURE TOKEN HANDLING $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($GitHubToken) $PlainToken = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) $headers = @{ "Authorization" = "token $PlainToken" "Accept" = "application/vnd.github.v3+json" } # 3. VERIFY GITHUB ACCESS try { $repoCheck = Invoke-RestMethod -Uri "https://api.github.com/user/repos" -Headers $headers if (-not $repoCheck) { throw "GitHub token validation failed" } } catch { Write-Error "GitHub authentication failed: $_" return $false } # 4. DOWNLOAD CORE SYSTEM $installSuccess = $false $sources = @($RepoUrl, $BackupRepo) foreach ($source in $sources) { try { Write-Host "Attempting download from $source" $tempFile = "$env:TEMP\UltimateAssistant_Deploy.ps1" Invoke-WebRequest "$source/releases/latest/download/Deploy.ps1" -OutFile $tempFile # Validate script signature $sig = Get-AuthenticodeSignature -FilePath $tempFile if ($sig.Status -ne "Valid") { throw "Invalid script signature" } & $tempFile -GitHubToken $PlainToken $installSuccess = $true break } catch { Write-Warning "Download failed from $source : $_" } } if (-not $installSuccess) { throw "All download sources failed" } # 5. SECURE CONFIGURATION $config = @{ GitHub = @{ Token = $PlainToken | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString TopRepositories = $LinkedRepos Features = @{ Copilot = $EnableCopilot Actions = $EnableActions Pages = $EnablePages } } } $config | ConvertTo-Json -Depth 3 | Out-File $ConfigPath attrib +h +s $ConfigPath # 6. POST-INSTALL Write-Host "Installation complete!" -ForegroundColor Green Start-Process "https://github.com/badman576/UltimateAssistant/wiki/First-Time-Setup" return $true } catch { Write-Error "INSTALLATION FAILED: $_" Write-Host "Attempting repair..." -ForegroundColor Yellow Repair-Assistant -ResetGitHub -ClearCache return $false } finally { # Clear sensitive data from memory [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR) Remove-Variable PlainToken -ErrorAction SilentlyContinue } } # ===== IMPROVED TROUBLESHOOTING ===== function Repair-Assistant { [CmdletBinding()] param ( [switch]$ResetGitHub, [switch]$ClearCache ) try { if ($ResetGitHub -and (Test-Path $ConfigPath)) { $config = Get-Content $ConfigPath | ConvertFrom-Json $config.GitHub.Token = $null $config | ConvertTo-Json | Out-File $ConfigPath Write-Host "GitHub credentials reset" -ForegroundColor Green } if ($ClearCache) { $cachePath = "$env:LOCALAPPDATA\UltimateAssistant\cache" if (Test-Path $cachePath) { Remove-Item "$cachePath\*" -Recurse -Force Write-Host "Cache cleared" -ForegroundColor Green } } if (Test-Path "$env:ProgramFiles\UltimateAssistant\UltimateAssistant.exe") { & "$env:ProgramFiles\UltimateAssistant\UltimateAssistant.exe" --repair } } catch { Write-Error "REPAIR FAILED: $_" } } # ===== SAFE USAGE EXAMPLES ===== # RECOMMENDED INSTALL METHOD: $secureToken = Read-Host "Enter GitHub PAT" -AsSecureString Install-UltimateAssistant -GitHubToken $secureToken -EnableCopilot -EnableActions # ADVANCED INSTALL: # $secureToken = ConvertTo-SecureString "ghp_yourTokenHere" -AsPlainText -Force # Install-UltimateAssistant -GitHubToken $secureToken -LinkedRepos @("badman576/peter", "badman576/a-bot") # REPAIR COMMAND: # Repair-Assistant -ResetGitHub -ClearCache
合并状态:未合并 关闭于 2025-03-31 0 条评论