AllPac/pkg/packagemanager/installer_utils.go
VetheonGames 9f21313942 Major Update 7 (Pre-Release Binary 0.9)
Update version

Refactor Pacman to always use `-Syu` regardless of what operation it's doing.
I did this solely to prevent partial updates from even being possible. Unlike pacman, which let's you do bad commands with no warning.

Remove un-needed Root question from AUR Installer

Set up AUR installer to update the system before cloning and building (to be safe, we add a warning about partial updates. See, it isn't that hard Pacman!)

Add repair command that will fix issues with the pkg.list file

Add a check to the handleUpdate function that advises the user to run `repair` if it has a problem reading the pkg.list
2024-01-08 14:30:51 -07:00

59 lines
1.6 KiB
Go

package packagemanager
import (
"bufio"
"os"
"path/filepath"
"strings"
"fmt"
"pixelridgesoftworks.com/AllPac/pkg/logger"
)
// reads the PKGBUILD file and extracts the package version
func ExtractVersionFromPKGBUILD(repoDir string) (string, error) {
pkgbuildPath := filepath.Join(repoDir, "PKGBUILD")
file, err := os.Open(pkgbuildPath)
if err != nil {
logger.Errorf("An error has occured:", err)
return "", err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "pkgver=") {
return strings.TrimPrefix(line, "pkgver="), nil
}
}
if err := scanner.Err(); err != nil {
logger.Errorf("An error has occured:", err)
return "", err
}
logger.Errorf("pkgver not found in PKGBUILD")
return "", fmt.Errorf("pkgver not found in PKGBUILD")
}
// prompts the user with a yes/no question and returns true if the answer is yes
func confirmAction(question string) bool {
reader := bufio.NewReader(os.Stdin)
for {
fmt.Printf("%s [Y/n]: ", question)
response, err := reader.ReadString('\n')
if err != nil {
logger.Errorf("Error reading response: %v", err)
fmt.Println("Error reading response:", err)
return false
}
response = strings.ToLower(strings.TrimSpace(response))
if response == "y" || response == "yes" {
return true
} else if response == "n" || response == "no" {
return false
}
}
}