Toby Chui 2 tahun lalu
induk
melakukan
c160073c6e
8 mengubah file dengan 296 tambahan dan 289 penghapusan
  1. 38 31
      build.bat
  2. 151 151
      fs.go
  3. TEMPAT SAMPAH
      launcher_darwin_amd64
  4. TEMPAT SAMPAH
      launcher_linux_amd64
  5. TEMPAT SAMPAH
      launcher_linux_arm64
  6. TEMPAT SAMPAH
      launcher_linux_armv6
  7. TEMPAT SAMPAH
      launcher_linux_armv7l
  8. 107 107
      main.go

+ 38 - 31
build.bat

@@ -1,31 +1,38 @@
-echo "Building darwin"
-set GOOS=darwin
-set GOARCH=amd64
-
-for %%I in (.) do SET EXENAME=%%~nxI
-
-go build
-MOVE "%EXENAME%" "%EXENAME%_darwin_amd64"
-
-echo "Building linux"
-set GOOS=linux
-set GOARCH=amd64
-go build
-MOVE "%EXENAME%" "%EXENAME%_linux_amd64"
-
-set GOOS=linux
-set GOARCH=arm
-go build
-MOVE "%EXENAME%" "%EXENAME%_linux_arm"
-
-set GOOS=linux
-set GOARCH=arm64
-go build
-MOVE "%EXENAME%" "%EXENAME%_linux_arm64"
-
-echo "Building windows"
-set GOOS=windows
-set GOARCH=amd64
-go build
-
-echo "Completed"
+echo "Building darwin"
+set GOOS=darwin
+set GOARCH=amd64
+
+for %%I in (.) do SET EXENAME=%%~nxI
+
+go build
+MOVE "%EXENAME%" "%EXENAME%_darwin_amd64"
+
+echo "Building linux"
+set GOOS=linux
+set GOARCH=amd64
+go build
+MOVE "%EXENAME%" "%EXENAME%_linux_amd64"
+
+set GOOS=linux
+set GOARCH=arm
+set GOARM=6
+go build
+MOVE "%EXENAME%" "%EXENAME%_linux_armv6"
+
+set GOOS=linux
+set GOARCH=arm
+set GOARM=7
+go build
+MOVE "%EXENAME%" "%EXENAME%_linux_armv7l"
+
+set GOOS=linux
+set GOARCH=arm64
+go build
+MOVE "%EXENAME%" "%EXENAME%_linux_arm64"
+
+echo "Building windows"
+set GOOS=windows
+set GOARCH=amd64
+go build
+
+echo "Completed"

+ 151 - 151
fs.go

@@ -1,151 +1,151 @@
-package main
-
-import (
-	"errors"
-	"fmt"
-	"io"
-	"os"
-	"path/filepath"
-	"runtime"
-
-	cp "github.com/otiai10/copy"
-)
-
-func restoreConfigs() {
-	restoreIfExists("system/bridge.json")
-	restoreIfExists("system/dev.uuid")
-	restoreIfExists("system/cron.json")
-	restoreIfExists("system/storage.json")
-	restoreIfExists("web/SystemAO/vendor/")
-
-	//Restore start script
-	if fileExists("./arozos.old/start.sh") {
-		copy("./arozos.old/start.sh", "./start.sh")
-	}
-	if fileExists("./arozos.old/start.bat") {
-		copy("./arozos.old/start.bat", "./start.bat")
-	}
-}
-
-func restoreOldArozOS() {
-	fmt.Println("[LAUNCHER] ArozOS unable to launch. Restoring from backup")
-	if fileExists("arozos.old") {
-		backupfiles, err := filepath.Glob("arozos.old/*")
-		if err != nil {
-			fmt.Println("[LAUNCHER] Unable to restore backup. Exiting.")
-			os.Exit(1)
-		}
-
-		for _, thisBackupFile := range backupfiles {
-			if isDir(thisBackupFile) {
-				cp.Copy(thisBackupFile, "./"+filepath.Base(thisBackupFile))
-			} else {
-				copy(thisBackupFile, "./"+filepath.Base(thisBackupFile))
-			}
-		}
-	} else {
-		fmt.Println("[LAUNCHER] ArozOS backup not found. Exiting.")
-		os.Exit(1)
-	}
-
-}
-
-func restoreIfExists(fileRelPath string) {
-	if fileExists(filepath.Join("arozos.old", fileRelPath)) {
-		if !isDir(filepath.Join("arozos.old", fileRelPath)) {
-			copy(filepath.Join("arozos.old", fileRelPath), fileRelPath)
-		} else {
-			cp.Copy(filepath.Join("arozos.old", fileRelPath), fileRelPath)
-		}
-	}
-}
-
-//Auto detect and execute the correct binary
-func autoDetectExecutable() string {
-	if runtime.GOOS == "windows" {
-		if fileExists("arozos.exe") {
-			return "arozos.exe"
-		}
-	} else {
-		if fileExists("arozos") {
-			return "./arozos"
-		}
-	}
-
-	//Not build from source. Look for release binary names
-	binaryExecPath := "arozos_" + runtime.GOOS + "_" + runtime.GOARCH
-	if runtime.GOOS == "windows" {
-		binaryExecPath += ".exe"
-	} else {
-		binaryExecPath = "./" + binaryExecPath
-	}
-
-	if fileExists(binaryExecPath) {
-		return binaryExecPath
-	} else {
-		fmt.Println("[LAUNCHER] Unable to detect ArozOS start binary")
-		os.Exit(1)
-		return ""
-	}
-}
-
-func getUpdateBinaryFilename() (string, error) {
-	updateFiles, err := filepath.Glob("./updates/*")
-	if err != nil {
-		return "", err
-	}
-
-	for _, thisFile := range updateFiles {
-		if !isDir(thisFile) && filepath.Ext(thisFile) != ".gz" {
-			//This might be the file
-			return thisFile, nil
-		}
-	}
-
-	return "", errors.New("file not found")
-}
-
-func copy(src, dst string) (int64, error) {
-	sourceFileStat, err := os.Stat(src)
-	if err != nil {
-		return 0, err
-	}
-
-	if !sourceFileStat.Mode().IsRegular() {
-		return 0, errors.New("invalid file")
-	}
-
-	source, err := os.Open(src)
-	if err != nil {
-		return 0, err
-	}
-	defer source.Close()
-
-	destination, err := os.Create(dst)
-	if err != nil {
-		return 0, err
-	}
-	defer destination.Close()
-	nBytes, err := io.Copy(destination, source)
-	return nBytes, err
-}
-
-func isDir(path string) bool {
-	fileInfo, err := os.Stat(path)
-	if err != nil {
-		return false
-	}
-
-	return fileInfo.IsDir()
-}
-
-func fileExists(name string) bool {
-	_, err := os.Stat(name)
-	if err == nil {
-		return true
-	}
-	if errors.Is(err, os.ErrNotExist) {
-		return false
-	}
-	return false
-}
+package main
+
+import (
+	"errors"
+	"fmt"
+	"io"
+	"os"
+	"path/filepath"
+	"runtime"
+
+	cp "github.com/otiai10/copy"
+)
+
+func restoreConfigs() {
+	restoreIfExists("system/bridge.json")
+	restoreIfExists("system/dev.uuid")
+	restoreIfExists("system/cron.json")
+	restoreIfExists("system/storage.json")
+	restoreIfExists("web/SystemAO/vendor/")
+
+	//Restore start script
+	if fileExists("./arozos.old/start.sh") {
+		copy("./arozos.old/start.sh", "./start.sh")
+	}
+	if fileExists("./arozos.old/start.bat") {
+		copy("./arozos.old/start.bat", "./start.bat")
+	}
+}
+
+func restoreOldArozOS() {
+	fmt.Println("[LAUNCHER] ArozOS unable to launch. Restoring from backup")
+	if fileExists("arozos.old") {
+		backupfiles, err := filepath.Glob("arozos.old/*")
+		if err != nil {
+			fmt.Println("[LAUNCHER] Unable to restore backup. Exiting.")
+			os.Exit(1)
+		}
+
+		for _, thisBackupFile := range backupfiles {
+			if isDir(thisBackupFile) {
+				cp.Copy(thisBackupFile, "./"+filepath.Base(thisBackupFile))
+			} else {
+				copy(thisBackupFile, "./"+filepath.Base(thisBackupFile))
+			}
+		}
+	} else {
+		fmt.Println("[LAUNCHER] ArozOS backup not found. Exiting.")
+		os.Exit(1)
+	}
+
+}
+
+func restoreIfExists(fileRelPath string) {
+	if fileExists(filepath.Join("arozos.old", fileRelPath)) {
+		if !isDir(filepath.Join("arozos.old", fileRelPath)) {
+			copy(filepath.Join("arozos.old", fileRelPath), fileRelPath)
+		} else {
+			cp.Copy(filepath.Join("arozos.old", fileRelPath), fileRelPath)
+		}
+	}
+}
+
+//Auto detect and execute the correct binary
+func autoDetectExecutable() string {
+	if runtime.GOOS == "windows" {
+		if fileExists("arozos.exe") {
+			return "arozos.exe"
+		}
+	} else {
+		if fileExists("arozos") {
+			return "./arozos"
+		}
+	}
+
+	//Not build from source. Look for release binary names
+	binaryExecPath := "arozos_" + runtime.GOOS + "_" + runtime.GOARCH
+	if runtime.GOOS == "windows" {
+		binaryExecPath = "./" + binaryExecPath + ".exe"
+	} else {
+		binaryExecPath = "./" + binaryExecPath
+	}
+
+	if fileExists(binaryExecPath) {
+		return binaryExecPath
+	} else {
+		fmt.Println("[LAUNCHER] Unable to detect ArozOS start binary")
+		os.Exit(1)
+		return ""
+	}
+}
+
+func getUpdateBinaryFilename() (string, error) {
+	updateFiles, err := filepath.Glob("./updates/*")
+	if err != nil {
+		return "", err
+	}
+
+	for _, thisFile := range updateFiles {
+		if !isDir(thisFile) && filepath.Ext(thisFile) != ".gz" {
+			//This might be the file
+			return thisFile, nil
+		}
+	}
+
+	return "", errors.New("file not found")
+}
+
+func copy(src, dst string) (int64, error) {
+	sourceFileStat, err := os.Stat(src)
+	if err != nil {
+		return 0, err
+	}
+
+	if !sourceFileStat.Mode().IsRegular() {
+		return 0, errors.New("invalid file")
+	}
+
+	source, err := os.Open(src)
+	if err != nil {
+		return 0, err
+	}
+	defer source.Close()
+
+	destination, err := os.Create(dst)
+	if err != nil {
+		return 0, err
+	}
+	defer destination.Close()
+	nBytes, err := io.Copy(destination, source)
+	return nBytes, err
+}
+
+func isDir(path string) bool {
+	fileInfo, err := os.Stat(path)
+	if err != nil {
+		return false
+	}
+
+	return fileInfo.IsDir()
+}
+
+func fileExists(name string) bool {
+	_, err := os.Stat(name)
+	if err == nil {
+		return true
+	}
+	if errors.Is(err, os.ErrNotExist) {
+		return false
+	}
+	return false
+}

TEMPAT SAMPAH
launcher_darwin_amd64


TEMPAT SAMPAH
launcher_linux_amd64


TEMPAT SAMPAH
launcher_linux_arm64


TEMPAT SAMPAH
launcher_linux_armv6


TEMPAT SAMPAH
launcher_linux_armv7l


+ 107 - 107
main.go

@@ -1,107 +1,107 @@
-package main
-
-import (
-	"fmt"
-	"log"
-	"net/http"
-	"os"
-	"os/exec"
-	"path/filepath"
-	"time"
-)
-
-/*
-	ArozOS Launcher
-	For auto update and future extension purpose
-
-	Author: tobychui
-
-*/
-
-const (
-	launcherVersion   = "1.1"
-	restoreRetryCount = 3 //The number of retry before restore old version, if not working after restoreRetryCount + 1 launcher will exit
-)
-
-var (
-	norestart bool = false
-)
-
-func main() {
-	//Print basic information
-	fmt.Println("[LAUNCHER] ArozOS Launcher ver " + launcherVersion)
-	binaryName := autoDetectExecutable()
-	fmt.Println("[LAUNCHER] Choosing binary executable: " + binaryName)
-
-	//Check if updates exists. If yes, overwrite it
-	updateIfExists(binaryName)
-
-	//Check launch paramter for norestart
-	for _, arg := range os.Args[1:] {
-		if arg == "-h" || arg == "-help" {
-			//help argument, do not restart
-			norestart = true
-		} else if arg == "-version" || arg == "-v" {
-			//version argument, no restart
-			norestart = true
-		}
-	}
-
-	//Register the binary start path
-	cmd := exec.Command(binaryName, os.Args[1:]...)
-	cmd.Dir = filepath.Dir(binaryName)
-	cmd.Stdout = os.Stdout
-	cmd.Stderr = os.Stderr
-
-	//Register the http server to notify ArozOS there is a launcher will handle the update
-	go func() {
-		http.HandleFunc("/chk", func(w http.ResponseWriter, r *http.Request) {
-			w.Write([]byte("LauncherA v" + launcherVersion))
-			fmt.Println("[LAUNCHER] CHK RECV - DONE")
-		})
-
-		http.ListenAndServe("127.0.0.1:25576", nil)
-	}()
-
-	retryCounter := 0
-	//Start the cmd
-	for {
-		startTime := time.Now().Unix()
-		err := cmd.Run()
-		endTime := time.Now().Unix()
-
-		if err != nil {
-			panic(err)
-		}
-		if norestart {
-			return
-		}
-		if endTime-startTime < 3 {
-			//Less than 3 seconds, shd be crashed. Add to retry counter
-			fmt.Println("[LAUNCHER] ArozOS Crashed. Restarting in 3 seconds... ")
-			retryCounter++
-		} else {
-			fmt.Println("[LAUNCHER] ArozOS Exited. Restarting in 3 seconds... ")
-			retryCounter = 0
-		}
-
-		time.Sleep(3 * time.Second)
-
-		if retryCounter > restoreRetryCount+1 {
-			//Fail to start. Exit program
-			log.Fatal("Unable to start ArozOS. Exiting to OS")
-			return
-		} else if retryCounter > restoreRetryCount {
-			//Restore from old version of the binary
-			restoreOldArozOS()
-		} else {
-			updateIfExists(binaryName)
-		}
-
-		//Rebuild the start paramters
-		cmd = exec.Command(binaryName, os.Args[1:]...)
-		cmd.Stdout = os.Stdout
-		cmd.Stderr = os.Stderr
-	}
-
-}
+package main
+
+import (
+	"fmt"
+	"log"
+	"net/http"
+	"os"
+	"os/exec"
+	"path/filepath"
+	"time"
+)
+
+/*
+	ArozOS Launcher
+	For auto update and future extension purpose
+
+	Author: tobychui
+
+*/
+
+const (
+	launcherVersion   = "2"
+	restoreRetryCount = 3 //The number of retry before restore old version, if not working after restoreRetryCount + 1 launcher will exit
+)
+
+var (
+	norestart bool = false
+)
+
+func main() {
+	//Print basic information
+	fmt.Println("[LAUNCHER] ArozOS Launcher ver " + launcherVersion)
+	binaryName := autoDetectExecutable()
+	fmt.Println("[LAUNCHER] Choosing binary executable: " + binaryName)
+
+	//Check if updates exists. If yes, overwrite it
+	updateIfExists(binaryName)
+
+	//Check launch paramter for norestart
+	for _, arg := range os.Args[1:] {
+		if arg == "-h" || arg == "-help" {
+			//help argument, do not restart
+			norestart = true
+		} else if arg == "-version" || arg == "-v" {
+			//version argument, no restart
+			norestart = true
+		}
+	}
+
+	//Register the binary start path
+	cmd := exec.Command(binaryName, os.Args[1:]...)
+	cmd.Dir = filepath.Dir(binaryName)
+	cmd.Stdout = os.Stdout
+	cmd.Stderr = os.Stderr
+
+	//Register the http server to notify ArozOS there is a launcher will handle the update
+	go func() {
+		http.HandleFunc("/chk", func(w http.ResponseWriter, r *http.Request) {
+			w.Write([]byte("LauncherA v" + launcherVersion))
+			fmt.Println("[LAUNCHER] CHK RECV - DONE")
+		})
+
+		http.ListenAndServe("127.0.0.1:25576", nil)
+	}()
+
+	retryCounter := 0
+	//Start the cmd
+	for {
+		startTime := time.Now().Unix()
+		err := cmd.Run()
+		endTime := time.Now().Unix()
+
+		if err != nil {
+			panic(err)
+		}
+		if norestart {
+			return
+		}
+		if endTime-startTime < 3 {
+			//Less than 3 seconds, shd be crashed. Add to retry counter
+			fmt.Println("[LAUNCHER] ArozOS Crashed. Restarting in 3 seconds... ")
+			retryCounter++
+		} else {
+			fmt.Println("[LAUNCHER] ArozOS Exited. Restarting in 3 seconds... ")
+			retryCounter = 0
+		}
+
+		time.Sleep(3 * time.Second)
+
+		if retryCounter > restoreRetryCount+1 {
+			//Fail to start. Exit program
+			log.Fatal("Unable to start ArozOS. Exiting to OS")
+			return
+		} else if retryCounter > restoreRetryCount {
+			//Restore from old version of the binary
+			restoreOldArozOS()
+		} else {
+			updateIfExists(binaryName)
+		}
+
+		//Rebuild the start paramters
+		cmd = exec.Command(binaryName, os.Args[1:]...)
+		cmd.Stdout = os.Stdout
+		cmd.Stderr = os.Stderr
+	}
+
+}