Minor update to patch new issue with AUR logic

This commit is contained in:
VetheonGames 2024-01-08 15:32:43 -07:00
parent 779ce34013
commit a3cc14f9df
2 changed files with 35 additions and 1 deletions

View File

@ -173,7 +173,8 @@ func CloneAndInstallFromAUR(repoURL string, skipConfirmation bool) (string, erro
} }
// Build the package using makepkg as the non-root user // Build the package using makepkg as the non-root user
cmdMakePkg := exec.Command("sudo", "-u", sudoUser, "makepkg", "-si", "--noconfirm") cmdMakePkg := exec.Command("makepkg", "-si", "--noconfirm")
cmdMakePkg.Env = []string{"HOME=" + usr.HomeDir, "USER=" + usr.Username, "LOGNAME=" + usr.Username}
if output, err := cmdMakePkg.CombinedOutput(); err != nil { if output, err := cmdMakePkg.CombinedOutput(); err != nil {
logger.Errorf("error building package with makepkg: %s, %v", output, err) logger.Errorf("error building package with makepkg: %s, %v", output, err)
return "", fmt.Errorf("error building package with makepkg: %s, %v", output, err) return "", fmt.Errorf("error building package with makepkg: %s, %v", output, err)

View File

@ -7,6 +7,10 @@ import (
"strings" "strings"
"fmt" "fmt"
"pixelridgesoftworks.com/AllPac/pkg/logger" "pixelridgesoftworks.com/AllPac/pkg/logger"
"os/exec"
"os/user"
"strconv"
"syscall"
) )
// reads the PKGBUILD file and extracts the package version // reads the PKGBUILD file and extracts the package version
@ -56,3 +60,32 @@ func confirmAction(question string) bool {
} }
} }
} }
// this is unused, just incase I need to do it this way since makepkg is being a pain in the neck
func RunMakepkgAsUser(username string) error {
// Lookup the non-root user
usr, err := user.Lookup(username)
if err != nil {
return err
}
// Convert UID and GID to integers
uid, _ := strconv.Atoi(usr.Uid)
gid, _ := strconv.Atoi(usr.Gid)
// Set UID and GID of the process
err = syscall.Setgid(gid)
if err != nil {
return err
}
err = syscall.Setuid(uid)
if err != nil {
return err
}
// Now run makepkg as the non-root user
cmd := exec.Command("makepkg", "-si", "--noconfirm")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}