@@ -12,6 +12,7 @@ import (
12
12
"path/filepath"
13
13
"runtime"
14
14
"strconv"
15
+ "strings"
15
16
"time"
16
17
17
18
"github.com/pkg/browser"
@@ -53,22 +54,24 @@ More info: https://github.com/codercom/sshcode
53
54
54
55
const codeServerPath = "/tmp/codessh-code-server"
55
56
56
- // Downloads the latest code-server and allows it to be executed.
57
- sshCmd := exec .Command ("ssh" ,
58
- "-tt" ,
59
- host ,
60
- `/bin/bash -c 'set -euxo pipefail || exit 1
61
- wget -q https://codesrv-ci.cdr.sh/latest-linux -O ` + codeServerPath + `
57
+ downloadScript := `/bin/bash -c 'set -euxo pipefail || exit 1
58
+ wget -q https://codesrv-ci.cdr.sh/latest-linux -O ` + codeServerPath + `
62
59
mkdir -p ~/.local/share/code-server
63
- cd ` + filepath .Dir (codeServerPath )+ `
60
+ cd ` + filepath .Dir (codeServerPath ) + `
64
61
wget -N https://codesrv-ci.cdr.sh/latest-linux
65
- [ -f ` + codeServerPath + ` ] && rm ` + codeServerPath + `
66
- ln latest-linux ` + codeServerPath + `
67
- chmod +x ` + codeServerPath + `
68
- '` ,
62
+ [ -f ` + codeServerPath + ` ] && rm ` + codeServerPath + `
63
+ ln latest-linux ` + codeServerPath + `
64
+ chmod +x ` + codeServerPath + `
65
+ '`
66
+ // Downloads the latest code-server and allows it to be executed.
67
+ sshCmdStr := fmt .Sprintf ("ssh" +
68
+ " -tt " + * sshFlags + " " +
69
+ host ,
69
70
)
71
+ sshCmd := exec .Command ("sh" , "-c" , sshCmdStr )
70
72
sshCmd .Stdout = os .Stdout
71
73
sshCmd .Stderr = os .Stderr
74
+ sshCmd .Stdin = strings .NewReader (downloadScript )
72
75
err := sshCmd .Run ()
73
76
if err != nil {
74
77
flog .Fatal ("failed to update code-server: %v" , err )
@@ -77,14 +80,14 @@ chmod +x `+codeServerPath+`
77
80
if ! (* skipSyncFlag ) {
78
81
start := time .Now ()
79
82
flog .Info ("syncing settings" )
80
- err = syncUserSettings (host )
83
+ err = syncUserSettings (* sshFlags , host )
81
84
if err != nil {
82
85
flog .Fatal ("failed to sync settings: %v" , err )
83
86
}
84
87
flog .Info ("synced settings in %s" , time .Since (start ))
85
88
86
89
flog .Info ("syncing extensions" )
87
- err = syncExtensions (host )
90
+ err = syncExtensions (host , * sshFlags )
88
91
if err != nil {
89
92
flog .Fatal ("failed to sync extensions: %v" , err )
90
93
}
@@ -97,7 +100,7 @@ chmod +x `+codeServerPath+`
97
100
flog .Fatal ("failed to find available port: %v" , err )
98
101
}
99
102
100
- sshCmdStr : = fmt .Sprintf ("ssh -tt -q -L %v %v %v 'cd %v; %v --host 127.0.0.1 --allow-http --no-auth --port=%v'" ,
103
+ sshCmdStr = fmt .Sprintf ("ssh -tt -q -L %v %v %v 'cd %v; %v --host 127.0.0.1 --allow-http --no-auth --port=%v'" ,
101
104
localPort + ":localhost:" + localPort , * sshFlags , host , dir , codeServerPath , localPort ,
102
105
)
103
106
@@ -197,35 +200,35 @@ func randomPort() (string, error) {
197
200
return "" , xerrors .Errorf ("max number of tries exceeded: %d" , maxTries )
198
201
}
199
202
200
- func syncUserSettings (host string ) error {
203
+ func syncUserSettings (sshFlags string , host string ) error {
201
204
localConfDir , err := configDir ()
202
205
if err != nil {
203
206
return err
204
207
}
205
208
const remoteSettingsDir = ".local/share/code-server/User"
206
209
207
210
// Append "/" to have rsync copy the contents of the dir.
208
- return rsync (localConfDir + "/" , remoteSettingsDir , host , "workspaceStorage" , "logs" , "CachedData" )
211
+ return rsync (localConfDir + "/" , remoteSettingsDir , sshFlags , host , "workspaceStorage" , "logs" , "CachedData" )
209
212
}
210
213
211
- func syncExtensions (host string ) error {
214
+ func syncExtensions (sshFlags string , host string ) error {
212
215
localExtensionsDir , err := extensionsDir ()
213
216
if err != nil {
214
217
return err
215
218
}
216
219
const remoteExtensionsDir = ".local/share/code-server/extensions"
217
220
218
- return rsync (localExtensionsDir + "/" , remoteExtensionsDir , host )
221
+ return rsync (localExtensionsDir + "/" , remoteExtensionsDir , sshFlags , host )
219
222
}
220
223
221
- func rsync (src string , dest string , host string , excludePaths ... string ) error {
224
+ func rsync (src string , dest string , sshFlags string , host string , excludePaths ... string ) error {
222
225
remoteDest := fmt .Sprintf ("%s:%s" , host , dest )
223
226
excludeFlags := make ([]string , len (excludePaths ))
224
227
for i , path := range excludePaths {
225
228
excludeFlags [i ] = "--exclude=" + path
226
229
}
227
230
228
- cmd := exec .Command ("rsync" , append (excludeFlags , "-azv" , "--copy-unsafe-links" , src , remoteDest )... )
231
+ cmd := exec .Command ("rsync" , append (excludeFlags , "-e" , "ssh " + sshFlags , "- azv" , "--copy-unsafe-links" , src , remoteDest )... )
229
232
cmd .Stdout = os .Stdout
230
233
cmd .Stderr = os .Stderr
231
234
err := cmd .Run ()
0 commit comments