outreachy.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mbuto: always display help message
@ 2022-04-18 16:55 Sevinj Aghayeva
  2022-04-21 15:56 ` Stefano Brivio
  0 siblings, 1 reply; 3+ messages in thread
From: Sevinj Aghayeva @ 2022-04-18 16:55 UTC (permalink / raw)
  To: sbrivio; +Cc: outreachy

Currently, if the user is not root or if fakeroot is not available, no help
message is displayed. Parse the command line, display the help message and then
exit if the user is not root or if fakeroot is not available.

v1 -> v2: Testing with fakeroot removed revealed some bugs that are now fixed.

Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>
---
 mbuto | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/mbuto b/mbuto
index 49b8139..26c4189 100755
--- a/mbuto
+++ b/mbuto
@@ -1177,12 +1177,10 @@ usage() {
 
 
 # If we're not running as root, re-run with fakeroot
-if [ "${LD_PRELOAD}" != "libfakeroot-sysv.so" ] && [ "$(id -u)" -ne 0 ]; then
-	if ! FAKEROOT="$(command -v fakeroot)"; then
-		err "Not root and no fakeroot available, exiting"
-	fi
-	PATH="${PATH}:/sbin:/usr/sbin" "${FAKEROOT}" "${0}" "${@}"
-	exit ${?}
+__not_root_and_missing_fakeroot=0
+if [ "${LD_PRELOAD}" != "libfakeroot-sysv.so" ] && [ "$(id -u)" -ne 0 ] && \
+		! FAKEROOT="$(command -v fakeroot)"; then
+	__not_root_and_missing_fakeroot=1
 fi
 
 # Parse options
@@ -1204,6 +1202,14 @@ while getopts :c:df:k:m:p:s:vh __opt; do
 	esac
 done
 shift $((OPTIND - 1))
+
+if [ ${__not_root_and_missing_fakeroot} -eq 1 ]; then
+	err "Not root and no fakeroot available, exiting"
+elif [ "${LD_PRELOAD}" != "libfakeroot-sysv.so" ]; then
+	PATH="${PATH}:/sbin:/usr/sbin" "${FAKEROOT}" "${0}" "${@}"
+	exit ${?}
+fi
+
 [ -z "${PROFILE}" ] && PROFILE="base"
 
 # Check needed tools, exit if any is missing
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-21 16:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-18 16:55 [PATCH v2] mbuto: always display help message Sevinj Aghayeva
2022-04-21 15:56 ` Stefano Brivio
2022-04-21 16:49   ` Sevinj Aghayeva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).