mirror of https://gitee.com/godoos/godoos.git
9 changed files with 1353 additions and 39 deletions
@ -1,4 +1,25 @@ |
|||
wails build -platform linux/amd64 -s -o godoos-linux-amd64 |
|||
wails build -platform linux/arm64 -s -o godoos-linux-arm64 |
|||
wails build -platform darwin/amd64 -s -o godoos-darwin-amd64 |
|||
wails build -platform darwin/arm64 -s -o godoos-darwin-arm64 |
|||
#!/bin/bash |
|||
|
|||
# 定义一个函数来执行压缩操作 |
|||
compress_to_zip() { |
|||
local target_file="./build/bin/godoos$2" |
|||
local zip_name="./build/bin/$1.zip" |
|||
|
|||
# 检查ZIP文件是否已经存在,如果存在则跳过压缩 |
|||
if [ ! -f "$zip_name" ]; then |
|||
echo "Compressing $target_file to $zip_name" |
|||
zip -j "$zip_name" "$target_file" |
|||
else |
|||
echo "$zip_name already exists. Skipping compression." |
|||
fi |
|||
} |
|||
|
|||
# 构建和压缩 |
|||
wails build -platform linux/amd64 -s |
|||
compress_to_zip "godoos-linux-amd64" "" |
|||
wails build -platform linux/arm64 -s |
|||
compress_to_zip "godoos-linux-arm64" "" |
|||
wails build -platform darwin/amd64 -s |
|||
compress_to_zip "godoos-darwin-amd64" ".app" |
|||
wails build -platform darwin/arm64 -s |
|||
compress_to_zip "godoos-darwin-arm64" ".app" |
File diff suppressed because it is too large
@ -0,0 +1,153 @@ |
|||
package store |
|||
|
|||
import ( |
|||
"bufio" |
|||
"fmt" |
|||
"os" |
|||
"os/exec" |
|||
"runtime" |
|||
"strings" |
|||
"syscall" |
|||
) |
|||
|
|||
// DetectOperatingSystem returns the operating system name and version.
|
|||
func DetectOperatingSystem() (name string, version string, err error) { |
|||
switch runtime.GOOS { |
|||
case "darwin": |
|||
// macOS specific detection
|
|||
cmd := exec.Command("sw_vers") |
|||
out, err := cmd.CombinedOutput() |
|||
if err != nil { |
|||
return "", "", err |
|||
} |
|||
output := string(out) |
|||
lines := strings.Split(output, "\n") |
|||
if len(lines) >= 2 { |
|||
name = strings.TrimSpace(strings.Split(lines[0], ":")[1]) |
|||
version = strings.TrimSpace(strings.Split(lines[1], ":")[1]) |
|||
} |
|||
case "linux": |
|||
// Linux specific detection
|
|||
file, err := os.Open("/etc/os-release") |
|||
if err != nil { |
|||
return "", "", err |
|||
} |
|||
defer file.Close() |
|||
|
|||
scanner := bufio.NewScanner(file) |
|||
for scanner.Scan() { |
|||
line := scanner.Text() |
|||
if strings.HasPrefix(line, "ID=") { |
|||
name = strings.TrimPrefix(line, "ID=") |
|||
name = strings.Trim(name, "\"") |
|||
} else if strings.HasPrefix(line, "VERSION_ID=") { |
|||
version = strings.TrimPrefix(line, "VERSION_ID=") |
|||
version = strings.Trim(version, "\"") |
|||
} |
|||
} |
|||
|
|||
if err := scanner.Err(); err != nil { |
|||
return "", "", err |
|||
} |
|||
|
|||
if name == "" || version == "" { |
|||
return "", "", fmt.Errorf("could not determine Linux distribution from /etc/os-release") |
|||
} |
|||
case "windows": |
|||
// Windows specific detection
|
|||
cmd := exec.Command("cmd", "/c", "ver") |
|||
out, err := cmd.CombinedOutput() |
|||
if err != nil { |
|||
return "", "", err |
|||
} |
|||
version = strings.TrimSpace(string(out)) |
|||
name = "Windows" |
|||
default: |
|||
// For other operating systems, just return the GOOS value
|
|||
name = runtime.GOOS |
|||
version = "" |
|||
} |
|||
|
|||
return name, version, nil |
|||
} |
|||
|
|||
// DetectPackageManager returns the package manager based on the detected operating system.
|
|||
func DetectPackageManager() (pm string, err error) { |
|||
switch runtime.GOOS { |
|||
case "darwin": |
|||
// macOS specific detection
|
|||
cmd := exec.Command("which", "brew") |
|||
out, err := cmd.CombinedOutput() |
|||
if err != nil { |
|||
return "", fmt.Errorf("homebrew not found: %w", err) |
|||
} |
|||
pm = strings.TrimSpace(string(out)) |
|||
if pm != "" { |
|||
pm = "brew" |
|||
} |
|||
case "linux": |
|||
// Linux specific detection
|
|||
file, err := os.Open("/etc/os-release") |
|||
if err != nil { |
|||
return "", err |
|||
} |
|||
defer file.Close() |
|||
|
|||
scanner := bufio.NewScanner(file) |
|||
for scanner.Scan() { |
|||
line := scanner.Text() |
|||
if strings.HasPrefix(line, "ID=") { |
|||
id := strings.TrimPrefix(line, "ID=") |
|||
id = strings.Trim(id, "\"") |
|||
switch id { |
|||
case "debian", "ubuntu", "linuxmint", "elementary": |
|||
pm = "apt" |
|||
case "centos", "fedora", "rhel": |
|||
cmd := exec.Command("which", "dnf") |
|||
out, err := cmd.CombinedOutput() |
|||
if err != nil { |
|||
cmd = exec.Command("which", "yum") |
|||
out, err = cmd.CombinedOutput() |
|||
if err != nil { |
|||
return "", fmt.Errorf("neither dnf nor yum found: %w", err) |
|||
} |
|||
} |
|||
pm = strings.TrimSpace(string(out)) |
|||
if pm != "" { |
|||
pm = "dnf" |
|||
} else { |
|||
pm = "yum" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
if err := scanner.Err(); err != nil { |
|||
return "", err |
|||
} |
|||
case "windows": |
|||
// Windows specific detection - Not applicable for this context
|
|||
return "", fmt.Errorf("windows does not use apt, yum, or brew") |
|||
default: |
|||
// For other operating systems, just return an error
|
|||
return "", fmt.Errorf("unsupported operating system: %s", runtime.GOOS) |
|||
} |
|||
|
|||
return pm, nil |
|||
} |
|||
|
|||
func CheckPathInstalled(execName string, execCommands string) bool { |
|||
cmd := exec.Command(execName, execCommands) |
|||
out, err := cmd.CombinedOutput() |
|||
if err != nil { |
|||
// 如果命令执行失败,可能是因为brew没有安装
|
|||
if exitErr, ok := err.(*exec.ExitError); ok { |
|||
// 判断是否是因为找不到命令导致的错误
|
|||
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok && status.ExitStatus() == 127 { |
|||
return false // brew没有安装
|
|||
} |
|||
} |
|||
} |
|||
fmt.Printf("Homebrew version: %s\n", out) |
|||
return true |
|||
} |
Loading…
Reference in new issue