Skip to content

Commit a62afad

Browse files
committed
Have deps.ts optionally add a virtual VNC-based desktop to the container to support GUI applications
1 parent ad90c74 commit a62afad

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
openvscode-server-v*
22
config.json
3+
noVNC-*
34
rclone-v*
45
refresh_tokens.json
6+
tigervnc-*
57
vendor
68
vscode
9+
websockify-*

deps.ts

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env -S deno run --allow-net --allow-read=. --allow-write=. --allow-run --check
1+
#!/usr/bin/env -S deno run --allow-net --allow-read --allow-write --allow-run --check
22

33
import { ROOT, exists } from "./filesystem.ts";
44

@@ -32,6 +32,26 @@ Deno.renameSync(dropExtension(rclone) + "/rclone", ROOT + "/bin/rclone");
3232
Deno.linkSync("plugins/openvscode-drive", ROOT + "/bin/openvscode-drive");
3333
Deno.remove(dropExtension(rclone), {recursive: true});
3434

35+
if(confirm("Enable support for GUI applications via VNC?")) {
36+
let tigervnc = await sourceForgeFileUrl("tigervnc", "tigervnc", ".x86_64.tar.gz");
37+
tigervnc = await download(tigervnc);
38+
await unpack(tigervnc, ["tar", "xf"]);
39+
Deno.renameSync(dropExtension(tigervnc) + "/usr/bin/Xvnc", ROOT + "/bin/Xvnc");
40+
Deno.remove(dropExtension(tigervnc), {recursive: true});
41+
42+
let novnc = await releaseUrl("novnc", "novnc");
43+
novnc = await download(novnc, "noVNC");
44+
await unpack(novnc, ["tar", "xf"]);
45+
Deno.renameSync(dropExtension(novnc), ROOT + "/opt");
46+
47+
let websockify = await releaseUrl("novnc", "websockify");
48+
websockify = await download(websockify, "websockify");
49+
await unpack(websockify, ["tar", "xf"]);
50+
Deno.renameSync(dropExtension(websockify), ROOT + "/opt/utils/websockify");
51+
52+
Deno.symlinkSync("../opt/utils/novnc_proxy", ROOT + "/bin/novnc_proxy");
53+
}
54+
3555
console.log("All dependencies fetched!");
3656

3757
async function releaseUrl(org: string, repo: string, suffix?: string): Promise<string> {
@@ -51,6 +71,23 @@ async function releaseUrl(org: string, repo: string, suffix?: string): Promise<s
5171
return "https://github.com/" + org + "/" + repo + "/archive/refs/tags/" + info.tag_name + ".tar.gz";
5272
}
5373

74+
async function sourceForgeFileUrl(org: string, repo: string, suffix: string): Promise<string> {
75+
const info = await promptVersion(org, repo);
76+
const listingUrl = info.body.match(/^https:\/\/.+/m);
77+
if(!listingUrl) {
78+
console.error("Unexpected error parsing latest " + repo + " release description!");
79+
Deno.exit(4);
80+
}
81+
82+
const listing = await (await fetch(listingUrl[0])).text();
83+
const fileUrl = listing.match(new RegExp("https://[^\"]+" + suffix));
84+
if(!fileUrl) {
85+
console.error("Unexpected error parsing " + repo + " SourceForge files listing!");
86+
Deno.exit(5);
87+
}
88+
return fileUrl[0];
89+
}
90+
5491
async function promptVersion(org: string, repo: string): Promise<ReleaseInfo> {
5592
let info = await releaseInfo(org, repo);
5693
const tag = info.tag_name.match(/([^0-9]+)(.+)/);
@@ -88,11 +125,13 @@ function basename(url: string): string {
88125
}
89126

90127
function dropExtension(url: string): string {
91-
return basename(url).replace(/\.[^0-9].+/, "");
128+
return basename(url).replace(/\.[^0-9]+$/, "");
92129
}
93130

94-
async function download(url: string) {
95-
const filename = basename(url);
131+
async function download(url: string, product?: string): Promise<string> {
132+
let filename = basename(url);
133+
if(product)
134+
filename = product + "-" + filename.slice(1);
96135
if(await exists(filename))
97136
console.warn("Skipping download of " + filename + " that already exists.");
98137
else {
@@ -101,6 +140,7 @@ async function download(url: string) {
101140
const body = await fetch(url);
102141
await Deno.writeFile(filename, new Uint8Array(await body.arrayBuffer()));
103142
}
143+
return filename;
104144
}
105145

106146
async function unpack(filename: string, cmd: Readonly<string[]>): Promise<boolean> {
@@ -113,6 +153,7 @@ async function unpack(filename: string, cmd: Readonly<string[]>): Promise<boolea
113153

114154
type ReleaseInfo = {
115155
tag_name: string,
156+
body: string,
116157
assets: ReleaseAsset[],
117158
};
118159

0 commit comments

Comments
 (0)