# SPDX-License-Identifier: GPL-2.0-or-later """Ready: pycdlib ISO authoring + BeautifulSoup HTML edits + stdlib archive reads. 7-Zip/innoextract/unar supplied frozen original embedded files; no Windows EXE runs. No filesystem-format or installer-format parser is implemented here. """ from pathlib import Path from datetime import datetime, timezone from bs4 import BeautifulSoup import argparse, hashlib, io, json, os, shutil, tarfile, zipfile import pycdlib HERE = Path(__file__).resolve().parent def sha(path): h = hashlib.sha256() with path.open('rb') as f: for block in iter(lambda: f.read(1024 * 1024), b''): h.update(block) return h.hexdigest() def main(): ap = argparse.ArgumentParser() ap.add_argument('--out-dir', required=True, type=Path) args = ap.parse_args() if args.out_dir.exists(): raise ValueError('Use a new output directory; previous runs are immutable.') config = json.loads((HERE / 'inputs.json').read_text()) embedded_path = HERE / config['embeddedManifest'] if sha(embedded_path) != config['embeddedManifestSha256']: raise ValueError('Frozen embedded-file manifest changed') embedded = {row['sourcePath']: row for row in json.loads(embedded_path.read_text())} for path, row in embedded.items(): source = Path(path) if path.startswith('/tmp/') else Path(config['workRoot']) / 'inspect' / path.lstrip('/') if source.stat().st_size != row['bytes'] or sha(source) != row['sha256']: raise ValueError('Original embedded bytes changed: ' + path) work = Path(config['workRoot']) original_path = Path(config['original']['file']) if sha(original_path) != config['original']['hashes']['sha256']: raise ValueError('Original ISO SHA mismatch') for row in config['sources']: if sha(Path(row['file'])) != row['sha256']: raise ValueError('Source SHA mismatch: ' + row['name']) args.out_dir.mkdir(parents=True) tree = args.out_dir / 'tree' tree.mkdir() archive = args.out_dir.parent / 'archive' archive.mkdir(exist_ok=True) archived = archive / 'gnuwinII_November_30_2004-original.iso' if not archived.exists(): os.link(original_path, archived) if sha(archived) != config['original']['hashes']['sha256']: raise ValueError('Archived original differs') inventory = json.loads(Path('/tmp/svits-gnuwin-original-20261021/main-directory.json').read_text())['files'] apps = set(config['apps']) original = pycdlib.PyCdlib() original.open(str(original_path)) retained, deleted, added, modified = [], [], [], [] image_names = {'title.png', 'logosmall.gif', 'gwicon.png', 'bullet.gif', 'bulletanim.gif', 'gnuwinCD.jpg', 'gnuwinCD-small.jpg', 'legal.jpg', 'faq.jpg', 'install.jpg'} languages = {'en', 'fr', 'de', 'it', 'es', 'pt', 'ct', 'hi', 'sv', 'hu'} # Keep the original interface structure and reviewed application descriptions. # All installers/archives are replaced by exact portable bytes below, not new applications. for row in inventory: p = row['path'] parts = Path(p).parts keep = p in {'/index.html', '/autorun.inf'} or p.startswith('/gpl/') if len(parts) > 2 and parts[1] == 'apps': keep = (parts[2] in apps and '/install/' not in p and '/doc/' not in p) or parts[2] in languages if len(parts) > 2 and parts[1] in languages: keep = p.endswith('.html') if p.startswith('/classes/'): keep = p.endswith('.html') if p.startswith('/images/'): name = parts[-1] keep = p.startswith('/images/border/') or name in image_names or name in {lang + suffix for lang in languages for suffix in ['.gif', '-small.gif']} if p.startswith('/glossaire/'): keep = p.endswith(('.html', '.gif', '.png')) if keep: target = tree / p.lstrip('/') target.parent.mkdir(parents=True, exist_ok=True) original.get_file_from_iso(str(target), joliet_path=p) retained.append({'originalPath': p, 'outputPath': p, 'bytes': target.stat().st_size, 'sha256': sha(target)}) else: reason = 'Outside this fully reviewed subset; omitted under owner cleanup instruction, not declared prohibited.' if p.startswith('/apps/vidomi/'): reason = 'Entire Vidomi package omitted: exact Product EULA is personal/nonredistributable except encoder.exe.' elif '/install/' in p and len(parts) > 2 and parts[2] in apps: reason = 'Original package omitted; reviewed byte-exact portable application parts retained separately.' deleted.append({'originalPath': p, 'bytes': row['bytes'], 'reason': reason}) original.close() targets = {} def portable(app, source, excluded=()): dest = tree / 'apps' / app / 'en' / 'install' / 'portable' for p in sorted(x for x in source.rglob('*') if x.is_file()): rel = p.relative_to(source) if any(rel.as_posix() == item or rel.parts[0] == item for item in excluded) or p.name.startswith('_extract'): continue target = dest / rel target.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(p, target) added.append({'path': '/' + target.relative_to(tree).as_posix(), 'bytes': target.stat().st_size, 'sha256': sha(target), 'provenance': str(p), 'change': 'Exact embedded bytes; no binary patch'}) return dest up = work / 'unpacked/apps' portable('putty', up / 'putty/en/install/putty-0.55-installer.exe/app') targets['putty'] = 'putty.exe' portable('SciTE', up / 'SciTE/en/install/SciTE-1.57-en-fr-de-es-pt.exe/app') targets['SciTE'] = 'SciTE.exe' # Native README explicitly calls the compiled opening book optional. portable('gnuchess', up / 'gnuchess/en/install/GNUChessSetup.exe/app', {'GNUCHESS.DAT'}) targets['gnuchess'] = 'GNUCHESS.EXE' portable('gnuplot', up / 'gnuplot/en/install/GnuplotSetup.exe/app') targets['gnuplot'] = 'wgnupl32.exe' portable('gpg', up / 'gpg/en/install/gnupg-w32cli-1.2.3.zip') targets['gpg'] = 'gpg.exe' for version in ['nh340win.zip', 'nh342win3.zip']: portable('nethack2', up / ('nethack2/en/install/' + version)) if version == 'nh342win3.zip' else None targets['nethack2'] = 'NetHackW.exe' # Retain the older official release as its unchanged original archive too. nh340 = work / 'inspect/apps/nethack2/en/install/nh340win.zip' nhdest = tree / 'apps/nethack2/en/install/nh340win.zip' nhdest.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(nh340, nhdest) added.append({'path': '/apps/nethack2/en/install/nh340win.zip', 'bytes': nhdest.stat().st_size, 'sha256': sha(nhdest), 'provenance': '/apps/nethack2/en/install/nh340win.zip', 'change': 'Unchanged original archive'}) portable('virtualdub', up / 'virtualdub/en/install/VirtualDub-1.5.10.zip') targets['virtualdub'] = 'VirtualDub.exe' # Vim permits unmodified parts. Omit optional diff/gettext and shell/IDE integration. vim = work / 'gvim-unar/gvim62/Register 0, 1' portable('vim', vim, {'lang', 'keymap', 'libintl.dll', 'diff.exe', 'install.exe', 'uninstal.exe', 'gvimext.dll', 'VisVim.dll'}) targets['vim'] = 'gvim.exe' openssl = tree / 'apps/openssl/en/install/portable' openssl.mkdir(parents=True, exist_ok=True) src = work / 'inspect/apps/openssl/en/install/openssl.exe' shutil.copy2(src, openssl / 'openssl.exe') added.append({'path': '/apps/openssl/en/install/portable/openssl.exe', 'bytes': src.stat().st_size, 'sha256': sha(src), 'provenance': '/apps/openssl/en/install/openssl.exe', 'change': 'Unchanged original PE'}) targets['openssl'] = 'openssl.exe' source_rows = [] for row in config['sources']: name = 'gnuwin-interface-2002-09-06.tar' if row['name'] == 'gnuwin2Source-2002-09-06.tar.gz' else row['name'] target = tree / 'sources' / name target.parent.mkdir(exist_ok=True) shutil.copy2(row['file'], target) source_rows.append({**row, 'outputPath': '/sources/' + name}) notices = tree / 'notices' notices.mkdir() copies = { 'PuTTY-LICENCE.txt': up / 'putty/en/install/putty-0.55-installer.exe/app/LICENCE', 'NetHack-license.txt': up / 'nethack2/en/install/nh342win3.zip/license', 'SciTE-License.txt': up / 'SciTE/en/install/SciTE-1.57-en-fr-de-es-pt.exe/app/License.txt', 'GNUChess-GPL.txt': up / 'gnuchess/en/install/GNUChessSetup.exe/app/DOC/COPYING.TXT', 'gnuplot-Copyright.txt': up / 'gnuplot/en/install/GnuplotSetup.exe/app/Copyright', 'GnuPG-GPL.txt': up / 'gpg/en/install/gnupg-w32cli-1.2.3.zip/COPYING', 'Vim-license.txt': vim / 'doc/uganda.txt', 'VirtualDub-GPL.txt': up / 'virtualdub/en/install/VirtualDub-1.5.10.zip/copying', } for name, path in copies.items(): shutil.copy2(path, notices / name) with tarfile.open(work / 'sources/openssl-0.9.7-git.tar.gz') as t: member = next(m for m in t.getmembers() if m.name.endswith('/LICENSE')) (notices / 'OpenSSL-LICENSE.txt').write_bytes(t.extractfile(member).read()) with tarfile.open(work / 'sources/libpng-1.0.5-git.tar.gz') as t: member = next(m for m in t.getmembers() if m.name.endswith('/png.h')) # The complete original header retains the exact libpng copyright/permission text. (notices / 'libpng-1.0.5-png.h').write_bytes(t.extractfile(member).read()) with tarfile.open(work / 'sources/zlib-1.1.3.tar.gz') as t: member = next(m for m in t.getmembers() if m.name.endswith('/zlib.h')) (notices / 'zlib-1.1.3-zlib.h').write_bytes(t.extractfile(member).read()) for page in sorted(tree.rglob('*.html')): # The historical multilingual pages use several declared encodings. # Let the ready HTML decoder read their actual bytes before UTF-8 output. soup = BeautifulSoup(page.read_bytes(), 'html.parser') for a in list(soup.find_all('a', href=True)): # Removing an omitted