45 lines
1.3 KiB
PowerShell
45 lines
1.3 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$Root = Split-Path -Parent $ScriptDir
|
|
$SingBox = Join-Path $Root 'works/sing-box'
|
|
$RevFile = Join-Path $Root 'works/rev'
|
|
|
|
# defaults
|
|
$RepoUrl = 'https://git.sfclub.cc/icybear/sing-box.git'
|
|
$UpstreamBranch = 'main'
|
|
|
|
$ConfigFile = Join-Path $Root 'works/config'
|
|
if (Test-Path $ConfigFile) {
|
|
Get-Content $ConfigFile | ForEach-Object {
|
|
if ($_ -match '^([^#=]+)=(.*)$') {
|
|
$key = $Matches[1].Trim()
|
|
$val = $Matches[2].Trim()
|
|
if ($key -eq 'REPO_URL') { $RepoUrl = $val }
|
|
elseif ($key -eq 'UPSTREAM_BRANCH') { $UpstreamBranch = $val }
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Test-Path (Join-Path $SingBox '.git')) {
|
|
Write-Host 'Updating sing-box...'
|
|
git -C $SingBox fetch --all
|
|
if ($UpstreamBranch) { git -C $SingBox checkout $UpstreamBranch }
|
|
git -C $SingBox pull
|
|
} else {
|
|
Write-Host 'Cloning sing-box...'
|
|
if ($UpstreamBranch) {
|
|
git clone -b $UpstreamBranch $RepoUrl $SingBox
|
|
} else {
|
|
git clone $RepoUrl $SingBox
|
|
}
|
|
}
|
|
|
|
$Rev = git -C $SingBox rev-parse HEAD
|
|
Set-Content -Path $RevFile -Value $Rev -NoNewline
|
|
|
|
$version = git -C $SingBox describe --tags --always 2>$null
|
|
if (-not $version) { $version = $Rev.Substring(0, 7) }
|
|
Write-Host "Done. Version: $version"
|
|
Write-Host "Stored rev: $Rev"
|