├── README.md └── codeserver.sh /README.md: -------------------------------------------------------------------------------- 1 | # VS Code Online 2 | 3 | ```code-server``` is [VS Code](https://github.com/Microsoft/vscode) running on a remote server, accessible through the browser. 4 | 5 | I saw this Idea in a [Christiaan Hees](https://medium.com/google-cloud/how-to-run-visual-studio-code-in-google-cloud-shell-354d125d5748) post and made some adjustments to get the procedure done faster. 6 | 7 | ## Usage 8 | 9 | This script runs the latest version of [code-server (VS Code)](https://github.com/cdr/code-server) with just one command. 10 | 11 | ## via curl 12 | ```bash 13 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/renanteixeira/vscodegcs/master/codeserver.sh)" 14 | ``` 15 | 16 | ## via wget 17 | ```bash 18 | sh -c "$(wget https://raw.githubusercontent.com/renanteixeira/vscodegcs/master/codeserver.sh -O -)" 19 | ``` 20 | 21 | ## Running 22 | 23 | > First run, you will have to select the settings. 24 | This screen will create a configuration file in "~/ .config/code-server/config.yaml" 25 | 26 | ![bindAddr](https://user-images.githubusercontent.com/6026211/89003094-378bd780-d2d5-11ea-90c3-ac9e38efcc8a.png) 27 | ![authMode](https://user-images.githubusercontent.com/6026211/89003167-66a24900-d2d5-11ea-9615-425d6b93652d.png) 28 | 29 | > New executions, you will be asked if you want to use the settings already saved or if you want to create new ones. 30 | 31 | ![config](https://user-images.githubusercontent.com/6026211/89003709-e381f280-d2d6-11ea-8e9a-570cc3b963c0.png) 32 | 33 | ```bash 34 | password: (Random string or Custom Password) 35 | 36 | info Using config file ~/.config/code-server/config.yaml 37 | info Using user-data-dir ~/.local/share/code-server 38 | info code-server 3.4.1 48f7c2724827e526eeaa6c2c151c520f48a61259 39 | info HTTP server listening on http://127.0.0.1:8080 40 | info - Using password from ~/.config/code-server/config.yaml 41 | info - To disable use `--auth none` 42 | info - Not serving HTTPS 43 | ``` 44 | 45 | If you are using the local machine, simply access the Localhost address. 46 | 47 | ```bash 48 | http://localhost:8080 49 | ``` 50 | In [Google Cloud Shell](https://cloud.google.com/shell/) click the Web Preview icon and select Preview on port 8080. 51 | 52 | ![GCS Web Preview](https://miro.medium.com/max/636/1*tcyI0xwhSF7Wn1upszdhDA.png) 53 | 54 | I recommend using [Boost Mode in Cloud Shell](https://cloud.google.com/shell/docs/how-cloud-shell-works#boost_mode) before running 55 | 56 | ![Boost Mode](https://miro.medium.com/max/2574/1*D8J4okWRgFRnxo7MhbHGPg.png) 57 | 58 | ## That’s it, now you have an IDE running in your browser! 59 | ![VS Code Online](https://miro.medium.com/max/1996/1*BVCoNecwFAR7vcmaJ9a2gA.png) 60 | 61 | ## FAQ Code Server 62 | See [CDR FAQ](https://github.com/cdr/code-server/blob/master/doc/guide.md). 63 | 64 | ## Contributing 65 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 66 | 67 | ## License 68 | [MIT](https://choosealicense.com/licenses/mit/) -------------------------------------------------------------------------------- /codeserver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eu 3 | 4 | ################################################################### 5 | #Script Name : codeserver.sh 6 | #Description : Run the latest version of Code Server (Visual Studio Code) in the browser. 7 | #Author : Renan Teixeira 8 | #Email : contato@renanteixeira.com.br 9 | #Version : 0.5 - 03/07/2020 - 21:50 10 | ################################################################### 11 | 12 | #Global variables 13 | GREEN="\e[92m" 14 | RED="\e[31m" 15 | END="\e[0m" 16 | BLUE="\e[34m" 17 | YELLOW="\e[33m" 18 | 19 | echo_latest_version() { 20 | version="$(curl -fsSLI -o /dev/null -w "%{url_effective}" https://github.com/cdr/code-server/releases/latest)" 21 | version="${version#https://github.com/cdr/code-server/releases/tag/}" 22 | version="${version#v}" 23 | echo "$version" 24 | } 25 | 26 | VERSION="${VERSION-$(echo_latest_version)}" 27 | 28 | CODE_PATH="$HOME/.config/code-server" 29 | CONFIG_FILE=$CODE_PATH/config.yaml 30 | CODE_FILE=$CODE_PATH/$VERSION/bin/code-server 31 | 32 | main() { 33 | OS="$(os)" 34 | if [ ! "$OS" ]; then 35 | echoerr "Unsupported OS $(uname)." 36 | exit 1 37 | fi 38 | 39 | distro_name 40 | 41 | ARCH="$(arch)" 42 | 43 | if [ ! -d "$CODE_PATH" ]; then 44 | mkdir $CODE_PATH 45 | if [ ! -f $CODE_FILE ]; then 46 | downloadCodeServer 47 | else 48 | runCodeServer 49 | fi 50 | else 51 | clear 52 | runCodeServer 53 | fi 54 | } 55 | 56 | os() { 57 | case "$(uname)" in 58 | Linux) 59 | echo linux 60 | ;; 61 | Darwin) 62 | echo macos 63 | ;; 64 | FreeBSD) 65 | echo freebsd 66 | ;; 67 | esac 68 | } 69 | 70 | distro() { 71 | if [ "$OS" = "macos" ] || [ "$OS" = "freebsd" ]; then 72 | echo "$OS" 73 | return 74 | fi 75 | 76 | if [ -f /etc/os-release ]; then 77 | ( 78 | . /etc/os-release 79 | case "$ID" in opensuse-*) 80 | # opensuse's ID's look like opensuse-leap and opensuse-tumbleweed. 81 | echo "opensuse" 82 | return 83 | ;; 84 | esac 85 | 86 | echo "$ID" 87 | ) 88 | return 89 | fi 90 | } 91 | 92 | # os_name prints a pretty human readable name for the OS/Distro. 93 | distro_name() { 94 | if [ "$(uname)" = "Darwin" ]; then 95 | echo "macOS v$(sw_vers -productVersion)" 96 | return 97 | fi 98 | 99 | if [ -f /etc/os-release ]; then 100 | ( 101 | . /etc/os-release 102 | echo "$PRETTY_NAME" 103 | ) 104 | return 105 | fi 106 | 107 | # Prints something like: Linux 4.19.0-9-amd64 108 | uname -sr 109 | } 110 | 111 | arch() { 112 | case "$(uname -m)" in 113 | aarch64) 114 | echo arm64 115 | ;; 116 | x86_64) 117 | echo amd64 118 | ;; 119 | amd64) # FreeBSD. 120 | echo amd64 121 | ;; 122 | esac 123 | } 124 | 125 | downloadCodeServer(){ 126 | echoh "Downloading standalone release archive v$VERSION from GitHub releases." 127 | echoh 128 | 129 | cd $CODE_PATH 130 | fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$OS-$ARCH.tar.gz" \ 131 | "$VERSION.tar.gz" 132 | 133 | untarCodeServer 134 | } 135 | 136 | untarCodeServer(){ 137 | cd $CODE_PATH 138 | mkdir $VERSION && tar xzf $VERSION.tar.gz -C $VERSION --strip-components 1 139 | 140 | echo "Unpacking completed..." 141 | rm -f $VERSION.tar.gz 142 | 143 | configFile 144 | } 145 | 146 | runCodeServer(){ 147 | if [ -f $CODE_FILE ]; then 148 | printf "${GREEN}" 149 | printf "Code Server Version ${BLUE}$VERSION${END} ${GREEN}exists\n" 150 | echo "Running..." 151 | echo 152 | printf "${END}" 153 | 154 | configFile 155 | else 156 | downloadCodeServer 157 | fi 158 | } 159 | 160 | aboutConfigFile(){ 161 | cath << EOF 162 | The configuration file contains the variables that facilitate the parameterization of the Code Server according to its environment. 163 | 164 | This file is located at $CONFIG_FILE if you need to modify it manually. 165 | 166 | EOF 167 | } 168 | 169 | randomString() { 170 | # Return random alpha-numeric string of given LENGTH 171 | # 172 | # Usage: VALUE=$(randomString $LENGTH) 173 | # or: VALUE=$(randomString) 174 | 175 | local DEFAULT_LENGTH=64 176 | local LENGTH=${1:-$DEFAULT_LENGTH} 177 | 178 | tr -dc A-Za-z0-9 > $CONFIG_FILE;; 241 | 2) echo "Enter the host and port in the format: domain.com:8181" && read bindAddr && echo "bind-addr:" $bindAddr >> $CONFIG_FILE;; 242 | *) newConfigFile ;; 243 | esac 244 | 245 | #auth 246 | echo 247 | printf "${GREEN}" 248 | echo "Authentication mode!" 249 | printf "${END}" 250 | echo 251 | echo "[1] Generate random password" 252 | echo "[2] Define custom password" 253 | echo "[3] No password" 254 | echo 255 | echo -n "Chose an option: " 256 | read optionAuth 257 | 258 | NEWPWD=$(randomString 15) 259 | case $optionAuth in 260 | 1) echo "auth: password" >> $CONFIG_FILE && echo "password:" $NEWPWD >> $CONFIG_FILE;; 261 | 2) echo "Enter the custom password:" && customPasswd;; 262 | 3) echo "auth: none" >> $CONFIG_FILE;; 263 | *) newConfigFile ;; 264 | esac 265 | 266 | execCodeServer 267 | } 268 | 269 | customPasswd(){ 270 | read -s authPass 271 | if [ -z "${authPass}" ];then 272 | echo "Password is required!" 273 | customPasswd 274 | else 275 | echo "auth: password" >> $CONFIG_FILE 276 | echo "password:" $authPass >> $CONFIG_FILE 277 | fi 278 | } 279 | 280 | execCodeServer(){ 281 | clear 282 | 283 | printf "\n${GREEN}" 284 | if grep -q "password:" $CONFIG_FILE; then 285 | cat $CONFIG_FILE | grep password: 286 | else 287 | echo "No password" 288 | fi 289 | printf "${END}\n" 290 | $CODE_FILE 291 | } 292 | 293 | fetch() { 294 | URL="$1" 295 | FILE="$2" 296 | 297 | if [ -e "$FILE" ]; then 298 | echoh "+ Reusing $FILE" 299 | return 300 | fi 301 | 302 | sh_c curl \ 303 | -#fL \ 304 | -o "$FILE.incomplete" \ 305 | -C - \ 306 | "$URL" 307 | sh_c mv "$FILE.incomplete" "$FILE" 308 | } 309 | 310 | 311 | sh_c() { 312 | echoh "+ $*" 313 | if [ ! "${DRY_RUN-}" ]; then 314 | sh -c "$*" 315 | fi 316 | } 317 | 318 | echoh() { 319 | echo "$@" | humanpath 320 | } 321 | 322 | cath() { 323 | humanpath 324 | } 325 | 326 | echoerr() { 327 | echoh "$@" >&2 328 | } 329 | 330 | # humanpath replaces all occurances of " $HOME" with " ~" 331 | # and all occurances of '"$HOME' with the literal '"$HOME'. 332 | humanpath() { 333 | sed "s# $HOME# ~#g; s#\"$HOME#\"\$HOME#g" 334 | } 335 | 336 | main "$@" --------------------------------------------------------------------------------