ab2582dc60
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 ```
103 lines
3.1 KiB
Go
103 lines
3.1 KiB
Go
package search
|
|
|
|
// This package is responsible for searching various sources for the availability of the requested package
|
|
|
|
import (
|
|
"os/exec"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// AURResponse represents the structure of the response from AUR RPC
|
|
type AURResponse struct {
|
|
Version int `json:"version"`
|
|
Type string `json:"type"`
|
|
ResultCount int `json:"resultcount"`
|
|
Results []AURPackage `json:"results"`
|
|
}
|
|
|
|
// AURPackage represents a package in the AUR
|
|
type AURPackage struct {
|
|
ID int `json:"ID"`
|
|
Name string `json:"Name"`
|
|
Version string `json:"Version"`
|
|
Description string `json:"Description"`
|
|
URL string `json:"URL"`
|
|
// Add other fields as needed
|
|
}
|
|
|
|
// SearchPacman searches for a package in the Pacman repositories
|
|
func SearchPacman(packageName string) ([]string, error) {
|
|
cmd := exec.Command("pacman", "-Ss", packageName)
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error searching Pacman: %v", err)
|
|
}
|
|
return parsePacmanOutput(string(output)), nil
|
|
}
|
|
|
|
// SearchSnap searches for a package in the Snap store
|
|
func SearchSnap(packageName string) ([]string, error) {
|
|
cmd := exec.Command("snap", "find", packageName)
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error searching Snap: %v", err)
|
|
}
|
|
return strings.Split(string(output), "\n"), nil
|
|
}
|
|
|
|
// SearchFlatpak searches for a package in Flatpak repositories
|
|
func SearchFlatpak(packageName string) ([]string, error) {
|
|
cmd := exec.Command("flatpak", "search", packageName)
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error searching Flatpak: %v", err)
|
|
}
|
|
return strings.Split(string(output), "\n"), nil
|
|
}
|
|
|
|
// SearchAUR searches the AUR for the given term
|
|
func SearchAUR(searchTerm string) ([]AURPackage, error) {
|
|
url := fmt.Sprintf("https://aur.archlinux.org/rpc/?v=5&type=search&arg=%s", searchTerm)
|
|
resp, err := http.Get(url)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error making request to AUR: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var aurResponse AURResponse
|
|
if err := json.NewDecoder(resp.Body).Decode(&aurResponse); err != nil {
|
|
return nil, fmt.Errorf("error decoding AUR response: %v", err)
|
|
}
|
|
|
|
return aurResponse.Results, nil
|
|
}
|
|
|
|
// parsePacmanOutput parses the output from Pacman search command
|
|
func parsePacmanOutput(output string) []string {
|
|
// Split the output into sections, each representing a package
|
|
sections := strings.Split(output, "\n\n")
|
|
|
|
var packages []string
|
|
for _, section := range sections {
|
|
// Split each section into lines
|
|
lines := strings.Split(section, "\n")
|
|
|
|
// The first line should contain the package name and version
|
|
if len(lines) > 0 {
|
|
packageNameLine := lines[0]
|
|
|
|
// Check if the package is installed
|
|
if strings.Contains(packageNameLine, "[installed]") {
|
|
packageNameLine += " (Installed)"
|
|
}
|
|
|
|
packages = append(packages, packageNameLine)
|
|
}
|
|
}
|
|
|
|
return packages
|
|
}
|