[pacman-dev] [PATCH 7/9] Reduced the number of commands run inside fakeroot to the bare minimum.

Andrew Fyfe andrew at neptune-one.net
Sun Apr 1 18:49:59 EDT 2007


Only the following functions now run inside fakeroot
	* run_build()
	* tidy_install()
	* create_package()

Added check for inproper use of '-F' option.

Added yn_question() function. Asks the user a simple yes/no question. Returns 0=yes 1=no.

Added warning if makepkg is run as root.

Signed-off-by: Andrew Fyfe <andrew at neptune-one.net>

diff --git a/scripts/makepkg.in b/scripts/makepkg.in
index 75832f1..a50e795 100755
--- a/scripts/makepkg.in
+++ b/scripts/makepkg.in
@@ -49,6 +49,7 @@ DEP_BIN=0
 DEP_SRC=0
 SUDO=0
 FORCE=0
+INFAKEROOT=0
 GENINTEG=0
 INSTALL=0
 NOBUILD=0
@@ -60,14 +61,6 @@ LOGGING=0
 
 PACMAN_OPTS=
 
-#determine if we are running with fakeroot
-if [ "$1" = "-F" ]; then
-	INFAKEROOT=1
-	shift
-else
-	INFAKEROOT=0
-fi
-
 ### SUBROUTINES ###
 
 plain() {
@@ -110,6 +103,24 @@ error() {
 	fi
 }
 
+yn_question () {
+	if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
+		echo -en "    \033[1;1m$1\033[1;0m " >&2
+	else
+		echo -n "    $1 " >&2
+	fi
+
+	local answer
+	read answer
+	answer="$(echo $answer | tr [:upper:] [:lower:])"
+
+	if [ "$answer" = 'y' -o "$answer" = 'yes' ]; then
+		return 0
+	else
+		return 1
+	fi
+}
+
 strip_url() {
 	echo "$1" | sed 's|^.*://.*/||g'
 }
@@ -685,7 +696,7 @@ while [ "$#" -ne "0" ]; do
 					exit 1
 					;;
 		-*)
-		while getopts "bcCdefghiLmop:rRsS-" opt; do
+		while getopts "bcCdefFghiLmop:rRsS-" opt; do
 			case $opt in
 				b) DEP_SRC=1 ;;
 				c) CLEANUP=1 ;;
@@ -693,6 +704,7 @@ while [ "$#" -ne "0" ]; do
 				d) NODEPS=1 ;;
 				e) NOEXTRACT=1 ;;
 				f) FORCE=1 ;;
+				F) INFAKEROOT=1 ;;
 				g) GENINTEG=1 ;;
 				h)
 						usage
@@ -761,6 +773,46 @@ if [ "$CLEANCACHE" = "1" ]; then
 	fi
 fi
 
+if [ "$INFAKEROOT" = "0" ]; then
+	if [ $EUID -eq 0 ]; then
+		# Warn those who like to live dangerously.
+		warning "$(gettext "Running makepkg as root is a BAD idea!")"
+		plain ""
+		plain "$(gettext "Running makepkg as root can result in permanent, catastropic damage to ")"
+		plain "$(gettext "your system.")"
+		plain ""
+		if ! yn_question "$(gettext "Are you sure you want to continue? [N/y]")"; then
+			error "$(gettext "Aborting...")"
+			exit 1 # $E_USER_ABORT
+		fi
+	elif [ "$(check_buildenv fakeroot)" = "y" ]; then
+		if [ ! $(type -p fakeroot) ]; then
+			warning "$(gettext "Fakeroot is not installed. Building as an unprivileged user")"
+			plain   "$(gettext "will result in non-root ownership of the packaged files. Install")"
+			plain   "$(gettext "the fakeroot package to correctly build as a non-root user.")"
+			plain ""
+			if ! yn_question "$(gettext "Are you sure you want to continue? [N/y]")"; then
+				error "Aborting..."
+				exit 1 # $E_USER_ABORT
+			fi
+		fi
+	else
+		warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")"
+		plain   "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
+		plain   "$(gettext "placing 'fakeroot' in the BUILDENV array in /etc/makepkg.conf")"
+		plain ""
+		if ! yn_question "$(gettext "Are you sure you want to continue? [N/y]")"; then
+			error "$(gettext "Aborting...")"
+			exit 1 # $E_USER_ABORT
+		fi
+	fi
+else
+	if [ "$FAKEROOTKEY" = "" ]; then
+		error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
+		exit 1 # TODO: error code
+	fi
+fi
+
 unset pkgname pkgver pkgrel pkgdesc url license groups provides md5sums force
 unset replaces depends conflicts backup source install build makedepends
 unset options noextract
@@ -820,29 +872,20 @@ if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT}" \
 	fi
 fi
 
-# Enter the fakeroot environment if necessary.  This will call the makepkg
-# script again as the fake root user.  We detect this by passing a sentinel
-# option (-F) to makepkg.
-if [ "$EUID" != "0" ]; then
-	if [ "$(check_buildenv fakeroot)" = "y" ]; then
-		if [ $(type -p fakeroot) ]; then
-			msg "$(gettext "Entering fakeroot environment")"
-			fakeroot -- $0 -F $ARGLIST
-			exit $?
-		else
-			warning "$(gettext "Fakeroot is not installed. Building as an unprivileged user")"
-			plain "$(gettext "will result in non-root ownership of the packaged files. Install")"
-			plain "$(gettext "the fakeroot package to correctly build as a non-root user.")"
-			plain ""
-			sleep 1
-		fi
+# Run the bear minimum in fakeroot
+# fix flyspray bug 6208 -- using makepkg with fakeroot gives an error
+if [ "$INFAKEROOT" = "1" ]; then
+	if [ "$REPKG" = "1" ]; then
+		warning "$(gettext "Skipping build.")"
 	else
-		warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")"
-		plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment")"
-		plain "$(gettext "by placing 'fakeroot' in the BUILDENV array in makepkg.conf.")"
-		plain ""
-		sleep 1
-	fi
+		run_build
+		tidy_install
+ 	fi
+
+	create_package
+
+	msg "$(gettext "Leaveing fakeroot environment.")"
+	exit 0 # $E_OK
 fi
 
 date=$(date)
@@ -1075,22 +1118,34 @@ fi
 if [ "$NOBUILD" = "1" ]; then
 	msg "$(gettext "Sources are ready.")"
 	exit 0
-elif [ "$REPKG" = "1" ]; then
-	warning "$(gettext "Skipping build")"
 else
 	# check for existing pkg directory
-	if [ -d "$startdir/pkg" ]; then
+	if [ -d "$startdir/pkg" -a "$REPKG" = "0" ]; then
 		msg "$(gettext "Removing existing pkg/ directory...")"
 		rm -rf "$startdir/pkg"
 	fi
 	mkdir -p "$startdir/pkg"
 
-	run_build
-fi
+	if [ $EUID -eq 0 ]; then
+		if [ "$REPKG" = "1" ]; then
+			warning "$(gettext "Skipping build.")"
+		else
+			run_build
+			tidy_install
+		fi
+
+		create_package
+	else
+		msg "$(gettext "Entering fakeroot environment...")"
+		cd "$startdir"
 
-tidy_install
+		ret=0
+		fakeroot -- $0 -F $ARGLIST || ret=$?
+		[ $ret -ne 0 ] && exit $ret
 
-create_package
+		unset ret
+	fi
+fi
 
 cd "$startdir"
 if [ "$CLEANUP" = "1" ]; then
-- 
1.5.0.6





More information about the pacman-dev mailing list