2024-01-04 09:49:03 -07:00
|
|
|
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"
|
2024-01-04 13:08:32 -07:00
|
|
|
"pixelridgesoftworks.com/AllPac/pkg/packagemanager"
|
Major update 4
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
```
2024-01-04 19:17:43 -07:00
|
|
|
"pixelridgesoftworks.com/AllPac/pkg/logger"
|
2024-01-04 09:49:03 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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") {
|
Major update 4
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
```
2024-01-04 19:17:43 -07:00
|
|
|
logger.Errorf("pacman is not available, which is required for AllPac to function")
|
2024-01-04 09:49:03 -07:00
|
|
|
// 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") {
|
2024-01-04 13:08:32 -07:00
|
|
|
return packagemanager.InstallSnap()
|
2024-01-04 09:49:03 -07:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// EnsureGit ensures that Git is installed and available
|
|
|
|
func EnsureGit() error {
|
|
|
|
if !isCommandAvailable("git") {
|
2024-01-04 13:08:32 -07:00
|
|
|
return packagemanager.InstallGit()
|
2024-01-04 09:49:03 -07:00
|
|
|
}
|
|
|
|
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
|
2024-01-04 13:08:32 -07:00
|
|
|
return packagemanager.InstallBaseDevel()
|
2024-01-04 09:49:03 -07:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// EnsureFlatpak ensures that Flatpak is installed and available
|
|
|
|
func EnsureFlatpak() error {
|
|
|
|
if !isCommandAvailable("flatpak") {
|
2024-01-04 13:08:32 -07:00
|
|
|
return packagemanager.InstallFlatpak()
|
2024-01-04 09:49:03 -07:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|