Merge pull request #1192 from mvdan/shfmt

Add shell formatting via shfmt
This commit is contained in:
Qiang Huang 2016-11-19 09:42:58 +08:00 committed by GitHub
commit 692254b91d
7 changed files with 325 additions and 309 deletions

View File

@ -36,6 +36,15 @@ RUN mkdir -p /usr/src/criu \
&& cd /usr/src/criu \ && cd /usr/src/criu \
&& make install-criu && make install-criu
# install shfmt
RUN mkdir -p /go/src/github.com/mvdan \
&& cd /go/src/github.com/mvdan \
&& git clone https://github.com/mvdan/sh \
&& cd sh \
&& git checkout -f v0.4.0 \
&& go install ./cmd/shfmt \
&& rm -rf /go/src/github.com/mvdan
# setup a playground for us to spawn containers in # setup a playground for us to spawn containers in
ENV ROOTFS /busybox ENV ROOTFS /busybox
RUN mkdir -p ${ROOTFS} \ RUN mkdir -p ${ROOTFS} \

View File

@ -119,6 +119,7 @@ clean:
validate: validate:
script/validate-gofmt script/validate-gofmt
script/validate-shfmt
go vet ./... go vet ./...
ci: validate localtest ci: validate localtest

View File

@ -16,7 +16,6 @@
# Configuration: # Configuration:
# #
# Note for developers: # Note for developers:
# Please arrange options sorted alphabetically by long name with the short # Please arrange options sorted alphabetically by long name with the short
# options immediately following their corresponding long form. # options immediately following their corresponding long form.
@ -26,7 +25,7 @@ __runc_previous_extglob_setting=$(shopt -p extglob)
shopt -s extglob shopt -s extglob
__runc_list_all() { __runc_list_all() {
COMPREPLY=( $( compgen -W "$(runc list -q)" -- $cur) ) COMPREPLY=($(compgen -W "$(runc list -q)" -- $cur))
} }
__runc_pos_first_nonflag() { __runc_pos_first_nonflag() {
@ -35,17 +34,16 @@ __runc_pos_first_nonflag() {
local counter=$((${subcommand_pos:-${command_pos}} + 1)) local counter=$((${subcommand_pos:-${command_pos}} + 1))
while [ $counter -le $cword ]; do while [ $counter -le $cword ]; do
if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
(( counter++ )) ((counter++))
else else
case "${words[$counter]}" in case "${words[$counter]}" in
-*) -*) ;;
;;
*) *)
break break
;; ;;
esac esac
fi fi
(( counter++ )) ((counter++))
done done
echo $counter echo $counter
@ -55,7 +53,7 @@ __runc_pos_first_nonflag() {
# with the words separated by "|". # with the words separated by "|".
# This is used to prepare arguments to __runc_pos_first_nonflag(). # This is used to prepare arguments to __runc_pos_first_nonflag().
__runc_to_alternatives() { __runc_to_alternatives() {
local parts=( $1 ) local parts=($1)
local IFS='|' local IFS='|'
echo "${parts[*]}" echo "${parts[*]}"
} }
@ -63,7 +61,7 @@ __runc_to_alternatives() {
# Transforms a multiline list of options into an extglob pattern # Transforms a multiline list of options into an extglob pattern
# suitable for use in case statements. # suitable for use in case statements.
__runc_to_extglob() { __runc_to_extglob() {
local extglob=$( __runc_to_alternatives "$1" ) local extglob=$(__runc_to_alternatives "$1")
echo "@($extglob)" echo "@($extglob)"
} }
@ -83,7 +81,7 @@ __runc_subcommands() {
local counter=$(($command_pos + 1)) local counter=$(($command_pos + 1))
while [ $counter -lt $cword ]; do while [ $counter -lt $cword ]; do
case "${words[$counter]}" in case "${words[$counter]}" in
$(__runc_to_extglob "$subcommands") ) $(__runc_to_extglob "$subcommands"))
subcommand_pos=$counter subcommand_pos=$counter
local subcommand=${words[$counter]} local subcommand=${words[$counter]}
local completions_func=_runc_${command}_${subcommand} local completions_func=_runc_${command}_${subcommand}
@ -91,14 +89,14 @@ __runc_subcommands() {
return 0 return 0
;; ;;
esac esac
(( counter++ )) ((counter++))
done done
return 1 return 1
} }
# List all Signals # List all Signals
__runc_list_signals() { __runc_list_signals() {
COMPREPLY=( $( compgen -W "$(for i in $(kill -l | xargs); do echo $i; done | grep SIG)")) COMPREPLY=($(compgen -W "$(for i in $(kill -l | xargs); do echo $i; done | grep SIG)"))
} }
# suppress trailing whitespace # suppress trailing whitespace
@ -109,7 +107,7 @@ __runc_nospace() {
# The list of capabilities is defined in types.go, ALL was added manually. # The list of capabilities is defined in types.go, ALL was added manually.
__runc_complete_capabilities() { __runc_complete_capabilities() {
COMPREPLY=( $( compgen -W " COMPREPLY=($(compgen -W "
ALL ALL
AUDIT_CONTROL AUDIT_CONTROL
AUDIT_WRITE AUDIT_WRITE
@ -149,10 +147,9 @@ __runc_complete_capabilities() {
SYS_TIME SYS_TIME
SYS_TTY_CONFIG SYS_TTY_CONFIG
WAKE_ALARM WAKE_ALARM
" -- "$cur" ) ) " -- "$cur"))
} }
_runc_exec() { _runc_exec() {
local boolean_options=" local boolean_options="
--help --help
@ -176,18 +173,16 @@ _runc_exec() {
local all_options="$options_with_args $boolean_options" local all_options="$options_with_args $boolean_options"
case "$prev" in case "$prev" in
--cap|-c) --cap | -c)
__runc_complete_capabilities __runc_complete_capabilities
return return
;; ;;
--console|--cwd|--process|--apparmor) --console | --cwd | --process | --apparmor)
case "$cur" in case "$cur" in
*:*) *:*) ;; # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
# TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
;;
'') '')
COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) COMPREPLY=($(compgen -W '/' -- "$cur"))
__runc_nospace __runc_nospace
;; ;;
/*) /*)
@ -197,19 +192,19 @@ _runc_exec() {
esac esac
return return
;; ;;
--env|-e) --env | -e)
COMPREPLY=( $( compgen -e -- "$cur" ) ) COMPREPLY=($(compgen -e -- "$cur"))
__runc_nospace __runc_nospace
return return
;; ;;
$(__runc_to_extglob "$options_with_args") ) $(__runc_to_extglob "$options_with_args"))
return return
;; ;;
esac esac
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) COMPREPLY=($(compgen -W "$all_options" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -233,13 +228,11 @@ _runc_runc() {
" "
case "$prev" in case "$prev" in
--log|--root|--criu) --log | --root | --criu)
case "$cur" in case "$cur" in
*:*) *:*) ;; # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
# TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
;;
'') '')
COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) COMPREPLY=($(compgen -W '/' -- "$cur"))
__runc_nospace __runc_nospace
;; ;;
*) *)
@ -251,23 +244,23 @@ _runc_runc() {
;; ;;
--log-format) --log-format)
COMPREPLY=( $( compgen -W 'text json' -- "$cur" ) ) COMPREPLY=($(compgen -W 'text json' -- "$cur"))
return return
;; ;;
$(__runc_to_extglob "$options_with_args") ) $(__runc_to_extglob "$options_with_args"))
return return
;; ;;
esac esac
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
local counter=$( __runc_pos_first_nonflag $(__runc_to_extglob "$options_with_args") ) local counter=$(__runc_pos_first_nonflag $(__runc_to_extglob "$options_with_args"))
if [ $cword -eq $counter ]; then if [ $cword -eq $counter ]; then
COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) ) COMPREPLY=($(compgen -W "${commands[*]} help" -- "$cur"))
fi fi
;; ;;
esac esac
@ -281,7 +274,7 @@ _runc_pause() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -297,7 +290,7 @@ _runc_ps() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -313,7 +306,7 @@ _runc_delete() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -341,7 +334,7 @@ _runc_kill() {
esac esac
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -367,7 +360,7 @@ _runc_events() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -388,8 +381,8 @@ _runc_list() {
" "
case "$prev" in case "$prev" in
--format|-f) --format | -f)
COMPREPLY=( $( compgen -W 'text json' -- "$cur" ) ) COMPREPLY=($(compgen -W 'text json' -- "$cur"))
return return
;; ;;
@ -400,10 +393,10 @@ _runc_list() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
local counter=$( __runc_pos_first_nonflag $(__runc_to_extglob "$options_with_args") ) local counter=$(__runc_pos_first_nonflag $(__runc_to_extglob "$options_with_args"))
;; ;;
esac esac
} }
@ -419,10 +412,10 @@ _runc_spec() {
" "
case "$prev" in case "$prev" in
--bundle|-b) --bundle | -b)
case "$cur" in case "$cur" in
'') '')
COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) COMPREPLY=($(compgen -W '/' -- "$cur"))
__runc_nospace __runc_nospace
;; ;;
/*) /*)
@ -440,10 +433,10 @@ _runc_spec() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
local counter=$( __runc_pos_first_nonflag $(__runc_to_extglob "$options_with_args") ) local counter=$(__runc_pos_first_nonflag $(__runc_to_extglob "$options_with_args"))
;; ;;
esac esac
} }
@ -466,10 +459,10 @@ _runc_run() {
" "
case "$prev" in case "$prev" in
--bundle|-b|--console|--pid-file) --bundle | -b | --console | --pid-file)
case "$cur" in case "$cur" in
'') '')
COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) COMPREPLY=($(compgen -W '/' -- "$cur"))
__runc_nospace __runc_nospace
;; ;;
/*) /*)
@ -487,7 +480,7 @@ _runc_run() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -514,21 +507,18 @@ _runc_checkpoint() {
" "
case "$prev" in case "$prev" in
--page-server) --page-server) ;;
;;
--manage-cgroups-mode) --manage-cgroups-mode)
COMPREPLY=( $( compgen -W "soft full strict" -- "$cur" ) ) COMPREPLY=($(compgen -W "soft full strict" -- "$cur"))
return return
;; ;;
--image-path|--work-path) --image-path | --work-path)
case "$cur" in case "$cur" in
*:*) *:*) ;; # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
# TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
;;
'') '')
COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) COMPREPLY=($(compgen -W '/' -- "$cur"))
__runc_nospace __runc_nospace
;; ;;
*) *)
@ -546,7 +536,7 @@ _runc_checkpoint() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -567,10 +557,10 @@ _runc_create() {
--pid-file --pid-file
" "
case "$prev" in case "$prev" in
--bundle|-b|--console|--pid-file) --bundle | -b | --console | --pid-file)
case "$cur" in case "$cur" in
'') '')
COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) COMPREPLY=($(compgen -W '/' -- "$cur"))
__runc_nospace __runc_nospace
;; ;;
/*) /*)
@ -588,7 +578,7 @@ _runc_create() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -600,7 +590,7 @@ _runc_create() {
_runc_help() { _runc_help() {
local counter=$(__runc_pos_first_nonflag) local counter=$(__runc_pos_first_nonflag)
if [ $cword -eq $counter ]; then if [ $cword -eq $counter ]; then
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) COMPREPLY=($(compgen -W "${commands[*]}" -- "$cur"))
fi fi
} }
@ -630,17 +620,15 @@ _runc_restore() {
case "$prev" in case "$prev" in
--manage-cgroups-mode) --manage-cgroups-mode)
COMPREPLY=( $( compgen -W "soft full strict" -- "$cur" ) ) COMPREPLY=($(compgen -W "soft full strict" -- "$cur"))
return return
;; ;;
--pid-file|--image-path|--work-path|--bundle|-b) --pid-file | --image-path | --work-path | --bundle | -b)
case "$cur" in case "$cur" in
*:*) *:*) ;; # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
# TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
;;
'') '')
COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) COMPREPLY=($(compgen -W '/' -- "$cur"))
__runc_nospace __runc_nospace
;; ;;
/*) /*)
@ -651,14 +639,14 @@ _runc_restore() {
return return
;; ;;
$(__runc_to_extglob "$options_with_args") ) $(__runc_to_extglob "$options_with_args"))
return return
;; ;;
esac esac
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) COMPREPLY=($(compgen -W "$all_options" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -674,7 +662,7 @@ _runc_resume() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -690,7 +678,7 @@ _runc_state() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -705,7 +693,7 @@ _runc_start() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -742,7 +730,7 @@ _runc_update() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
;; ;;
*) *)
__runc_list_all __runc_list_all
@ -791,10 +779,9 @@ _runc() {
local counter=1 local counter=1
while [ $counter -lt $cword ]; do while [ $counter -lt $cword ]; do
case "${words[$counter]}" in case "${words[$counter]}" in
-*) -*) ;;
;;
=) =)
(( counter++ )) ((counter++))
;; ;;
*) *)
command="${words[$counter]}" command="${words[$counter]}"
@ -802,7 +789,7 @@ _runc() {
break break
;; ;;
esac esac
(( counter++ )) ((counter++))
done done
local completions_func=_runc_${command} local completions_func=_runc_${command}

View File

@ -16,7 +16,7 @@ possibleConfigFiles=(
'.config' '.config'
) )
if ! command -v zgrep &> /dev/null; then if ! command -v zgrep &>/dev/null; then
zgrep() { zgrep() {
zcat "$2" | grep "$1" zcat "$2" | grep "$1"
} }
@ -28,19 +28,19 @@ kernelMinor="${kernelVersion#$kernelMajor.}"
kernelMinor="${kernelMinor%%.*}" kernelMinor="${kernelMinor%%.*}"
is_set() { is_set() {
zgrep "CONFIG_$1=[y|m]" "$CONFIG" > /dev/null zgrep "CONFIG_$1=[y|m]" "$CONFIG" >/dev/null
} }
is_set_in_kernel() { is_set_in_kernel() {
zgrep "CONFIG_$1=y" "$CONFIG" > /dev/null zgrep "CONFIG_$1=y" "$CONFIG" >/dev/null
} }
is_set_as_module() { is_set_as_module() {
zgrep "CONFIG_$1=m" "$CONFIG" > /dev/null zgrep "CONFIG_$1=m" "$CONFIG" >/dev/null
} }
color() { color() {
local codes=() local codes=()
if [ "$1" = 'bold' ]; then if [ "$1" = 'bold' ]; then
codes=( "${codes[@]}" '1' ) codes=("${codes[@]}" '1')
shift shift
fi fi
if [ "$#" -gt 0 ]; then if [ "$#" -gt 0 ]; then
@ -57,7 +57,7 @@ color() {
white) code=37 ;; white) code=37 ;;
esac esac
if [ "$code" ]; then if [ "$code" ]; then
codes=( "${codes[@]}" "$code" ) codes=("${codes[@]}" "$code")
fi fi
fi fi
local IFS=';' local IFS=';'
@ -109,8 +109,7 @@ check_distro_userns() {
fi fi
} }
is_config() is_config() {
{
local config="$1" local config="$1"
# Todo: more check # Todo: more check
@ -118,8 +117,7 @@ is_config()
return 1 return 1
} }
search_config() search_config() {
{
local target_dir="$1" local target_dir="$1"
[[ "$target_dir" ]] || target_dir=("${possibleConfigs[@]}") [[ "$target_dir" ]] || target_dir=("${possibleConfigs[@]}")
@ -181,14 +179,14 @@ fi
if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
echo -n '- ' echo -n '- '
if command -v apparmor_parser &> /dev/null; then if command -v apparmor_parser &>/dev/null; then
echo "$(wrap_good 'apparmor' 'enabled and tools installed')" echo "$(wrap_good 'apparmor' 'enabled and tools installed')"
else else
echo "$(wrap_bad 'apparmor' 'enabled, but apparmor_parser missing')" echo "$(wrap_bad 'apparmor' 'enabled, but apparmor_parser missing')"
echo -n ' ' echo -n ' '
if command -v apt-get &> /dev/null; then if command -v apt-get &>/dev/null; then
echo "$(wrap_color '(use "apt-get install apparmor" to fix this)')" echo "$(wrap_color '(use "apt-get install apparmor" to fix this)')"
elif command -v yum &> /dev/null; then elif command -v yum &>/dev/null; then
echo "$(wrap_color '(your best bet is "yum install apparmor-parser")')" echo "$(wrap_color '(your best bet is "yum install apparmor-parser")')"
else else
echo "$(wrap_color '(look for an "apparmor" package for your distribution)')" echo "$(wrap_color '(look for an "apparmor" package for your distribution)')"

View File

@ -3,14 +3,14 @@
source "$(dirname "$BASH_SOURCE")/.validate" source "$(dirname "$BASH_SOURCE")/.validate"
IFS=$'\n' IFS=$'\n'
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^Godeps/' || true) ) files=($(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^Godeps/' || true))
unset IFS unset IFS
badFiles=() badFiles=()
for f in "${files[@]}"; do for f in "${files[@]}"; do
# we use "git show" here to validate that what's committed is formatted # we use "git show" here to validate that what's committed is formatted
if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then
badFiles+=( "$f" ) badFiles+=("$f")
fi fi
done done

21
script/validate-shfmt Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
badFiles=()
while read f; do
badFiles+=("$f")
done < <(shfmt -l . | grep -v Godeps/)
if [ ${#badFiles[@]} -eq 0 ]; then
echo 'Congratulations! All shell source files are properly formatted.'
else
{
echo "These files are not properly shfmt'd:"
for f in "${badFiles[@]}"; do
echo " - $f"
done
echo
echo 'Please reformat the above files using "shfmt -w" and commit the result.'
echo
} >&2
false
fi

View File

@ -85,9 +85,9 @@ function retry() {
shift shift
local i local i
for ((i=0; i < attempts; i++)); do for ((i = 0; i < attempts; i++)); do
run "$@" run "$@"
if [[ "$status" -eq 0 ]] ; then if [[ "$status" -eq 0 ]]; then
return 0 return 0
fi fi
sleep $delay sleep $delay
@ -104,9 +104,9 @@ function wait_for_container() {
local cid=$3 local cid=$3
local i local i
for ((i=0; i < attempts; i++)); do for ((i = 0; i < attempts; i++)); do
runc state $cid runc state $cid
if [[ "$status" -eq 0 ]] ; then if [[ "$status" -eq 0 ]]; then
return 0 return 0
fi fi
sleep $delay sleep $delay
@ -123,9 +123,9 @@ function wait_for_container_inroot() {
local cid=$3 local cid=$3
local i local i
for ((i=0; i < attempts; i++)); do for ((i = 0; i < attempts; i++)); do
ROOT=$4 runc state $cid ROOT=$4 runc state $cid
if [[ "$status" -eq 0 ]] ; then if [[ "$status" -eq 0 ]]; then
return 0 return 0
fi fi
sleep $delay sleep $delay