Create remotedesk.py
Browse files- remotedesk.py +69 -0
remotedesk.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CRD:
|
| 2 |
+
def __init__(self, user):
|
| 3 |
+
os.system("apt update")
|
| 4 |
+
self.installCRD()
|
| 5 |
+
self.installDesktopEnvironment()
|
| 6 |
+
self.installGoogleChorme()
|
| 7 |
+
self.finish(user)
|
| 8 |
+
print("\nRDP created succesfully move to https://remotedesktop.google.com/access")
|
| 9 |
+
|
| 10 |
+
@staticmethod
|
| 11 |
+
def installCRD():
|
| 12 |
+
print("Installing Chrome Remote Desktop")
|
| 13 |
+
subprocess.run(['wget', 'https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb'], stdout=subprocess.PIPE)
|
| 14 |
+
subprocess.run(['dpkg', '--install', 'chrome-remote-desktop_current_amd64.deb'], stdout=subprocess.PIPE)
|
| 15 |
+
subprocess.run(['apt', 'install', '--assume-yes', '--fix-broken'], stdout=subprocess.PIPE)
|
| 16 |
+
|
| 17 |
+
@staticmethod
|
| 18 |
+
def installDesktopEnvironment():
|
| 19 |
+
print("Installing Desktop Environment")
|
| 20 |
+
os.system("export DEBIAN_FRONTEND=noninteractive")
|
| 21 |
+
os.system("apt install --assume-yes xfce4 desktop-base xfce4-terminal")
|
| 22 |
+
os.system("bash -c 'echo \"exec /etc/X11/Xsession /usr/bin/xfce4-session\" > /etc/chrome-remote-desktop-session'")
|
| 23 |
+
os.system("apt remove --assume-yes gnome-terminal")
|
| 24 |
+
os.system("apt install --assume-yes xscreensaver")
|
| 25 |
+
os.system("systemctl disable lightdm.service")
|
| 26 |
+
|
| 27 |
+
@staticmethod
|
| 28 |
+
def installGoogleChorme():
|
| 29 |
+
print("Installing Google Chrome")
|
| 30 |
+
subprocess.run(["wget", "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"], stdout=subprocess.PIPE)
|
| 31 |
+
subprocess.run(["dpkg", "--install", "google-chrome-stable_current_amd64.deb"], stdout=subprocess.PIPE)
|
| 32 |
+
subprocess.run(['apt', 'install', '--assume-yes', '--fix-broken'], stdout=subprocess.PIPE)
|
| 33 |
+
|
| 34 |
+
@staticmethod
|
| 35 |
+
def finish(user):
|
| 36 |
+
print("Finalizing")
|
| 37 |
+
if Autostart:
|
| 38 |
+
os.makedirs(f"/home/{user}/.config/autostart", exist_ok=True)
|
| 39 |
+
link = "https://colab.research.google.com/github/PradyumnaKrishna/Colab-Hacks/blob/master/Colab%20RDP/Colab%20RDP.ipynb"
|
| 40 |
+
colab_autostart = """[Desktop Entry]
|
| 41 |
+
Type=Application
|
| 42 |
+
Name=Colab
|
| 43 |
+
Exec=sh -c "sensible-browser {}"
|
| 44 |
+
Icon=
|
| 45 |
+
Comment=Open a predefined notebook at session signin.
|
| 46 |
+
X-GNOME-Autostart-enabled=true""".format(link)
|
| 47 |
+
with open(f"/home/{user}/.config/autostart/colab.desktop", "w") as f:
|
| 48 |
+
f.write(colab_autostart)
|
| 49 |
+
os.system(f"chmod +x /home/{user}/.config/autostart/colab.desktop")
|
| 50 |
+
os.system(f"chown {user}:{user} /home/{user}/.config")
|
| 51 |
+
|
| 52 |
+
os.system(f"adduser {user} chrome-remote-desktop")
|
| 53 |
+
command = f"{CRP} --pin={Pin}"
|
| 54 |
+
os.system(f"su - {user} -c '{command}'")
|
| 55 |
+
os.system("service chrome-remote-desktop start")
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
print("Finished Succesfully")
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
if CRP == "":
|
| 63 |
+
print("Please enter authcode from the given link")
|
| 64 |
+
elif len(str(Pin)) < 6:
|
| 65 |
+
print("Enter a pin more or equal to 6 digits")
|
| 66 |
+
else:
|
| 67 |
+
CRD(username)
|
| 68 |
+
except NameError as e:
|
| 69 |
+
print("'username' variable not found, Create a user first")
|