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
2
2
3
3
import { ROOT , exists } from "./filesystem.ts" ;
4
4
@@ -32,6 +32,26 @@ Deno.renameSync(dropExtension(rclone) + "/rclone", ROOT + "/bin/rclone");
32
32
Deno . linkSync ( "plugins/openvscode-drive" , ROOT + "/bin/openvscode-drive" ) ;
33
33
Deno . remove ( dropExtension ( rclone ) , { recursive : true } ) ;
34
34
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
+
35
55
console . log ( "All dependencies fetched!" ) ;
36
56
37
57
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
51
71
return "https://github.com/" + org + "/" + repo + "/archive/refs/tags/" + info . tag_name + ".tar.gz" ;
52
72
}
53
73
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 ( / ^ h t t p s : \/ \/ .+ / 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
+
54
91
async function promptVersion ( org : string , repo : string ) : Promise < ReleaseInfo > {
55
92
let info = await releaseInfo ( org , repo ) ;
56
93
const tag = info . tag_name . match ( / ( [ ^ 0 - 9 ] + ) ( .+ ) / ) ;
@@ -88,11 +125,13 @@ function basename(url: string): string {
88
125
}
89
126
90
127
function dropExtension ( url : string ) : string {
91
- return basename ( url ) . replace ( / \. [ ^ 0 - 9 ] . + / , "" ) ;
128
+ return basename ( url ) . replace ( / \. [ ^ 0 - 9 ] + $ / , "" ) ;
92
129
}
93
130
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 ) ;
96
135
if ( await exists ( filename ) )
97
136
console . warn ( "Skipping download of " + filename + " that already exists." ) ;
98
137
else {
@@ -101,6 +140,7 @@ async function download(url: string) {
101
140
const body = await fetch ( url ) ;
102
141
await Deno . writeFile ( filename , new Uint8Array ( await body . arrayBuffer ( ) ) ) ;
103
142
}
143
+ return filename ;
104
144
}
105
145
106
146
async function unpack ( filename : string , cmd : Readonly < string [ ] > ) : Promise < boolean > {
@@ -113,6 +153,7 @@ async function unpack(filename: string, cmd: Readonly<string[]>): Promise<boolea
113
153
114
154
type ReleaseInfo = {
115
155
tag_name : string ,
156
+ body : string ,
116
157
assets : ReleaseAsset [ ] ,
117
158
} ;
118
159
0 commit comments