Skip to content
This repository was archived by the owner on Jan 17, 2021. It is now read-only.

Commit fedfbb7

Browse files
committed
Pass ssh flags to rsync
- Also use ssh flags when running the download script Resolves #19
1 parent 3f4919f commit fedfbb7

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

main.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"path/filepath"
1313
"runtime"
1414
"strconv"
15+
"strings"
1516
"time"
1617

1718
"github.com/pkg/browser"
@@ -53,22 +54,24 @@ More info: https://github.com/codercom/sshcode
5354

5455
const codeServerPath = "/tmp/codessh-code-server"
5556

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 + `
6259
mkdir -p ~/.local/share/code-server
63-
cd `+filepath.Dir(codeServerPath)+`
60+
cd ` + filepath.Dir(codeServerPath) + `
6461
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,
6970
)
71+
sshCmd := exec.Command("sh", "-c", sshCmdStr)
7072
sshCmd.Stdout = os.Stdout
7173
sshCmd.Stderr = os.Stderr
74+
sshCmd.Stdin = strings.NewReader(downloadScript)
7275
err := sshCmd.Run()
7376
if err != nil {
7477
flog.Fatal("failed to update code-server: %v", err)
@@ -77,14 +80,14 @@ chmod +x `+codeServerPath+`
7780
if !(*skipSyncFlag) {
7881
start := time.Now()
7982
flog.Info("syncing settings")
80-
err = syncUserSettings(host)
83+
err = syncUserSettings(*sshFlags, host)
8184
if err != nil {
8285
flog.Fatal("failed to sync settings: %v", err)
8386
}
8487
flog.Info("synced settings in %s", time.Since(start))
8588

8689
flog.Info("syncing extensions")
87-
err = syncExtensions(host)
90+
err = syncExtensions(host, *sshFlags)
8891
if err != nil {
8992
flog.Fatal("failed to sync extensions: %v", err)
9093
}
@@ -97,7 +100,7 @@ chmod +x `+codeServerPath+`
97100
flog.Fatal("failed to find available port: %v", err)
98101
}
99102

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'",
101104
localPort+":localhost:"+localPort, *sshFlags, host, dir, codeServerPath, localPort,
102105
)
103106

@@ -197,35 +200,35 @@ func randomPort() (string, error) {
197200
return "", xerrors.Errorf("max number of tries exceeded: %d", maxTries)
198201
}
199202

200-
func syncUserSettings(host string) error {
203+
func syncUserSettings(sshFlags string, host string) error {
201204
localConfDir, err := configDir()
202205
if err != nil {
203206
return err
204207
}
205208
const remoteSettingsDir = ".local/share/code-server/User"
206209

207210
// 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")
209212
}
210213

211-
func syncExtensions(host string) error {
214+
func syncExtensions(sshFlags string, host string) error {
212215
localExtensionsDir, err := extensionsDir()
213216
if err != nil {
214217
return err
215218
}
216219
const remoteExtensionsDir = ".local/share/code-server/extensions"
217220

218-
return rsync(localExtensionsDir+"/", remoteExtensionsDir, host)
221+
return rsync(localExtensionsDir+"/", remoteExtensionsDir, sshFlags, host)
219222
}
220223

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 {
222225
remoteDest := fmt.Sprintf("%s:%s", host, dest)
223226
excludeFlags := make([]string, len(excludePaths))
224227
for i, path := range excludePaths {
225228
excludeFlags[i] = "--exclude=" + path
226229
}
227230

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)...)
229232
cmd.Stdout = os.Stdout
230233
cmd.Stderr = os.Stderr
231234
err := cmd.Run()

0 commit comments

Comments
 (0)