| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ import ( | |||
| 13 | 13 | "path/filepath" | |
| 14 | 14 | "runtime" | |
| 15 | 15 | "strconv" | |
| 16 | + "strings" | ||
| 16 | 17 | "time" | |
| 17 | 18 | ||
| 18 | 19 | "github.com/pkg/browser" | |
@@ -58,41 +59,42 @@ More info: https://github.com/codercom/sshcode | |||
| 58 | 59 | ||
| 59 | 60 | const codeServerPath = "/tmp/codessh-code-server" | |
| 60 | 61 | ||
| 61 | - // Downloads the latest code-server and allows it to be executed. | ||
| 62 | - sshCmd := exec.Command("ssh", | ||
| 63 | - "-tt", | ||
| 64 | - host, | ||
| 65 | - `/bin/bash -c 'set -euxo pipefail || exit 1 | ||
| 66 | - # Make sure any currently running code-server is gone so we can overwrite | ||
| 67 | - # the binary. | ||
| 68 | - pkill -9 `+filepath.Base(codeServerPath)+` || true | ||
| 69 | - wget -q https://codesrv-ci.cdr.sh/latest-linux -O `+codeServerPath+` | ||
| 62 | + downloadScript := `set -euxo pipefail || exit 1 | ||
| 63 | + | ||
| 70 | 64 | mkdir -p ~/.local/share/code-server | |
| 71 | - cd `+filepath.Dir(codeServerPath)+` | ||
| 65 | + cd ` + filepath.Dir(codeServerPath) + ` | ||
| 72 | 66 | wget -N https://codesrv-ci.cdr.sh/latest-linux | |
| 73 | - [ -f `+codeServerPath+` ] && rm `+codeServerPath+` | ||
| 74 | - ln latest-linux `+codeServerPath+` | ||
| 75 | - chmod +x `+codeServerPath+` | ||
| 76 | - '`, | ||
| 67 | + [ -f ` + codeServerPath + ` ] && rm ` + codeServerPath + ` | ||
| 68 | + ln latest-linux ` + codeServerPath + ` | ||
| 69 | + chmod +x ` + codeServerPath | ||
| 70 | + // Downloads the latest code-server and allows it to be executed. | ||
| 71 | + sshCmdStr := fmt.Sprintf("ssh" + | ||
| 72 | + " " + *sshFlags + " " + | ||
| 73 | + host + " /bin/bash", | ||
| 77 | 74 | ) | |
| 75 | + sshCmd := exec.Command("sh", "-c", sshCmdStr) | ||
| 78 | 76 | sshCmd.Stdout = os.Stdout | |
| 79 | 77 | sshCmd.Stderr = os.Stderr | |
| 78 | + sshCmd.Stdin = strings.NewReader(downloadScript) | ||
| 80 | 79 | err := sshCmd.Run() | |
| 81 | 80 | if err != nil { | |
| 82 | - flog.Fatal("failed to update code-server: %v", err) | ||
| 81 | + flog.Fatal("failed to update code-server: %v\n---ssh cmd---\n%s\n---download script---\n%s", err, | ||
| 82 | + sshCmdStr, | ||
| 83 | + downloadScript, | ||
| 84 | + ) | ||
| 83 | 85 | } | |
| 84 | 86 | ||
| 85 | 87 | if !*skipSyncFlag { | |
| 86 | 88 | start := time.Now() | |
| 87 | 89 | flog.Info("syncing settings") | |
| 88 | - err = syncUserSettings(host, false) | ||
| 90 | + err = syncUserSettings(*sshFlags, host, false) | ||
| 89 | 91 | if err != nil { | |
| 90 | 92 | flog.Fatal("failed to sync settings: %v", err) | |
| 91 | 93 | } | |
| 92 | 94 | flog.Info("synced settings in %s", time.Since(start)) | |
| 93 | 95 | ||
| 94 | 96 | flog.Info("syncing extensions") | |
| 95 | - err = syncExtensions(host, false) | ||
| 97 | + err = syncExtensions(*sshFlags, host, false) | ||
| 96 | 98 | if err != nil { | |
| 97 | 99 | flog.Fatal("failed to sync extensions: %v", err) | |
| 98 | 100 | } | |
@@ -105,7 +107,7 @@ chmod +x `+codeServerPath+` | |||
| 105 | 107 | flog.Fatal("failed to find available port: %v", err) | |
| 106 | 108 | } | |
| 107 | 109 | ||
| 108 | - sshCmdStr := fmt.Sprintf("ssh -tt -q -L %v %v %v 'cd %v; %v --host 127.0.0.1 --allow-http --no-auth --port=%v'", | ||
| 110 | + sshCmdStr = fmt.Sprintf("ssh -tt -q -L %v %v %v 'cd %v; %v --host 127.0.0.1 --allow-http --no-auth --port=%v'", | ||
| 109 | 111 | localPort+":localhost:"+localPort, *sshFlags, host, dir, codeServerPath, localPort, | |
| 110 | 112 | ) | |
| 111 | 113 | ||
@@ -162,12 +164,12 @@ chmod +x `+codeServerPath+` | |||
| 162 | 164 | ||
| 163 | 165 | flog.Info("synchronizing VS Code back to local") | |
| 164 | 166 | ||
| 165 | - err = syncExtensions(host, true) | ||
| 167 | + err = syncExtensions(*sshFlags, host, true) | ||
| 166 | 168 | if err != nil { | |
| 167 | 169 | flog.Fatal("failed to sync extensions back: %v", err) | |
| 168 | 170 | } | |
| 169 | 171 | ||
| 170 | - err = syncUserSettings(host, true) | ||
| 172 | + err = syncUserSettings(*sshFlags, host, true) | ||
| 171 | 173 | if err != nil { | |
| 172 | 174 | flog.Fatal("failed to user settigns extensions back: %v", err) | |
| 173 | 175 | } | |
@@ -235,7 +237,7 @@ func randomPort() (string, error) { | |||
| 235 | 237 | return "", xerrors.Errorf("max number of tries exceeded: %d", maxTries) | |
| 236 | 238 | } | |
| 237 | 239 | ||
| 238 | - func syncUserSettings(host string, back bool) error { | ||
| 240 | + func syncUserSettings(sshFlags string, host string, back bool) error { | ||
| 239 | 241 | localConfDir, err := configDir() | |
| 240 | 242 | if err != nil { | |
| 241 | 243 | return err | |
@@ -252,10 +254,10 @@ func syncUserSettings(host string, back bool) error { | |||
| 252 | 254 | } | |
| 253 | 255 | ||
| 254 | 256 | // Append "/" to have rsync copy the contents of the dir. | |
| 255 | - return rsync(src, dest, "workspaceStorage", "logs", "CachedData") | ||
| 257 | + return rsync(src, dest, sshFlags, "workspaceStorage", "logs", "CachedData") | ||
| 256 | 258 | } | |
| 257 | 259 | ||
| 258 | - func syncExtensions(host string, back bool) error { | ||
| 260 | + func syncExtensions(sshFlags string, host string, back bool) error { | ||
| 259 | 261 | localExtensionsDir, err := extensionsDir() | |
| 260 | 262 | if err != nil { | |
| 261 | 263 | return err | |
@@ -270,16 +272,17 @@ func syncExtensions(host string, back bool) error { | |||
| 270 | 272 | dest, src = src, dest | |
| 271 | 273 | } | |
| 272 | 274 | ||
| 273 | - return rsync(src, dest) | ||
| 275 | + return rsync(src, dest, sshFlags) | ||
| 274 | 276 | } | |
| 275 | 277 | ||
| 276 | - func rsync(src string, dest string, excludePaths ...string) error { | ||
| 278 | + func rsync(src string, dest string, sshFlags string, excludePaths ...string) error { | ||
| 277 | 279 | excludeFlags := make([]string, len(excludePaths)) | |
| 278 | 280 | for i, path := range excludePaths { | |
| 279 | 281 | excludeFlags[i] = "--exclude=" + path | |
| 280 | 282 | } | |
| 281 | 283 | ||
| 282 | 284 | cmd := exec.Command("rsync", append(excludeFlags, "-azvr", | |
| 285 | + "-e", "ssh "+sshFlags, | ||
| 283 | 286 | // Only update newer directories, and sync times | |
| 284 | 287 | // to keep things simple. | |
| 285 | 288 | "-u", "--times", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments