Minor patch to fix issue with makepkg occasionally running as the root user

This commit is contained in:
VetheonGames 2024-01-08 15:24:05 -07:00
parent 2697ad9b1c
commit 779ce34013
2 changed files with 10 additions and 3 deletions

View File

@ -1 +1 @@
AllPac V0.9.1 AllPac V0.9.2

View File

@ -165,8 +165,15 @@ func CloneAndInstallFromAUR(repoURL string, skipConfirmation bool) (string, erro
return "", fmt.Errorf("error changing directory: %v", err) return "", fmt.Errorf("error changing directory: %v", err)
} }
// Build the package using makepkg // Get the username of the user who invoked sudo
cmdMakePkg := exec.Command("makepkg", "-si", "--noconfirm") sudoUser := os.Getenv("SUDO_USER")
if sudoUser == "" {
logger.Errorf("cannot determine the non-root user to run makepkg")
return "", fmt.Errorf("cannot determine the non-root user to run makepkg")
}
// Build the package using makepkg as the non-root user
cmdMakePkg := exec.Command("sudo", "-u", sudoUser, "makepkg", "-si", "--noconfirm")
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)