mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-16 18:01:46 +02:00
working update
This commit is contained in:
@ -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() {
|
||||
@ -28,7 +28,7 @@ func main() {
|
||||
case "export":
|
||||
export()
|
||||
case "init":
|
||||
lib.CheckFatalError(lib.Setup( os.Args))
|
||||
lib.CheckFatalError(lib.Setup(os.Args))
|
||||
case "install":
|
||||
lib.CheckFatalError(lib.Install())
|
||||
case "enable":
|
||||
@ -53,7 +53,7 @@ func retrieveAdditionalEntriesFromRemote(db *gorm.DB) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := http.Get(lib.GetServerHostname()+"/api/v1/equery?device_id=" + config.DeviceId)
|
||||
resp, err := http.Get(lib.GetServerHostname() + "/api/v1/equery?device_id=" + config.DeviceId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to pull latest history entries from the backend: %v", err)
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func RunInteractiveBashCommands(t *testing.T, script string) string {
|
||||
shared.Check(t, ioutil.WriteFile("/tmp/hishtory-test-in.sh", []byte("set -euo pipefail\n" + script), 0600))
|
||||
shared.Check(t, ioutil.WriteFile("/tmp/hishtory-test-in.sh", []byte("set -euo pipefail\n"+script), 0600))
|
||||
cmd := exec.Command("bash", "-i")
|
||||
cmd.Stdin = strings.NewReader(script)
|
||||
var out bytes.Buffer
|
||||
@ -56,8 +56,8 @@ func TestIntegrationWithNewDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
// Set the secret key to the previous secret key
|
||||
out = RunInteractiveBashCommands(t, `hishtory init ` + userSecret)
|
||||
if !strings.Contains(out, "Setting secret hishtory key to " + userSecret) {
|
||||
out = RunInteractiveBashCommands(t, `hishtory init `+userSecret)
|
||||
if !strings.Contains(out, "Setting secret hishtory key to "+userSecret) {
|
||||
t.Fatalf("Failed to re-init with the user secret: %v", out)
|
||||
}
|
||||
|
||||
@ -98,8 +98,8 @@ func TestIntegrationWithNewDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
// Set the secret key to the previous secret key
|
||||
out = RunInteractiveBashCommands(t, `hishtory init ` + userSecret)
|
||||
if !strings.Contains(out, "Setting secret hishtory key to " + userSecret) {
|
||||
out = RunInteractiveBashCommands(t, `hishtory init `+userSecret)
|
||||
if !strings.Contains(out, "Setting secret hishtory key to "+userSecret) {
|
||||
t.Fatalf("Failed to re-init with the user secret: %v", out)
|
||||
}
|
||||
|
||||
@ -141,12 +141,11 @@ func testIntegration(t *testing.T) string {
|
||||
}
|
||||
userSecret := matches[1]
|
||||
|
||||
|
||||
// TODO(ddworken): Test the status subcommand
|
||||
out = RunInteractiveBashCommands(t, `
|
||||
hishtory status
|
||||
`)
|
||||
if out != "Hishtory: Offline Mode\nEnabled: true\n"{
|
||||
if out != "Hishtory: Offline Mode\nEnabled: true\n" {
|
||||
t.Fatalf("status command has unexpected output: %#v", out)
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
||||
@ -131,12 +132,12 @@ func Setup(args []string) error {
|
||||
return fmt.Errorf("failed to persist config to disk: %v", err)
|
||||
}
|
||||
|
||||
_, err = http.Get(GetServerHostname()+"/api/v1/eregister?user_id=" + shared.UserId(userSecret) + "&device_id=" + config.DeviceId)
|
||||
_, err = http.Get(GetServerHostname() + "/api/v1/eregister?user_id=" + shared.UserId(userSecret) + "&device_id=" + config.DeviceId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to register device with backend: %v", err)
|
||||
}
|
||||
|
||||
resp, err := http.Get(GetServerHostname()+"/api/v1/ebootstrap?user_id=" + shared.UserId(userSecret) + "&device_id=" + config.DeviceId)
|
||||
resp, err := http.Get(GetServerHostname() + "/api/v1/ebootstrap?user_id=" + shared.UserId(userSecret) + "&device_id=" + config.DeviceId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to bootstrap device from the backend: %v", err)
|
||||
}
|
||||
@ -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
|
||||
|
@ -3,8 +3,8 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/ddworken/hishtory/shared"
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
@ -39,7 +39,7 @@ func buildServer(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to chdir: %v", err)
|
||||
}
|
||||
cmd := exec.Command("go", "build", "-o", "/tmp/server","server/server.go")
|
||||
cmd := exec.Command("go", "build", "-o", "/tmp/server", "server/server.go")
|
||||
var stdout bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
var stderr bytes.Buffer
|
||||
@ -55,9 +55,9 @@ func buildServer(t *testing.T) {
|
||||
}
|
||||
|
||||
func RunTestServer(t *testing.T) func() {
|
||||
os.Setenv("HISHTORY_SERVER" ,"http://localhost:8080")
|
||||
os.Setenv("HISHTORY_SERVER", "http://localhost:8080")
|
||||
buildServer(t)
|
||||
cmd := exec.Command( "/tmp/server" )
|
||||
cmd := exec.Command("/tmp/server")
|
||||
var stdout bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
var stderr bytes.Buffer
|
||||
@ -66,7 +66,7 @@ func RunTestServer(t *testing.T) func() {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to start server: %v", err)
|
||||
}
|
||||
time.Sleep(time.Second*3)
|
||||
time.Sleep(time.Second * 3)
|
||||
go func() {
|
||||
cmd.Wait()
|
||||
}()
|
||||
|
BIN
web/landing/www/binaries/hishtory-linux
Executable file
BIN
web/landing/www/binaries/hishtory-linux
Executable file
Binary file not shown.
Reference in New Issue
Block a user