limit ps version

replace ghproxy to dn-dao-github-mirror.daocloud.io
revised some tips
This commit is contained in:
dysf888 2022-06-23 14:03:03 +08:00 committed by GitHub
parent f15bd9c6dd
commit 608d0db9fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,13 @@
#Get server and key #Get server and key
param($server, $key, $tls) param($server, $key, $tls)
# Download latest release from github # Download latest release from github
$repo = "naiba/nezha" if($PSVersionTable.PSVersion.Major -lt 5){
Write-Host "Require PS >= 5,your PSVersion:"$PSVersionTable.PSVersion.Major -BackgroundColor DarkGreen -ForegroundColor White
Write-Host "Refer to the community article and install manually! https://nyko.me/2020/12/13/nezha-windows-client.html" -BackgroundColor DarkRed -ForegroundColor Green
exit
}
$agentrepo = "naiba/nezha"
$nssmrepo = "nezhahq/nssm-backup"
# x86 or x64 # x86 or x64
if ([System.Environment]::Is64BitOperatingSystem) { if ([System.Environment]::Is64BitOperatingSystem) {
$file = "nezha-agent_windows_amd64.zip" $file = "nezha-agent_windows_amd64.zip"
@ -9,7 +15,8 @@ if ([System.Environment]::Is64BitOperatingSystem) {
else { else {
$file = "nezha-agent_windows_386.zip" $file = "nezha-agent_windows_386.zip"
} }
$releases = "https://api.github.com/repos/$repo/releases" $agentreleases = "https://api.github.com/repos/$agentrepo/releases"
$nssmreleases = "https://api.github.com/repos/$nssmrepo/releases"
#重复运行自动更新 #重复运行自动更新
if (Test-Path "C:\nezha") { if (Test-Path "C:\nezha") {
Write-Host "Nezha monitoring already exists, delete and reinstall" -BackgroundColor DarkGreen -ForegroundColor White Write-Host "Nezha monitoring already exists, delete and reinstall" -BackgroundColor DarkGreen -ForegroundColor White
@ -20,28 +27,26 @@ if (Test-Path "C:\nezha") {
#TLS/SSL #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 $agenttag = (Invoke-WebRequest -Uri $agentreleases -UseBasicParsing | ConvertFrom-Json)[0].tag_name
$nssmtag = (Invoke-WebRequest -Uri $nssmreleases -UseBasicParsing | ConvertFrom-Json)[0].tag_name
#Region判断 #Region判断
$ipapi= Invoke-RestMethod -Uri "https://api.myip.com/" -UserAgent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1" $ipapi= Invoke-RestMethod -Uri "https://api.myip.com/" -UserAgent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1"
$region=$ipapi.cc $region=$ipapi.cc
echo $ipapi echo $ipapi
if($region -ne "CN"){ if($region -ne "CN"){
$download = "https://github.com/$repo/releases/download/$tag/$file" $download = "https://github.com/$agentrepo/releases/download/$agenttag/$file"
Write-Host "Overseas machine("$region") direct connection!" -BackgroundColor DarkRed -ForegroundColor Green $nssmdownload="https://github.com/$nssmrepo/releases/download/$nssmtag/nssm.zip"
echo $download Write-Host "Location:$region,connect directly!" -BackgroundColor DarkRed -ForegroundColor Green
}elseif($region -eq $null){
cls
$download = "https://ghproxy.com/github.com/$repo/releases/download/$tag/$file"
Write-Host "Error,Most of the time, it is caused by the domestic network environment,use ghproxy.com" -BackgroundColor DarkRed -ForegroundColor Green
echo $download
}else{ }else{
$download = "https://ghproxy.com/github.com/$repo/releases/download/$tag/$file" $download = "https://dn-dao-github-mirror.daocloud.io/$agentrepo/releases/download/$agenttag/$file"
Write-Host "China's servers will be downloaded using the image address" -BackgroundColor DarkRed -ForegroundColor Green $nssmdownload="https://dn-dao-github-mirror.daocloud.io/$nssmrepo/releases/download/$nssmtag/nssm.zip"
echo $download Write-Host "Location:CN,use mirror address" -BackgroundColor DarkRed -ForegroundColor Green
} }
echo $download
echo $nssmdownload
Invoke-WebRequest $download -OutFile "C:\nezha.zip" Invoke-WebRequest $download -OutFile "C:\nezha.zip"
#使用nssm安装服务 #使用nssm安装服务
Invoke-WebRequest "http://nssm.cc/release/nssm-2.24.zip" -OutFile "C:\nssm.zip" Invoke-WebRequest $nssmdownload -OutFile "C:\nssm.zip"
#解压 #解压
Expand-Archive "C:\nezha.zip" -DestinationPath "C:\temp" -Force 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