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 }
相关推荐
wshzd34 分钟前
LLM之Agent(六十八)|PI(七)构建测试与开发流程
人工智能
H03111698535 分钟前
App竞品数据平台功能梳理:月狐数据、七麦数据、点点数据
人工智能
YOLO数据集集合40 分钟前
高铁轨道紧固件损坏检测数据集 | 高铁巡检 紧固件缺陷 轨道安全9093期
人工智能·目标检测·计算机视觉·目标跟踪·轨道·铁轨紧固件·铁轨
冬奇Lab42 分钟前
一天一个开源项目(第223篇):TeamAI-CLI —— 腾讯开源的团队级 AI Agent 中间层,让每个人的 AI 能力变成团队共享能力
人工智能·开源·资讯
ShineWinsu1 小时前
对于Coze—AI:SDK的解析
人工智能·python·ai·sdk·项目·coze·字节跳动
代码方舟1 小时前
零信任架构实战:基于天远名下企业A构建自动化B2B供应链准入网关
人工智能·ai·工具分享
IvorySQL1 小时前
IvorySQL 5.6 发布:PG 18.6 内核升级,沙盒即开即用
数据库·人工智能·postgresql
俗人六哥AI企业获客盈利系统1 小时前
知识库才是AI落地的分水岭
人工智能·线性代数·矩阵·自动化
漂流瓶jz1 小时前
UVA-1442 洞穴 题解答案代码 算法竞赛入门经典第二版
c++·算法·题解·aoapc·算法竞赛入门经典·uva
H0311169852 小时前
App竞品数据查询工具整理 月狐数据 蝉大师 点点数据功能概览
人工智能