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"
"encoding/json"
"fmt"
"net/http"
"io/ioutil"
"net/http"
"os"
"strings"
"gorm.io/gorm"
"github.com/ddworken/hishtory/shared"
"github.com/ddworken/hishtory/client/lib"
"github.com/ddworken/hishtory/shared"
)
func main() {

View File

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

View File

@ -9,6 +9,7 @@ import (
"io"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"os/user"
@ -16,8 +17,8 @@ import (
"path/filepath"
"strconv"
"strings"
"syscall"
"time"
"net/http"
"gorm.io/gorm"
@ -375,17 +376,29 @@ func copyFile(src, dst string) error {
func Update(url string) error {
var stdout 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.Stderr = &stderr
err := cmd.Run()
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
}
func GetServerHostname() string {
if server := os.Getenv("HISHTORY_SERVER"); server != "" {
return server

View File

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

View File

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

View File

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

Binary file not shown.