* [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
* Re: [PATCH v2] mbuto: always display help message 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 0 siblings, 1 reply; 3+ messages in thread From: Stefano Brivio @ 2022-04-21 15:56 UTC (permalink / raw) To: Sevinj Aghayeva; +Cc: outreachy Hi Sevinj, Sorry for the delay, I'm finally testing this and updating the demos around it. The previous series looks fine (I'm hitting some issues with grep, still checking). However, this: On Mon, 18 Apr 2022 12:55:19 -0400 Sevinj Aghayeva <sevinj.aghayeva@gmail.com> wrote: > [...] > > # 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}" "${@}" ...breaks everything, that is, options are not passed anymore, the "base" profile is always selected, because: > - 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}" "${@}" $@ here doesn't contain options anymore, being that it comes after shift $((OPTIND - 1)), which renumbers (shifts) positional parameters in a way that $1, at this point, is the first non-option argument. And $@ follows the same pattern: the first token in it will be $1 now. I'm replacing this with something like: diff --git a/mbuto b/mbuto index 49b8139..6918415 100755 --- a/mbuto +++ b/mbuto @@ -1179,10 +1179,11 @@ 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" + __fakeroot_missing="y" + else + PATH="${PATH}:/sbin:/usr/sbin" "${FAKEROOT}" "${0}" "${@}" + exit ${?} fi - PATH="${PATH}:/sbin:/usr/sbin" "${FAKEROOT}" "${0}" "${@}" - exit ${?} fi # Parse options @@ -1206,6 +1207,11 @@ done shift $((OPTIND - 1)) [ -z "${PROFILE}" ] && PROFILE="base" +if [ "${__fakeroot_missing}" = "y" ]; then + err "Not root and no fakeroot available, exiting" + exit 1 +fi + and I would push it (please have a look, first!) together with your series as soon as I get the demo to work with test collections. -- Stefano ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mbuto: always display help message 2022-04-21 15:56 ` Stefano Brivio @ 2022-04-21 16:49 ` Sevinj Aghayeva 0 siblings, 0 replies; 3+ messages in thread From: Sevinj Aghayeva @ 2022-04-21 16:49 UTC (permalink / raw) To: Stefano Brivio; +Cc: outreachy linux kernel On Thu, Apr 21, 2022 at 11:57 AM Stefano Brivio <sbrivio@redhat.com> wrote: > > Hi Sevinj, > > Sorry for the delay, I'm finally testing this and updating the demos > around it. > > The previous series looks fine (I'm hitting some issues with > grep, still checking). However, this: > > On Mon, 18 Apr 2022 12:55:19 -0400 > Sevinj Aghayeva <sevinj.aghayeva@gmail.com> wrote: > > > [...] > > > > # 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}" "${@}" > > ...breaks everything, that is, options are not passed anymore, the > "base" profile is always selected, because: > > > - 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}" "${@}" > > $@ here doesn't contain options anymore, being that it comes after > shift $((OPTIND - 1)), which renumbers (shifts) positional parameters > in a way that $1, at this point, is the first non-option argument. > > And $@ follows the same pattern: the first token in it will be $1 now. > > I'm replacing this with something like: > > diff --git a/mbuto b/mbuto > index 49b8139..6918415 100755 > --- a/mbuto > +++ b/mbuto > @@ -1179,10 +1179,11 @@ 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" > + __fakeroot_missing="y" > + else > + PATH="${PATH}:/sbin:/usr/sbin" "${FAKEROOT}" "${0}" "${@}" > + exit ${?} > fi > - PATH="${PATH}:/sbin:/usr/sbin" "${FAKEROOT}" "${0}" "${@}" > - exit ${?} > fi > > # Parse options > @@ -1206,6 +1207,11 @@ done > shift $((OPTIND - 1)) > [ -z "${PROFILE}" ] && PROFILE="base" > > +if [ "${__fakeroot_missing}" = "y" ]; then > + err "Not root and no fakeroot available, exiting" > + exit 1 > +fi > + > > and I would push it (please have a look, first!) together with your series as > soon as I get the demo to work with test collections. Looks good, thanks for catching this. I didn't test it properly. > > -- > Stefano > -- Sevinj.Aghayeva ^ permalink raw reply [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).