mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-06 08:25:15 -04:00
Make scripts to build PT binaries, and run those in CI
This commit is contained in:
parent
7526141024
commit
8ff1a0b294
10 changed files with 187 additions and 336 deletions
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
import platform
|
||||
import inspect
|
||||
import os
|
||||
from re import M
|
||||
|
@ -8,18 +7,30 @@ import hashlib
|
|||
import shutil
|
||||
import subprocess
|
||||
import requests
|
||||
import click
|
||||
|
||||
torbrowser_version = "11.0.14"
|
||||
expected_exe_sha256 = "c14b979c81310ad039985e047dbb5b8058662bb3105b9022f7b9e0d18a29d0d6"
|
||||
expected_dmg_sha256 = "558ae5ab188f62feb04c6b2e7f43eae2361e8ec1718e0f4f927801411d911e22"
|
||||
expected_txz_sha256 = "b606924fdf8237e697cf95c229189da5875c190875d729769655c7b67aeb9aa6"
|
||||
expected_win32_sha256 = (
|
||||
"c14b979c81310ad039985e047dbb5b8058662bb3105b9022f7b9e0d18a29d0d6"
|
||||
)
|
||||
expected_win64_sha256 = (
|
||||
"ced3de06d089fbbeb8cee309971ac26983aba8eaf948fedce472d40cdd572301"
|
||||
)
|
||||
expected_macos_sha256 = (
|
||||
"558ae5ab188f62feb04c6b2e7f43eae2361e8ec1718e0f4f927801411d911e22"
|
||||
)
|
||||
expected_linux64_sha256 = (
|
||||
"b606924fdf8237e697cf95c229189da5875c190875d729769655c7b67aeb9aa6"
|
||||
)
|
||||
|
||||
exe_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/torbrowser-install-{torbrowser_version}_en-US.exe"
|
||||
exe_filename = f"torbrowser-install-{torbrowser_version}_en-US.exe"
|
||||
dmg_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/TorBrowser-{torbrowser_version}-osx64_en-US.dmg"
|
||||
dmg_filename = f"TorBrowser-{torbrowser_version}-osx64_en-US.dmg"
|
||||
tarball_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/tor-browser-linux64-{torbrowser_version}_en-US.tar.xz"
|
||||
tarball_filename = f"tor-browser-linux64-{torbrowser_version}_en-US.tar.xz"
|
||||
win32_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/torbrowser-install-{torbrowser_version}_en-US.exe"
|
||||
win32_filename = f"torbrowser-install-{torbrowser_version}_en-US.exe"
|
||||
win64_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/torbrowser-install-win64-{torbrowser_version}_en-US.exe"
|
||||
win64_filename = f"torbrowser-install-win64-{torbrowser_version}_en-US.exe"
|
||||
macos_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/TorBrowser-{torbrowser_version}-osx64_en-US.dmg"
|
||||
macos_filename = f"TorBrowser-{torbrowser_version}-osx64_en-US.dmg"
|
||||
linux64_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/tor-browser-linux64-{torbrowser_version}_en-US.tar.xz"
|
||||
linux64_filename = f"tor-browser-linux64-{torbrowser_version}_en-US.tar.xz"
|
||||
|
||||
|
||||
# Common paths
|
||||
|
@ -29,9 +40,21 @@ root_path = os.path.dirname(
|
|||
working_path = os.path.join(root_path, "build", "tor")
|
||||
|
||||
|
||||
def get_tor_windows():
|
||||
def get_tor_windows(platform):
|
||||
if platform == "win32":
|
||||
win_url = win32_url
|
||||
win_filename = win32_filename
|
||||
expected_win_sha256 = expected_win32_sha256
|
||||
elif platform == "win64":
|
||||
win_url = win64_url
|
||||
win_filename = win64_filename
|
||||
expected_win_sha256 = expected_win64_sha256
|
||||
else:
|
||||
click.echo("invalid platform")
|
||||
return
|
||||
|
||||
# Build paths
|
||||
exe_path = os.path.join(working_path, exe_filename)
|
||||
win_path = os.path.join(working_path, win_filename)
|
||||
dist_path = os.path.join(root_path, "onionshare", "resources", "tor")
|
||||
|
||||
# Make sure the working folder exists
|
||||
|
@ -39,21 +62,21 @@ def get_tor_windows():
|
|||
os.makedirs(working_path)
|
||||
|
||||
# Make sure Tor Browser is downloaded
|
||||
if not os.path.exists(exe_path):
|
||||
print("Downloading {}".format(exe_url))
|
||||
r = requests.get(exe_url)
|
||||
open(exe_path, "wb").write(r.content)
|
||||
if not os.path.exists(win_path):
|
||||
print("Downloading {}".format(win_url))
|
||||
r = requests.get(win_url)
|
||||
open(win_path, "wb").write(r.content)
|
||||
exe_sha256 = hashlib.sha256(r.content).hexdigest()
|
||||
else:
|
||||
print("Already downloaded: {}".format(exe_path))
|
||||
exe_data = open(exe_path, "rb").read()
|
||||
exe_sha256 = hashlib.sha256(exe_data).hexdigest()
|
||||
print("Already downloaded: {}".format(win_path))
|
||||
win_data = open(win_path, "rb").read()
|
||||
win_sha256 = hashlib.sha256(win_data).hexdigest()
|
||||
|
||||
# Compare the hash
|
||||
if exe_sha256 != expected_exe_sha256:
|
||||
if win_sha256 != expected_win_sha256:
|
||||
print("ERROR! The sha256 doesn't match:")
|
||||
print("expected: {}".format(expected_exe_sha256))
|
||||
print(" actual: {}".format(exe_sha256))
|
||||
print("expected: {}".format(expected_win32_sha256))
|
||||
print(" actual: {}".format(win_sha256))
|
||||
sys.exit(-1)
|
||||
|
||||
# Extract the bits we need from the exe
|
||||
|
@ -62,7 +85,7 @@ def get_tor_windows():
|
|||
"7z",
|
||||
"e",
|
||||
"-y",
|
||||
exe_path,
|
||||
win_path,
|
||||
"Browser\\TorBrowser\\Tor",
|
||||
"-o%s" % os.path.join(working_path, "Tor"),
|
||||
]
|
||||
|
@ -72,7 +95,7 @@ def get_tor_windows():
|
|||
"7z",
|
||||
"e",
|
||||
"-y",
|
||||
exe_path,
|
||||
win_path,
|
||||
"Browser\\TorBrowser\\Data\\Tor\\geoip*",
|
||||
"-o%s" % os.path.join(working_path, "Data"),
|
||||
]
|
||||
|
@ -113,7 +136,7 @@ def get_tor_macos():
|
|||
dmg_tor_path = os.path.join(
|
||||
"/Volumes", "Tor Browser", "Tor Browser.app", "Contents"
|
||||
)
|
||||
dmg_path = os.path.join(working_path, dmg_filename)
|
||||
dmg_path = os.path.join(working_path, macos_filename)
|
||||
dist_path = os.path.join(root_path, "onionshare", "resources", "tor")
|
||||
if not os.path.exists(dist_path):
|
||||
os.makedirs(dist_path, exist_ok=True)
|
||||
|
@ -124,8 +147,8 @@ def get_tor_macos():
|
|||
|
||||
# Make sure the zip is downloaded
|
||||
if not os.path.exists(dmg_path):
|
||||
print("Downloading {}".format(dmg_url))
|
||||
r = requests.get(dmg_url)
|
||||
print("Downloading {}".format(macos_url))
|
||||
r = requests.get(macos_url)
|
||||
open(dmg_path, "wb").write(r.content)
|
||||
dmg_sha256 = hashlib.sha256(r.content).hexdigest()
|
||||
else:
|
||||
|
@ -133,9 +156,9 @@ def get_tor_macos():
|
|||
dmg_sha256 = hashlib.sha256(dmg_data).hexdigest()
|
||||
|
||||
# Compare the hash
|
||||
if dmg_sha256 != expected_dmg_sha256:
|
||||
if dmg_sha256 != expected_macos_sha256:
|
||||
print("ERROR! The sha256 doesn't match:")
|
||||
print("expected: {}".format(expected_dmg_sha256))
|
||||
print("expected: {}".format(expected_macos_sha256))
|
||||
print(" actual: {}".format(dmg_sha256))
|
||||
sys.exit(-1)
|
||||
|
||||
|
@ -182,9 +205,9 @@ def get_tor_macos():
|
|||
update_tor_bridges()
|
||||
|
||||
|
||||
def get_tor_linux():
|
||||
def get_tor_linux64():
|
||||
# Build paths
|
||||
tarball_path = os.path.join(working_path, tarball_filename)
|
||||
tarball_path = os.path.join(working_path, linux64_filename)
|
||||
dist_path = os.path.join(root_path, "onionshare", "resources", "tor")
|
||||
|
||||
# Make sure dirs exist
|
||||
|
@ -196,8 +219,8 @@ def get_tor_linux():
|
|||
|
||||
# Make sure the tarball is downloaded
|
||||
if not os.path.exists(tarball_path):
|
||||
print("Downloading {}".format(tarball_url))
|
||||
r = requests.get(tarball_url)
|
||||
print("Downloading {}".format(linux64_url))
|
||||
r = requests.get(linux64_url)
|
||||
open(tarball_path, "wb").write(r.content)
|
||||
tarball_sha256 = hashlib.sha256(r.content).hexdigest()
|
||||
else:
|
||||
|
@ -205,9 +228,9 @@ def get_tor_linux():
|
|||
tarball_sha256 = hashlib.sha256(tarball_data).hexdigest()
|
||||
|
||||
# Compare the hash
|
||||
if tarball_sha256 != expected_txz_sha256:
|
||||
if tarball_sha256 != expected_linux64_sha256:
|
||||
print("ERROR! The sha256 doesn't match:")
|
||||
print("expected: {}".format(expected_txz_sha256))
|
||||
print("expected: {}".format(expected_linux64_sha256))
|
||||
print(" actual: {}".format(tarball_sha256))
|
||||
sys.exit(-1)
|
||||
|
||||
|
@ -250,18 +273,6 @@ def get_tor_linux():
|
|||
os.path.join(tarball_tor_path, "Tor", "libstdc++", "libstdc++.so.6"),
|
||||
os.path.join(dist_path, "libstdc++.so.6"),
|
||||
)
|
||||
shutil.copyfile(
|
||||
os.path.join(tarball_tor_path, "Tor", "PluggableTransports", "obfs4proxy"),
|
||||
os.path.join(dist_path, "obfs4proxy"),
|
||||
)
|
||||
os.chmod(os.path.join(dist_path, "obfs4proxy"), 0o755)
|
||||
shutil.copyfile(
|
||||
os.path.join(
|
||||
tarball_tor_path, "Tor", "PluggableTransports", "snowflake-client"
|
||||
),
|
||||
os.path.join(dist_path, "snowflake-client"),
|
||||
)
|
||||
os.chmod(os.path.join(dist_path, "snowflake-client"), 0o755)
|
||||
|
||||
print(f"Tor binaries extracted to: {dist_path}")
|
||||
|
||||
|
@ -317,19 +328,27 @@ def update_tor_bridges():
|
|||
f.write(f"Bridge {item}\n")
|
||||
|
||||
|
||||
def main():
|
||||
@click.command()
|
||||
@click.argument("platform")
|
||||
def main(platform):
|
||||
"""
|
||||
Download Tor Browser and extract tor binaries
|
||||
"""
|
||||
system = platform.system()
|
||||
if system == "Windows":
|
||||
get_tor_windows()
|
||||
elif system == "Darwin":
|
||||
valid_platforms = ["win32", "win64", "macos", "linux64"]
|
||||
if platform not in valid_platforms:
|
||||
click.echo(f"platform must be one of: {valid_platforms}")
|
||||
return
|
||||
|
||||
if platform == "win32":
|
||||
get_tor_windows(platform)
|
||||
elif platform == "win64":
|
||||
get_tor_windows(platform)
|
||||
elif platform == "macos":
|
||||
get_tor_macos()
|
||||
elif system == "Linux":
|
||||
get_tor_linux()
|
||||
elif platform == "linux64":
|
||||
get_tor_linux64()
|
||||
else:
|
||||
print("Platform not supported")
|
||||
click.echo("invalid platform")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue