[pacman-dev] [PATCH] makepkg: fall back to su if sudo is not available

Ray Kohler ataraxia937 at gmail.com
Thu Feb 25 22:15:11 EST 2010


On Thu, Feb 25, 2010 at 9:52 PM, Jim Pryor
<lists+pacman-dev at jimpryor.net> wrote:
> On Thu, Feb 25, 2010 at 09:05:11PM -0500, Ray Kohler wrote:
>> On Thu, Feb 25, 2010 at 7:25 PM, Allan McRae <allan at archlinux.org> wrote:
>> >
>> > does:
>> > su -c "$PACMAN $PACMAN_OPTS $@"
>> > not work?
>>
>> No, that somehow gets parsed as:
>>
>> su -c 'pacman -U' pkgname
>>
>> Which makes su complain that there's no such user as pkgname. I found
>> no other way to get the whole command into a single string other than
>> stuffing it into another variable as I did, and I spent over an hour
>> trying various things.
>
> That's the result of the "$@". This should work:
>
>    su -c "$PACMAN $PACMAN_OPTS $*"
>
> The normal advantages of using "$@" over using "$*" would have been eliminated
> in this context, anyway.

Excellent, that does work. Third, and cleanest, patch version follows.

>From 65453dfdfe709b1d83e200e478513bb799dcc747 Mon Sep 17 00:00:00 2001
From: Ray Kohler <ataraxia937 at gmail.com>
Date: Sat, 20 Feb 2010 21:08:25 -0500
Subject: [PATCH] makepkg: fall back to su if sudo is not available

Signed-off-by: Ray Kohler <ataraxia937 at gmail.com>
---
 scripts/makepkg.sh.in |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 5bd294c..dcea3a0 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -344,8 +344,12 @@ download_file() {

 run_pacman() {
 	local ret=0
-	if (( ! ASROOT )) && [[ $1 != "-T" ]] && sudo -l $PACMAN &>/dev/null; then
-		sudo $PACMAN $PACMAN_OPTS "$@" || ret=$?
+	if (( ! ASROOT )) && [[ $1 != "-T" ]]; then
+		if [ "$(type -p sudo)" ] && sudo -l $PACMAN &>/dev/null; then
+			sudo $PACMAN $PACMAN_OPTS "$@" || ret=$?
+		else
+			su -c "$PACMAN $PACMAN_OPTS $*" || ret=$?
+		fi
 	else
 		$PACMAN $PACMAN_OPTS "$@" || ret=$?
 	fi
@@ -1689,10 +1693,7 @@ fi
 # check for sudo if we will need it during makepkg execution
 if (( ! ASROOT && ( DEP_BIN || RMDEPS || INSTALL ) )); then
 	if [ ! "$(type -p sudo)" ]; then
-		error "$(gettext "Cannot find the sudo binary! Is sudo installed?")"
-		plain "$(gettext "Missing dependencies cannot be installed or
removed as a normal user")"
-		plain "$(gettext "without sudo; install and configure sudo to
auto-resolve dependencies.")"
-		exit 1
+		warning "$(gettext "sudo can not be found; falling back to su for
acquiring root privileges.")"
 	fi
 fi

-- 
1.7.0


More information about the pacman-dev mailing list