50af1b9613
This should be the final code update before we start testing things. I think all the code is now in place to have the program function, barring any bugs in my code. So, with that said, here's the changelog: global changes: ``` - implement logger.go across the whole program ``` changes to main.go: ``` - add an import for strings - implement the roughed in handling functions ``` changes to logger.go: ``` - create this little helper package to just handle all our logging nice and gracefully ``` changes to all_updater.go: ``` - basically completely redone. Accomplishes the same thing, just in a different, more efficient way. ``` changes to aur.go: ``` - add a function to clear the AllPac build cache for aur ``` changes to install.go: ``` - removed a duplicate function, set install.go to call the right one ``` changes to pacman.go: ``` - removed GetVersionFromPacman function (it shouldn't be here, it should be in search.go) ``` changes to search.go: ``` - add functions for getting info from, and parsing output from Snap, Pacman, Flatpak, and aur ```
66 lines
2.0 KiB
Go
66 lines
2.0 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/packagemanager"
|
|
"pixelridgesoftworks.com/AllPac/pkg/logger"
|
|
)
|
|
|
|
// 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") {
|
|
logger.Errorf("pacman is not available, which is required for AllPac to function")
|
|
// 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 packagemanager.InstallSnap()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EnsureGit ensures that Git is installed and available
|
|
func EnsureGit() error {
|
|
if !isCommandAvailable("git") {
|
|
return packagemanager.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 packagemanager.InstallBaseDevel()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EnsureFlatpak ensures that Flatpak is installed and available
|
|
func EnsureFlatpak() error {
|
|
if !isCommandAvailable("flatpak") {
|
|
return packagemanager.InstallFlatpak()
|
|
}
|
|
return nil
|
|
}
|