40 lines
1.2 KiB
PowerShell
40 lines
1.2 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$Root = Split-Path -Parent $ScriptDir
|
|
$SingBox = Join-Path $Root 'works/sing-box'
|
|
|
|
# defaults
|
|
$RepoUrl = 'git@git.inker.bot:arknights/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
|
|
}
|
|
}
|
|
|
|
$version = git -C $SingBox describe --tags --always 2>$null
|
|
if (-not $version) { $version = git -C $SingBox rev-parse --short HEAD }
|
|
Write-Host "Done. Version: $version"
|