[pacman-dev,v2] Option to enable running makepkg in

Message ID 20200116171702.21833-1-jemzipx@gmail.com
State Rejected, archived
Headers show
Series [pacman-dev,v2] Option to enable running makepkg in | expand

Commit Message

Saul Tigh Jan. 16, 2020, 5:17 p.m. UTC
Although running makepkg in root is frowned upon, there ae
circumstances that one might need to do so. For example, during the
bootstrap process of building my own toy gnu/linux distro, I need to run makepkg in root. This option is disabled by
default. It can be enabled by setting 'ALLOWROOT' in makepkg to 1.
---
 scripts/makepkg.sh.in | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Patch

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index ca3e7459..b2cd8ee4 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -79,6 +79,7 @@  SIGNPKG=''
 SPLITPKG=0
 SOURCEONLY=0
 VERIFYSOURCE=0
+ALLOWROOT=0
 
 if [[ -n $SOURCE_DATE_EPOCH ]]; then
 	REPRODUCIBLE=1
@@ -1175,9 +1176,13 @@  fi
 
 if (( ! INFAKEROOT )); then
 	if (( EUID == 0 )); then
-		error "$(gettext "Running %s as root is not allowed as it can cause permanent,\n\
-catastrophic damage to your system.")" "makepkg"
-		exit $E_ROOT
+		if (( ALLOWROOT )); then
+			plain "Running as root is not recommended. Proceed with caution."
+		else
+			error "$(gettext "Running %s as root is not allowed as it can cause permanent,\n\
+			catastrophic damage to your system.")" "makepkg"
+			exit $E_ROOT
+		fi
 	fi
 else
 	if [[ -z $FAKEROOTKEY ]]; then
@@ -1352,6 +1357,10 @@  if (( SOURCEONLY )); then
 	check_source_integrity all
 	cd_safe "$startdir"
 
+	# allow makepkg to run in root
+	if (( ALLOWROOT )); then
+		unset FAKEROOTKEY
+	fi
 	enter_fakeroot
 
 	if [[ $SIGNPKG = 'y' ]]; then