|
@ -209,12 +209,43 @@ function arg2_required() { |
|
|
return 0 |
|
|
return 0 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# test arg3 required |
|
|
|
|
|
function arg3_required() { |
|
|
|
|
|
[[ -z "${3:-}" ]] && echoerr "ERROR: arg#3 expected!" && return 125 || return 0 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
# test whether container <ct> exists yet? |
|
|
# test whether container <ct> exists yet? |
|
|
function container_exists() { |
|
|
function container_exists() { |
|
|
arg1_required "$@" |
|
|
arg1_required "$@" |
|
|
lxc list "$1" -c n -f csv | grep -q "^$1\$" |
|
|
lxc list "$1" -c n -f csv | grep -q "^$1\$" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# 3 args expected: <commmand> <delay in s, example: 0.2> <max_attempts> |
|
|
|
|
|
function wait_for_command { |
|
|
|
|
|
arg3_required "$@" |
|
|
|
|
|
|
|
|
|
|
|
command=$1 |
|
|
|
|
|
delay=$2 |
|
|
|
|
|
max_attempt=$3 |
|
|
|
|
|
|
|
|
|
|
|
attempt=0 |
|
|
|
|
|
while ! eval "$command"; do |
|
|
|
|
|
attempt=$((attempt + 1)) |
|
|
|
|
|
if [[ $attempt -gt $max_attempt ]]; then |
|
|
|
|
|
echoerr "command <$command> failed after a delay of $(bc <<<"$max_attempt * $delay")s and $max_attempt attempts" |
|
|
|
|
|
return 1 |
|
|
|
|
|
else |
|
|
|
|
|
sleep "$delay" |
|
|
|
|
|
fi |
|
|
|
|
|
done |
|
|
|
|
|
echo SUCCESS |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function wait_for_container_full_initialization { |
|
|
|
|
|
arg1_required "$@" |
|
|
|
|
|
wait_for_command "lxc exec $1 -- test -f /root/cloud-status.json" 0.2 40 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
# build debian image with prebuild miaou-bash and various useful settings |
|
|
# build debian image with prebuild miaou-bash and various useful settings |
|
|
# ARG1=release [bullseye, buster] |
|
|
# ARG1=release [bullseye, buster] |
|
|
function build_miaou_image() { |
|
|
function build_miaou_image() { |
|
@ -304,6 +335,14 @@ EOF1 |
|
|
fi |
|
|
fi |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# convert array to string according to IFS arg1 |
|
|
|
|
|
# example: join "," "${MY_ARRAY[@]}" => one,two,three |
|
|
|
|
|
function join() { |
|
|
|
|
|
local IFS="$1" |
|
|
|
|
|
shift |
|
|
|
|
|
echo "$*" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
# execute remote scripting onto one LXC container <CONTAINER> [COMMANDS, ...] |
|
|
# execute remote scripting onto one LXC container <CONTAINER> [COMMANDS, ...] |
|
|
# may use one command like: `lxc_exec ct1 uname -a` |
|
|
# may use one command like: `lxc_exec ct1 uname -a` |
|
|
# or pipe like so: ` |
|
|
# or pipe like so: ` |
|
|