Allow unhiding the error output when desired

This adds a --verbose flag which will prevent the error stream of the
child commands from being redirected to /dev/null. The intermediate
file descriptor is arbitrarily hard coded as 42 because shell
variables and redirection don't appear to play well together.
This commit is contained in:
Debarshi Ray 2018-09-12 20:13:32 +02:00
parent 678bdbaf4e
commit d7219ba512

View file

@ -44,44 +44,44 @@ create()
--uid $UID \ --uid $UID \
--groups wheel \ --groups wheel \
$USER \ $USER \
>/dev/null 2>&1; then >/dev/null 2>&42; then
buildah rmi $working_container_name >/dev/null 2>&1 buildah rmi $working_container_name >/dev/null 2>&42
echo "$0: failed to create user $USER with UID $UID" echo "$0: failed to create user $USER with UID $UID"
exit 1 exit 1
fi fi
if ! buildah run $working_container_name -- passwd -d $USER >/dev/null 2>&1; then if ! buildah run $working_container_name -- passwd -d $USER >/dev/null 2>&42; then
buildah rmi $working_container_name >/dev/null 2>&1 buildah rmi $working_container_name >/dev/null 2>&42
echo "$0: failed to remove password for user $USER" echo "$0: failed to remove password for user $USER"
exit 1 exit 1
fi fi
if ! buildah config --volume $HOME $working_container_name >/dev/null 2>&1; then if ! buildah config --volume $HOME $working_container_name >/dev/null 2>&42; then
buildah rmi $working_container_name >/dev/null 2>&1 buildah rmi $working_container_name >/dev/null 2>&42
echo "$0: failed to configure volume for $HOME" echo "$0: failed to configure volume for $HOME"
exit 1 exit 1
fi fi
if ! buildah config --volume $XDG_RUNTIME_DIR $working_container_name >/dev/null 2>&1; then if ! buildah config --volume $XDG_RUNTIME_DIR $working_container_name >/dev/null 2>&42; then
buildah rmi $working_container_name >/dev/null 2>&1 buildah rmi $working_container_name >/dev/null 2>&42
echo "$0: failed to configure volume for /run/user/$UID" echo "$0: failed to configure volume for /run/user/$UID"
exit 1 exit 1
fi fi
if ! buildah config --user $USER $working_container_name >/dev/null 2>&1; then if ! buildah config --user $USER $working_container_name >/dev/null 2>&42; then
buildah rmi $working_container_name >/dev/null 2>&1 buildah rmi $working_container_name >/dev/null 2>&42
echo "$0: failed to configure the default user as $USER" echo "$0: failed to configure the default user as $USER"
exit 1 exit 1
fi fi
if ! buildah config --workingdir $HOME $working_container_name >/dev/null 2>&1; then if ! buildah config --workingdir $HOME $working_container_name >/dev/null 2>&42; then
buildah rmi $working_container_name >/dev/null 2>&1 buildah rmi $working_container_name >/dev/null 2>&42
echo "$0: failed to configure the initial working directory to $HOME" echo "$0: failed to configure the initial working directory to $HOME"
exit 1 exit 1
fi fi
if ! buildah commit --rm $working_container_name $toolbox_image >/dev/null 2>&1; then if ! buildah commit --rm $working_container_name $toolbox_image >/dev/null 2>&42; then
buildah rmi $working_container_name >/dev/null 2>&1 buildah rmi $working_container_name >/dev/null 2>&42
echo "$0: failed to create image $toolbox_image" echo "$0: failed to create image $toolbox_image"
exit 1 exit 1
fi fi
@ -97,7 +97,7 @@ create()
--tty \ --tty \
--volume $HOME:$HOME \ --volume $HOME:$HOME \
--volume $XDG_RUNTIME_DIR:$XDG_RUNTIME_DIR \ --volume $XDG_RUNTIME_DIR:$XDG_RUNTIME_DIR \
$toolbox_image >/dev/null 2>&1; then $toolbox_image >/dev/null 2>&42; then
echo "$0: failed to create container $toolbox_container" echo "$0: failed to create container $toolbox_container"
exit 1 exit 1
fi fi
@ -106,7 +106,7 @@ create()
enter() enter()
{ {
if ! podman start $toolbox_container >/dev/null 2>&1; then if ! podman start $toolbox_container >/dev/null 2>&42; then
echo "$0: failed to start container $toolbox_container" echo "$0: failed to start container $toolbox_container"
exit 1 exit 1
fi fi
@ -134,24 +134,29 @@ enter()
--interactive \ --interactive \
--tty \ --tty \
$toolbox_container \ $toolbox_container \
$SHELL -l 2>/dev/null $SHELL -l 2>&42
} }
usage() usage()
{ {
echo "Usage: $0 create" echo "Usage: $0 [-v | --verbose ] create"
echo " or: $0 enter" echo " or: $0 [-v | --verbose ] enter"
echo " or: $0 --help" echo " or: $0 --help"
} }
exec 42>/dev/null
while [[ "$1" == -* ]]; do while [[ "$1" == -* ]]; do
case $1 in case $1 in
-h | --help ) -h | --help )
usage usage
exit exit
;; ;;
-v | --verbose )
exec 42>&2
;;
* ) * )
echo "$0: unrecognized option '$1'" echo "$0: unrecognized option '$1'"
echo "Try '$0 --help' for more information." echo "Try '$0 --help' for more information."