AllPac/pkg/packagemanager/pacman.go
VetheonGames 4b0a6e6d59 Major Update 3
changes to main.go:
```
- rough write main.go
```

changes to install package:
```
- merged install package with packagemanager package
```

changes to packagemanager package:
```
- merged search and install packages into this one
- write all_updater.go in rough form, this will handle when the user wants to update all the packages across all backends
- rough write all of aur.go, this will handle AUR package update logic, and AUR package uninstall logic
- add a function to flatpak.go to retrieve a packages version
- move utility functions out of install.go and into installer_utils.go
- add a function to pacman.go to fetch a programs version from pacman
- add a function to snap.go to fetch a programs version from pacman
```

changes to toolcheck package:
```
- change toolcheck.go to import the packagemanager instead of install, since we merged the two
```
2024-01-04 13:08:32 -07:00

51 lines
1.7 KiB
Go

package packagemanager
// This package is responsible for handling updating and uninstalling pacman packages
import (
"os/exec"
"fmt"
"strings"
)
// UpdatePacmanPackages updates specified Pacman packages or all if no specific package is provided
func UpdatePacmanPackages(packageNames ...string) error {
var cmd *exec.Cmd
if len(packageNames) == 0 {
cmd = exec.Command("sudo", "pacman", "-Syu")
} else {
args := append([]string{"sudo", "pacman", "-S", "--noconfirm"}, packageNames...)
cmd = exec.Command(args[0], args[1:]...)
}
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("error updating Pacman packages: %s, %v", string(output), err)
}
return nil
}
// UninstallPacmanPackage uninstalls a specified Pacman package
func UninstallPacmanPackage(packageName string) error {
cmd := exec.Command("sudo", "pacman", "-Rns", "--noconfirm", packageName)
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("error uninstalling Pacman package: %s, %v", output, err)
}
return nil
}
// getVersionFromPacman gets the installed version of a package using Pacman
func GetVersionFromPacman(packageName string) (string, error) {
cmd := exec.Command("pacman", "-Qi", packageName)
output, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("error getting package version: %v", err)
}
for _, line := range strings.Split(string(output), "\n") {
if strings.HasPrefix(line, "Version") {
return strings.Fields(line)[2], nil
}
}
return "", fmt.Errorf("version not found for package: %s", packageName)
}