fix(deploy): -e 인자 단따옴표 변경 + 키파일 존재 검증

- -e 'ssh ...' 단따옴표 사용으로 -i 경로의 따옴표 충돌 방지
- 키 파일 없을 때 명확한 에러 메시지 출력 후 종료

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 09:39:27 +09:00
parent 11e4f00ae6
commit 35ce362d20

View File

@@ -57,14 +57,24 @@ if (isWin) {
} }
// macOS Keychain은 서브프로세스(rsync)에서 SSH 키를 자동 로드하지 못함 → -i 명시 // macOS Keychain은 서브프로세스(rsync)에서 SSH 키를 자동 로드하지 못함 → -i 명시
const keyFile = process.env.NAS_SSH_KEY || path.join(os.homedir(), ".ssh", "id_rsa"); const keyFile = (process.env.NAS_SSH_KEY || path.join(os.homedir(), ".ssh", "id_rsa"))
.replace(/[\r\n]/g, "").trim();
if (!fs.existsSync(keyFile)) {
console.error(`SSH 키 파일을 찾을 수 없습니다: ${keyFile}`);
console.error("NAS_SSH_KEY 환경변수를 올바른 키 경로로 설정하거나, ~/.ssh/id_rsa 가 있는지 확인하세요.");
process.exit(1);
}
const portOpt = cleanPort ? `-p ${cleanPort}` : ""; const portOpt = cleanPort ? `-p ${cleanPort}` : "";
const sshCmd = `ssh ${portOpt} -i "${keyFile}" -o StrictHostKeyChecking=accept-new -o BatchMode=yes`.trim(); // -e 인자는 단따옴표로 감싸야 -i 경로의 공백/따옴표 충돌을 방지
const sshCmd = `ssh ${portOpt} -i ${keyFile} -o StrictHostKeyChecking=accept-new -o BatchMode=yes`
.replace(/\s+/g, " ").trim();
console.log(`Deploying via SSH → ${cleanTarget}:${cleanPath}`); console.log(`Deploying via SSH → ${cleanTarget}:${cleanPath}`);
console.log(`SSH command: ${sshCmd}`); console.log(`SSH command: ${sshCmd}`);
execSync( execSync(
`rsync -r --delete --delete-delay -e "${sshCmd}" ${src}/ ${cleanTarget}:${cleanPath}`, `rsync -r --delete --delete-delay -e '${sshCmd}' ${src}/ ${cleanTarget}:${cleanPath}`,
{ stdio: "inherit" } { stdio: "inherit" }
); );
process.exit(0); process.exit(0);