github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/system/packagemanager/eopkg.go (about) 1 //go:build linux 2 // +build linux 3 4 package packagemanager 5 6 import ( 7 "regexp" 8 "strings" 9 10 "github.com/AlpineAIO/wails/v2/internal/shell" 11 ) 12 13 // Eopkg represents the Eopkg manager 14 type Eopkg struct { 15 name string 16 osid string 17 } 18 19 // NewEopkg creates a new Eopkg instance 20 func NewEopkg(osid string) *Eopkg { 21 result := &Eopkg{ 22 name: "eopkg", 23 osid: osid, 24 } 25 result.intialiseName() 26 return result 27 } 28 29 // Packages returns the packages that we need for Wails to compile 30 // They will potentially differ on different distributions or versions 31 func (e *Eopkg) Packages() packagemap { 32 return packagemap{ 33 "libgtk-3": []*Package{ 34 {Name: "libgtk-3-devel", SystemPackage: true, Library: true}, 35 }, 36 "libwebkit": []*Package{ 37 {Name: "libwebkit-gtk-devel", SystemPackage: true, Library: true}, 38 }, 39 "gcc": []*Package{ 40 {Name: "gcc", SystemPackage: true}, 41 }, 42 "pkg-config": []*Package{ 43 {Name: "pkg-config", SystemPackage: true}, 44 }, 45 "npm": []*Package{ 46 {Name: "nodejs", SystemPackage: true}, 47 }, 48 "docker": []*Package{ 49 {Name: "docker", SystemPackage: true, Optional: true}, 50 }, 51 } 52 } 53 54 // Name returns the name of the package manager 55 func (e *Eopkg) Name() string { 56 return e.name 57 } 58 59 // PackageInstalled tests if the given package is installed 60 func (e *Eopkg) PackageInstalled(pkg *Package) (bool, error) { 61 if pkg.SystemPackage == false { 62 return false, nil 63 } 64 stdout, _, err := shell.RunCommand(".", "eopkg", "info", pkg.Name) 65 return strings.HasPrefix(stdout, "Installed"), err 66 } 67 68 // PackageAvailable tests if the given package is available for installation 69 func (e *Eopkg) PackageAvailable(pkg *Package) (bool, error) { 70 if pkg.SystemPackage == false { 71 return false, nil 72 } 73 stdout, _, err := shell.RunCommand(".", "eopkg", "info", pkg.Name) 74 // We add a space to ensure we get a full match, not partial match 75 output := e.removeEscapeSequences(stdout) 76 installed := strings.Contains(output, "Package found in Solus repository") 77 e.getPackageVersion(pkg, output) 78 return installed, err 79 } 80 81 // InstallCommand returns the package manager specific command to install a package 82 func (e *Eopkg) InstallCommand(pkg *Package) string { 83 if pkg.SystemPackage == false { 84 return pkg.InstallCommand[e.osid] 85 } 86 return "sudo eopkg it " + pkg.Name 87 } 88 89 func (e *Eopkg) removeEscapeSequences(in string) string { 90 escapechars, _ := regexp.Compile(`\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])`) 91 return escapechars.ReplaceAllString(in, "") 92 } 93 94 func (e *Eopkg) intialiseName() { 95 result := "eopkg" 96 stdout, _, err := shell.RunCommand(".", "eopkg", "--version") 97 if err == nil { 98 result = strings.TrimSpace(stdout) 99 } 100 e.name = result 101 } 102 103 func (e *Eopkg) getPackageVersion(pkg *Package, output string) { 104 105 versionRegex := regexp.MustCompile(`.*Name.*version:\s+(.*)+, release: (.*)`) 106 matches := versionRegex.FindStringSubmatch(output) 107 pkg.Version = "" 108 noOfMatches := len(matches) 109 if noOfMatches > 1 { 110 pkg.Version = matches[1] 111 if noOfMatches > 2 { 112 pkg.Version += " (r" + matches[2] + ")" 113 } 114 } 115 }