모델 저장 위치 표시·변경 기능 추가

- 상단 상태 정보에 Ollama·ComfyUI 모델 폴더, 크기, 남은 공간 표시
- 메인 메뉴 '모델 저장 위치'에서 폴더 변경 (기존 모델은 새 위치로 이동)
- Windows: 사용자 환경 변수 OLLAMA_MODELS, Mac: 설정 파일 + launchctl
- ComfyUI 컨테이너는 새 위치로 다시 만들어 적용

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K3UWnbHEdCxxWhyNx7Cpd2
This commit is contained in:
2026-10-28 03:13:44 +00:00
parent 120039a824
commit ead7f16744
3 changed files with 595 additions and 11 deletions

View File

@@ -86,7 +86,9 @@ $WebuiDiskGB = 60 # Podman 가상 머신
# - 버전마다 컨테이너가 따로 있고 포트만 다르게 동시에 실행 가능 (8188, 8189 ...)
# - 모델 파일(comfyui\models)은 모든 버전이 함께 사용, 출력·작업흐름·노드는 버전별 폴더
$ComfyDir = Join-Path $ScriptDir 'comfyui'
$ComfyModels = Join-Path $ComfyDir 'models' # 모든 버전이 함께 쓰는 모델
$ComfyModels = Join-Path $ComfyDir 'models' # 모든 버전이 함께 쓰는 모델 (기본 위치)
$ComfyModelsFile = Join-Path $CacheDir 'comfy_models_dir.txt' # 저장 위치를 바꿨으면 그 경로가 적힘
if (Test-Path $ComfyModelsFile) { $cmTmp = ([IO.File]::ReadAllText($ComfyModelsFile)).Trim(); if ($cmTmp) { $ComfyModels = $cmTmp } }
$ComfyInstDir = Join-Path $ComfyDir 'instances' # 버전별 output·input·user·custom_nodes
$ComfyBackupDir = Join-Path $ComfyDir 'backups'
$ComfyBuildDir = Join-Path $ComfyDir 'build' # 이미지 빌드 파일 (자동 생성)
@@ -1337,6 +1339,9 @@ function Get-MonitorText([switch]$Full) {
if ($ram) { $ramText = "$($ram.UsedGB)/$($ram.TotalGB)GB ($($ram.Pct)%)" }
$L.Add("${BOLD}자원${RESET} CPU $cpu% ($($script:HW.Threads)스레드) · 램 $ramText · Ollama $(Get-OllamaMemGB)GB · 디스크 남음 $(Get-FreeDiskGB)GB")
# 모델 저장 위치
foreach ($sl in (Get-StorageLines)) { $L.Add($sl) }
# 그래픽 카드
$gpus = @(Get-GpuUsage)
if ($gpus.Count -eq 0) {
@@ -4381,6 +4386,264 @@ function Show-StackMenu {
}
}
# --------------------------------------------------
# 모델 저장 위치 (Ollama 대화 모델 · ComfyUI 그림 모델) 표시·변경
# - Ollama: 사용자 환경 변수 OLLAMA_MODELS 에 저장 (트레이 앱도 같은 위치를 씀)
# - ComfyUI: 설정 파일(캐시 폴더\comfy_models_dir.txt)에 저장, 컨테이너를 다시 만들어 적용
# - 위치를 바꾸면 이미 받은 모델은 새 위치로 옮김
# --------------------------------------------------
$OllamaModelsDefault = Join-Path $HOME '.ollama\models'
# 폴더 크기(GB, 소수 1자리)
function Get-PathSizeGB([string]$Path) {
if (-not $Path -or -not (Test-Path -LiteralPath $Path)) { return 0 }
$sum = (Get-ChildItem -LiteralPath $Path -Recurse -File -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
if (-not $sum) { return 0 }
return [math]::Round($sum / 1GB, 1)
}
# 경로가 있는 드라이브의 남은 공간(GB) (폴더가 아직 없어도 드라이브 기준)
function Get-PathFreeGB([string]$Path) {
try {
$q = Split-Path -Qualifier $Path -ErrorAction Stop
$d = Get-PSDrive -Name ($q.TrimEnd(':')) -ErrorAction Stop
return [int][math]::Floor($d.Free / 1GB)
} catch { return -1 }
}
# 상태 화면용 크기 (60초 캐시: 메뉴를 열 때마다 큰 폴더를 다시 세지 않도록)
function Get-StorageInfo {
if ($script:StorageCache -and ((Get-Date) - $script:StorageCacheAt).TotalSeconds -lt 60) { return $script:StorageCache }
$od = Get-ModelsDir
$info = [pscustomobject]@{
OllamaDir = $od; OllamaGB = (Get-PathSizeGB $od); OllamaFree = (Get-PathFreeGB $od)
ComfyDir = $ComfyModels; ComfyGB = (Get-PathSizeGB $ComfyModels); ComfyFree = (Get-PathFreeGB $ComfyModels)
}
$script:StorageCache = $info
$script:StorageCacheAt = Get-Date
return $info
}
function Clear-StorageCache { $script:StorageCache = $null }
function Get-StorageLines {
$s = Get-StorageInfo
$of = ''; if ($s.OllamaFree -ge 0) { $of = " · 남은 공간 $($s.OllamaFree)GB" }
$cf = ''; if ($s.ComfyFree -ge 0) { $cf = " · 남은 공간 $($s.ComfyFree)GB" }
$od = ''; if ($s.OllamaDir -eq $OllamaModelsDefault) { $od = ' (기본)' }
$cd = ''; if ($s.ComfyDir -eq "$ComfyDir\models") { $cd = ' (기본)' }
return @(
"${BOLD}저장${RESET} Ollama 모델 ${CYAN}$($s.OllamaDir)${RESET}$od · $($s.OllamaGB)GB$of"
" ComfyUI 모델 ${CYAN}$($s.ComfyDir)${RESET}$cd · $($s.ComfyGB)GB$cf"
)
}
# 새 폴더 고르기: 폴더 선택 창 또는 직접 입력 → 전체 경로 / $null
function Select-FolderPath([string]$Title, [string]$Current, [string]$Default) {
$items = @(
(New-MenuItem 'dialog' " 폴더 선택 창 열기")
(New-MenuItem 'type' " 경로 직접 입력 ${GRAY}(예: D:\AI\models)${RESET}")
)
if ($Current -ne $Default) { $items += New-MenuItem 'default' " 기본 위치로 되돌리기 ${GRAY}($Default)${RESET}" }
$items += Get-BackItem '← 취소'
$sel = Show-Menu -Header "${BLUE}$Title${RESET}`n${GRAY}현재: $Current${RESET}`n$($script:KeyHelp)" -Items $items
$path = $null
switch ($sel) {
'dialog' {
try {
Add-Type -AssemblyName System.Windows.Forms -ErrorAction Stop
$owner = New-Object System.Windows.Forms.Form -Property @{ TopMost = $true }
$dlg = New-Object System.Windows.Forms.FolderBrowserDialog
$dlg.Description = $Title
$dlg.ShowNewFolderButton = $true
if (Test-Path -LiteralPath $Current) { $dlg.SelectedPath = $Current }
if ($dlg.ShowDialog($owner) -eq [System.Windows.Forms.DialogResult]::OK) { $path = $dlg.SelectedPath }
$owner.Dispose()
} catch {
Write-C "${YELLOW}폴더 선택 창을 열지 못했습니다. 경로를 직접 입력해 주세요.${RESET}"
$path = (Read-Host '새 폴더 경로 (엔터만 누르면 취소)').Trim().Trim('"')
}
}
'type' { $path = (Read-Host '새 폴더 경로 (엔터만 누르면 취소)').Trim().Trim('"') }
'default' { $path = $Default }
}
if (-not $path) { return $null }
try { $path = [IO.Path]::GetFullPath($path).TrimEnd('\') } catch { Write-C "${RED}올바른 경로가 아닙니다: $path${RESET}"; return $null }
if ($path -notmatch '^[A-Za-z]:\\.+') {
Write-C "${RED}드라이브 문자로 시작하는 폴더를 지정해 주세요. (예: D:\AI\models, 드라이브 맨 위는 불가)${RESET}"
return $null
}
return $path
}
# 두 경로가 같거나 한쪽이 다른 쪽 안에 있는지
function Test-PathOverlap([string]$A, [string]$B) {
$a = $A.TrimEnd('\').ToLower() + '\'
$b = $B.TrimEnd('\').ToLower() + '\'
return ($a.StartsWith($b) -or $b.StartsWith($a))
}
# 폴더 안의 내용을 새 폴더로 옮김 (같은 드라이브·빈 폴더면 순간 이동, 아니면 robocopy로 복사 후 삭제)
function Move-FolderContent([string]$Src, [string]$Dst) {
if (-not (Test-Path -LiteralPath $Dst)) { New-Item -ItemType Directory -Path $Dst -Force | Out-Null }
if (-not (Test-Path -LiteralPath $Src)) { return $true }
$children = @(Get-ChildItem -LiteralPath $Src -Force -ErrorAction SilentlyContinue)
if ($children.Count -eq 0) { return $true }
$sameDrive = ((Split-Path -Qualifier $Src) -eq (Split-Path -Qualifier $Dst))
$dstEmpty = (@(Get-ChildItem -LiteralPath $Dst -Force -ErrorAction SilentlyContinue).Count -eq 0)
if ($sameDrive -and $dstEmpty) {
try {
foreach ($c in $children) { Move-Item -LiteralPath $c.FullName -Destination $Dst -Force -ErrorAction Stop }
return $true
} catch {
Write-C "${YELLOW}바로 옮기지 못해 복사 방식으로 진행합니다: $($_.Exception.Message)${RESET}"
}
}
Write-C "${CYAN}옮기는 중... (다른 드라이브면 크기에 따라 시간이 걸립니다)${RESET}"
& robocopy.exe $Src $Dst /E /MOVE /R:1 /W:1 /NFL /NDL /NJH /NP | Out-Host
$rc = $LASTEXITCODE
if ($rc -ge 8) { Write-C "${RED}❌ 옮기는 중 오류가 났습니다 (robocopy 코드 $rc). 원래 폴더의 남은 파일을 확인해 주세요: $Src${RESET}"; return $false }
return $true
}
# 공통 확인: 겹침·남은 공간
function Test-MoveTarget([string]$Old, [string]$New, [double]$SizeGB) {
if ($Old.TrimEnd('\') -eq $New.TrimEnd('\')) { Write-C "${YELLOW}지금과 같은 위치입니다.${RESET}"; return $false }
if (Test-PathOverlap $Old $New) { Write-C "${RED}❌ 지금 폴더 안이나 바깥 폴더로는 옮길 수 없습니다. 다른 폴더를 골라 주세요.${RESET}"; return $false }
$sameDrive = ((Split-Path -Qualifier $Old) -eq (Split-Path -Qualifier $New))
$free = Get-PathFreeGB $New
if ($free -lt 0) { Write-C "${RED}❌ 드라이브를 찾을 수 없습니다: $New${RESET}"; return $false }
if (-not $sameDrive -and $free -lt ($SizeGB + 1)) {
Write-C "${RED}❌ 남은 공간이 부족합니다. 필요 약 $([math]::Ceiling($SizeGB + 1))GB · 남은 공간 ${free}GB${RESET}"
return $false
}
return $true
}
# Ollama 모델 저장 위치 변경
function Set-OllamaModelsLocation {
$old = Get-ModelsDir
$new = Select-FolderPath 'Ollama 모델 저장 위치 변경' $old $OllamaModelsDefault
if (-not $new) { return }
Clear-Host
$size = Get-PathSizeGB $old
if (-not (Test-MoveTarget $old $new $size)) { return }
Write-C "${CYAN}Ollama 모델 저장 위치를 바꿉니다${RESET}"
Write-C " 지금: $old ($size GB)"
Write-C " 새 위치: $new (남은 공간 $(Get-PathFreeGB $new)GB)"
Write-C "${GRAY} 받은 모델은 새 위치로 옮기고, 사용자 환경 변수 OLLAMA_MODELS 에 저장합니다.${RESET}"
$wasRunning = Test-Server
$owner = ''
if ($wasRunning) {
$owner = (Get-ServerInfo).Owner
Write-C "${YELLOW} 옮기는 동안 Ollama 서버를 잠시 종료합니다.${RESET}"
}
if (-not (Confirm-Choice "Ollama 모델을 새 위치로 옮길까요?")) { return }
$before = @((Get-ModelIdMap).Keys).Count
if ($wasRunning) {
Stop-OllamaServer
if (Test-Server) { Write-C "${RED}❌ 서버가 아직 실행 중이라 옮기지 않았습니다.${RESET}"; return }
}
if (-not (Move-FolderContent $old $new)) { return }
if ($new -eq $OllamaModelsDefault) {
[Environment]::SetEnvironmentVariable('OLLAMA_MODELS', $null, 'User')
Remove-Item Env:OLLAMA_MODELS -ErrorAction SilentlyContinue
} else {
[Environment]::SetEnvironmentVariable('OLLAMA_MODELS', $new, 'User')
$env:OLLAMA_MODELS = $new
}
if ((Test-Path -LiteralPath $old) -and @(Get-ChildItem -LiteralPath $old -Recurse -File -Force -ErrorAction SilentlyContinue).Count -eq 0) {
Remove-Item -LiteralPath $old -Recurse -Force -ErrorAction SilentlyContinue
}
Clear-StorageCache
Write-C "${GREEN}✅ 저장 위치를 바꿨습니다: $new${RESET}"
if ($wasRunning) {
Write-C "${CYAN}서버를 다시 기동합니다...${RESET}"
[void](Invoke-ServerLaunch $script:Perf.ContextLength)
Start-Sleep -Seconds 1
$after = @((Get-ModelIdMap).Keys).Count
if ($after -eq $before) { Write-C "${GREEN}✅ 실행 확인: 설치된 모델 ${after}개가 새 위치에서 그대로 보입니다.${RESET}" }
else { Write-C "${YELLOW}⚠️ 모델 개수가 다릅니다 (전 ${before}개 → 지금 ${after}개). 새 폴더를 확인해 주세요: $new${RESET}" }
}
if ($owner -and $owner -ne '스크립트') {
Write-C "${YELLOW}※ 서버를 Ollama 트레이 앱이 켜고 있었습니다. 트레이 아이콘에서 Quit 후 다시 실행해야 앱도 새 위치를 씁니다.${RESET}"
}
}
# ComfyUI 모델 저장 위치 변경 (모든 버전 공용)
function Set-ComfyModelsLocation {
$old = $ComfyModels
$default = Join-Path $ComfyDir 'models'
$new = Select-FolderPath 'ComfyUI 그림 모델 저장 위치 변경 (모든 버전 공용)' $old $default
if (-not $new) { return }
Clear-Host
# 네트워크 드라이브는 Podman 가상 머신(WSL)에서 보이지 않음
try {
$drv = Get-PSDrive -Name ((Split-Path -Qualifier $new).TrimEnd(':')) -ErrorAction Stop
if ("$($drv.DisplayRoot)" -like '\\*') {
Write-C "${RED}❌ 네트워크 드라이브($($drv.Name): → $($drv.DisplayRoot))는 ComfyUI 컨테이너에서 쓸 수 없습니다. 이 PC의 디스크를 골라 주세요.${RESET}"
return
}
} catch { }
$size = Get-PathSizeGB $old
if (-not (Test-MoveTarget $old $new $size)) { return }
Write-C "${CYAN}ComfyUI 그림 모델 저장 위치를 바꿉니다${RESET}"
Write-C " 지금: $old ($size GB)"
Write-C " 새 위치: $new (남은 공간 $(Get-PathFreeGB $new)GB)"
Write-C "${GRAY} 받은 모델을 옮긴 뒤, ComfyUI 컨테이너를 새 위치로 다시 만듭니다. (작업흐름·그림은 그대로)${RESET}"
$list = @(Get-ComfyInstances)
$running = @()
if ($list.Count -gt 0 -and (Test-Podman) -and (Get-MachineInfo).State -eq 'running') {
$states = Get-ComfyStates
$running = @($list | Where-Object { $states[$_.Container] -eq 'running' })
if ($running.Count -gt 0) { Write-C "${YELLOW} 실행 중인 ComfyUI($(@($running | ForEach-Object { $_.Name }) -join ', '))는 잠시 종료했다가 다시 켭니다.${RESET}" }
}
if (-not (Confirm-Choice "ComfyUI 모델을 새 위치로 옮길까요?")) { return }
foreach ($i in $running) { Stop-ComfyInstance $i }
if (-not (Move-FolderContent $old $new)) { return }
if (-not (Test-Path $CacheDir)) { New-Item -ItemType Directory -Path $CacheDir -Force | Out-Null }
if ($new -eq $default) { Remove-Item $ComfyModelsFile -Force -ErrorAction SilentlyContinue }
else { [IO.File]::WriteAllText($ComfyModelsFile, $new, $Utf8NoBom) }
$script:ComfyModels = $new
if ((Test-Path -LiteralPath $old) -and @(Get-ChildItem -LiteralPath $old -Recurse -File -Force -ErrorAction SilentlyContinue).Count -eq 0 -and $old -ne $default) {
Remove-Item -LiteralPath $old -Recurse -Force -ErrorAction SilentlyContinue
}
Clear-StorageCache
Write-C "${GREEN}✅ 저장 위치를 바꿨습니다: $new${RESET}"
# 컨테이너는 만들 때 폴더를 연결하므로 다시 만들어야 새 위치를 씀
if ($list.Count -gt 0 -and (Test-Podman) -and (Get-MachineInfo).State -eq 'running') {
foreach ($i in $list) { & $script:PodmanExe rm -f $i.Container *> $null }
Write-C "${GRAY}ComfyUI 컨테이너를 정리했습니다. 다음 기동 때 새 위치로 다시 만들어집니다.${RESET}"
foreach ($i in $running) { [void](Start-ComfyInstance $i) }
}
}
function Show-StorageMenu {
while ($true) {
Clear-StorageCache
$s = Get-StorageInfo
$items = @(
(New-MenuItem '-' "${CYAN}──────── Ollama 대화 모델 ────────${RESET}" '-o')
(New-MenuItem 'o_change' " 저장 위치 변경 ${GRAY}$($s.OllamaDir) · $($s.OllamaGB)GB · 남은 $($s.OllamaFree)GB${RESET}")
(New-MenuItem 'o_open' ' 폴더 열기')
(New-MenuItem '-' "${CYAN}──────── ComfyUI 그림 모델 (모든 버전 공용) ────────${RESET}" '-c')
(New-MenuItem 'c_change' " 저장 위치 변경 ${GRAY}$($s.ComfyDir) · $($s.ComfyGB)GB · 남은 $($s.ComfyFree)GB${RESET}")
(New-MenuItem 'c_open' ' 폴더 열기')
(Get-BackItem)
)
$sel = Show-Menu -Header "${BLUE}${BOLD}모델 저장 위치${RESET} ${GRAY}위치를 바꾸면 받은 모델은 새 위치로 옮깁니다${RESET}`n$($script:KeyHelp)" -Items $items
if (-not $sel -or $sel -eq 'back') { return }
if ($sel -eq '-') { continue }
switch ($sel) {
'o_change' { Set-OllamaModelsLocation; Wait-Return }
'c_change' { Set-ComfyModelsLocation; Wait-Return }
'o_open' { $d = Get-ModelsDir; if (-not (Test-Path -LiteralPath $d)) { New-Item -ItemType Directory -Path $d -Force | Out-Null }; Invoke-Item -LiteralPath $d }
'c_open' { if (-not (Test-Path -LiteralPath $ComfyModels)) { New-Item -ItemType Directory -Path $ComfyModels -Force | Out-Null }; Invoke-Item -LiteralPath $ComfyModels }
}
}
}
# --------------------------------------------------
# 시작 준비 (서버는 기동하지 않음)
# --------------------------------------------------
@@ -4416,6 +4679,7 @@ while ($true) {
(New-MenuItem 'launch' " 도구 연동 ${GRAY}(Claude Code · Codex · OpenCode · Droid · OpenClaw · Hermes)${RESET}")
(New-MenuItem 'bulk' ' 추천 모델 일괄 다운로드')
(New-MenuItem 'ko' " 한국어 전용 모드: $(Get-KoModeLabel) ${GRAY}(답변에 한자·중국어 섞임 방지)${RESET}")
(New-MenuItem 'storage' " 모델 저장 위치 ${GRAY}(Ollama · ComfyUI 폴더 확인·변경)${RESET}")
(New-MenuItem '-' "${CYAN}──────── Open WebUI · ComfyUI ────────${RESET}" '-w')
(New-MenuItem 'stack' " ▶ 통합 운영 ${GRAY}(Ollama + WebUI + ComfyUI 전체 기동·종료·점검)${RESET}")
(New-MenuItem 'webui' " Open WebUI (Podman) 관리 ${GRAY}(기동·종료·업데이트·로그·백업)${RESET}")
@@ -4450,6 +4714,7 @@ while ($true) {
'launch' { Show-LaunchMenu }
'bulk' { Show-BulkDownloadMenu }
'ko' { Show-KoMenu }
'storage' { Show-StorageMenu }
'live' { Show-LiveMonitor }
'status' { Clear-Host; Show-ServerStatus; Wait-Return }
'log' { Clear-Host; Show-ServerLog }