outreachy.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>
To: sbrivio@redhat.com
Cc: outreachy@lists.linux.dev
Subject: [PATCH v2] mbuto: always display help message
Date: Mon, 18 Apr 2022 12:55:19 -0400	[thread overview]
Message-ID: <20220418165519.GA54466@euclid> (raw)

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


             reply	other threads:[~2022-04-18 16:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-18 16:55 Sevinj Aghayeva [this message]
2022-04-21 15:56 ` [PATCH v2] mbuto: always display help message Stefano Brivio
2022-04-21 16:49   ` Sevinj Aghayeva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220418165519.GA54466@euclid \
    --to=sevinj.aghayeva@gmail.com \
    --cc=outreachy@lists.linux.dev \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).