mbuto: always display help message
PATCH v2 1/1 mbuto: always display help message
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.
--- mbuto | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
mbuto +12 -6
@@ -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
Signature · 1 line
2.25.1
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:
Review
Quoted 8 lines · On Mon, 18 Apr 2022 12:55:19 -0400 Sevinj Aghayeva <[email protected]>…
[...]
# If we're not running as root, re-run with fakeroot
(quoted diff) +0
-5-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:
Quoted 9 lines
(quoted diff) +4
-1- 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
Review while getopts :c:df:k:m:p:s:vh __opt; do · line 1209
Quoted 8 lines
(quoted diff) +5
-0@@ -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:
mbuto +9 -3
@@ -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.
Signature · 1 line
Stefano
Quoted 79 lines · Stefano Brivio
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:
Review
Quoted 8 lines · On Mon, 18 Apr 2022 12:55:19 -0400 Sevinj Aghayeva <[email protected]>…
[...]
# If we're not running as root, re-run with fakeroot
(quoted diff) +0
-5-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:
Quoted 9 lines
mbuto +4
-1- 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 optionsmbuto while getopts :c:df:k:m:p:s:vh __opt; do · line 1209
Quoted 8 lines
mbuto +5
-0@@ -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:
mbuto +9
-3@@ -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 +
Quoted 2 lines
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.
Quoted 4 lines
--
Stefano
Signature · 1 line
Sevinj.Aghayeva