78 lines
2.6 KiB
Python
78 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
import paramiko
|
|
|
|
HOST = "10.10.0.10"
|
|
USER = "localadministrator"
|
|
PASS = "Bbt9115xty9176!"
|
|
GITEA_CTR = "gitea-c11eg5g4s3n9sa4js8wapvbj"
|
|
APP = "ira4bw4nhbvm87o7s3fgqu6v"
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, username=USER, password=PASS, timeout=20, allow_agent=False, look_for_keys=False)
|
|
|
|
|
|
def run(cmd, t=180):
|
|
print("$", cmd[:160])
|
|
_, o, e = c.exec_command(cmd, timeout=t)
|
|
code = o.channel.recv_exit_status()
|
|
out = (o.read() + e.read()).decode(errors="replace")
|
|
print(out[-8000:])
|
|
print("exit", code, "\n")
|
|
return code, out
|
|
|
|
|
|
run(f"docker exec -u git {GITEA_CTR} gitea admin user generate-access-token --help 2>&1")
|
|
|
|
_, out = run(
|
|
f"docker exec -u git {GITEA_CTR} gitea admin user generate-access-token "
|
|
f"--username localadministrator --token-name exposedgays-setup "
|
|
f"--scopes 'write:user,write:repository,read:user' --raw 2>&1"
|
|
)
|
|
|
|
# Extract token from output
|
|
token = ""
|
|
for line in out.splitlines():
|
|
line = line.strip()
|
|
if line and not line.startswith("$") and "exit=" not in line and "Incorrect" not in line and "NAME:" not in line and "USAGE:" not in line and "OPTIONS:" not in line and "DEFAULT" not in line and "help" not in line.lower()[:10]:
|
|
if len(line) > 20 and " " not in line:
|
|
token = line
|
|
break
|
|
|
|
print(f"TOKEN_LEN={len(token)}")
|
|
|
|
if token:
|
|
run(
|
|
f"curl -sS -X POST 'https://gitea.onsethost.com/api/v1/user/repos' "
|
|
f"-H 'Authorization: token {token}' "
|
|
f"-H 'Content-Type: application/json' "
|
|
f"-d '{{\"name\":\"exposedgays\",\"private\":true}}'"
|
|
)
|
|
GIT_AUTH = f"https://{USER}:{token}@gitea.onsethost.com/localadministrator/exposedgays.git"
|
|
else:
|
|
GIT_AUTH = f"https://{USER}:{PASS}@gitea.onsethost.com/localadministrator/exposedgays.git"
|
|
|
|
run(
|
|
"curl -sS -o /dev/null -w '%{http_code}' "
|
|
"https://gitea.onsethost.com/localadministrator/exposedgays"
|
|
)
|
|
|
|
run(f"cd /tmp/exposedgays && git remote set-url origin '{GIT_AUTH}' && git push -u origin main --force")
|
|
|
|
run(
|
|
f"docker exec coolify-db psql -U coolify -d coolify -c "
|
|
f"\"UPDATE applications SET git_full_url='{GIT_AUTH}', "
|
|
f"git_repository='https://gitea.onsethost.com/localadministrator/exposedgays.git' "
|
|
f"WHERE uuid='{APP}';\""
|
|
)
|
|
|
|
run(
|
|
"TOKEN=$(cat /home/localadministrator/.coolify-token | tail -1); "
|
|
f"curl -sS -X POST 'http://127.0.0.1:8000/api/v1/deploy?uuid={APP}&force_rebuild=true' "
|
|
'-H "Authorization: Bearer $TOKEN"'
|
|
)
|
|
|
|
for i in range(8):
|
|
run("docker exec coolify php artisan queue:work --queue=high,default --once --timeout=900 2>&1", t=920)
|
|
|
|
c.close() |