Files
voice_copy/voice-changer/installer/deploy.ps1
EJClaw c1d9242b81 voice-changer installer 1.0.4: refuse admin-token deploy; do not carry over the v1.0.2 uninstall log
Review/arbiter REVISE on 85f5782:
- If the installer is started elevated ("Run as administrator", admin terminal), ExecAsOriginalUser is
  elevated too, so deploy.ps1 copied into the user's folder and ran its scripts with admin rights.
  deploy.ps1 now checks the real token first (WindowsPrincipal.IsInRole(Administrator)) and exits 33
  before touching any path; the installer explains to start it by double-click. The post-install launch
  only runs when deploy succeeded (Check: DeployDone).
- v1.0.2 and later share AppId and uninstall dir, and the default UninstallLogMode=append kept v1.0.2's
  entries for files in the user's folder, which the elevated uninstaller would delete through a junction.
  UninstallLogMode=overwrite starts a fresh log. Since pre-existing folders are then not recorded as
  created, the uninstaller removes Program Files\VoiceChanger's apo\ scripts\ payload\ itself and launches
  a detached `rmdir` for the then-empty uninstall\ and install folder (Program Files only).

Windows 11 VM, Inno 6.7.4, AppVersion 1.0.4 (final build):
- A: setup started from an elevated process with /DATADIR=<Desktop>\VCA: deploy exit 33, the folder was
  never created, no shortcuts; REFUSED_BEFORE_WRITE PASS.
- L: deploy.ps1 under the logged-on user's limited token (Administrators deny-only) copies the app,
  folder owned by the user.
- C (control): v1.0.2 on Desktop -> v1.0.3, unins000.dat mentions Desktop\VC2; folder swapped for a junction
  to admin-only C:\vctarget, uninstall deletes the target's same-named files (FAIL, the bug).
- B: v1.0.2 on Desktop -> 1.0.4: unins000.dat no longer mentions it; same swap + uninstall: target files and
  SDDL unchanged (PASS); Program Files\VoiceChanger fully removed.
- R: fresh -> reinstall -> uninstall: Program Files\VoiceChanger fully removed; FxProperties restored.
- python unittest: 16 run, 2 skipped (tkinter missing).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 23:04:18 +09:00

59 lines
3.6 KiB
PowerShell

# 고른 폴더에 앱을 설치한다. 설치 프로그램이 "설치를 시작한 사용자" 권한으로 실행한다 (ExecAsOriginalUser).
# 고른 폴더(바탕 화면 등)는 상위가 사용자 소유일 수 있어서 관리자 권한으로는 건드리지 않는다:
# 관리자 권한으로 경로를 다루는 도중에 폴더를 정션으로 바꿔치면 엉뚱한 곳에 쓰거나 권한을 바꾸게 되기 때문.
# deploy.ps1 -Data <고른 폴더> [-From <이전 버전 폴더>]
# 1. 이전 버전 폴더에서 데이터 폴더(models · config · env 등)를 옮겨 온다
# - v1.0.0 · v1.0.1: 설치 프로그램(legacy.ps1)이 <폴더>.old 로 비켜 두고 -From 으로 알려 줌
# - v1.0.2: 고른 폴더가 관리자 소유로 잠겨 있으면, 상위 폴더가 내 것일 때 이름을 바꿔 비켜 두고 새로 만든다
# 2. Program Files\VoiceChanger\payload 의 앱 파일을 복사한다
# 3. scripts\install.ps1 로 Python · 엔진 · 기본 모델을 받는다
# 종료 코드: 0 성공, 31 고른 폴더가 링크(정션), 32 폴더를 만들거나 복사하지 못함,
# 33 관리자 권한으로 실행됨(설치 프로그램을 관리자 권한으로 시작하면 "원래 사용자" 도 관리자), 그 밖 = install.ps1 실패
param([Parameter(Mandatory)][string]$Data, [string]$From)
$ErrorActionPreference = 'Stop'
# 경로를 건드리기 전에 실제 토큰을 확인한다. 관리자 권한이면 이 스크립트가 지키려는 분리가 없어지므로 아무것도 하지 않는다
$me = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if ($me.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "[deploy] 관리자 권한으로 실행되어 중단합니다. 설치 프로그램을 그냥 더블클릭해서 실행해 주세요."
exit 33
}
[Console]::OutputEncoding = [Text.Encoding]::UTF8
$Payload = Join-Path (Split-Path -Parent $PSScriptRoot) 'payload'
$DataDirs = 'models', 'training', 'datasets', 'config', 'cache', 'env', 'engine', 'tools'
$Data = [IO.Path]::GetFullPath($Data).TrimEnd('\')
function Say($m) { Write-Host "[deploy] $m" }
function Is-Link([string]$p) { ([IO.File]::GetAttributes($p) -band [IO.FileAttributes]::ReparsePoint) -ne 0 }
function Can-Write([string]$d) {
$t = Join-Path $d ".vc-write-test-$PID"
try { [IO.File]::WriteAllText($t, ''); Remove-Item -LiteralPath $t -Force; return $true } catch { return $false }
}
try {
if (Test-Path -LiteralPath $Data) {
if (Is-Link $Data) { Say "고른 폴더가 링크(정션)입니다: $Data"; exit 31 }
if (-not (Can-Write $Data)) {
$old = "$Data.old-$(Get-Date -Format yyyyMMddHHmmss)"
Rename-Item -LiteralPath $Data -NewName (Split-Path -Leaf $old)
Say "이전 버전 폴더를 비켜 둠: $old"
$From = $old
}
}
New-Item -ItemType Directory -Force -Path $Data | Out-Null
if ($From -and (Test-Path -LiteralPath $From)) {
foreach ($d in $DataDirs) {
$s = Join-Path $From $d
$t = Join-Path $Data $d
if ((Test-Path -LiteralPath $s) -and -not (Test-Path -LiteralPath $t)) { Move-Item -LiteralPath $s -Destination $t; Say "옮김: $d" }
}
}
} catch {
Say "실패: $($_.Exception.Message)"
exit 32
}
& robocopy $Payload $Data /E /R:1 /W:1 /NFL /NDL /NJH /NJS /NP | Out-Host
if ($LASTEXITCODE -ge 8) { Say "앱 파일을 복사하지 못함 (robocopy $LASTEXITCODE)"; exit 32 }
$global:LASTEXITCODE = 0
& (Join-Path $Data 'scripts\install.ps1')
exit $LASTEXITCODE