81 行
3.4 KiB
Python
81 行
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Build a self-contained native fnOS FPK with the validated Linux driver."""
|
|
from pathlib import Path
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import shutil
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
import zlib
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
stage = ROOT / 'build/fpk'
|
|
if stage.exists():
|
|
shutil.rmtree(stage)
|
|
shutil.copytree(ROOT / 'packaging/fpk', stage)
|
|
(stage / 'wizard').mkdir(exist_ok=True)
|
|
(stage / 'wizard/.gitkeep').touch()
|
|
app = stage / 'app'
|
|
for path in (ROOT / 'application').iterdir():
|
|
if path.is_file():
|
|
shutil.copy2(path, app / path.name)
|
|
shutil.copy2(ROOT / 'scripts/copy-directories.py', app / 'copy_worker.py')
|
|
shutil.copy2(ROOT / 'scripts/save-xattrs.py', app / 'save_xattrs.py')
|
|
(app / 'bin').mkdir()
|
|
for name, expected in [('apfs-fuse','89a7083c42fb498b021d9f7fabbc5b754eaae503649500e4926965fdcfbcb11e'),
|
|
('apfsutil','692bbd961678c5db1a48e00cb2bc96c50e82dd77e39d87cfe11087608b4658ae')]:
|
|
binary = ROOT / 'build/linux-bin' / name
|
|
if hashlib.sha256(binary.read_bytes()).hexdigest() != expected:
|
|
raise SystemExit('Driver hash mismatch: ' + name)
|
|
shutil.copy2(binary, app / 'bin' / name)
|
|
(app / 'bin' / name).chmod(0o755)
|
|
shutil.copytree(ROOT / 'vendor/apfs-fuse', app / 'source/apfs-fuse')
|
|
shutil.copy2(ROOT / 'UPSTREAM.json', app / 'source/UPSTREAM.json')
|
|
shutil.copy2(ROOT / 'packaging/Dockerfile', app / 'source/Dockerfile')
|
|
for path in (stage / 'cmd').iterdir():
|
|
path.chmod(0o755)
|
|
|
|
|
|
def icon(size):
|
|
def chunk(kind, payload):
|
|
return struct.pack('>I', len(payload)) + kind + payload + struct.pack('>I', zlib.crc32(kind + payload) & 0xffffffff)
|
|
rows = []
|
|
for y in range(size):
|
|
row = bytearray()
|
|
for x in range(size):
|
|
px, py = x * 256 / size, y * 256 / size
|
|
radius = 50
|
|
dx, dy = max(abs(px - 128) - 78, 0), max(abs(py - 128) - 78, 0)
|
|
inside = dx * dx + dy * dy <= radius * radius
|
|
color = (22, 118, 102, 255) if inside else (0, 0, 0, 0)
|
|
if 53 <= px <= 203 and 62 <= py <= 192 and (px < 63 or px > 193 or py < 72 or py > 182 or 144 < py < 153):
|
|
color = (255, 255, 255, 255)
|
|
if 78 <= px <= 90 and 164 <= py <= 172:
|
|
color = (255, 255, 255, 255)
|
|
if 100 <= px <= 126 and abs(py - (px - 3)) < 5 or 122 <= px <= 165 and abs(py - (249 - px)) < 5:
|
|
color = (158, 229, 199, 255)
|
|
row.extend(color)
|
|
rows.append(b'\0' + row)
|
|
return b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', struct.pack('>IIBBBBB', size, size, 8, 6, 0, 0, 0)) + chunk(b'IDAT', zlib.compress(b''.join(rows))) + chunk(b'IEND', b'')
|
|
|
|
|
|
images = app / 'ui/images'
|
|
images.mkdir(exist_ok=True)
|
|
for size in (64, 256):
|
|
payload = icon(size)
|
|
(images / ('icon_' + str(size) + '.png')).write_bytes(payload)
|
|
(stage / ('ICON.PNG' if size == 64 else 'ICON_256.PNG')).write_bytes(payload)
|
|
subprocess.run([sys.argv[1], 'build', '--directory', str(stage)], cwd=stage, check=True)
|
|
output = ROOT / 'dist'
|
|
output.mkdir(exist_ok=True)
|
|
packages = list(stage.glob('*.fpk'))
|
|
if len(packages) != 1:
|
|
raise SystemExit('Expected one FPK package')
|
|
version = next(line.split('=',1)[1].strip() for line in (stage / 'manifest').read_text().splitlines() if line.startswith('version='))
|
|
destination = output / ('dayu-diskcopy-' + version + '-x86.fpk')
|
|
shutil.copy2(packages[0], destination)
|
|
print(destination)
|
|
print('sha256:', hashlib.sha256(destination.read_bytes()).hexdigest())
|