Permission denied on git mv, used robocopy instead. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
89 lines
3.1 KiB
Python
89 lines
3.1 KiB
Python
"""Gitea push - URL 인코딩 수정"""
|
|
import paramiko, sys, os, subprocess
|
|
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=30)
|
|
sftp = client.open_sftp()
|
|
|
|
# URL 인코딩된 비밀번호: Zio@Admin2026! → Zio%40Admin2026%21
|
|
GITEA_AUTH_URL = 'zio:Zio%40Admin2026%21'
|
|
GITEA_INTERNAL = 'http://127.0.0.1:9003'
|
|
GITEA_AUTH_BASIC = 'zio:Zio@Admin2026!'
|
|
|
|
def run(label, cmd, timeout=300):
|
|
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(f' {out[-300:]}')
|
|
if err:
|
|
bad = [l for l in err.splitlines() if not any(k in l.lower() for k in ['warn','hint','cloning','into','updating'])]
|
|
if bad: print(f' ERR: {bad[-1]}')
|
|
return out
|
|
|
|
REPOS = {
|
|
"zioinfo-web": "zio/zioinfo-web",
|
|
"guardia-itsm": "zio/guardia-itsm",
|
|
"guardia-manager": "zio/guardia-manager",
|
|
"guardia-messenger": "zio/guardia-messenger",
|
|
"guardia-docs": "zio/guardia-docs",
|
|
}
|
|
|
|
print('[번들 전송 + 내부 포트 push (URL 인코딩 수정)]')
|
|
for local, gitea in REPOS.items():
|
|
local_path = f"C:/GUARDiA/repos/{local}"
|
|
bundle_path = f"C:/GUARDiA/repos/{local}.bundle"
|
|
server_bundle = f"/tmp/{local}.bundle"
|
|
name = gitea.split('/')[1]
|
|
|
|
print(f'\n {local} → {gitea}')
|
|
|
|
# 번들 생성
|
|
r = subprocess.run(['git', '-C', local_path, 'bundle', 'create', bundle_path, 'HEAD', '--all'],
|
|
capture_output=True, text=True, timeout=120)
|
|
if r.returncode != 0:
|
|
print(f' bundle 실패: {r.stderr[:100]}')
|
|
continue
|
|
size_mb = os.path.getsize(bundle_path) // (1024*1024)
|
|
print(f' bundle: {size_mb}MB')
|
|
|
|
# 서버 전송
|
|
sftp.put(bundle_path, server_bundle)
|
|
os.remove(bundle_path)
|
|
print(f' 전송 완료')
|
|
|
|
# 내부 포트 + URL 인코딩 비밀번호로 push
|
|
gitea_url = f"http://{GITEA_AUTH_URL}@127.0.0.1:9003/{gitea}.git"
|
|
run(f'push {local}', f"""
|
|
rm -rf /tmp/{name}_w
|
|
git clone "{server_bundle}" /tmp/{name}_w 2>&1 | grep -v "Cloning"
|
|
if [ $? -ne 0 ]; then echo "clone failed"; exit 1; fi
|
|
cd /tmp/{name}_w
|
|
BRANCH=$(git log --oneline -1 2>/dev/null | head -1)
|
|
echo "최신 커밋: $BRANCH"
|
|
BNAME=$(git branch | head -1 | sed 's/\\* //')
|
|
if [ "$BNAME" != "main" ]; then git branch -m "$BNAME" main 2>/dev/null; fi
|
|
git remote set-url origin '{gitea_url}'
|
|
git push origin main --force 2>&1 | tail -3
|
|
rm -rf /tmp/{name}_w {server_bundle}
|
|
echo "완료"
|
|
""")
|
|
|
|
# 최종 확인
|
|
run('최종 저장소 확인', f"""
|
|
curl -sf '{GITEA_INTERNAL}/api/v1/repos/search?limit=20' \
|
|
-u '{GITEA_AUTH_BASIC}' 2>/dev/null | \
|
|
python3 -c "
|
|
import sys,json
|
|
data = json.load(sys.stdin).get('data',[])
|
|
for r in data:
|
|
print(f\" {r['full_name']} ({r.get('size',0)}KB)\")
|
|
"
|
|
""")
|
|
|
|
sftp.close()
|
|
client.close()
|
|
print('\n=== Phase 2 완료 ===')
|