AllPac/pkg/toolcheck/toolcheck.go
VetheonGames ab2582dc60 Main Update 1
Install.go Changes
```
- Add comments to each file/package to elaborate on their purpose
- Add package list functions to install.go to keep track of installed packages and their sources
- Remove the dependancy on YAY, we are just gonna handle AUR operations ourselves.
- Remove YAY methods from install.go
- Add calls to the package install logger to the end of each install functions
- Add dependancy install functions to install.go
```

flatpak.go Changes:
```
- Completely write flatpak.go
- Include functions for uninstalling flatpak programs
- Include functions for updating flatpak programs
```

pacman.go Changes:
```
- Completely write pacman.go
- Include functions for uninstalling pacman packages
- Include functions for updating pacman packages
```

yay.go Changes:
```
- Completely removed
```

search.go Changes:
```
- Completely write search.go
- Include functions for searching pacman
- Include functions for searching snap
- Include functions for searching flatpak
```

toolcheck.go Changes:
```
- Completely write toolcheck.go
- Include functions for checking for Git
- Include functions for checking for base-devel group
- Include functions for checking for pacman
- Include functions for checking for Snapd
- Include functions for checking for flatpak
- Include function to ask to install flatpak
- Include function to ask to install Snapd
- Include function to ask to install Git
- Include function to ask to install the base-devel group
```
2024-01-04 09:49:03 -07:00

64 lines
1.9 KiB
Go

package toolcheck
// This package is responsible for checking to ensure all our tools are available to us.
// Since we aren't hooking directly into the internals of anything, we require the availability of the packages
// on the system in order to use their CLIs.
// In the future, we might hook directly into the backends for pacman, flatpak, and snapd
// but for now, this is a perfectly fine way of going about it without introducing weird bugs
import (
"os/exec"
"fmt"
"pixelridgesoftworks.com/AllPac/pkg/install"
)
// isCommandAvailable checks if a command exists
func isCommandAvailable(name string) bool {
cmd := exec.Command("which", name)
if err := cmd.Run(); err != nil {
return false
}
return true
}
// EnsurePacman ensures that Pacman is installed and available
func EnsurePacman() error {
if !isCommandAvailable("pacman") {
// Pacman should always be available on Arch-based systems, handle this as an error or special case
return fmt.Errorf("pacman is not available, which is required for AllPac to function")
}
return nil
}
// EnsureSnap ensures that Snap is installed and available
func EnsureSnap() error {
if !isCommandAvailable("snap") {
return install.InstallSnap()
}
return nil
}
// EnsureGit ensures that Git is installed and available
func EnsureGit() error {
if !isCommandAvailable("git") {
return install.InstallGit()
}
return nil
}
// EnsureBaseDevel ensures that the base-devel group is installed
func EnsureBaseDevel() error {
if !isCommandAvailable("make") { // 'make' is part of base-devel, this is the best method to check
return install.InstallBaseDevel()
}
return nil
}
// EnsureFlatpak ensures that Flatpak is installed and available
func EnsureFlatpak() error {
if !isCommandAvailable("flatpak") {
return install.InstallFlatpak()
}
return nil
}