Spaces:
Runtime error
Runtime error
File size: 5,379 Bytes
0e5e412 4eef109 0e5e412 4eef109 0e5e412 70c3898 0e5e412 70c3898 0e5e412 70c3898 0e5e412 d81280a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# import os
# import subprocess
# import logging
# import threading
# # Set up logging
# logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[logging.StreamHandler()])
# def setup_chrome_remote_desktop():
# logging.info("Starting Chrome Remote Desktop setup...")
# # Execute the command with the DISPLAY environment variable set
# command = [
# "bash", "-c",
# 'DISPLAY= /opt/google/chrome-remote-desktop/start-host --code="4/0AQlEd8yLHti1p8P_Oi7Df1oKGRZ50qCxAKWyMj0VGxBzCfRlnmSPa52PcQ51CCdItLHobQ" '
# '--redirect-url="https://remotedesktop.google.com/_/oauthredirect" '
# '--name=$(hostname) '
# '--pin=123456'
# ]
# # Run the command
# subprocess.run(command, shell=False)
# logging.info("Chrome Remote Desktop setup complete.")
# # Run the Chrome Remote Desktop setup in a separate thread
# crd_thread = threading.Thread(target=setup_chrome_remote_desktop)
# crd_thread.start()
# # Keep the container running
# subprocess.run(["tail", "-f", "/dev/null"])
#@title **Create User**
#@markdown Enter Username and Password
import os
username = "mohammed" #@param {type:"string"}
password = "root" #@param {type:"string"}
print("Creating User and Setting it up")
# Creation of user
os.system(f"useradd -m {username}")
# Add user to sudo group
os.system(f"adduser {username} sudo")
# Set password of user to 'root'
os.system(f"echo '{username}:{password}' | sudo chpasswd")
# Change default shell from sh to bash
os.system("sed -i 's/\/bin\/sh/\/bin\/bash/g' /etc/passwd")
print(f"User created and configured having username `{username}` and password `{password}`")
#@title **RDP**
#@markdown It takes 4-5 minutes for installation
import os
import subprocess
#@markdown Visit http://remotedesktop.google.com/headless and copy the command after Authentication
CRP = "DISPLAY= /opt/google/chrome-remote-desktop/start-host --code="4/0AQlEd8yLHti1p8P_Oi7Df1oKGRZ50qCxAKWyMj0VGxBzCfRlnmSPa52PcQ51CCdItLHobQ" --redirect-url="https://remotedesktop.google.com/_/oauthredirect" --name=$(hostname)" #@param {type:"string"}
#@markdown Enter a Pin (more or equal to 6 digits)
Pin = 123456 #@param {type: "integer"}
#@markdown Autostart Notebook in RDP
Autostart = True #@param {type: "boolean"}
class CRD:
def __init__(self, user):
os.system("apt update")
self.installCRD()
self.installDesktopEnvironment()
self.installGoogleChorme()
self.finish(user)
print("\nRDP created succesfully move to https://remotedesktop.google.com/access")
@staticmethod
def installCRD():
print("Installing Chrome Remote Desktop")
subprocess.run(['wget', 'https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb'], stdout=subprocess.PIPE)
subprocess.run(['dpkg', '--install', 'chrome-remote-desktop_current_amd64.deb'], stdout=subprocess.PIPE)
subprocess.run(['apt', 'install', '--assume-yes', '--fix-broken'], stdout=subprocess.PIPE)
@staticmethod
def installDesktopEnvironment():
print("Installing Desktop Environment")
os.system("export DEBIAN_FRONTEND=noninteractive")
os.system("apt install --assume-yes xfce4 desktop-base xfce4-terminal")
os.system("bash -c 'echo \"exec /etc/X11/Xsession /usr/bin/xfce4-session\" > /etc/chrome-remote-desktop-session'")
os.system("apt remove --assume-yes gnome-terminal")
os.system("apt install --assume-yes xscreensaver")
os.system("systemctl disable lightdm.service")
@staticmethod
def installGoogleChorme():
print("Installing Google Chrome")
subprocess.run(["wget", "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"], stdout=subprocess.PIPE)
subprocess.run(["dpkg", "--install", "google-chrome-stable_current_amd64.deb"], stdout=subprocess.PIPE)
subprocess.run(['apt', 'install', '--assume-yes', '--fix-broken'], stdout=subprocess.PIPE)
@staticmethod
def finish(user):
print("Finalizing")
if Autostart:
os.makedirs(f"/home/{user}/.config/autostart", exist_ok=True)
link = "https://colab.research.google.com/github/PradyumnaKrishna/Colab-Hacks/blob/master/Colab%20RDP/Colab%20RDP.ipynb"
colab_autostart = """[Desktop Entry]
Type=Application
Name=Colab
Exec=sh -c "sensible-browser {}"
Icon=
Comment=Open a predefined notebook at session signin.
X-GNOME-Autostart-enabled=true""".format(link)
with open(f"/home/{user}/.config/autostart/colab.desktop", "w") as f:
f.write(colab_autostart)
os.system(f"chmod +x /home/{user}/.config/autostart/colab.desktop")
os.system(f"chown {user}:{user} /home/{user}/.config")
os.system(f"adduser {user} chrome-remote-desktop")
command = f"{CRP} --pin={Pin}"
os.system(f"su - {user} -c '{command}'")
os.system("service chrome-remote-desktop start")
print("Finished Succesfully")
try:
if CRP == "":
print("Please enter authcode from the given link")
elif len(str(Pin)) < 6:
print("Enter a pin more or equal to 6 digits")
else:
CRD(username)
except NameError as e:
print("'username' variable not found, Create a user first")
|