Merge pull request #201 from dysf888/master [no ci]

Co-authored-by: dysf888 <47450409+dysf888@users.noreply.github.com>
This commit is contained in:
naiba 2022-05-10 13:38:26 +08:00 committed by GitHub
commit a9ffccf894
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,14 @@ else {
$file = "nezha-agent_windows_386.zip" $file = "nezha-agent_windows_386.zip"
} }
$releases = "https://api.github.com/repos/$repo/releases" $releases = "https://api.github.com/repos/$repo/releases"
#重复运行自动更新
if (Test-Path "C:\nezha") {
Write-Host "Nezha monitoring already exists, delete and reinstall" -BackgroundColor DarkGreen -ForegroundColor White
C:/nezha/nssm.exe stop nezha
C:/nezha/nssm.exe remove nezha
Remove-Item "C:\nezha" -Recurse
}
#TLS/SSL
Write-Host "Determining latest nezha release" -BackgroundColor DarkGreen -ForegroundColor White Write-Host "Determining latest nezha release" -BackgroundColor DarkGreen -ForegroundColor White
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$tag = (Invoke-WebRequest -Uri $releases -UseBasicParsing | ConvertFrom-Json)[0].tag_name $tag = (Invoke-WebRequest -Uri $releases -UseBasicParsing | ConvertFrom-Json)[0].tag_name
@ -39,7 +47,7 @@ Expand-Archive "C:\nezha.zip" -DestinationPath "C:\temp" -Force
Expand-Archive "C:\nssm.zip" -DestinationPath "C:\temp" -Force Expand-Archive "C:\nssm.zip" -DestinationPath "C:\temp" -Force
if (!(Test-Path "C:\nezha")) { New-Item -Path "C:\nezha" -type directory } if (!(Test-Path "C:\nezha")) { New-Item -Path "C:\nezha" -type directory }
#整理文件 #整理文件
Move-Item -Path "C:\temp\nezha-agent.exe" -Destination "C:\nezha\nezha.exe" Move-Item -Path "C:\temp\nezha-agent.exe" -Destination "C:\nezha\nezha-agent.exe"
if ($file = "nezha-agent_windows_amd64.zip") { if ($file = "nezha-agent_windows_amd64.zip") {
Move-Item -Path "C:\temp\nssm-2.24\win64\nssm.exe" -Destination "C:\nezha\nssm.exe" Move-Item -Path "C:\temp\nssm-2.24\win64\nssm.exe" -Destination "C:\nezha\nssm.exe"
} }
@ -51,7 +59,7 @@ Remove-Item "C:\nezha.zip"
Remove-Item "C:\nssm.zip" Remove-Item "C:\nssm.zip"
Remove-Item "C:\temp" -Recurse Remove-Item "C:\temp" -Recurse
#安装部分 #安装部分
C:\nezha\nssm.exe install nezha C:\nezha\nezha.exe -s $server -p $key -d C:\nezha\nssm.exe install nezha C:\nezha\nezha-agent.exe -s $server -p $key -d
C:\nezha\nssm.exe start nezha C:\nezha\nssm.exe start nezha
#enjoy #enjoy
Write-Host "Enjoy It!" -BackgroundColor DarkGreen -ForegroundColor Red Write-Host "Enjoy It!" -BackgroundColor DarkGreen -ForegroundColor Red