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
This commit is contained in:
VetheonGames 2024-01-08 14:30:51 -07:00
parent 84099a8afc
commit 9f21313942
7 changed files with 44 additions and 26 deletions

View File

@ -1 +1 @@
AllPac V0.8 AllPac V0.9

View File

@ -1,10 +1,12 @@
package main package main
import ( import (
"fmt"
"embed" "embed"
"fmt"
"io/fs" "io/fs"
"pixelridgesoftworks.com/AllPac/pkg/logger" "pixelridgesoftworks.com/AllPac/pkg/logger"
"pixelridgesoftworks.com/AllPac/pkg/packagemanager"
) )
func handleUpdateError(updateOption string, err error) { func handleUpdateError(updateOption string, err error) {
@ -25,3 +27,13 @@ func handleVersion(args []string) {
} }
fmt.Println(string(content)) fmt.Println(string(content))
} }
func handleRepair(args []string) {
// Assuming GetPkgListPath() returns a string path
pkgListPath, _ := packagemanager.GetPkgListPath()
err :=packagemanager.InitializePkgListFile(pkgListPath)
if err != nil {
logger.Errorf("Error initializing version file: %v", err)
}
}

View File

@ -45,6 +45,8 @@ func main() {
handleToolCheck(args) handleToolCheck(args)
case "version": case "version":
handleVersion(args) handleVersion(args)
case "repair":
handleRepair(args)
default: default:
fmt.Printf("Unknown subcommand: %s\n", command) fmt.Printf("Unknown subcommand: %s\n", command)
os.Exit(1) os.Exit(1)
@ -57,6 +59,11 @@ func handleUpdate(args []string) {
return return
} }
_, err := packagemanager.ReadPackageList()
if err != nil {
fmt.Printf("error reading package list. Consider running 'allpac repair': %v", err)
}
updateFuncs := map[string]func() error{ updateFuncs := map[string]func() error{
"everything": packagemanager.UpdateAllPackages, "everything": packagemanager.UpdateAllPackages,
"snaps": func() error { return packagemanager.UpdateSnapPackages() }, "snaps": func() error { return packagemanager.UpdateSnapPackages() },

View File

@ -14,9 +14,9 @@ import (
"pixelridgesoftworks.com/AllPac/pkg/logger" "pixelridgesoftworks.com/AllPac/pkg/logger"
) )
// InstallPackagePacman installs a package using Pacman and logs the installation // installs a package using Pacman and logs the installation
func InstallPackagePacman(packageName string) error { func InstallPackagePacman(packageName string) error {
cmd := exec.Command("sudo", "pacman", "-S", "--noconfirm", packageName) cmd := exec.Command("sudo", "pacman", "-Syu", "--noconfirm", packageName)
if output, err := cmd.CombinedOutput(); err != nil { if output, err := cmd.CombinedOutput(); err != nil {
logger.Errorf("error installing package with Pacman: %s, %v", output, err) logger.Errorf("error installing package with Pacman: %s, %v", output, err)
return fmt.Errorf("error installing package with Pacman: %s, %v", output, err) return fmt.Errorf("error installing package with Pacman: %s, %v", output, err)
@ -35,7 +35,7 @@ func InstallPackagePacman(packageName string) error {
return nil return nil
} }
// InstallPackageSnap installs a package using Snap and logs the installation // installs a package using Snap and logs the installation
func InstallPackageSnap(packageName string) error { func InstallPackageSnap(packageName string) error {
cmd := exec.Command("sudo", "snap", "install", packageName) cmd := exec.Command("sudo", "snap", "install", packageName)
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
@ -77,7 +77,7 @@ func InstallPackageSnap(packageName string) error {
return nil return nil
} }
// InstallPackageFlatpak installs a package using Flatpak and logs the installation // installs a package using Flatpak and logs the installation
func InstallPackageFlatpak(packageName string) error { func InstallPackageFlatpak(packageName string) error {
cmd := exec.Command("flatpak", "install", "-y", packageName) cmd := exec.Command("flatpak", "install", "-y", packageName)
if output, err := cmd.CombinedOutput(); err != nil { if output, err := cmd.CombinedOutput(); err != nil {
@ -98,14 +98,19 @@ func InstallPackageFlatpak(packageName string) error {
return nil return nil
} }
// cloneAndInstallFromAUR clones the given AUR repository and installs it // clones the given AUR repository and installs it
func CloneAndInstallFromAUR(repoURL string, skipConfirmation bool) (string, error) { func CloneAndInstallFromAUR(repoURL string, skipConfirmation bool) (string, error) {
// Request root permissions // System update
if !skipConfirmation && !requestRootPermissions() { if !skipConfirmation && !confirmAction("Do you want to update the system before proceeding? (skipping this step may result in partial updates, and break your system)") {
logger.Warnf("root permissions denied") logger.Warnf("user aborted the system update")
return "", fmt.Errorf("root permissions denied") return "", fmt.Errorf("user aborted the system update")
} }
cmdUpdate := exec.Command("sudo", "pacman", "-Syu", "--noconfirm")
if output, err := cmdUpdate.CombinedOutput(); err != nil {
logger.Errorf("error updating system: %s, %v", output, err)
return "", fmt.Errorf("error updating system: %s, %v", output, err)
}
// Confirm before proceeding with each step // Confirm before proceeding with each step
if !skipConfirmation && !confirmAction("Do you want to download and build package from " + repoURL + "?") { if !skipConfirmation && !confirmAction("Do you want to download and build package from " + repoURL + "?") {
logger.Warnf("user aborted the action") logger.Warnf("user aborted the action")
@ -172,7 +177,7 @@ func CloneAndInstallFromAUR(repoURL string, skipConfirmation bool) (string, erro
return version, nil return version, nil
} }
// InstallSnap installs Snap manually from the AUR // installs Snap manually from the AUR
func InstallSnap() error { func InstallSnap() error {
version, err := CloneAndInstallFromAUR("https://aur.archlinux.org/snapd.git", true) version, err := CloneAndInstallFromAUR("https://aur.archlinux.org/snapd.git", true)
if err != nil { if err != nil {
@ -187,7 +192,7 @@ func InstallSnap() error {
return nil return nil
} }
// InstallGit installs Git using Pacman // installs Git using Pacman
func InstallGit() error { func InstallGit() error {
if err := InstallPackagePacman("git"); err != nil { if err := InstallPackagePacman("git"); err != nil {
logger.Errorf("error installing Git: %v", err) logger.Errorf("error installing Git: %v", err)
@ -196,7 +201,7 @@ func InstallGit() error {
return nil return nil
} }
// InstallBaseDevel installs the base-devel group using Pacman // installs the base-devel group using Pacman
func InstallBaseDevel() error { func InstallBaseDevel() error {
if err := InstallPackagePacman("base-devel"); err != nil { if err := InstallPackagePacman("base-devel"); err != nil {
logger.Errorf("error installing base-devel: %v", err) logger.Errorf("error installing base-devel: %v", err)
@ -205,7 +210,7 @@ func InstallBaseDevel() error {
return nil return nil
} }
// InstallFlatpak installs the Flatpak package using Pacman // installs the Flatpak package using Pacman
func InstallFlatpak() error { func InstallFlatpak() error {
if err := InstallPackagePacman("flatpak"); err != nil { if err := InstallPackagePacman("flatpak"); err != nil {
logger.Errorf("error installing flatpak: %v", err) logger.Errorf("error installing flatpak: %v", err)

View File

@ -9,7 +9,7 @@ import (
"pixelridgesoftworks.com/AllPac/pkg/logger" "pixelridgesoftworks.com/AllPac/pkg/logger"
) )
// extractVersionFromPKGBUILD reads the PKGBUILD file and extracts the package version // reads the PKGBUILD file and extracts the package version
func ExtractVersionFromPKGBUILD(repoDir string) (string, error) { func ExtractVersionFromPKGBUILD(repoDir string) (string, error) {
pkgbuildPath := filepath.Join(repoDir, "PKGBUILD") pkgbuildPath := filepath.Join(repoDir, "PKGBUILD")
file, err := os.Open(pkgbuildPath) file, err := os.Open(pkgbuildPath)
@ -36,13 +36,7 @@ func ExtractVersionFromPKGBUILD(repoDir string) (string, error) {
return "", fmt.Errorf("pkgver not found in PKGBUILD") return "", fmt.Errorf("pkgver not found in PKGBUILD")
} }
// requestRootPermissions prompts the user for root permissions // prompts the user with a yes/no question and returns true if the answer is yes
func requestRootPermissions() bool {
fmt.Println("Root permissions are required to install AUR packages.")
return confirmAction("Do you want to continue with root permissions?")
}
// confirmAction prompts the user with a yes/no question and returns true if the answer is yes
func confirmAction(question string) bool { func confirmAction(question string) bool {
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
for { for {

View File

@ -41,7 +41,7 @@ func GetPkgListPath() (string, error) {
if _, err := os.Stat(pkgListPath); os.IsNotExist(err) { if _, err := os.Stat(pkgListPath); os.IsNotExist(err) {
logger.Infof("pkg.list file does not exist, initializing: %s", pkgListPath) logger.Infof("pkg.list file does not exist, initializing: %s", pkgListPath)
// Create and initialize the file if it doesn't exist // Create and initialize the file if it doesn't exist
if err := initializePkgListFile(pkgListPath); err != nil { if err := InitializePkgListFile(pkgListPath); err != nil {
return "", err // Error already logged in initializePkgListFile return "", err // Error already logged in initializePkgListFile
} }
} else if err != nil { } else if err != nil {
@ -55,7 +55,7 @@ func GetPkgListPath() (string, error) {
} }
// creates a new pkg.list file with an empty JSON object // creates a new pkg.list file with an empty JSON object
func initializePkgListFile(filePath string) error { func InitializePkgListFile(filePath string) error {
file, err := os.Create(filePath) file, err := os.Create(filePath)
if err != nil { if err != nil {
logger.Errorf("error creating package list file: %v", err) logger.Errorf("error creating package list file: %v", err)

View File

@ -48,7 +48,7 @@ func UpdatePacmanPackages(packageNames ...string) error {
} }
if len(packagesToUpdate) > 0 { if len(packagesToUpdate) > 0 {
args := append([]string{"sudo", "pacman", "-S", "--noconfirm"}, packagesToUpdate...) args := append([]string{"sudo", "pacman", "-Syu", "--noconfirm"}, packagesToUpdate...)
cmd := exec.Command(args[0], args[1:]...) cmd := exec.Command(args[0], args[1:]...)
if output, err := cmd.CombinedOutput(); err != nil { if output, err := cmd.CombinedOutput(); err != nil {
logger.Errorf("error updating Pacman packages: %s, %v", string(output), err) logger.Errorf("error updating Pacman packages: %s, %v", string(output), err)