"""Gitea 저장소 생성 확인 및 직접 push""" import paramiko, sys sys.stdout.reconfigure(encoding='utf-8', errors='replace') client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=15) def run(label, cmd, timeout=60): print(f'[{label}]') _, o, e = client.exec_command(cmd, timeout=timeout) out = o.read().decode('utf-8', errors='replace').strip() err = e.read().decode('utf-8', errors='replace').strip() if out: print(out[:400]) if err: bad = [l for l in err.splitlines() if not any(k in l.lower() for k in ['warn','hint','note','cloning'])] if bad: print('ERR:', '\n'.join(bad[:3])) return out # 1. 현재 Gitea 저장소 목록 run('저장소 목록', """ curl -sf 'http://localhost:3000/api/v1/repos/search?limit=20' \ -H 'Authorization: basic emlvOlppb0BBZG1pbjIwMjYh' 2>/dev/null | \ python3 -c "import sys,json; [print(r['full_name']) for r in json.load(sys.stdin).get('data',[])]" 2>/dev/null """) # 2. 토큰 생성 및 저장소 생성 run('토큰 생성', """ # Gitea API 토큰 생성 TOKEN=$(curl -sf -X POST 'http://localhost:3000/api/v1/users/zio/tokens' \ -u 'zio:Zio@Admin2026!' \ -H 'Content-Type: application/json' \ -d '{"name":"deploy-token-'$(date +%s)'"}' 2>/dev/null | python3 -c "import sys,json; print(json.load(sys.stdin).get('sha1',''))" 2>/dev/null) echo "TOKEN=$TOKEN" """) # 3. 새 저장소 생성 (올바른 auth 방식) for name, desc in [("guardia-manager","GUARDiA Manager"),("guardia-messenger","GUARDiA Messenger"),("guardia-docs","GUARDiA Docs")]: run(f'create {name}', f""" R=$(curl -sf -X POST 'http://localhost:3000/api/v1/user/repos' \ -u 'zio:Zio@Admin2026!' \ -H 'Content-Type: application/json' \ -d '{{"name":"{name}","description":"{desc}","private":false,"auto_init":true,"default_branch":"main"}}' 2>/dev/null) echo "$R" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('full_name') or d.get('message','?'))" 2>/dev/null || echo "$R" """) # 4. 저장소 확인 run('생성 후 목록', """ curl -sf 'http://localhost:3000/api/v1/repos/search?limit=20' \ -u 'zio:Zio@Admin2026!' 2>/dev/null | \ python3 -c "import sys,json; [print(r['full_name']) for r in json.load(sys.stdin).get('data',[])]" 2>/dev/null """) # 5. 각 repo push (auto_init으로 생성했으므로 push 가능) REPOS = [ ("/opt/repos/zioinfo-web.bundle", "zio/zioinfo-web"), ("/opt/repos/guardia-itsm.bundle", "zio/guardia-itsm"), ("/opt/repos/guardia-manager.bundle", "zio/guardia-manager"), ("/opt/repos/guardia-messenger.bundle", "zio/guardia-messenger"), ("/opt/repos/guardia-docs.bundle", "zio/guardia-docs"), ] for bundle, gitea in REPOS: name = gitea.split('/')[1] run(f'push {name}', f""" if [ -f "{bundle}" ]; then rm -rf /tmp/{name}_work git clone "{bundle}" /tmp/{name}_work 2>/dev/null cd /tmp/{name}_work git remote set-url origin 'http://zio:Zio@Admin2026!@localhost:3000/{gitea}.git' git push origin main --force 2>&1 | tail -3 rm -rf /tmp/{name}_work else echo "bundle not found: {bundle}" fi """, timeout=120) client.close()