Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a script to install tigervnc and remove tigervnc binaries from package #62

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions jupyter_remote_desktop_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@ def setup_desktop():
# This is only readable, writeable & searchable by our uid
sockets_dir = tempfile.mkdtemp()
sockets_path = os.path.join(sockets_dir, 'vnc-socket')
vncserver = which('vncserver')

# Try to find a local install of vncserver script.
# If installed with jupyter-remote-desktop-proxy.install,
# it will by default in of two location based on the tigervnc version:
# - bundled_bin: tigervnc < 1.11.0
# - bundled_exec: tigervnc > 1.11.0
# If no vncserver is found in the default bundled path, which will
# look in the user's PATH. If which return None, vncserver was not found
# and an exception is raised.
bundled_bin = os.path.join(HERE, 'share/tigervnc/bin')
bundled_libexec = os.path.join(HERE, 'share/tigervnc/libexec')
vncserver = which(
cmd='vncserver',
path=f"{bundled_bin}:{bundled_libexec}:{os.environ.get('PATH', os.defpath)}"
)

if vncserver is None:
# Use bundled tigervnc
vncserver = os.path.join(HERE, 'share/tigervnc/bin/vncserver')
raise FileNotFoundError('jupyter-remote-desktop-proxy: could not find vncserver')

# TigerVNC provides the option to connect a Unix socket. TurboVNC does not.
# TurboVNC and TigerVNC share the same origin and both use a Perl script
Expand Down
152 changes: 152 additions & 0 deletions jupyter_remote_desktop_proxy/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import argparse
import hashlib
import os
import platform
import shutil
import tarfile
import textwrap
from urllib.request import HTTPError, urlopen, urlretrieve

from xml.etree import ElementTree

HERE = os.path.dirname(os.path.abspath(__file__))

def checksum_file(path):
"""Compute the md5 checksum of a path"""
hasher = hashlib.md5()
with open(path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hasher.update(chunk)
return hasher.hexdigest()

def fetch_release_info(tigervnc_archive, tigervnc_version):
"""Fetch the download url and md5 checksum from tigervnc release rss"""
url = (
"https://sourceforge.net/projects/tigervnc/rss"
f"?path=/stable/{tigervnc_version}"
)
release_title = f'/stable/{tigervnc_version}/{tigervnc_archive}'
print(f"Fetching md5 and download url from {url}")

with urlopen(url) as f:
tree = ElementTree.parse(f)
root = tree.getroot()
channel = root.find('channel')
for item in channel.iterfind('item'):
title = item.find('title')
if title.text == release_title:
media = item.find('{http://video.search.yahoo.com/mrss/}content')
url = media.get('url')
md5 = media.find('{http://video.search.yahoo.com/mrss/}hash').text
break
else:
raise Exception(f"Could not find a tarball \"{tigervnc_archive}\" on sourceforge.net")
return url, md5


def install_tigervnc(prefix, plat, tigervnc_version):
tigervnc_path = os.path.join(prefix, "bin", "vncconfig")
if os.path.exists(tigervnc_path):
cmd-ntrf marked this conversation as resolved.
Show resolved Hide resolved
print(f"Tigervnc already exists at {tigervnc_path}. Remove it to re-install.")
print("--- Done ---")
return

tigervnc_archive = f"tigervnc-{tigervnc_version}.{plat}.tar.gz"
tigervnc_archive_path = os.path.join(prefix, tigervnc_archive)
try:
tigervnc_url, tigervnc_md5 = fetch_release_info(tigervnc_archive, tigervnc_version)
except HTTPError as e:
print(f"Failed to retrieve md5 and download url: {e}")
return
except Exception as e:
print(f"Failed to retrieve md5 and download url: {e}")
return

print(f"Downloading tigervnc {tigervnc_version} from {tigervnc_url}...")
urlretrieve(tigervnc_url, tigervnc_archive_path)

md5 = checksum_file(tigervnc_archive_path)
if md5 != tigervnc_md5:
raise OSError(f"Checksum failed {md5} != {tigervnc_md5}")

print("Extracting the archive...")
with tarfile.open(tigervnc_archive_path, "r") as tar_ref:
tar_ref.extractall(prefix)

shutil.copytree(
src=f"{prefix}/tigervnc-{tigervnc_version}.{plat}/usr",
dst=prefix,
dirs_exist_ok=True,
)

print(f"Installed tigervnc {tigervnc_version}")
shutil.rmtree(f"{prefix}/tigervnc-{tigervnc_version}.{plat}")
os.unlink(tigervnc_archive_path)
print("--- Done ---")


def main():
# extract supported and default versions from urls
parser = argparse.ArgumentParser(
description="Dependency installer helper",
formatter_class=argparse.RawTextHelpFormatter,
)

parser.add_argument(
"--output",
dest="installation_dir",
default=f"{HERE}/share/tigervnc",
help=textwrap.dedent(
"""\
The installation directory (absolute or relative path).
If it doesn't exist, it will be created.
If no directory is provided, it defaults to:
--- %(default)s ---
"""
),
)

machine = platform.machine()
parser.add_argument(
"--platform",
dest="plat",
default=machine,
help=textwrap.dedent(
"""\
The platform to download for.
If no platform is provided, it defaults to:
--- %(default)s ---
"""
),
)

parser.add_argument(
"--tigervnc-version",
dest="tigervnc_version",
default="1.10.1",
choices=["1.10.1", "1.10.0", "1.9.0"],
help=textwrap.dedent(
"""\
The version of tigervnc to download.
If no version is provided, it defaults to:
--- %(default)s ---
"""
),
)

args = parser.parse_args()
deps_dir = args.installation_dir
plat = args.plat
tigervnc_version = args.tigervnc_version.lstrip("v")

if os.path.exists(deps_dir):
print(f"Using existing output directory {deps_dir}...")
else:
print(f"Creating output directory {deps_dir}...")
os.makedirs(deps_dir)

install_tigervnc(deps_dir, plat, tigervnc_version)


if __name__ == "__main__":
main()
Binary file removed jupyter_remote_desktop_proxy/share/tigervnc/bin/Xvnc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading