# ============================================================================ # koax 배포 플랫폼 - Git 로그인 1회 설정 (Windows / PowerShell) # # 이 스크립트는 git.koces.com 에 "브라우저 로그인"으로 push 할 수 있게 해줍니다. # (GitHub 처럼 push 하면 브라우저가 떠서 로그인하고, 이후 다시 묻지 않습니다.) # # 실행 방법 - 둘 중 아무거나: # (1) 웹에서 바로 : irm https://setup.koax.site/koax-git-setup.ps1 | iex # (2) 파일로 받아서 : powershell -ExecutionPolicy Bypass -File .\koax-git-setup.ps1 # # 아래 CLIENT_ID / CLIENT_SECRET 은 "공개 클라이언트(public client)" 값입니다. # 비밀번호가 아니며, 모든 사용자가 동일한 값을 사용합니다. 안심하고 쓰세요. # # ⚠️ 이 파일은 `irm | iex` 로도 실행되므로 최상위에서 `exit` 를 쓰면 안 된다 # (사용자의 PowerShell 창이 통째로 닫힌다). 전체를 함수로 감싸고 return 을 쓴다. # ============================================================================ function Invoke-KoaxGitSetup { $GitHost = 'git.koces.com' $ClientId = '97f5027b22011ae2dadd9db983a09bbfeb7452f5840afc0c7314c3932de58de2' $ClientSecret = 'gloas-405db5408006c96b1828e04b5baf23fc7e2be20a6ed21ee41dabe523e56a51cc' Write-Host '' Write-Host '=== koax Git 로그인 설정 시작 ===' -ForegroundColor Cyan # 1) Git 설치 확인 $git = Get-Command git -ErrorAction SilentlyContinue if (-not $git) { Write-Host '[X] Git 이 설치돼 있지 않습니다.' -ForegroundColor Red Write-Host ' https://git-scm.com/download/win 에서 설치한 뒤 다시 실행하세요.' return } Write-Host ('[OK] Git 발견: ' + (git --version)) # 2) Git Credential Manager 확인 (Git for Windows 에 기본 포함) # # ⚠️ PATH 만 보면(Get-Command) 안 된다. Git for Windows 는 GCM 을 # "C:\Program Files\Git\mingw64\bin" 에 두는데 이 경로는 사용자 PATH 에 없다. # git 자신은 exec-path 로 찾으므로 `git credential-manager` 는 정상 동작한다. # PATH 로만 판단하면 제대로 설치된 PC 대부분에서 "GCM 없음" 오탐이 난다. $gcmVersion = $null try { $gcmVersion = & git credential-manager --version 2>$null | Select-Object -First 1 } catch {} if (-not $gcmVersion) { # 구버전은 git-credential-manager-core 로 불릴 수 있음 try { $gcmVersion = & git credential-manager-core --version 2>$null | Select-Object -First 1 } catch {} } if (-not $gcmVersion) { Write-Host '[!] Git Credential Manager 를 찾지 못했습니다.' -ForegroundColor Yellow Write-Host ' Git for Windows 를 재설치하거나 최신 버전으로 업데이트하세요.' Write-Host ' (설정은 계속 진행합니다. push 시 브라우저가 안 뜨면 이 메시지를 참고하세요.)' } else { Write-Host "[OK] Credential Manager 발견: $gcmVersion" # 자격증명 관리자를 manager 로 지정(기본이 아닐 때 대비, 무해) git config --global credential.helper manager | Out-Null } # 3) git.koces.com 을 브라우저 OAuth 로그인으로 설정 $prefix = "credential.https://$GitHost" git config --global "$prefix.provider" 'gitlab' git config --global "$prefix.gitLabDevClientId" $ClientId git config --global "$prefix.gitLabDevClientSecret" $ClientSecret git config --global "$prefix.gitLabAuthModes" 'browser' Write-Host '' Write-Host "[OK] $GitHost 브라우저 로그인 설정 완료" -ForegroundColor Green # 3.5) 낡은 자격증명 제거 (중요) # git 은 push 시 GCM 에게 "저장된 자격증명 있냐"를 먼저 묻는다. 예전에 저장된 # git.koces.com 항목이 남아 있으면 GCM 이 그걸 그대로 돌려줘 OAuth 를 아예 시작하지 # 않고, 결과적으로 "HTTP Basic: Access denied" 로 막힌다. 그래서 미리 지운다. Write-Host '' Write-Host "이전에 저장된 $GitHost 자격증명을 정리합니다(있으면)..." -ForegroundColor Cyan $removed = 0 # (a) Windows 자격 증명 관리자에 남은 항목을 전부 찾아 지운다. # 계정이 섞인 항목(git:https://user@git.koces.com)도 있어서 목록을 훑는다. # cmdkey /list 출력은 언어별로 다르므로 라벨이 아니라 호스트명으로 매칭한다. $listed = @() try { $listed = & cmd /c cmdkey /list 2>$null } catch {} foreach ($line in $listed) { if ("$line" -match "(\S*$([regex]::Escape($GitHost))\S*)") { $target = $Matches[1] cmd /c "cmdkey /delete:$target" 2>&1 | Out-Null if ($LASTEXITCODE -eq 0) { $removed++ } } } # (b) 목록에 안 잡히는 경우까지 대비한 표준 타깃 직접 삭제 cmd /c "cmdkey /delete:git:https://$GitHost" 2>&1 | Out-Null # (c) credential helper 쪽에도 삭제를 지시한다. # ⚠️ `git credential erase` 는 존재하지 않는 서브커맨드다(fill|approve|reject 뿐). # 예전 스크립트가 이걸 써서 이 단계가 조용히 무동작이었다. try { "protocol=https`nhost=$GitHost`n" | git credential reject 2>$null } catch {} Write-Host "[OK] 정리 완료 (자격증명 $removed 건 삭제) - 다음 push 때 브라우저 로그인이 새로 뜹니다" # 4) 확인 출력 Write-Host '' Write-Host '--- 현재 설정 ---' -ForegroundColor Cyan git config --global --get-urlmatch credential "https://$GitHost" Write-Host '' Write-Host '=== 끝났습니다 ===' -ForegroundColor Cyan Write-Host '' Write-Host '이제 이렇게 쓰면 됩니다:' -ForegroundColor White Write-Host " git clone https://$GitHost/<본인계정>/<저장소>.git" Write-Host ' git push <- 처음 한 번 브라우저가 떠서 로그인하면, 이후 자동입니다.' Write-Host '' Write-Host '저장소를 미리 안 만들어도 됩니다(push 하면 자동 생성):' -ForegroundColor White Write-Host " git remote add origin https://$GitHost/<본인계정>/<저장소>.git" Write-Host ' git push -u origin main' Write-Host '' Write-Host '배포하려면 저장소 루트에 deploy.json 을 두세요:' -ForegroundColor White Write-Host ' { "buildPack": "static" } (정적 사이트)' Write-Host ' { "buildPack": "nixpacks", "port": 3000 } (Node 등)' Write-Host ' -> 약 1분 뒤 https://<저장소명>.koax.site 로 뜨고, 커밋 옆에 deploy/koax 상태가 표시됩니다.' Write-Host '' Write-Host '사용설명서: https://setup.koax.site/manual.html' -ForegroundColor White Write-Host '' Write-Host "[문제 해결] push 시 브라우저가 안 뜨고 'Access denied' 가 나오면:" -ForegroundColor Yellow Write-Host ' 이 스크립트를 다시 실행하세요(낡은 자격증명을 지우고 OAuth 를 새로 시작합니다).' Write-Host ' irm https://setup.koax.site/koax-git-setup.ps1 | iex' Write-Host '' } Invoke-KoaxGitSetup