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 }
相关推荐
向上的车轮几秒前
Coze Studio 本地部署教程 + 私有化AI智能体搭建实战(保姆级零踩坑,可直接落地)
人工智能
qq_25294131687 分钟前
航拍羊群目标检测数据集 | 航拍羊群 智慧畜牧业 动物检测 无人机巡检5010期
人工智能·yolo·目标检测·计算机视觉·无人机·羊群识别·羊群
A.说学逗唱的Coke9 分钟前
【AI·Coding】多工具协作实战:同一个项目如何无缝切换 Qoder / Claude Code / Codex / Cursor / Trae
人工智能
不会就选b10 分钟前
算法日常・每日刷题--<BFS拓扑排序>4
算法
Wang's Blog13 分钟前
Vibe Coding一人即团队系列40: 基于Git历史与自定义Skill的自动化周报生成实践
人工智能·自动化
1878770860915 分钟前
Hip-Hop 音乐制作工具推荐:从 Beat、录音到混音的实用选型
人工智能
cqsztech16 分钟前
Oracle ai database 26ai rac 通过gold image 更新季度补
数据库·人工智能·oracle
不正经学生19 分钟前
C语言动态内存管理(上):堆上的自由与责任
c语言·开发语言·c++·算法·面试
伟大的车尔尼20 分钟前
贪心的概念
数据结构·算法·贪心
Wang's Blog21 分钟前
Vibe Coding一人即团队系列42: 跨端App开发前期准备与工具链搭建
人工智能