Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions backend/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,32 @@ func main() {
} else {

fmt.Println("Backend folder not detected. Launching existing updater...")
osType := detectOS()

execPath, err := os.Executable()
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting executable path: %v\n", err)
os.Exit(1)
}
updatersDir := filepath.Join(filepath.Dir(execPath), "updaters")

var updaterExe string
switch osType {
case "updaters/updater-windows-64.exe":
updaterExe = filepath.Join(updatersDir, "updater-windows-64")
case "updaters/updater-linux":
updaterExe = filepath.Join(updatersDir, "updater-linux")
case "updaters/updater-macos-m1":
updaterExe = filepath.Join(updatersDir, "updater-macos-m1")
case "updaters/updater-macos-64":
updaterExe = filepath.Join(updatersDir, "updater-macos-64")
default:
fmt.Fprintf(os.Stderr, "Unsupported updater: %s\n", osType)
os.Exit(1)
}

updaterExe := filepath.Join(execDir, "updater.exe")
cmd := exec.Command(updaterExe)
cmd.Dir = filepath.Dir(updaterExe)
cmd.Dir = updatersDir
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Expand Down Expand Up @@ -715,3 +737,20 @@ func getLatestVersionFromGitHub() (string, error) {
version := strings.TrimPrefix(release.TagName, "v")
return version, nil
}
func detectOS() string {
switch runtime.GOOS {
case "windows":
return "updaters/updater-windows-64.exe"
case "darwin":
if strings.Contains(runtime.GOARCH, "arm") {
return "updaters/updater-macos-m1"
}
return "updaters/updater-macos-64"
case "linux":
return "updaters/updater-linux"
default:
fmt.Fprintf(os.Stderr, "Unsupported operating system: %s\n", runtime.GOOS)
os.Exit(1)
return ""
}
}
23 changes: 13 additions & 10 deletions updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,43 +194,46 @@ func downloadFile(filepath string, url string) error {
}

func extractBinaryFromZip(zipPath, binaryName string) (string, error) {
// Open the ZIP file
r, err := zip.OpenReader(zipPath)
if err != nil {
return "", err
}
defer r.Close()

// Iterate through the files in the ZIP
var binaryPath string
parentDir, _ := filepath.Abs(filepath.Join(".", ".."))

for _, f := range r.File {
if f.Name == binaryName {
// Open the file inside the ZIP
baseName := filepath.Base(f.Name)
if baseName == binaryName || baseName == "VERSION.md" {
rc, err := f.Open()
if err != nil {
return "", err
}
defer rc.Close()

// Create the output file
outPath := "./" + binaryName
outPath := filepath.Join(parentDir, baseName)
outFile, err := os.Create(outPath)
if err != nil {
return "", err
}
defer outFile.Close()

// Copy the contents of the file
_, err = io.Copy(outFile, rc)
if err != nil {
return "", err
}

// Return the path to the extracted binary
return outPath, nil
if baseName == binaryName {
binaryPath = outPath
}
}
}

return "", fmt.Errorf("binary %s not found in ZIP", binaryName)
if binaryPath == "" {
return "", fmt.Errorf("binary %s not found in ZIP", binaryName)
}
return binaryPath, nil
}

func getLatestVersion() (string, error) {
Expand Down
Loading