diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 144f012c..cdbe4b96 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,7 +33,7 @@ jobs: run: | 7z a -mx9 Netch.7z release 7z rn Netch.7z release Netch - echo "NETCH_SHA256=$(.\sha256.ps1 Netch.7z)" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV + echo "NETCH_SHA256=$((Get-FileHash Netch.7z -Algorithm SHA256).Hash.ToLower())" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV - name: Release uses: softprops/action-gh-release@v1 diff --git a/Netch/Controllers/Mode/TunController.cs b/Netch/Controllers/Mode/TunController.cs index 191bd31d..998def59 100644 --- a/Netch/Controllers/Mode/TunController.cs +++ b/Netch/Controllers/Mode/TunController.cs @@ -133,7 +133,7 @@ namespace Netch.Controllers.Mode public bool Create(Models.Server.Server s, Models.Mode.Mode m) { - Global.Logger.Info(String.Format("{0:x} tun2socks.bin", Utils.FileHelper.Checksum("Bin\\tun2socks.bin")); + Global.Logger.Info(String.Format("{0:x} tun2socks.bin", Utils.FileHelper.Checksum("Bin\\tun2socks.bin"))); if (!this.Outbound.Get()) { diff --git a/Other/aiodns/build.ps1 b/Other/aiodns/build.ps1 index b24aecd5..c3956ade 100644 --- a/Other/aiodns/build.ps1 +++ b/Other/aiodns/build.ps1 @@ -1,7 +1,6 @@ $exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) -$last=(Get-Location).Path -Set-Location $exec +Push-Location $exec $Env:CGO_ENABLED="0" $Env:GOROOT_FINAL="/usr" @@ -10,5 +9,5 @@ $Env:GOOS="windows" $Env:GOARCH="amd64" go build -a -trimpath -asmflags "-s -w" -ldflags "-s -w" -o "..\release\aiodns.exe" -Set-Location $last +Pop-Location exit $lastExitCode diff --git a/Other/aiodns/deps.ps1 b/Other/aiodns/deps.ps1 index 800eeefb..7c6e4058 100644 --- a/Other/aiodns/deps.ps1 +++ b/Other/aiodns/deps.ps1 @@ -1,11 +1,10 @@ $exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) -$last=(Get-Location).Path -Set-Location $exec +Push-Location $exec rm -Force go.* go mod init aiodns go mod tidy -Set-Location $last +Pop-Location exit $lastExitCode diff --git a/Other/build.ps1 b/Other/build.ps1 index c1a269c5..06e1c302 100644 --- a/Other/build.ps1 +++ b/Other/build.ps1 @@ -1,7 +1,6 @@ $exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) -$last=(Get-Location).Path -Set-Location $exec +Push-Location $exec .\clean.ps1 @@ -17,5 +16,14 @@ Get-ChildItem -Path . -Directory | ForEach-Object { } } -Set-Location $last +Write-Host + +Get-ChildItem -Path .\release -File | ForEach-Object { + $name=$_.Name + $hash=(Get-FileHash ".\release\$name" -Algorithm SHA256).Hash.ToLower() + + Write-Host "$hash $name" +} + +Pop-Location exit 0 diff --git a/Other/clean.ps1 b/Other/clean.ps1 index f5b0271d..9d56fc0e 100644 --- a/Other/clean.ps1 +++ b/Other/clean.ps1 @@ -1,11 +1,10 @@ $exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) -$last=(Get-Location).Path -Set-Location $exec +Push-Location $exec if (Test-Path release) { Remove-Item -Recurse -Force release } -Set-Location $last +Pop-Location exit 0 diff --git a/Other/deps.ps1 b/Other/deps.ps1 index da61ab8b..f2dbdeb6 100644 --- a/Other/deps.ps1 +++ b/Other/deps.ps1 @@ -1,7 +1,6 @@ $exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) -$last=(Get-Location).Path -Set-Location $exec +Push-Location $exec .\clean.ps1 @@ -14,5 +13,5 @@ Get-ChildItem -Path . -Directory | ForEach-Object { } } -Set-Location $last +Pop-Location exit 0 diff --git a/Other/tap2socks/build.ps1 b/Other/tap2socks/build.ps1 index 04077fa5..6490124f 100644 --- a/Other/tap2socks/build.ps1 +++ b/Other/tap2socks/build.ps1 @@ -1,7 +1,6 @@ $exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) -$last=(Get-Location).Path -Set-Location $exec +Push-Location $exec $Env:CGO_ENABLED="0" $Env:GOROOT_FINAL="/usr" @@ -10,5 +9,5 @@ $Env:GOOS="windows" $Env:GOARCH="amd64" go build -a -trimpath -asmflags "-s -w" -ldflags "-s -w" -o "..\release\tap2socks.exe" -Set-Location $last +Pop-Location exit $lastExitCode diff --git a/Other/tap2socks/deps.ps1 b/Other/tap2socks/deps.ps1 index 4063a6cb..1458b9bf 100644 --- a/Other/tap2socks/deps.ps1 +++ b/Other/tap2socks/deps.ps1 @@ -1,11 +1,10 @@ $exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) -$last=(Get-Location).Path -Set-Location $exec +Push-Location $exec rm -Force go.* go mod init tap2socks go mod tidy -Set-Location $last +Pop-Location exit $lastExitCode diff --git a/Other/tun2socks/build.ps1 b/Other/tun2socks/build.ps1 index 157172aa..03c74dcc 100644 --- a/Other/tun2socks/build.ps1 +++ b/Other/tun2socks/build.ps1 @@ -1,7 +1,6 @@ $exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) -$last=(Get-Location).Path -Set-Location $exec +Push-Location $exec $Env:CGO_ENABLED="0" $Env:GOROOT_FINAL="/usr" @@ -10,5 +9,5 @@ $Env:GOOS="windows" $Env:GOARCH="amd64" go build -a -trimpath -asmflags "-s -w" -ldflags "-s -w" -o "..\release\tun2socks.exe" -Set-Location $last +Pop-Location exit $lastExitCode diff --git a/Other/tun2socks/deps.ps1 b/Other/tun2socks/deps.ps1 index a533d0b6..030b4489 100644 --- a/Other/tun2socks/deps.ps1 +++ b/Other/tun2socks/deps.ps1 @@ -1,11 +1,10 @@ $exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) -$last=(Get-Location).Path -Set-Location $exec +Push-Location $exec rm -Force go.* go mod init tun2socks go mod tidy -Set-Location $last +Pop-Location exit $lastExitCode diff --git a/build.ps1 b/build.ps1 index 2dee95d6..16cf9d72 100644 --- a/build.ps1 +++ b/build.ps1 @@ -24,12 +24,25 @@ param ( Set-Location (Split-Path $MyInvocation.MyCommand.Path -Parent) -.\scripts\download.ps1 $OutputPath +if (Test-Path -Path $OutputPath) { + Remove-Item -Recurse -Force $OutputPath +} + +if (Test-Path -Path $OutputPath -IsValid) { + New-Item -ItemType Directory -Name $OutputPath | Out-Null +} + +.\deps.ps1 $OutputPath if ( -Not $? ) { exit $lastExitCode } -.\Other\build.ps1 +.\other\build.ps1 if ( -Not $? ) { exit $lastExitCode } +if (Test-Path .\other\release) { + Copy-Item -Recurse -Force .\other\release\* $OutputPath\bin +} + +Write-Host Write-Host "Building Netch" dotnet publish ` -c $Configuration ` @@ -41,5 +54,11 @@ dotnet publish ` -p:PublishReadyToRun=$PublishReadyToRun ` -o $OutputPath ` Netch\Netch.csproj +if ( -Not $? ) { exit $lastExitCode } -exit $lastExitCode +if ( "Release".Equals($Configuration) ) { + Remove-Item -Force $OutputPath\*.pdb + Remove-Item -Force $OutputPath\*.xml +} + +exit 0 \ No newline at end of file diff --git a/deps.ps1 b/deps.ps1 new file mode 100644 index 00000000..04eff82e --- /dev/null +++ b/deps.ps1 @@ -0,0 +1,35 @@ +param ( + [string] + $OutputPath = 'release' +) + +Push-Location $OutputPath + +New-Item -ItemType Directory -Name bin | Out-Null +New-Item -ItemType Directory -Name mode | Out-Null +New-Item -ItemType Directory -Name i18n | Out-Null + +# Get-ChildItem -Path ..\scripts\deps\base -File | ForEach-Object { +# $name=$_.Name + +# Write-Host "Executing $name" +# & "..\scripts\deps\base\$name" +# if (-Not $?) { +# Pop-Location +# exit $lastExitCode +# } +# } + +Get-ChildItem -Path ..\scripts\deps -File | ForEach-Object { + $name=$_.Name + + Write-Host "Executing $name" + & "..\scripts\deps\$name" -OutputPath bin + if (-Not $?) { + Pop-Location + exit $lastExitCode + } +} + +Pop-Location +exit 0 \ No newline at end of file diff --git a/scripts/deps/base/netch-data.ps1 b/scripts/deps/base/netch-data.ps1 new file mode 100644 index 00000000..64bbda39 --- /dev/null +++ b/scripts/deps/base/netch-data.ps1 @@ -0,0 +1,14 @@ +$name="data.zip" +$address="https://github.com/netchx/netch-data/archive/refs/heads/main.zip" + +..\scripts\download.ps1 $name $address +if (-Not $?) { exit $lastExitCode } + +..\scripts\extract.ps1 $name "bin" +if (-Not $?) { exit $lastExitCode } + +Copy-Item -Recurse -Force .\netch-data-main\* .\bin + +Remove-Item -Force $name +Remove-Item -Recurse -Force netch-data-main +exit 0 \ No newline at end of file diff --git a/scripts/deps/base/netch-i18n.ps1 b/scripts/deps/base/netch-i18n.ps1 new file mode 100644 index 00000000..cc404cfa --- /dev/null +++ b/scripts/deps/base/netch-i18n.ps1 @@ -0,0 +1,14 @@ +$name="i18n.zip" +$address="https://github.com/netchx/netch-i18n/archive/refs/heads/main.zip" + +..\scripts\download.ps1 $name $address +if (-Not $?) { exit $lastExitCode } + +..\scripts\extract.ps1 $name "i18n" +if (-Not $?) { exit $lastExitCode } + +Copy-Item -Recurse -Force .\netch-i18n-main\* .\i18n + +Remove-Item -Force $name +Remove-Item -Recurse -Force netch-i18n-main +exit 0 \ No newline at end of file diff --git a/scripts/deps/base/netch-mode.ps1 b/scripts/deps/base/netch-mode.ps1 new file mode 100644 index 00000000..20921f59 --- /dev/null +++ b/scripts/deps/base/netch-mode.ps1 @@ -0,0 +1,14 @@ +$name="mode.zip" +$address="https://github.com/netchx/netch-mode/archive/refs/heads/main.zip" + +..\scripts\download.ps1 $name $address +if (-Not $?) { exit $lastExitCode } + +..\scripts\extract.ps1 $name "mode" +if (-Not $?) { exit $lastExitCode } + +Copy-Item -Recurse -Force .\netch-mode-main\* .\mode + +Remove-Item -Force $name +Remove-Item -Recurse -Force netch-mode-main +exit 0 \ No newline at end of file diff --git a/scripts/download/cloak.ps1 b/scripts/deps/cloak.ps1 similarity index 70% rename from scripts/download/cloak.ps1 rename to scripts/deps/cloak.ps1 index 853e68fd..5a56f7f4 100644 --- a/scripts/download/cloak.ps1 +++ b/scripts/deps/cloak.ps1 @@ -2,7 +2,8 @@ param([string]$OutputPath) $name="ck-client.exe" $address="https://github.com/cbeuw/Cloak/releases/download/v2.5.4/ck-client-windows-amd64-v2.5.4.exe" -Invoke-WebRequest -Uri $address -OutFile $name +..\scripts\download.ps1 $name $address +if (-Not $?) { exit $lastExitCode } Move-Item -Force $name $OutputPath exit 0 \ No newline at end of file diff --git a/scripts/download/geoip.ps1 b/scripts/deps/geoip.ps1 similarity index 67% rename from scripts/download/geoip.ps1 rename to scripts/deps/geoip.ps1 index 9f612f84..53dcff87 100644 --- a/scripts/download/geoip.ps1 +++ b/scripts/deps/geoip.ps1 @@ -2,7 +2,8 @@ param([string]$OutputPath) $name="geoip.dat" $address="https://github.com/v2fly/geoip/releases/download/202107080024/geoip.dat" -Invoke-WebRequest -Uri $address -OutFile $name +..\scripts\download.ps1 $name $address +if (-Not $?) { exit $lastExitCode } Move-Item -Force $name $OutputPath exit 0 \ No newline at end of file diff --git a/scripts/download/geosite.ps1 b/scripts/deps/geosite.ps1 similarity index 69% rename from scripts/download/geosite.ps1 rename to scripts/deps/geosite.ps1 index 289e31bf..26f78732 100644 --- a/scripts/download/geosite.ps1 +++ b/scripts/deps/geosite.ps1 @@ -2,7 +2,8 @@ param([string]$OutputPath) $name="geosite.dat" $address="https://github.com/v2fly/domain-list-community/releases/download/20210709152606/dlc.dat" -Invoke-WebRequest -Uri $address -OutFile $name +..\scripts\download.ps1 $name $address +if (-Not $?) { exit $lastExitCode } Move-Item -Force $name $OutputPath exit 0 \ No newline at end of file diff --git a/scripts/download/v2ray-core.ps1 b/scripts/deps/v2ray-core.ps1 similarity index 65% rename from scripts/download/v2ray-core.ps1 rename to scripts/deps/v2ray-core.ps1 index 17fb8d6b..5d483f1b 100644 --- a/scripts/download/v2ray-core.ps1 +++ b/scripts/deps/v2ray-core.ps1 @@ -1,8 +1,12 @@ param([string]$OutputPath) +$name="v2ray-core.zip" $address="https://github.com/v2fly/v2ray-core/releases/download/v4.40.1/v2ray-windows-64.zip" -Invoke-WebRequest -Uri $address -OutFile v2ray-core.zip -Expand-Archive -Force -Path v2ray-core.zip -DestinationPath v2ray-core +..\scripts\download.ps1 $name $address +if (-Not $?) { exit $lastExitCode } + +..\scripts\extract.ps1 $name "v2ray-core" +if (-Not $?) { exit $lastExitCode } Move-Item -Force v2ray-core\v2ctl.exe $OutputPath Move-Item -Force v2ray-core\v2ray.exe $OutputPath diff --git a/scripts/deps/xray-core.ps1 b/scripts/deps/xray-core.ps1 new file mode 100644 index 00000000..36f0e2bc --- /dev/null +++ b/scripts/deps/xray-core.ps1 @@ -0,0 +1,15 @@ +param([string]$OutputPath) +$name="xray-core.zip" +$address="https://github.com/XTLS/Xray-core/releases/download/v1.4.2/Xray-windows-64.zip" + +..\scripts\download.ps1 $name $address +if (-Not $?) { exit $lastExitCode } + +..\scripts\extract.ps1 $name "xray-core" +if (-Not $?) { exit $lastExitCode } + +Move-Item -Force "xray-core\xray.exe" $OutputPath + +Remove-Item -Recurse -Force xray-core +Remove-Item -Recurse -Force xray-core.zip +exit 0 \ No newline at end of file diff --git a/scripts/download.ps1 b/scripts/download.ps1 index 86ff6d50..516423af 100644 --- a/scripts/download.ps1 +++ b/scripts/download.ps1 @@ -1,42 +1,18 @@ -param([string]$OutputPath) +param ( + [string] + $name, -$NetchDataURL="https://github.com/netchx/netch-data/archive/refs/heads/main.zip" -$NetchModeURL="https://github.com/netchx/netch-mode/archive/refs/heads/main.zip" -$NetchI18NURL="https://github.com/netchx/netch-i18n/archive/refs/heads/main.zip" + [string] + $address +) -$last=(Get-Location).Path -New-Item -ItemType Directory -Name $OutputPath | Out-Null -Set-Location $OutputPath +try +{ + Invoke-WebRequest -OutFile $name -Uri $address +} +catch +{ + exit 1 +} -Invoke-WebRequest -Uri $NetchDataURL -OutFile data.zip -Invoke-WebRequest -Uri $NetchModeURL -OutFile mode.zip -Invoke-WebRequest -Uri $NetchI18NURL -OutFile i18n.zip - -Expand-Archive -Force -Path data.zip -DestinationPath . -Expand-Archive -Force -Path mode.zip -DestinationPath . -Expand-Archive -Force -Path i18n.zip -DestinationPath . - -New-Item -ItemType Directory -Name Bin | Out-Null -New-Item -ItemType Directory -Name Mode | Out-Null -New-Item -ItemType Directory -Name I18N | Out-Null - -Copy-Item -Recurse -Force .\netch-data-main\* .\Bin -Copy-Item -Recurse -Force .\netch-mode-main\mode\* .\Mode -Copy-Item -Recurse -Force .\netch-i18n-main\i18n\* .\I18N - -Remove-Item -Recurse -Force netch-data-main -Remove-Item -Recurse -Force netch-mode-main -Remove-Item -Recurse -Force netch-i18n-main -Remove-Item -Force data.zip -Remove-Item -Force mode.zip -Remove-Item -Force i18n.zip - -..\scripts\download\cloak.ps1 -OutputPath Bin -..\scripts\download\geoip.ps1 -OutputPath Bin -..\scripts\download\geosite.ps1 -OutputPath Bin -..\scripts\download\v2ray-core.ps1 -OutputPath Bin -..\scripts\download\x2ray-core.ps1 -OutputPath Bin - -Get-Item * -Set-Location $last -exit 0 +exit 0 \ No newline at end of file diff --git a/scripts/download/x2ray-core.ps1 b/scripts/download/x2ray-core.ps1 deleted file mode 100644 index ef20113d..00000000 --- a/scripts/download/x2ray-core.ps1 +++ /dev/null @@ -1,11 +0,0 @@ -param([string]$OutputPath) -$address="https://github.com/XTLS/Xray-core/releases/download/v1.4.2/Xray-windows-64.zip" - -Invoke-WebRequest -Uri $address -OutFile xray-core.zip -Expand-Archive -Force -Path xray-core.zip -DestinationPath xray-core - -Move-Item -Force xray-core\xray.exe $OutputPath - -Remove-Item -Recurse -Force xray-core -Remove-Item -Recurse -Force xray-core.zip -exit 0 \ No newline at end of file diff --git a/scripts/extract.ps1 b/scripts/extract.ps1 new file mode 100644 index 00000000..d8a9c5d7 --- /dev/null +++ b/scripts/extract.ps1 @@ -0,0 +1,19 @@ +param ( + [string] + $name, + + [string] + $address +) + +try +{ + Expand-Archive -Force -Path $name -DestinationPath $address +} +catch +{ + Write-Host "Extract $name failed" + exit 1 +} + +exit 0 \ No newline at end of file