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

Commit

Permalink
Support multiple users using same machine
Browse files Browse the repository at this point in the history
- code-server is now downloaded to ~/.cache/sshcode
  • Loading branch information
sreya committed Apr 30, 2019
1 parent 326938c commit 57ccf3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 5 additions & 4 deletions sshcode.go
Expand Up @@ -19,6 +19,8 @@ import (
"golang.org/x/xerrors"
)

const codeServerPath = "~/.cache/sshcode/sshcode-server"

type options struct {
skipSync bool
syncBack bool
Expand All @@ -30,8 +32,6 @@ type options struct {
func sshCode(host, dir string, o options) error {
flog.Info("ensuring code-server is updated...")

const codeServerPath = "/tmp/sshcode-code-server"

dlScript := downloadScript(codeServerPath)

// Downloads the latest code-server and allows it to be executed.
Expand Down Expand Up @@ -97,7 +97,7 @@ func sshCode(host, dir string, o options) error {
sshCmd.Stderr = os.Stderr
err = sshCmd.Start()
if err != nil {
flog.Fatal("failed to start code-server: %v", err)
return xerrors.Errorf("failed to start code-server: %w", err)
}

url := "http://127.0.0.1:" + o.localPort
Expand Down Expand Up @@ -313,12 +313,13 @@ func downloadScript(codeServerPath string) string {
return fmt.Sprintf(
`set -euxo pipefail || exit 1
mkdir -p ~/.local/share/code-server
mkdir -p ~/.local/share/code-server %v
cd %v
wget -N https://codesrv-ci.cdr.sh/latest-linux
[ -f %v ] && rm %v
ln latest-linux %v
chmod +x %v`,
filepath.Dir(codeServerPath),
filepath.Dir(codeServerPath),
codeServerPath,
codeServerPath,
Expand Down
7 changes: 6 additions & 1 deletion sshcode_test.go
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
"strconv"
"sync"
"testing"
Expand Down Expand Up @@ -50,7 +51,11 @@ func TestSSHCode(t *testing.T) {
waitForSSHCode(t, localPort, time.Second*30)
waitForSSHCode(t, remotePort, time.Second*30)

out, err := exec.Command("pkill", "sshcode-code").CombinedOutput()
// Typically we'd do an os.Stat call here but the os package doesn't expand '~'
out, err := exec.Command("sh", "-c", "stat "+codeServerPath).CombinedOutput()
require.NoError(t, err, "%s", out)

out, err = exec.Command("pkill", filepath.Base(codeServerPath)).CombinedOutput()
require.NoError(t, err, "%s", out)

wg.Wait()
Expand Down

0 comments on commit 57ccf3a

Please sign in to comment.