@@ -21,29 +21,29 @@ const (
2121
2222func main () {
2323 // Detect the operating system
24- osType := detectOS ()
24+ zipName := getZipName ()
2525
2626 // Check if the `../backend/` folder exists
2727 if _ , err := os .Stat ("../backend" ); err == nil {
2828 fmt .Println ("Directory '../backend' found. Updating from the repository..." )
2929 updateFromGit ()
3030 } else {
3131 fmt .Println ("Directory '../backend' not found. Checking binaries..." )
32- updateFromBinaries (osType )
32+ updateFromBinaries (zipName )
3333 }
3434}
3535
36- func detectOS () string {
36+ func getZipName () string {
3737 switch runtime .GOOS {
3838 case "windows" :
39- return "backend- windows-64.exe" // Incluye la extensión .exe para Windows
39+ return "windows"
4040 case "darwin" :
4141 if strings .Contains (runtime .GOARCH , "arm" ) {
42- return "backend- macos-m1-64 "
42+ return "macos-arm64 "
4343 }
44- return "backend- macos-64 "
44+ return "macos-intel "
4545 case "linux" :
46- return "backend- linux-64 "
46+ return "linux"
4747 default :
4848 fmt .Fprintf (os .Stderr , "Unsupported operating system: %s\n " , runtime .GOOS )
4949 os .Exit (1 )
@@ -104,42 +104,41 @@ func stopProcess(processName string) error {
104104 return nil
105105}
106106
107- func updateFromBinaries (osType string ) {
108- binaries := []string {"backend-windows-64.exe" , "backend-linux-64" , "backend-macos-64" , "backend-macos-m1-64" }
109- for _ , binary := range binaries {
110- if _ , err := os .Stat ("./" + binary ); err == nil {
111- // Check if the backend process is running
112- isRunning , err := isProcessRunning (binary )
113- if err != nil {
114- fmt .Fprintf (os .Stderr , "Error checking if process is running: %v\n " , err )
115- os .Exit (1 )
116- }
117-
118- // Stop the process if it's running
119- if isRunning {
120- fmt .Printf ("Process %s is running. Stopping it...\n " , binary )
121- if err := stopProcess (binary ); err != nil {
122- fmt .Fprintf (os .Stderr , "Error stopping process %s: %v\n " , binary , err )
123- os .Exit (1 )
124- }
125- time .Sleep (500 * time .Millisecond ) // waits 1/2 second to ensure the process is stopped
126- }
107+ func updateFromBinaries (zipBase string ) {
108+ binary := "backend"
109+ if runtime .GOOS == "windows" {
110+ binary += ".exe"
111+ }
127112
128- fmt .Printf ("Deleting old binary: %s\n " , binary )
129- deleted := false
130- for i := 0 ; i < 5 ; i ++ {
131- if err := os .Remove ("./" + binary ); err == nil {
132- deleted = true
133- break
134- } else {
135- fmt .Printf ("Retrying delete (%d/5)...\n " , i + 1 )
136- time .Sleep (300 * time .Millisecond )
137- }
138- }
139- if ! deleted {
140- fmt .Fprintf (os .Stderr , "Error deleting old binary after multiple attempts.\n " )
113+ // Stop and remove old binary if exists
114+ if _ , err := os .Stat ("./" + binary ); err == nil {
115+ isRunning , err := isProcessRunning (binary )
116+ if err != nil {
117+ fmt .Fprintf (os .Stderr , "Error checking if process is running: %v\n " , err )
118+ os .Exit (1 )
119+ }
120+ if isRunning {
121+ fmt .Printf ("Process %s is running. Stopping it...\n " , binary )
122+ if err := stopProcess (binary ); err != nil {
123+ fmt .Fprintf (os .Stderr , "Error stopping process %s: %v\n " , binary , err )
141124 os .Exit (1 )
142125 }
126+ time .Sleep (500 * time .Millisecond )
127+ }
128+ fmt .Printf ("Deleting old binary: %s\n " , binary )
129+ deleted := false
130+ for i := 0 ; i < 5 ; i ++ {
131+ if err := os .Remove ("./" + binary ); err == nil {
132+ deleted = true
133+ break
134+ } else {
135+ fmt .Printf ("Retrying delete (%d/5)...\n " , i + 1 )
136+ time .Sleep (300 * time .Millisecond )
137+ }
138+ }
139+ if ! deleted {
140+ fmt .Fprintf (os .Stderr , "Error deleting old binary after multiple attempts.\n " )
141+ os .Exit (1 )
143142 }
144143 }
145144
@@ -150,8 +149,7 @@ func updateFromBinaries(osType string) {
150149 os .Exit (1 )
151150 }
152151
153- // Construct the ZIP file URL
154- zipFileName := fmt .Sprintf ("control-station-v%s.zip" , strings .ReplaceAll (latestVersion , "." , "-" ))
152+ zipFileName := fmt .Sprintf ("%s-%s.zip" , zipBase , latestVersion )
155153 url := fmt .Sprintf ("https://github.com/%s/%s/releases/download/v%s/%s" , repoOwner , repoName , latestVersion , zipFileName )
156154 fmt .Printf ("Downloading ZIP from: %s\n " , url )
157155
@@ -162,8 +160,8 @@ func updateFromBinaries(osType string) {
162160 os .Exit (1 )
163161 }
164162
165- // Extract the binary from the ZIP file
166- binaryPath , err := extractBinaryFromZip ("./" + zipFileName , osType )
163+ // Extract the binary and VERSION.md from the ZIP file
164+ binaryPath , err := extractBinaryFromZip ("./" + zipFileName , binary )
167165 if err != nil {
168166 fmt .Fprintf (os .Stderr , "Error extracting the binary: %v\n " , err )
169167 os .Exit (1 )
0 commit comments