working update

This commit is contained in:
David Dworken
2022-04-06 18:18:46 -07:00
parent 7e51d5fe42
commit 684511f4f7
8 changed files with 73 additions and 61 deletions

View File

@ -4,15 +4,15 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http"
"io/ioutil" "io/ioutil"
"net/http"
"os" "os"
"strings" "strings"
"gorm.io/gorm" "gorm.io/gorm"
"github.com/ddworken/hishtory/shared"
"github.com/ddworken/hishtory/client/lib" "github.com/ddworken/hishtory/client/lib"
"github.com/ddworken/hishtory/shared"
) )
func main() { func main() {

View File

@ -141,7 +141,6 @@ func testIntegration(t *testing.T) string {
} }
userSecret := matches[1] userSecret := matches[1]
// TODO(ddworken): Test the status subcommand // TODO(ddworken): Test the status subcommand
out = RunInteractiveBashCommands(t, ` out = RunInteractiveBashCommands(t, `
hishtory status hishtory status

View File

@ -9,6 +9,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http"
"os" "os"
"os/exec" "os/exec"
"os/user" "os/user"
@ -16,8 +17,8 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"net/http"
"gorm.io/gorm" "gorm.io/gorm"
@ -375,17 +376,29 @@ func copyFile(src, dst string) error {
func Update(url string) error { func Update(url string) error {
var stdout bytes.Buffer var stdout bytes.Buffer
var stderr bytes.Buffer var stderr bytes.Buffer
cmd := exec.Command("bash", "-c", "curl -o /tmp/hishtory-client "+url+"; chmod +x /tmp/hishtory-client; /tmp/hishtory-client install") cmd := exec.Command("bash", "-c", "curl -o /tmp/hishtory-client "+url+"; chmod +x /tmp/hishtory-client")
cmd.Stdout = &stdout cmd.Stdout = &stdout
cmd.Stderr = &stderr cmd.Stderr = &stderr
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
return fmt.Errorf("Failed to update: %v, stdout=%+v, stderr=%+v", err, stdout.String(), stderr.String()) return fmt.Errorf("Failed to download update: %v, stdout=%#v, stderr=%#v", err, stdout.String(), stderr.String())
}
homedir, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("failed to get user's home directory: %v", err)
}
err = syscall.Unlink(path.Join(homedir, shared.HISHTORY_PATH, "hishtory"))
if err != nil {
return fmt.Errorf("Failed to unlink: %v", err)
}
cmd = exec.Command("/tmp/hishtory-client", "install")
err = cmd.Run()
if err != nil {
return fmt.Errorf("Failed to update: %v", err)
} }
return nil return nil
} }
func GetServerHostname() string { func GetServerHostname() string {
if server := os.Getenv("HISHTORY_SERVER"); server != "" { if server := os.Getenv("HISHTORY_SERVER"); server != "" {
return server return server

View File

@ -3,8 +3,8 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"io/ioutil" "io/ioutil"
"log"
"net/http" "net/http"
"github.com/ddworken/hishtory/shared" "github.com/ddworken/hishtory/shared"

View File

@ -8,8 +8,8 @@ import (
"net/http/httptest" "net/http/httptest"
"testing" "testing"
"github.com/google/uuid"
"github.com/ddworken/hishtory/shared" "github.com/ddworken/hishtory/shared"
"github.com/google/uuid"
) )
func TestESubmitThenQuery(t *testing.T) { func TestESubmitThenQuery(t *testing.T) {

View File

@ -1,13 +1,13 @@
package shared package shared
import ( import (
"testing"
"time"
"os"
"path"
"os/exec"
"bytes" "bytes"
"fmt" "fmt"
"os"
"os/exec"
"path"
"testing"
"time"
) )
func ResetLocalState(t *testing.T) { func ResetLocalState(t *testing.T) {

Binary file not shown.