Allow onionshare-cli binary made by cx_Freeze find tor binaries in macOS

This commit is contained in:
Micah Lee 2021-12-22 13:08:01 -08:00
parent ba5a746e93
commit 40b4d8f84c
No known key found for this signature in database
GPG key ID: 403C2657CD994F73

View file

@ -337,26 +337,41 @@ class Common:
# If tor.exe isn't there, mayber we're running from the source tree # If tor.exe isn't there, mayber we're running from the source tree
if not os.path.exists(tor_path): if not os.path.exists(tor_path):
base_path = os.path.join(os.getcwd(), "onionshare", "resources", "tor") base_path = os.path.join(os.getcwd(), "onionshare", "resources", "tor")
tor_path = os.path.join(base_path, "Tor", "tor.exe")
tor_path = os.path.join(base_path, "Tor", "tor.exe")
if not os.path.exists(tor_path): if not os.path.exists(tor_path):
print("Error: Cannot find tor.exe") raise CannotFindTor()
obfs4proxy_file_path = os.path.join(base_path, "Tor", "obfs4proxy.exe") obfs4proxy_file_path = os.path.join(base_path, "Tor", "obfs4proxy.exe")
snowflake_file_path = os.path.join(base_path, "Tor", "snowflake-client.exe") snowflake_file_path = os.path.join(base_path, "Tor", "snowflake-client.exe")
meek_client_file_path = os.path.join(base_path, "Tor", "meek-client.exe") meek_client_file_path = os.path.join(base_path, "Tor", "meek-client.exe")
tor_geo_ip_file_path = os.path.join(base_path, "Data", "Tor", "geoip") tor_geo_ip_file_path = os.path.join(base_path, "Data", "Tor", "geoip")
tor_geo_ipv6_file_path = os.path.join(base_path, "Data", "Tor", "geoip6") tor_geo_ipv6_file_path = os.path.join(base_path, "Data", "Tor", "geoip6")
elif self.platform == "Darwin": elif self.platform == "Darwin":
tor_path = shutil.which("tor") # Let's see if we have tor binaries in the onionshare GUI package
if not tor_path: base_path = self.get_resource_path("tor")
raise CannotFindTor() base_path = base_path.replace("onionshare_cli", "onionshare")
obfs4proxy_file_path = shutil.which("obfs4proxy") tor_path = os.path.join(base_path, "tor")
snowflake_file_path = shutil.which("snowflake-client") if os.path.exists(tor_path):
meek_client_file_path = shutil.which("meek-client") obfs4proxy_file_path = os.path.join(base_path, "obfs4proxy")
prefix = os.path.dirname(os.path.dirname(tor_path)) snowflake_file_path = os.path.join(base_path, "snowflake-client")
tor_geo_ip_file_path = os.path.join(prefix, "share/tor/geoip") meek_client_file_path = os.path.join(base_path, "meek-client")
tor_geo_ipv6_file_path = os.path.join(prefix, "share/tor/geoip6") tor_geo_ip_file_path = os.path.join(base_path, "geoip")
tor_geo_ipv6_file_path = os.path.join(base_path, "geoip6")
else:
# Fallback to looking in the path
tor_path = shutil.which("tor")
if not os.path.exists(tor_path):
raise CannotFindTor()
obfs4proxy_file_path = shutil.which("obfs4proxy")
snowflake_file_path = shutil.which("snowflake-client")
meek_client_file_path = shutil.which("meek-client")
prefix = os.path.dirname(os.path.dirname(tor_path))
tor_geo_ip_file_path = os.path.join(prefix, "share/tor/geoip")
tor_geo_ipv6_file_path = os.path.join(prefix, "share/tor/geoip6")
elif self.platform == "BSD": elif self.platform == "BSD":
tor_path = "/usr/local/bin/tor" tor_path = "/usr/local/bin/tor"
tor_geo_ip_file_path = "/usr/local/share/tor/geoip" tor_geo_ip_file_path = "/usr/local/share/tor/geoip"