67 lines
2.3 KiB
Python
67 lines
2.3 KiB
Python
import os
|
|
import shutil
|
|
import tarfile
|
|
import zipfile
|
|
import hashlib
|
|
|
|
DIST_DIR = "dist"
|
|
OUT_DIR = "out"
|
|
|
|
def make_zip(source_dir, output_zip):
|
|
with zipfile.ZipFile(output_zip, "w", zipfile.ZIP_DEFLATED) as zf:
|
|
for root, _, files in os.walk(source_dir):
|
|
for file in files:
|
|
full_path = os.path.join(root, file)
|
|
rel_path = os.path.relpath(full_path, source_dir)
|
|
zf.write(full_path, rel_path)
|
|
|
|
def make_tar_gz(source_dir, output_tar):
|
|
with tarfile.open(output_tar, "w:gz") as tf:
|
|
for root, _, files in os.walk(source_dir):
|
|
for file in files:
|
|
full_path = os.path.join(root, file)
|
|
rel_path = os.path.relpath(full_path, source_dir)
|
|
tf.add(full_path, arcname=rel_path)
|
|
|
|
def generate_checksums(dist_dir):
|
|
checksum_file = os.path.join(dist_dir, "SHA256SUMS.txt")
|
|
lines = []
|
|
for fname in sorted(os.listdir(dist_dir)):
|
|
if fname == "SHA256SUMS.txt":
|
|
continue
|
|
fpath = os.path.join(dist_dir, fname)
|
|
if os.path.isfile(fpath):
|
|
with open(fpath, "rb") as f:
|
|
digest = hashlib.sha256(f.read()).hexdigest()
|
|
lines.append(f"{digest} {fname}")
|
|
with open(checksum_file, "w", encoding="utf-8") as f:
|
|
f.write("\n".join(lines) + "\n")
|
|
|
|
def main():
|
|
os.makedirs(DIST_DIR, exist_ok=True)
|
|
|
|
server_src = os.path.join(OUT_DIR, "server")
|
|
win_src = os.path.join(OUT_DIR, "win_client")
|
|
linux_src = os.path.join(OUT_DIR, "linux_client")
|
|
|
|
print("[*] Packaging Server shippable...")
|
|
make_tar_gz(server_src, os.path.join(DIST_DIR, "logar-server.tar.gz"))
|
|
make_zip(server_src, os.path.join(DIST_DIR, "logar-server.zip"))
|
|
|
|
print("[*] Packaging Windows Client shippable...")
|
|
make_zip(win_src, os.path.join(DIST_DIR, "logar-win-client.zip"))
|
|
|
|
print("[*] Packaging Linux Client shippable...")
|
|
make_tar_gz(linux_src, os.path.join(DIST_DIR, "logar-linux-client.tar.gz"))
|
|
|
|
print("[*] Generating SHA-256 checksums...")
|
|
generate_checksums(DIST_DIR)
|
|
|
|
print(f"[+] All release artifacts assembled in '{DIST_DIR}/':")
|
|
for f in os.listdir(DIST_DIR):
|
|
sz = os.path.getsize(os.path.join(DIST_DIR, f))
|
|
print(f" - {f} ({sz} bytes)")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|