mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-22 22:21:10 +02:00
Remove dash-dash hack from enter_chroot.sh.
Currently, enter_chroot.sh uses a hack to ensure that "--" is preserved in commands. This is only necessary if you want to run commands that start with hyphens. E.g. if you wanted to run a command called "--foo", enter_chroot would break. But we don't have any existing commands that start with hyphens, so this logic seems unnecessary. This also makes enter_chroot more flexible, i.e. we now support case #6 below, which was not supported previously. Here are use cases: 1. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 -- cmd arg1 arg2 Set env vars and run cmd w/ args 2. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 Set env vars and run shell 3. ./enter_chroot [chroot_flags] -- cmd arg1 arg2 Run cmd w/ args 4. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 cmd arg1 arg2 Like #1 _if_ args aren't flags (if they are, enter_chroot will claim them) 5. ./enter_chroot [chroot_flags] cmd arg1 arg2 Like #3 _if_ args aren't flags (if they are, enter_chroot will claim them) 6. ./enter_chroot [chroot_flags] -- VAR1=val1 VAR2=val2 cmd arg1 arg2 Set env vars and run cmd w/ args 7. ./enter_chroot Just enter the chroot. BUG=chromium-os:17468 TEST=Test above cases Change-Id: I1801ac3927aacddd6d556c5939d3a42b31252675 Reviewed-on: http://gerrit.chromium.org/gerrit/3910 Reviewed-by: Doug Anderson <dianders@chromium.org> Tested-by: David James <davidjames@chromium.org>
This commit is contained in:
parent
e2f33fb50a
commit
986a0f74f0
@ -75,37 +75,6 @@ function debug {
|
||||
fi
|
||||
}
|
||||
|
||||
# Double up on the first '--' argument. Why? For enter_chroot, we want to
|
||||
# emulate the behavior of sudo for setting environment vars. That is, we want:
|
||||
# ./enter_chroot [flags] [VAR=val] [-- command]
|
||||
# ...but shflags ends up eating the '--' out of the command line and gives
|
||||
# us back "VAR=val" and "command" together in one chunk. By doubling up, we
|
||||
# end up getting what we want back from shflags.
|
||||
#
|
||||
# Examples of how people might be using enter_chroot:
|
||||
# 1. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 -- cmd arg1 arg2
|
||||
# Set env vars and run cmd w/ args
|
||||
# 2. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2
|
||||
# Set env vars and run shell
|
||||
# 3. ./enter_chroot [chroot_flags] -- cmd arg1 arg2
|
||||
# Run cmd w/ args
|
||||
# 4. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 cmd arg1 arg2
|
||||
# Like #1 _if_ args aren't flags (if they are, enter_chroot will claim them)
|
||||
# 5. ./enter_chroot [chroot_flags] cmd arg1 arg2
|
||||
# Like #3 _if_ args aren't flags (if they are, enter_chroot will claim them)
|
||||
_FLAGS_FIXED=''
|
||||
_SAW_DASHDASH=0
|
||||
while [ $# -gt 0 ]; do
|
||||
_FLAGS_FIXED="${_FLAGS_FIXED:+${_FLAGS_FIXED} }'$1'"
|
||||
if [ $_SAW_DASHDASH -eq 0 ] && [[ "$1" == "--" ]]; then
|
||||
_FLAGS_FIXED="${_FLAGS_FIXED:+${_FLAGS_FIXED} }'--'"
|
||||
_SAW_DASHDASH=1
|
||||
fi
|
||||
shift
|
||||
done
|
||||
eval set -- "${_FLAGS_FIXED}"
|
||||
|
||||
|
||||
# Parse command line flags
|
||||
FLAGS "$@" || exit 1
|
||||
eval set -- "${FLAGS_ARGV}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user