Skip to content

Commit 790ccfb

Browse files
authored
Merge branch 'main' into jsjoeio-docs-update
2 parents 8e1101f + e705948 commit 790ccfb

File tree

5 files changed

+203
-94
lines changed

5 files changed

+203
-94
lines changed

docs/termux.md

Lines changed: 115 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,144 @@
55
- [Install](#install)
66
- [Upgrade](#upgrade)
77
- [Known Issues](#known-issues)
8-
- [Search doesn't work](#search-doesnt-work)
9-
- [Backspace doesn't work](#backspace-doesnt-work)
8+
- [Git won't work in `/sdcard`](#git-wont-work-in-sdcard)
9+
- [Extra](#extra)
10+
- [Create a new user](#create-a-new-user)
11+
- [Install Go](#install-go)
12+
- [Install Python](#install-python)
1013

1114
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1215

13-
Termux is a terminal application and Linux environment that you can also use to
14-
run code-server from your Android phone.
15-
1616
## Install
1717

18-
1. Install Termux from [F-Droid](https://f-droid.org/en/packages/com.termux/).
19-
1. Make sure it's up-to-date: `apt update && apt upgrade`
20-
1. Install required packages: `apt install build-essential python git nodejs-lts yarn`
21-
1. Install code-server: `yarn global add code-server`
22-
1. Run code-server: `code-server` and navigate to localhost:8080 in your browser
18+
1. Get [Termux](https://f-droid.org/en/packages/com.termux/) from **F-Droid**.
19+
2. Install Debian by running the following.
20+
- Run `termux-setup-storage` to allow storage access, or else code-server won't be able to read from `/sdcard`.\
21+
If you used the Andronix command then you may have to edit the `start-debian.sh` script to mount `/sdcard` just as simple as uncommenting the `command+=" -b /sdcard"` line.
22+
> The following command was extracted from [Andronix](https://andronix.app/) you can also use [proot-distro](https://github.com/termux/proot-distro).
23+
> After Debian is installed the `~ $` will change to `root@localhost`.
24+
25+
```bash
26+
pkg update -y && pkg install wget curl proot tar -y && wget https://raw.githubusercontent.com/AndronixApp/AndronixOrigin/master/Installer/Debian/debian.sh -O debian.sh && chmod +x debian.sh && bash debian.sh
27+
```
28+
29+
3. Run the following commands to setup Debian.
30+
31+
```bash
32+
apt update
33+
apt upgrade -y
34+
apt-get install nano vim sudo curl wget git -y
35+
```
36+
37+
4. Install [NVM](https://github.com/nvm-sh/nvm) by following the install guide in the README, just a curl/wget command.
38+
5. Set up NVM for multi-user. After installing NVM it automatically adds the necessary commands for it to work, but it will only work if you are logged in as root;
39+
40+
- Copy the lines NVM asks you to run after running the install script.
41+
- Run `nano /root/.bashrc` and comment out those lines by adding a `#` at the start.
42+
- Run `nano /etc/profile` and paste those lines at the end and make sure to replace `$HOME` with `/root`
43+
- Now run `exit` and start Debain again.
44+
45+
6. After following the instructions and setting up NVM you can now install the [required node version](https://coder.com/docs/code-server/latest/npm#nodejs-version) using `nvm install version_here`.
46+
7. To install `code-server` run the following.
47+
> To check the install process (Will not actually install code-server)
48+
> If it all looks good, you can install code-server by running the second command
49+
50+
```bash
51+
curl -fsSL https://code-server.dev/install.sh | sh -s -- --dry-run
52+
```
53+
54+
```bash
55+
curl -fsSL https://code-server.dev/install.sh | sh
56+
```
57+
58+
8. You can now start code server by simply running `code-server`.
59+
60+
> Consider using a new user instead of root, read [here](https://www.howtogeek.com/124950/htg-explains-why-you-shouldnt-log-into-your-linux-system-as-root/) why using root is not recommended.\
61+
> Learn how to add a user [here](#create-a-new-user).
2362
2463
## Upgrade
2564

26-
To upgrade run: `yarn global upgrade code-server --latest`
65+
1. Remove all previous installs `rm -rf ~/.local/lib/code-server-*`
66+
2. Run the install script again `curl -fsSL https://code-server.dev/install.sh | sh`
2767

2868
## Known Issues
2969

30-
The following details known issues and suggested workarounds for using
31-
code-server with Termux.
70+
### Git won't work in `/sdcard`
71+
72+
Issue : Using git in the `/sdcard` directory will fail during cloning/commit/staging/etc...\
73+
Fix : None\
74+
Potential Workaround :
75+
76+
1. Create a soft-link from the debian-fs to your folder in `/sdcard`
77+
2. Use git from termux (preferred)
78+
79+
## Extra
80+
81+
### Create a new user
82+
83+
To create a new user follow these simple steps -
84+
85+
1. Create a new user by running `useradd username -m`.
86+
2. Change the password by running `passwd username`.
87+
3. Give your new user sudo access by runnning `visudo`, scroll down to `User privilege specification` and add the following line after root `username ALL=(ALL:ALL) ALL`.
88+
4. Now edit the `/etc/passwd` file with your commadline editor of choice and at the end of the line that specifies your user change `/bin/sh` to `/bin/bash`.
89+
5. Now switch users, by running `su - username`
90+
91+
- Remember the `-` betweeen `su` and username is required to execute `/etc/profile`,\
92+
since `/etc/profile` may have some necessary things to be executed you should always add a `-`.
93+
94+
### Install Go
3295

33-
### Search doesn't work
96+
> From https://golang.org/doc/install
3497
35-
There is a known issue with search not working on Android because it's missing
36-
`bin/rg` ([context](https://github.com/cdr/code-server/issues/1730#issuecomment-721515979)). To fix this:
98+
1. Go to https://golang.org/dl/ and copy the download link for `linux arm` and run the following.
3799

38-
1. Install `ripgrep` with `pkg`
100+
```bash
101+
wget download_link
102+
```
39103

40-
```sh
41-
pkg install ripgrep
42-
```
104+
2. Extract the downloaded archive. (This step will erase all previous GO installs, make sure to create a backup if you have previously installed GO)
43105

44-
1. Make a soft link using `ln -s`
106+
```bash
107+
rm -rf /usr/local/go && tar -C /usr/local -xzf archive_name
108+
```
45109

46-
```sh
47-
# run this command inside the code-server directory
48-
ln -s $PREFIX/bin/rg ./vendor/modules/code-oss-dev/vscode-ripgrep/bin/rg
49-
```
110+
3. Run `nano /etc/profile` and add the following line `export PATH=$PATH:/usr/local/go/bin`.
111+
4. Now run `exit` (depending on if you have switched users or not, you may have to run `exit` multiple times to get to normal termux shell) and start Debian again.
112+
5. Check if your install was successful by running `go version`
50113

51-
### Backspace doesn't work
114+
### Install Python
52115

53-
When using Android's on-screen keyboard, the backspace key doesn't work
54-
properly. This is a known upstream issue:
116+
> Run these commands as root
55117
56-
- [Issues with backspace in Codespaces on Android (Surface Duo)](https://github.com/microsoft/vscode/issues/107602)
57-
- [Support mobile platforms](https://github.com/xtermjs/xterm.js/issues/1101)
118+
1. Run the following command to install required packages to build python.
58119

59-
There are two workarounds.
120+
```bash
121+
sudo apt-get update
122+
sudo apt-get install make build-essential libssl-dev zlib1g-dev \
123+
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
124+
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
125+
```
60126

61-
**Option 1:** Modify keyboard dispatch settings
127+
2. Install [pyenv](https://github.com/pyenv/pyenv/) from [pyenv-installer](https://github.com/pyenv/pyenv-installer) by running.
62128

63-
1. Open the Command Palette
64-
2. Search for **Preferences: Open Settings (JSON)**
65-
3. Add `"keyboard.dispatch": "keyCode"`
129+
```bash
130+
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
131+
```
66132

67-
The backspace button should work at this point.
133+
3. Run `nano /etc/profile` and add the following
68134

69-
_Thanks to @Nefomemes for the [suggestion](https://github.com/cdr/code-server/issues/1141#issuecomment-789463707)!_
135+
```bash
136+
export PYENV_ROOT="/root/.pyenv"
137+
export PATH="/root/.pyenv/bin:$PATH"
138+
eval "$(pyenv init --path)"
139+
eval "$(pyenv virtualenv-init -)"
140+
```
70141

71-
**Option 2:** Use a Bluetooth keyboard.
142+
4. Exit start Debian again.
143+
5. Run `pyenv versions` to list all installable versions.
144+
6. Run `pyenv install version` to install the desired python version.
145+
> The build process may take some time (an hour or 2 depending on your device).
146+
7. Run `touch /root/.pyenv/version && echo "your_version_here" > /root/.pyenv/version`
147+
8. (You may have to start Debian again) Run `python3 -V` to verify if PATH works or not.
148+
> If `python3` doesn't work but pyenv says that the install was successful in step 6 then try running `$PYENV_ROOT/versions/your_version/bin/python3`.

src/node/routes/index.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { HttpCode, HttpError } from "../../common/http"
1010
import { plural } from "../../common/util"
1111
import { App } from "../app"
1212
import { AuthType, DefaultedArgs } from "../cli"
13-
import { commit, isDevMode, rootPath } from "../constants"
13+
import { commit, rootPath } from "../constants"
1414
import { Heart } from "../heart"
1515
import { ensureAuthenticated, redirect } from "../http"
1616
import { PluginAPI } from "../plugin"
@@ -23,7 +23,7 @@ import * as login from "./login"
2323
import * as logout from "./logout"
2424
import * as pathProxy from "./pathProxy"
2525
import * as update from "./update"
26-
import { createVSServerRouter, VSServerResult } from "./vscode"
26+
import { CodeServerRouteWrapper } from "./vscode"
2727

2828
/**
2929
* Register all routes and middleware.
@@ -138,20 +138,12 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
138138

139139
app.router.use("/update", update.router)
140140

141-
let vscode: VSServerResult
142-
try {
143-
vscode = await createVSServerRouter(args)
144-
app.router.use("/", vscode.router)
145-
app.wsRouter.use("/", vscode.wsRouter.router)
146-
app.router.use("/vscode", vscode.router)
147-
app.wsRouter.use("/vscode", vscode.wsRouter.router)
148-
} catch (error: any) {
149-
if (isDevMode) {
150-
logger.warn(error)
151-
logger.warn("VS Server router may still be compiling.")
152-
} else {
153-
throw error
154-
}
141+
const vsServerRouteHandler = new CodeServerRouteWrapper()
142+
143+
// Note that the root route is replaced in Coder Enterprise by the plugin API.
144+
for (const routePrefix of ["/", "/vscode"]) {
145+
app.router.use(routePrefix, vsServerRouteHandler.router)
146+
app.wsRouter.use(routePrefix, vsServerRouteHandler.wsRouter)
155147
}
156148

157149
app.router.use(() => {
@@ -164,6 +156,6 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
164156
return () => {
165157
heart.dispose()
166158
pluginApi?.dispose()
167-
vscode?.codeServerMain.dispose()
159+
vsServerRouteHandler.dispose()
168160
}
169161
}

src/node/routes/vscode.ts

Lines changed: 76 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,105 @@
1+
import { logger } from "@coder/logger"
12
import * as express from "express"
2-
import { DefaultedArgs } from "../cli"
3+
import { WebsocketRequest } from "../../../typings/pluginapi"
4+
import { logError } from "../../common/util"
5+
import { isDevMode } from "../constants"
36
import { ensureAuthenticated, authenticated, redirect } from "../http"
47
import { loadAMDModule } from "../util"
5-
import { Router as WsRouter, WebsocketRouter } from "../wsRouter"
8+
import { Router as WsRouter } from "../wsRouter"
69
import { errorHandler } from "./errors"
710

8-
export interface VSServerResult {
9-
router: express.Router
10-
wsRouter: WebsocketRouter
11-
codeServerMain: CodeServerLib.IServerAPI
12-
}
13-
14-
export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServerResult> => {
15-
// See ../../../vendor/modules/code-oss-dev/src/vs/server/main.js.
16-
const createVSServer = await loadAMDModule<CodeServerLib.CreateServer>(
17-
"vs/server/remoteExtensionHostAgent",
18-
"createServer",
19-
)
11+
export class CodeServerRouteWrapper {
12+
/** Assigned in `ensureCodeServerLoaded` */
13+
private _codeServerMain!: CodeServerLib.IServerAPI
14+
private _wsRouterWrapper = WsRouter()
15+
public router = express.Router()
2016

21-
const codeServerMain = await createVSServer(null, {
22-
connectionToken: "0000",
23-
...args,
24-
// For some reason VS Code takes the port as a string.
25-
port: typeof args.port !== "undefined" ? args.port.toString() : undefined,
26-
})
17+
public get wsRouter() {
18+
return this._wsRouterWrapper.router
19+
}
2720

28-
const router = express.Router()
29-
const wsRouter = WsRouter()
21+
//#region Route Handlers
3022

31-
router.get("/", async (req, res, next) => {
23+
private $root: express.Handler = async (req, res, next) => {
3224
const isAuthenticated = await authenticated(req)
25+
3326
if (!isAuthenticated) {
3427
return redirect(req, res, "login", {
3528
// req.baseUrl can be blank if already at the root.
3629
to: req.baseUrl && req.baseUrl !== "/" ? req.baseUrl : undefined,
3730
})
3831
}
32+
3933
next()
40-
})
34+
}
4135

42-
router.all("*", ensureAuthenticated, (req, res, next) => {
43-
req.on("error", (error: any) => {
36+
private $proxyRequest: express.Handler = async (req, res, next) => {
37+
// We allow certain errors to propagate so that other routers may handle requests
38+
// outside VS Code
39+
const requestErrorHandler = (error: any) => {
4440
if (error instanceof Error && ["EntryNotFound", "FileNotFound", "HttpError"].includes(error.message)) {
4541
next()
4642
}
4743

4844
errorHandler(error, req, res, next)
49-
})
45+
}
46+
47+
req.once("error", requestErrorHandler)
5048

51-
codeServerMain.handleRequest(req, res)
52-
})
49+
this._codeServerMain.handleRequest(req, res)
50+
}
5351

54-
wsRouter.ws("/", ensureAuthenticated, (req) => {
55-
codeServerMain.handleUpgrade(req, req.socket)
52+
private $proxyWebsocket = async (req: WebsocketRequest) => {
53+
this._codeServerMain.handleUpgrade(req, req.socket)
5654

5755
req.socket.resume()
58-
})
56+
}
57+
58+
//#endregion
59+
60+
/**
61+
* Fetches a code server instance asynchronously to avoid an initial memory overhead.
62+
*/
63+
private ensureCodeServerLoaded: express.Handler = async (req, _res, next) => {
64+
if (this._codeServerMain) {
65+
return next()
66+
}
67+
68+
const { args } = req
69+
70+
/**
71+
* @file ../../../vendor/modules/code-oss-dev/src/vs/server/main.js
72+
*/
73+
const createVSServer = await loadAMDModule<CodeServerLib.CreateServer>(
74+
"vs/server/remoteExtensionHostAgent",
75+
"createServer",
76+
)
77+
78+
try {
79+
this._codeServerMain = await createVSServer(null, {
80+
connectionToken: "0000",
81+
...args,
82+
// For some reason VS Code takes the port as a string.
83+
port: args.port?.toString(),
84+
})
85+
} catch (createServerError) {
86+
logError(logger, "CodeServerRouteWrapper", createServerError)
87+
88+
const loggedError = isDevMode ? new Error("VS Code may still be compiling...") : createServerError
89+
90+
return next(loggedError)
91+
}
92+
93+
return next()
94+
}
95+
96+
constructor() {
97+
this.router.get("/", this.ensureCodeServerLoaded, this.$root)
98+
this.router.all("*", ensureAuthenticated, this.ensureCodeServerLoaded, this.$proxyRequest)
99+
this._wsRouterWrapper.ws("/", ensureAuthenticated, this.ensureCodeServerLoaded, this.$proxyWebsocket)
100+
}
59101

60-
return {
61-
router,
62-
wsRouter,
63-
codeServerMain,
102+
dispose() {
103+
this._codeServerMain?.dispose()
64104
}
65105
}

vendor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"postinstall": "./postinstall.sh"
88
},
99
"devDependencies": {
10-
"code-oss-dev": "cdr/vscode#d62e8db202f80db7a42233cd56d04e6806109fb1"
10+
"code-oss-dev": "cdr/vscode#8db6c9bb0bc065bdb905dc076f4d4234f126aff7"
1111
}
1212
}

vendor/yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ clone-response@^1.0.2:
296296
dependencies:
297297
mimic-response "^1.0.0"
298298

299-
code-oss-dev@cdr/vscode#d62e8db202f80db7a42233cd56d04e6806109fb1:
299+
code-oss-dev@cdr/vscode#8db6c9bb0bc065bdb905dc076f4d4234f126aff7:
300300
version "1.61.1"
301-
resolved "https://codeload.github.com/cdr/vscode/tar.gz/d62e8db202f80db7a42233cd56d04e6806109fb1"
301+
resolved "https://codeload.github.com/cdr/vscode/tar.gz/8db6c9bb0bc065bdb905dc076f4d4234f126aff7"
302302
dependencies:
303303
"@microsoft/applicationinsights-web" "^2.6.4"
304304
"@vscode/sqlite3" "4.0.12"

0 commit comments

Comments
 (0)