RDP Google Colab Gpu Vncremote
RDP Google Colab Gpu Vncremote
RDP Google Colab Gpu Vncremote
class _NoteProgress(apt.progress.base.InstallProgress,
apt.progress.base.AcquireProgress, apt.progress.base.OpProgress):
def __init__(self):
apt.progress.base.InstallProgress.__init__(self)
self._label = ipywidgets.Label()
display(self._label)
self._float_progress = ipywidgets.FloatProgress(min = 0.0, max = 1.0, layout =
{'border':'1px solid #118800'})
display(self._float_progress)
def close(self):
self._float_progress.close()
self._label.close()
class _MyApt:
def __init__(self):
self._progress = _NoteProgress()
self._cache = apt.Cache(self._progress)
def close(self):
self._cache.close()
self._cache = None
self._progress.close()
self._progress = None
def update_upgrade(self):
self._cache.update()
self._cache.open(None)
self._cache.upgrade()
def commit(self):
self._cache.commit(self._progress, self._progress)
self._cache.clear()
def _get_gpu_name():
r = subprocess.run(["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
stdout = subprocess.PIPE, universal_newlines = True)
if r.returncode != 0:
return None
return r.stdout.strip()
def _check_gpu_available():
gpu_name = _get_gpu_name()
if gpu_name == None:
print("This is not a runtime with GPU")
else:
return True
return True
msg = ""
if not os.path.exists('ngrok.zip'):
_download("https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip",
"ngrok.zip")
shutil.unpack_archive("ngrok.zip")
pathlib.Path("ngrok").chmod(stat.S_IXUSR)
root_password = "12345678"
user_password = "12345678"
user_name = "colab"
msg += "✂ï¸"*24 + "\n"
msg += f"root password: {root_password}\n"
msg += f"{user_name} password: {user_password}\n"
msg += "✂ï¸"*24 + "\n"
subprocess.run(["useradd", "-s", "/bin/bash", "-m", user_name])
subprocess.run(["adduser", user_name, "sudo"], check = True)
subprocess.run(["chpasswd"], input = f"root:{root_password}", universal_newlines
= True)
subprocess.run(["chpasswd"], input = f"{user_name}:{user_password}",
universal_newlines = True)
if not pathlib.Path('/root/.ngrok2/ngrok.yml').exists():
subprocess.run(["./ngrok", "authtoken", ngrok_token])
hostname = m.group(1)
port = m.group(2)
if is_VNC:
msg += "Ready to Connect TurboVNC viewer:\n"
msg += f"{hostname}:{port}\n"
return msg
gpu_name = _get_gpu_name()
if gpu_name == None:
print("------------------------------")
if not ngrok_region:
print("Select your ngrok region :")
print("us - United States (Ohio)")
print("eu - Europe (Frankfurt)")
print("ap - Asia/Pacific (Singapore)")
print("au - Australia (Sydney)")
print("sa - South America (Sao Paulo)")
print("jp - Japan (Tokyo)")
print("in - India (Mumbai)")
ngrok_region = region = input()
clear_output()
apps()
#https://virtualgl.org/Documentation/HeadlessNV
subprocess.run(["nvidia-xconfig",
"-a",
"--allow-empty-initial-configuration",
"--virtual=1920x1200",
"--busid", "PCI:0:4:0"],
check = True
)
def _setupVNC():
libjpeg_ver = "2.0.5"
virtualGL_ver = "2.6.4"
turboVNC_ver = "2.2.5"
libjpeg_url =
"https://github.com/demotomohiro/turbovnc/releases/download/2.2.5/libjpeg-turbo-
official_{0}_amd64.deb".format(libjpeg_ver)
virtualGL_url =
"https://github.com/demotomohiro/turbovnc/releases/download/2.2.5/virtualgl_{0}_amd
64.deb".format(virtualGL_ver)
turboVNC_url =
"https://github.com/demotomohiro/turbovnc/releases/download/2.2.5/turbovnc_{0}_amd6
4.deb".format(turboVNC_ver)
_download(libjpeg_url, "libjpeg-turbo.deb")
_download(virtualGL_url, "virtualgl.deb")
_download(turboVNC_url, "turbovnc.deb")
my_apt = _MyApt()
my_apt.installDebPackage("libjpeg-turbo.deb")
my_apt.installDebPackage("virtualgl.deb")
my_apt.installDebPackage("turbovnc.deb")
my_apt.commit()
my_apt.close()
vnc_sec_conf_p = pathlib.Path("/etc/turbovncserver-security.conf")
vnc_sec_conf_p.write_text("""\
no-remote-connections
no-httpd
no-x11-tcp-connections
""")
gpu_name = _get_gpu_name()
if gpu_name != None:
_setup_nvidia_gl()
vnc_passwd = "12345678"[:8]
vnc_viewonly_passwd = "87654321"[:8]
print("✂ï¸"*24)
print("VNC password: {}".format(vnc_passwd))
print("VNC view only password: {}".format(vnc_viewonly_passwd))
print("✂ï¸"*24)
vncpasswd_input = "{0}\\n{1}".format(vnc_passwd, vnc_viewonly_passwd)
vnc_user_dir = pathlib.Path.home().joinpath(".vnc")
vnc_user_dir.mkdir(exist_ok=True)
vnc_user_passwd = vnc_user_dir.joinpath("passwd")
with vnc_user_passwd.open('wb') as f:
subprocess.run(
["/opt/TurboVNC/bin/vncpasswd", "-f"],
stdout=f,
input=vncpasswd_input,
universal_newlines=True)
vnc_user_passwd.chmod(0o600)
subprocess.run(
["/opt/TurboVNC/bin/vncserver"],
cwd = pathlib.Path.home()
)
def apps():
!sudo add-apt-repository ppa:obsproject/obs-studio -y
clear_output()
my_apt = _MyApt()
my_apt.installPkg("obs-studio", "vlc", "firefox", "xarchiver", "xfce4", "xfce4-
goodies")
my_apt.commit()
clear_output()
setupVNC()