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 }
相关推荐
锋行天下18 分钟前
langgraph 全栈项目(二)
前端·人工智能·后端
大模型真好玩24 分钟前
用 Seedance 2.5 Flash 实现1分钟AI短剧,满足孩子的超级英雄对战梦
人工智能·aigc·deepseek
FengY_HYY43 分钟前
从人类组织到人类&大模型组织,我的位置在哪里?
人工智能·程序员·llm
Flynn Liang1 小时前
大模型成本优化:基于 Redis 的可验证语义缓存架构
人工智能·redis·缓存·架构·ai agent·智能体
锋行天下1 小时前
langgraph全栈项目(一)
前端·人工智能·后端
程序员cxuan1 小时前
不得了,Google 造反了,Opus 5.5 又被干了
人工智能·后端·程序员
数字新视界2 小时前
能耗管理系统提升企业能源效率的实践与展望
大数据·人工智能·数据中心·机房管理·模块化机房
郝学胜-神的一滴2 小时前
Effective Python 条款36:优雅拼装迭代器与生成器
开发语言·数据结构·人工智能·python·numpy·scikit-learn
Frag0ut3 小时前
Chrome 2026浏览器AI助手全攻略:智能问答与内容创作实战进阶指南
人工智能·chrome·ai助手·本地大模型·浏览器ai·网页智能总结·侧边栏ai