wswg/scripts/publish.py

31 lines
3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""Publish built artifacts through the existing html_plans Caddy site."""
from pathlib import Path
import html
import os
import shutil
import sys
version=sys.argv[1] if len(sys.argv)>1 else '0.1.0'
if not version.replace('.','').replace('-','').isalnum():raise SystemExit('Invalid version')
root=Path(__file__).resolve().parent.parent
source=root/'dist';dest=Path('/opt/public-downloads/wswg')/version
if not (source/'wswg-all.zip').exists():raise SystemExit('Run scripts/build.sh first')
rows=[]
for archive in sorted(source.glob('wswg-*.zip')):
if archive.name=='wswg-all.zip':continue
folder=archive.stem
exe='wswg.exe' if 'windows' in folder else 'wswg'
rows.append(f'<tr><td>{html.escape(folder.removeprefix("wswg-"))}</td><td><a href="{archive.name}">ZIP</a></td><td>{archive.stat().st_size/1024/1024:.1f} MB</td><td><a href="{folder}/{exe}">wswg</a></td></tr>')
page='''<!doctype html><html lang="ru"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>wswg builds</title><style>body{font:15px system-ui;max-width:850px;padding:24px;margin:auto;color:#222}table{border-collapse:collapse;width:100%}td,th{text-align:left;padding:9px;border-bottom:1px solid #ccc}a{color:#125ba4}code{background:#eee;padding:2px 4px}</style>'''
page+=f'<h1>wswg {html.escape(version)}</h1><p>WireGuard + wstunnel. Простой GUI в локальном браузере и TUI.</p><p><a href="wswg-all.zip">Все платформы одним ZIP</a> · <a href="SHA256SUMS">SHA256SUMS</a> · <a href="README.md">Инструкция</a></p><table><tr><th>Платформа</th><th>Скачать</th><th>Размер</th><th>Бинарник отдельно</th></tr>'+''.join(rows)+'</table><p>Для обычной установки скачайте ZIP и распакуйте целиком. Папки bin и redist должны остаться рядом с программой.</p><p><code>./wswg -t</code> · <code>./wswg -a</code> · <code>./wswg -c 1 -d --no-wstunnel</code></p><p>Linux и Termux требуют root и ядро с WireGuard. Windows требует Administrator. Windows ARM32 не поддерживается. Системные требования и настройка DNS описаны в инструкции.</p><p><a href="https://git.snw.su/snw/wswg">Исходники</a> · <a href="VALIDATION.md">Проверки сборки</a></p></html>'
(source/'index.html').write_text(page)
shutil.copy2(root/'README.md',source/'README.md')
shutil.copy2(root/'VALIDATION.md',source/'VALIDATION.md')
shutil.copytree(source,dest,dirs_exist_ok=True)
shared=Path('/opt/html_plans');shared.mkdir(exist_ok=True)
link=shared/'wswg-builds'
if link.exists() and not link.is_symlink():raise SystemExit(f'Refusing to replace {link}: it is not a symlink')
temp=shared/'.wswg-builds-new'
if temp.is_symlink():temp.unlink()
temp.symlink_to(dest,target_is_directory=True);os.replace(temp,link)
print('http://html_plans.t.snw.su/wswg-builds/')