mirror of
				https://github.com/buzz-lightsnack-2007/Desktop-CoLab.git
				synced 2024-08-14 23:57:16 +00:00 
			
		
		
		
	created using Colaboratory
This commit is contained in:
		
							parent
							
								
									16f1f17b84
								
							
						
					
					
						commit
						b1511b6b53
					
				
					 1 changed files with 209 additions and 0 deletions
				
			
		
							
								
								
									
										209
									
								
								DesktopCoLab.ipynb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										209
									
								
								DesktopCoLab.ipynb
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,209 @@ | ||||||
|  | { | ||||||
|  |   "cells": [ | ||||||
|  |     { | ||||||
|  |       "cell_type": "markdown", | ||||||
|  |       "metadata": { | ||||||
|  |         "id": "view-in-github", | ||||||
|  |         "colab_type": "text" | ||||||
|  |       }, | ||||||
|  |       "source": [ | ||||||
|  |         "<a href=\"https://colab.research.google.com/github/buzz-lightsnack-2007/Desktop-CoLab/blob/main/DesktopCoLab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | ||||||
|  |       ] | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       "cell_type": "markdown", | ||||||
|  |       "metadata": { | ||||||
|  |         "id": "-j036FZBO7_O" | ||||||
|  |       }, | ||||||
|  |       "source": [ | ||||||
|  |         "# Desktop@CoLab\n", | ||||||
|  |         "\n", | ||||||
|  |         "**A Linux virtual machine, all in Google's servers.**\n", | ||||||
|  |         "\n", | ||||||
|  |         "<small>_Uses [remocolab](https://urlzs.com/jBN9S) by [demotomohiro](https://urlzs.com/ds5GF)._</small>\n", | ||||||
|  |         "\n", | ||||||
|  |         "---\n", | ||||||
|  |         "\n", | ||||||
|  |         "\n", | ||||||
|  |         "_**Important**: To start a new instance using the same account, please re-set the runtime. Forgetting to do so will cause an error._ \n", | ||||||
|  |         "\n", | ||||||
|  |         "---" | ||||||
|  |       ] | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       "cell_type": "code", | ||||||
|  |       "execution_count": null, | ||||||
|  |       "metadata": { | ||||||
|  |         "cellView": "form", | ||||||
|  |         "id": "Uys7SO6pOod_" | ||||||
|  |       }, | ||||||
|  |       "outputs": [], | ||||||
|  |       "source": [ | ||||||
|  |         "# DESKTOP@COLAB\n", | ||||||
|  |         "# Have a Linux virtual machine hosted by Google. \n", | ||||||
|  |         "\n", | ||||||
|  |         "#@title ## Configuration\n", | ||||||
|  |         "class config: \n", | ||||||
|  |         "  connection = \"SSH only\" #@param [\"SSH only\", \"VNC\"]\n", | ||||||
|  |         "\n", | ||||||
|  |         "  class software: \n", | ||||||
|  |         "  #@markdown ##Software  \n", | ||||||
|  |         "    upgrade_all_binaries = 0 #@param {type:\"slider\", min:0, max:1, step:1}\n", | ||||||
|  |         "\n", | ||||||
|  |         "  class storage: \n", | ||||||
|  |         "    #@markdown ##Storage\n", | ||||||
|  |         "    #@markdown ### Google Drive Storage Integration\n", | ||||||
|  |         "    use = 0 #@param {type:\"slider\", min:0, max:1, step:1}\n", | ||||||
|  |         "    drive_root = 'My Drive' #@param ['My Drive', 'Shared drives'] \n", | ||||||
|  |         "    folder = \"\" #@param {type:\"string\"}\n", | ||||||
|  |         "    drive_folder = '/'.join((drive_root, folder)) # Actual Google Drive folder\n", | ||||||
|  |         "    mount_point = '' #@param {type:\"string\"}\n", | ||||||
|  |         "\n", | ||||||
|  |         "# actual runtime\n", | ||||||
|  |         "## Import modules. \n", | ||||||
|  |         "import os\n", | ||||||
|  |         "\n", | ||||||
|  |         "## Set formatting.\n", | ||||||
|  |         "class formatting:\n", | ||||||
|  |         "  clear = '\\033[0m'\n", | ||||||
|  |         "  class color: \n", | ||||||
|  |         "    purple = '\\033[95m'\n", | ||||||
|  |         "    cyan = '\\033[96m'\n", | ||||||
|  |         "    cyan_dark = '\\033[36m'\n", | ||||||
|  |         "    blue = '\\033[94m'\n", | ||||||
|  |         "    green = '\\033[92m'\n", | ||||||
|  |         "    yellow = '\\033[93m'\n", | ||||||
|  |         "    red = '\\033[91m'\n", | ||||||
|  |         "  class font:\n", | ||||||
|  |         "    bold = '\\033[1m'\n", | ||||||
|  |         "    underline = '\\033[4m'\n", | ||||||
|  |         "\n", | ||||||
|  |         "## Define screen functions. \n", | ||||||
|  |         "def clear(): \n", | ||||||
|  |         "  from IPython.display import clear_output; return clear_output()\n", | ||||||
|  |         "\n", | ||||||
|  |         "class info: # screen messages\n", | ||||||
|  |         "  def status(message):\n", | ||||||
|  |         "    print(formatting.font.bold + 'Status: \\t' + formatting.clear + message)\n", | ||||||
|  |         "  def err(message):\n", | ||||||
|  |         "    print(formatting.font.bold + formatting.color.red + 'Error: \\t' + formatting.clear + formatting.clear + message)\n", | ||||||
|  |         "  def warning(message):\n", | ||||||
|  |         "    print(formatting.font.bold + formatting.color.yellow + 'Warning: \\t' + formatting.clear + formatting.clear + message)\n", | ||||||
|  |         "  def success(message):\n", | ||||||
|  |         "    print(formatting.font.bold + formatting.color.green + 'Success: \\t' + formatting.clear + formatting.clear + message)\n", | ||||||
|  |         "\n", | ||||||
|  |         "\n", | ||||||
|  |         "#try:\n", | ||||||
|  |         "def mount_GDrive():\n", | ||||||
|  |         "  ## Configure storage. \n", | ||||||
|  |         "  info.status('Google Drive integration has been enabled! To properly integrate to your Google Drive, please accept the Google Account permission prompts.')\n", | ||||||
|  |         "  \n", | ||||||
|  |         "  try:\n", | ||||||
|  |         "    from google.colab import drive\n", | ||||||
|  |         "    info.status('Connecting to Google Drive…')\n", | ||||||
|  |         "    drive.mount('/content/drive')\n", | ||||||
|  |         "  \n", | ||||||
|  |         "  except:\n", | ||||||
|  |         "    config.storage.use = 0\n", | ||||||
|  |         "    info.error('Google Drive could not be connected.')\n", | ||||||
|  |         "    info.status('Google Drive integration has been disabled for this instance. ')\n", | ||||||
|  |         "\n", | ||||||
|  |         "  else: \n", | ||||||
|  |         "    info.success('Google Drive has been connected.')\n", | ||||||
|  |         "    clear()\n", | ||||||
|  |         "\n", | ||||||
|  |         "# Upgrade necessary components. \n", | ||||||
|  |         "def update_components():\n", | ||||||
|  |         "  os.system('add-apt-repository ppa:apt-fast/stable -y && apt update && apt install apt-fast -y && apt-fast clean && apt-fast autoremove -y')\n", | ||||||
|  |         "\n", | ||||||
|  |         "  if config.software.upgrade_all_binaries:\n", | ||||||
|  |         "    info.status('Upgrading all binaries.')\n", | ||||||
|  |         "    try:\n", | ||||||
|  |         "      if os.system('apt-fast update && apt-fast upgrade -y && apt-fast clean && apt-fast autoremove -y') > 0: raise\n", | ||||||
|  |         "    except:\n", | ||||||
|  |         "      info.err('An exception has been raised when trying to upgrade one or more of the binaries.')\n", | ||||||
|  |         "    else: \n", | ||||||
|  |         "      info.success('All binaries have been upgraded!')\n", | ||||||
|  |         "\n", | ||||||
|  |         "def install_remoColab():\n", | ||||||
|  |         "  # Install RemoColab. \n", | ||||||
|  |         "  info.status('Installing RemoColab…')\n", | ||||||
|  |         "  try:\n", | ||||||
|  |         "    os.system('pip install git+https://github.com/demotomohiro/remocolab.git')\n", | ||||||
|  |         "    import remocolab\n", | ||||||
|  |         "  except:\n", | ||||||
|  |         "    info.err('Could not install RemoColab.')\n", | ||||||
|  |         "    os.kill(os.getpid(), 1)\n", | ||||||
|  |         "  else:  \n", | ||||||
|  |         "    info.success('Successfully installed RemoColab.')\n", | ||||||
|  |         "\n", | ||||||
|  |         "def establish_connection():\n", | ||||||
|  |         "  import remocolab\n", | ||||||
|  |         "\n", | ||||||
|  |         "  def install_wm():\n", | ||||||
|  |         "    # install xfce. \n", | ||||||
|  |         "    info.status('Installing XFCE.')\n", | ||||||
|  |         "    try:\n", | ||||||
|  |         "      if os.system('apt-fast install xfce4 xfce4-terminal -y') > 0: \n", | ||||||
|  |         "        if os.system('apt install xfce4 xfce4-terminal -y') > 0: raise\n", | ||||||
|  |         "    except:\n", | ||||||
|  |         "      info.err('Could not install the XFCE desktop.')\n", | ||||||
|  |         "      config.connection = 'SSH only'; info.status('VNC connection will be disabled.')\n", | ||||||
|  |         "    else:\n", | ||||||
|  |         "      info.success('Successfully installed the XFCE desktop.')\n", | ||||||
|  |         "\n", | ||||||
|  |         "  if config.connection == 'VNC': install_wm()\n", | ||||||
|  |         "\n", | ||||||
|  |         "  info.status('Setting up ' + config.connection + ' connection. ')\n", | ||||||
|  |         "  if config.connection == 'VNC':\n", | ||||||
|  |         "    if config.storage.use == 1:\n", | ||||||
|  |         "      if config.storage.mount_point != None:\n", | ||||||
|  |         "        remocolab.setupVNC(tunnel = \"argotunnel\", mount_gdrive_from = config.storage.drive_folder, mount_gdrive_to = 'Google Drive')\n", | ||||||
|  |         "      else:  \n", | ||||||
|  |         "        remocolab.setupVNC(tunnel = \"argotunnel\", mount_gdrive_from = config.storage.drive_folder, mount_gdrive_to = 'mount_point')\n", | ||||||
|  |         "    else:\n", | ||||||
|  |         "      remocolab.setupVNC(tunnel = \"argotunnel\")\n", | ||||||
|  |         "    info.success('The VNC connection is available at ' + formatting.font.bold + 'vnc://localhost:5901' + formatting.clear + ' unless stated otherwise.')\n", | ||||||
|  |         "  else:\n", | ||||||
|  |         "    if config.storage.use == 1:\n", | ||||||
|  |         "      try:\n", | ||||||
|  |         "        if config.storage.mount_point != None:\n", | ||||||
|  |         "          remocolab.setupSSHD(tunnel = \"argotunnel\", mount_gdrive_from = config.storage.drive_folder, mount_gdrive_to = 'Google Drive')\n", | ||||||
|  |         "        else:  \n", | ||||||
|  |         "          remocolab.setupSSHD(tunnel = \"argotunnel\", mount_gdrive_from = config.storage.drive_folder, mount_gdrive_to = 'mount_point')\n", | ||||||
|  |         "      except:\n", | ||||||
|  |         "        remocolab.setupSSHD(tunnel = \"argotunnel\")\n", | ||||||
|  |         "    else:\n", | ||||||
|  |         "      remocolab.setupSSHD(tunnel = \"argotunnel\")\n", | ||||||
|  |         "\n", | ||||||
|  |         "def main(): \n", | ||||||
|  |         "  if config.storage.use: mount_GDrive()\n", | ||||||
|  |         "  update_components()\n", | ||||||
|  |         "  install_remoColab()\n", | ||||||
|  |         "  establish_connection()\n", | ||||||
|  |         "\n", | ||||||
|  |         "main()" | ||||||
|  |       ] | ||||||
|  |     } | ||||||
|  |   ], | ||||||
|  |   "metadata": { | ||||||
|  |     "accelerator": "GPU", | ||||||
|  |     "colab": { | ||||||
|  |       "collapsed_sections": [], | ||||||
|  |       "name": "Desktop@CoLab.ipynb", | ||||||
|  |       "provenance": [], | ||||||
|  |       "include_colab_link": true | ||||||
|  |     }, | ||||||
|  |     "kernelspec": { | ||||||
|  |       "display_name": "Python 3 (ipykernel)", | ||||||
|  |       "language": "python", | ||||||
|  |       "name": "python3" | ||||||
|  |     }, | ||||||
|  |     "language_info": { | ||||||
|  |       "name": "python", | ||||||
|  |       "version": "3.10.4" | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "nbformat": 4, | ||||||
|  |   "nbformat_minor": 0 | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue