MATLAB MCP Server+ MATLAB Agentic Toolkit+Simulink Agentic Toolkit自动更新批处理文件.ps1

bash 复制代码
# MATLAB Toolkits Auto Update Checker (Unified)
# Can be run standalone (dir = script location) or called with -ScriptDir "D:\path"

param($ScriptDir)

$dir = if ($ScriptDir) { $ScriptDir.TrimEnd('\') } else { $PSScriptRoot }

$repos = @(
    [PSCustomObject]@{
        Name    = 'MATLAB MCP Server'
        Api     = 'https://api.github.com/repos/matlab/matlab-mcp-server/releases/latest'
        Page    = 'https://github.com/matlab/matlab-mcp-server/releases/latest'
        TagFile = '.matlab-mcp-server.version'
        Assets  = @(
            [PSCustomObject]@{ Remote = 'matlab-mcp-server-windows-x64.exe';        Local = 'matlab-mcp-server-windows-x64.exe' }
            [PSCustomObject]@{ Remote = 'MATLABMCPServerToolbox.mltbx';              Local = 'MATLABMCPServerToolbox.mltbx' }
        )
    },
    [PSCustomObject]@{
        Name    = 'MATLAB Agentic Toolkit'
        Api     = 'https://api.github.com/repos/matlab/matlab-agentic-toolkit/releases/latest'
        Page    = 'https://github.com/matlab/matlab-agentic-toolkit/releases/latest'
        TagFile = '.agentic-toolkit-tag'
        Assets  = @(
            [PSCustomObject]@{ Remote = 'agenticToolkitInstaller.mltbx';  Local = 'agenticToolkitInstaller.mltbx' }
        )
    },
    [PSCustomObject]@{
        Name    = 'Simulink Agentic Toolkit'
        Api     = 'https://api.github.com/repos/matlab/simulink-agentic-toolkit/releases/latest'
        Page    = 'https://github.com/matlab/simulink-agentic-toolkit/releases/latest'
        TagFile = '.simulink-toolkit-tag'
        Assets  = @(
            [PSCustomObject]@{ Remote = 'agenticToolkitInstaller.mltbx';  Local = 'simulink-agenticToolkitInstaller.mltbx' }
        )
    }
)

$updateCount = 0; $skipCount = 0; $failCount = 0

Write-Host ''
Write-Host '============================================'
Write-Host '  MATLAB Toolkits Auto Update Checker'
Write-Host '  ' (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
Write-Host ('  Dir : ' + $dir)
Write-Host '============================================'
Write-Host ''

foreach ($repo in $repos) {
    Write-Host ('>>> ' + $repo.Name) -ForegroundColor Cyan

    try {
        $rel    = Invoke-RestMethod -Uri $repo.Api -UseBasicParsing
        $newVer = $rel.tag_name
        Write-Host ('    Latest   : ' + $newVer)

        $tagPath = Join-Path $dir $repo.TagFile
        $curVer  = ''
        if (Test-Path $tagPath) { $curVer = (Get-Content $tagPath -Raw).Trim() }

        $anyLocal = $false
        foreach ($a in $repo.Assets) {
            if (Test-Path (Join-Path $dir $a.Local)) { $anyLocal = $true; break }
        }

        if (-not $anyLocal) {
            Write-Host '    Local    : no files, downloading directly...' -ForegroundColor Yellow
            if ($rel.assets.Count -eq 0) {
                Write-Host '    Warning  : No assets in this release.' -ForegroundColor DarkYellow
                Write-Host ('    Manual   : ' + $repo.Page)
                $newVer | Out-File -FilePath $tagPath -Encoding utf8 -NoNewline
                $skipCount++; Write-Host ''; continue
            }
            foreach ($a in $repo.Assets) {
                $asset = $rel.assets | Where-Object { $_.name -eq $a.Remote }
                $local = Join-Path $dir $a.Local
                if (-not $asset) {
                    $names = ($rel.assets | ForEach-Object { $_.name }) -join ', '
                    Write-Host ('    Miss     : ' + $a.Remote + ' (available: ' + $names + ')') -ForegroundColor DarkYellow
                    continue
                }
                $sz = if ($asset.size -gt 1MB) { [math]::Round($asset.size/1MB,1).ToString()+' MB' } else { [math]::Round($asset.size/1KB,1).ToString()+' KB' }
                Write-Host ('    Asset    : ' + $a.Remote + ' -> ' + $a.Local + ' (' + $sz + ')')
                Write-Host '      Downloading...'
                Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $local -UseBasicParsing
                Write-Host ('      Done    : ' + $local) -ForegroundColor Green
            }
            $newVer | Out-File -FilePath $tagPath -Encoding utf8 -NoNewline
            $updateCount++; Write-Host ''; continue
        }

        if ($curVer) { Write-Host ('    Local    : ' + $curVer) } else { Write-Host '    Local    : (no record)' }

        if ($curVer -eq $newVer) {
            Write-Host '    Status   : Up to date.' -ForegroundColor Green
            $skipCount++; Write-Host ''; continue
        }

        if ($curVer) {
            Write-Host ('    Version  : ' + $curVer + ' -> ' + $newVer) -ForegroundColor Yellow
        } else {
            Write-Host '    Status   : First run, downloading...' -ForegroundColor Yellow
        }

        if ($rel.assets.Count -eq 0) {
            Write-Host '    Warning  : No assets in this release.' -ForegroundColor DarkYellow
            Write-Host ('    Manual   : ' + $repo.Page)
            $newVer | Out-File -FilePath $tagPath -Encoding utf8 -NoNewline
            $skipCount++; Write-Host ''; continue
        }

        foreach ($a in $repo.Assets) {
            $asset = $rel.assets | Where-Object { $_.name -eq $a.Remote }
            $local = Join-Path $dir $a.Local
            if (-not $asset) {
                $names = ($rel.assets | ForEach-Object { $_.name }) -join ', '
                Write-Host ('    Miss     : ' + $a.Remote + ' (available: ' + $names + ')') -ForegroundColor DarkYellow
                continue
            }
            $sz = if ($asset.size -gt 1MB) { [math]::Round($asset.size/1MB,1).ToString()+' MB' } else { [math]::Round($asset.size/1KB,1).ToString()+' KB' }
            Write-Host ('    Asset    : ' + $a.Remote + ' -> ' + $a.Local + ' (' + $sz + ')')
            if (Test-Path $local) {
                Move-Item $local ($local + '.bak') -Force
                Write-Host ('      Backup : ' + (Split-Path $local -Leaf) + '.bak') -ForegroundColor DarkGray
            }
            Write-Host '      Downloading...'
            Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $local -UseBasicParsing
            Write-Host ('      Done    : ' + $local) -ForegroundColor Green
        }

        $newVer | Out-File -FilePath $tagPath -Encoding utf8 -NoNewline
        $updateCount++

    } catch {
        Write-Host ('    ERROR    : ' + $_.Exception.Message) -ForegroundColor Red
        $failCount++
    }

    Write-Host ''
}

Write-Host '============================================'
Write-Host ('  Updated : ' + $updateCount) -ForegroundColor $(if($updateCount -gt 0){'Green'}else{'Gray'})
Write-Host ('  Skipped : ' + $skipCount)
if ($failCount -gt 0) { Write-Host ('  Failed  : ' + $failCount) -ForegroundColor Red }
Write-Host '============================================'
Write-Host ''

if ($failCount -gt 0) { exit 1 }
相关推荐
深兰科技1 小时前
深兰科技携手绿地集团布局行业智能体,绿地深兰科技智能体科技公司揭牌
人工智能·科技·启发式算法·推荐算法·深兰科技·绿地集团·deepagent
AIVOClaw容剪1 小时前
AI 成片系统搭建如何让矩阵号差异化从「同一脚本 50 个号发」变成「反推提示词每号一版」——5 模块防止同质化被判搬运 · AI 视频智能体平台
人工智能·矩阵·音视频
A15362552 小时前
WMS 仓储系统的软件有哪些?2026 主流产品分类与选型参考
大数据·人工智能
爱炼丹的James2 小时前
目标检测任务
人工智能·深度学习
春末的南方城市2 小时前
消费级显卡迎来实时视频生成!FastVideo 开源 FastWan-QAD,RTX 5090 实现 1.8 秒生成 5 秒 480P 视频!
人工智能·深度学习·计算机视觉·aigc·音视频
ivywriter2 小时前
【具身智能】VLA大模型和世界模型有什么区别?
人工智能
Thom5802 小时前
【迅投 QMT】QMT如何获取ETF申赎清单?download_etf_info()与get_etf_info()教程
人工智能·经验分享·量化交易·ptrade·量化编程
大强同学2 小时前
我的 AI 真实使用情况与深度复盘
人工智能
正在走向自律2 小时前
我用 Doubao-Seed-Evolving 搭了个 AI 智能教育助手,从自适应评测到错因诊断的全程实测
人工智能·seed-evolving·ai智能教育·自适应评测·ai答疑·知识点树管理