Verified Commit 28534614 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

Bug 34451: Include Tor Browser Manual in packages during build

Include an output of the Tor Browser manual optimized for offline docs
in the browser/omni.ja file.

See also tor-browser#11698.
parent 6553058c
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
1. Go to https://gitlab.torproject.org/tpo/web/manual/-/jobs/
2. Open the latest build stage
3. Download the artifacts (they come in a .zip file).
4. Rename it to manual_$PIPELINEID.zip
5. Upload it to people.tpo
6. Update projects/manual/config
   6.1 Change the version to $PIPELINEID
   6.2 Update the URL if it was different from the previous uploader

projects/manual/build

0 → 100644
+11 −0
Original line number Diff line number Diff line
#!/bin/bash
[% c("var/set_default_env") -%]

mkdir -p chrome/browser/content/browser/manual
unzip $rootdir/[% c('input_files_by_name/manual') %]
python3 $rootdir/[% c('input_files_by_name/package_script') %] public chrome/browser/content/browser/manual

[% c('tar', {
        tar_src => [ 'chrome' ],
        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
    }) %]

projects/manual/config

0 → 100644
+21 −0
Original line number Diff line number Diff line
# To update, see doc/how-to-update-the-manual.txt
version: 40628
filename: 'manual-[% c("version") %].tar.gz'

var:
  container:
    use_container: 1
    suite: bullseye
    arch: amd64
  deps:
    - python3
    - unzip
  pre_pkginst: ''

input_files:
  - project: container-image
  - URL: 'https://people.torproject.org/~pierov/tbb_files/manual_[% c("version") %].zip'
    name: manual
    sha256sum: 64bab7e8b26014277b55cf2afc4f676f3a164f466fc33e72aa62004318994c3a
  - filename: packagemanual.py
    name: package_script
+50 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
from pathlib import Path
import re
import sys
import shutil


PAGE_NAME = 'offline-docs'
STATIC_PATH = 'chrome://browser/content/manual/static'

if len(sys.argv) < 3:
    print(f'Usage: {sys.argv[0]} lektor-out-directory target-directory')
    sys.exit(1)

source = Path(sys.argv[1])
target = Path(sys.argv[2])
if not target.exists():
    target.mkdir(exist_ok=True)

static_re = re.compile('"(?:../)*static/([^"]+)"')
link_re = re.compile('href="../([^"]+)"')


def clean_urls(match):
    m = re.match(r'(?:../)?([^/#]+)[/]?[#]?(.*)', match.group(1))
    slug = m.group(1)
    if m.group(2):
        anchor = '_' + m.group(2)
    else:
        anchor = ''
    return f'href="#{slug}{anchor}"'


htmls = source.rglob(f'{PAGE_NAME}/index.html')
for page in htmls:
    with page.open(encoding='utf8') as f:
        contents = f.read()
    contents = static_re.sub(f'"{STATIC_PATH}/\\1"', contents)
    contents = link_re.sub(clean_urls, contents)

    rel = page.relative_to(source)
    dest_name = str(list(rel.parents)[-2].name)
    if dest_name == PAGE_NAME:
        dest_name = 'en'
    dest_name += '.html'
    with (target / dest_name).open('w', encoding='utf8') as f:
        f.write(contents)

shutil.rmtree(target / 'static', ignore_errors=True)
shutil.copytree(source / 'static', target / 'static')
+10 −0
Original line number Diff line number Diff line
@@ -83,6 +83,16 @@ find chrome/ | sort | zip -X -@ "$TBDIR[% IF c("var/osx") %]/Contents/Resources[
popd
rm -rf $TMP_HTTPS_EVERYWHERE_PATH

# Include the Tor Browser manual
TMP_MANUAL_PATH=$rootdir/tmp_manual/
mkdir $TMP_MANUAL_PATH
pushd $TMP_MANUAL_PATH
tar -xf $rootdir/[% c('input_files_by_name/manual') %]
find . -exec [% c("var/touch") %] {} \;
find chrome/ | sort | zip -X -@ "$TBDIR[% IF c("var/osx") %]/Contents/Resources[% END %]/browser/omni.ja"
popd
rm -rf $TMP_MANUAL_PATH

tar -C "$TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %]" -xf [% c('input_files_by_name/tor') %]/tor.tar.gz
[% IF c("var/namecoin") %]
  # Extract Electrum-NMC
Loading