1#!/bin/bash 2 3# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4# Copyright © 2020 Intel Corporation 5# SPDX-License-Identifier: Apache-2.0 6 7CLI_NAME="Cloud Hypervisor" 8 9CTR_IMAGE_TAG="cloudhypervisor/dev" 10CTR_IMAGE_VERSION="20230123-0" 11CTR_IMAGE="${CTR_IMAGE_TAG}:${CTR_IMAGE_VERSION}" 12 13DOCKER_RUNTIME="docker" 14 15# Host paths 16CLH_SCRIPTS_DIR=$(cd "$(dirname "$0")" && pwd) 17CLH_ROOT_DIR=$(cd "${CLH_SCRIPTS_DIR}/.." && pwd) 18CLH_BUILD_DIR="${CLH_ROOT_DIR}/build" 19CLH_CARGO_TARGET="${CLH_BUILD_DIR}/cargo_target" 20CLH_DOCKERFILE="${CLH_SCRIPTS_DIR}/../resources/Dockerfile" 21CLH_CTR_BUILD_DIR="/tmp/cloud-hypervisor/ctr-build" 22CLH_INTEGRATION_WORKLOADS="${HOME}/workloads" 23 24# Container paths 25CTR_CLH_ROOT_DIR="/cloud-hypervisor" 26CTR_CLH_CARGO_BUILT_DIR="${CTR_CLH_ROOT_DIR}/build" 27CTR_CLH_CARGO_TARGET="${CTR_CLH_CARGO_BUILT_DIR}/cargo_target" 28CTR_CLH_INTEGRATION_WORKLOADS="/root/workloads" 29 30# Container networking option 31CTR_CLH_NET="bridge" 32 33# Cargo paths 34# Full path to the cargo registry dir on the host. This appears on the host 35# because we want to persist the cargo registry across container invocations. 36# Otherwise, any rust crates from crates.io would be downloaded again each time 37# we build or test. 38CARGO_REGISTRY_DIR="${CLH_BUILD_DIR}/cargo_registry" 39 40# Full path to the cargo git registry on the host. This serves the same purpose 41# as CARGO_REGISTRY_DIR, for crates downloaded from GitHub repos instead of 42# crates.io. 43CARGO_GIT_REGISTRY_DIR="${CLH_BUILD_DIR}/cargo_git_registry" 44 45# Full path to the cargo target dir on the host. 46CARGO_TARGET_DIR="${CLH_BUILD_DIR}/cargo_target" 47 48# Send a decorated message to stdout, followed by a new line 49# 50say() { 51 [ -t 1 ] && [ -n "$TERM" ] && 52 echo "$(tput setaf 2)[$CLI_NAME]$(tput sgr0) $*" || 53 echo "[$CLI_NAME] $*" 54} 55 56# Send a decorated message to stdout, without a trailing new line 57# 58say_noln() { 59 [ -t 1 ] && [ -n "$TERM" ] && 60 echo -n "$(tput setaf 2)[$CLI_NAME]$(tput sgr0) $*" || 61 echo "[$CLI_NAME] $*" 62} 63 64# Send a text message to stderr 65# 66say_err() { 67 [ -t 2 ] && [ -n "$TERM" ] && 68 echo "$(tput setaf 1)[$CLI_NAME] $*$(tput sgr0)" 1>&2 || 69 echo "[$CLI_NAME] $*" 1>&2 70} 71 72# Send a warning-highlighted text to stdout 73say_warn() { 74 [ -t 1 ] && [ -n "$TERM" ] && 75 echo "$(tput setaf 3)[$CLI_NAME] $*$(tput sgr0)" || 76 echo "[$CLI_NAME] $*" 77} 78 79# Exit with an error message and (optional) code 80# Usage: die [-c <error code>] <error message> 81# 82die() { 83 code=1 84 [[ "$1" = "-c" ]] && { 85 code="$2" 86 shift 2 87 } 88 say_err "$@" 89 exit "$code" 90} 91 92# Exit with an error message if the last exit code is not 0 93# 94ok_or_die() { 95 code=$? 96 [[ $code -eq 0 ]] || die -c $code "$@" 97} 98 99# Make sure the build/ dirs are available. Exit if we can't create them. 100# Upon returning from this call, the caller can be certain the build/ dirs exist. 101# 102ensure_build_dir() { 103 for dir in "$CLH_BUILD_DIR" \ 104 "$CLH_INTEGRATION_WORKLOADS" \ 105 "$CLH_CTR_BUILD_DIR" \ 106 "$CARGO_TARGET_DIR" \ 107 "$CARGO_REGISTRY_DIR" \ 108 "$CARGO_GIT_REGISTRY_DIR"; do 109 mkdir -p "$dir" || die "Error: cannot create dir $dir" 110 [ -x "$dir" ] && [ -w "$dir" ] || 111 { 112 say "Wrong permissions for $dir. Attempting to fix them ..." 113 chmod +x+w "$dir" 114 } || 115 die "Error: wrong permissions for $dir. Should be +x+w" 116 done 117} 118 119# Make sure we're using the latest dev container, by just pulling it. 120ensure_latest_ctr() { 121 if [ "$CTR_IMAGE_VERSION" = "local" ]; then 122 build_container 123 else 124 $DOCKER_RUNTIME pull "$CTR_IMAGE" 125 126 if [ $? -ne 0 ]; then 127 build_container 128 fi 129 130 ok_or_die "Error pulling/building container image. Aborting." 131 fi 132} 133 134# Fix main directory permissions after a container ran as root. 135# Since the container ran as root, any files it creates will be owned by root. 136# This fixes that by recursively changing the ownership of /cloud-hypervisor to the 137# current user. 138# 139fix_dir_perms() { 140 # Yes, running Docker to get elevated privileges, just to chown some files 141 # is a dirty hack. 142 $DOCKER_RUNTIME run \ 143 --workdir "$CTR_CLH_ROOT_DIR" \ 144 --rm \ 145 --volume /dev:/dev \ 146 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 147 "$CTR_IMAGE" \ 148 chown -R "$(id -u):$(id -g)" "$CTR_CLH_ROOT_DIR" 149 150 return "$1" 151} 152# Process exported volumes argument, separate the volumes and make docker compatible 153# Sample input: --volumes /a:/a#/b:/b 154# Sample output: --volume /a:/a --volume /b:/b 155# 156process_volumes_args() { 157 if [ -z "$arg_vols" ]; then 158 return 159 fi 160 exported_volumes="" 161 arr_vols=(${arg_vols//#/ }) 162 for var in "${arr_vols[@]}"; do 163 parts=(${var//:/ }) 164 if [[ ! -e "${parts[0]}" ]]; then 165 echo "The volume ${parts[0]} does not exist." 166 exit 1 167 fi 168 exported_volumes="$exported_volumes --volume $var" 169 done 170} 171cmd_help() { 172 echo "" 173 echo "Cloud Hypervisor $(basename "$0")" 174 echo "Usage: $(basename "$0") <command> [<command args>]" 175 echo "" 176 echo "Available commands:" 177 echo "" 178 echo " build [--debug|--release] [--libc musl|gnu] [-- [<cargo args>]]" 179 echo " Build the Cloud Hypervisor binaries." 180 echo " --debug Build the debug binaries. This is the default." 181 echo " --release Build the release binaries." 182 echo " --libc Select the C library Cloud Hypervisor will be built against. Default is gnu" 183 echo " --volumes Hash separated volumes to be exported. Example --volumes /mnt:/mnt#/myvol:/myvol" 184 echo " --hypervisor Underlying hypervisor. Options kvm, mshv" 185 echo "" 186 echo " tests [<test type (see below)>] [--libc musl|gnu] [-- [<test scripts args>] [-- [<test binary args>]]] " 187 echo " Run the Cloud Hypervisor tests." 188 echo " --unit Run the unit tests." 189 echo " --integration Run the integration tests." 190 echo " --integration-sgx Run the SGX integration tests." 191 echo " --integration-vfio Run the VFIO integration tests." 192 echo " --integration-windows Run the Windows guest integration tests." 193 echo " --integration-live-migration Run the live-migration integration tests." 194 echo " --integration-rate-limiter Run the rate-limiter integration tests." 195 echo " --libc Select the C library Cloud Hypervisor will be built against. Default is gnu" 196 echo " --metrics Generate performance metrics" 197 echo " --volumes Hash separated volumes to be exported. Example --volumes /mnt:/mnt#/myvol:/myvol" 198 echo " --hypervisor Underlying hypervisor. Options kvm, mshv" 199 echo " --all Run all tests." 200 echo "" 201 echo " build-container [--type]" 202 echo " Build the Cloud Hypervisor container." 203 echo "" 204 echo " clean [<cargo args>]]" 205 echo " Remove the Cloud Hypervisor artifacts." 206 echo "" 207 echo " shell" 208 echo " Run the development container into an interactive, privileged BASH shell." 209 echo " --volumes Hash separated volumes to be exported. Example --volumes /mnt:/mnt#/myvol:/myvol" 210 echo "" 211 echo " help" 212 echo " Display this help message." 213 echo "" 214} 215 216cmd_build() { 217 build="debug" 218 libc="gnu" 219 hypervisor="kvm" 220 features_build="" 221 exported_device="/dev/kvm" 222 while [ $# -gt 0 ]; do 223 case "$1" in 224 "-h" | "--help") { 225 cmd_help 226 exit 1 227 } ;; 228 "--debug") { build="debug"; } ;; 229 "--release") { build="release"; } ;; 230 "--runtime") 231 shift 232 DOCKER_RUNTIME="$1" 233 export DOCKER_RUNTIME 234 ;; 235 "--libc") 236 shift 237 [[ "$1" =~ ^(musl|gnu)$ ]] || 238 die "Invalid libc: $1. Valid options are \"musl\" and \"gnu\"." 239 libc="$1" 240 ;; 241 "--volumes") 242 shift 243 arg_vols="$1" 244 ;; 245 "--hypervisor") 246 shift 247 hypervisor="$1" 248 ;; 249 "--features") 250 shift 251 features_build="--features $1" 252 ;; 253 "--") { 254 shift 255 break 256 } ;; 257 *) 258 die "Unknown build argument: $1. Please use --help for help." 259 ;; 260 esac 261 shift 262 done 263 264 ensure_build_dir 265 ensure_latest_ctr 266 267 process_volumes_args 268 if [[ ! ("$hypervisor" = "kvm" || "$hypervisor" = "mshv") ]]; then 269 die "Hypervisor value must be kvm or mshv" 270 fi 271 if [[ "$hypervisor" = "mshv" ]]; then 272 exported_device="/dev/mshv" 273 fi 274 target="$(uname -m)-unknown-linux-${libc}" 275 276 cargo_args=("$@") 277 [ $build = "release" ] && cargo_args+=("--release") 278 cargo_args+=(--target "$target") 279 280 rustflags="" 281 target_cc="" 282 if [ "$(uname -m)" = "aarch64" ] && [ "$libc" = "musl" ]; then 283 rustflags="-C link-arg=-lgcc -C link_arg=-specs -C link_arg=/usr/lib/aarch64-linux-musl/musl-gcc.specs" 284 target_cc="musl-gcc" 285 fi 286 287 $DOCKER_RUNTIME run \ 288 --user "$(id -u):$(id -g)" \ 289 --workdir "$CTR_CLH_ROOT_DIR" \ 290 --rm \ 291 --volume $exported_device \ 292 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 293 --env RUSTFLAGS="$rustflags" \ 294 --env TARGET_CC="$target_cc" \ 295 "$CTR_IMAGE" \ 296 cargo build --all $features_build \ 297 --target-dir "$CTR_CLH_CARGO_TARGET" \ 298 "${cargo_args[@]}" && say "Binaries placed under $CLH_CARGO_TARGET/$target/$build" 299} 300 301cmd_clean() { 302 cargo_args=("$@") 303 304 ensure_build_dir 305 ensure_latest_ctr 306 307 $DOCKER_RUNTIME run \ 308 --user "$(id -u):$(id -g)" \ 309 --workdir "$CTR_CLH_ROOT_DIR" \ 310 --rm \ 311 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 312 "$CTR_IMAGE" \ 313 cargo clean \ 314 --target-dir "$CTR_CLH_CARGO_TARGET" \ 315 "${cargo_args[@]}" 316} 317 318cmd_tests() { 319 unit=false 320 integration=false 321 integration_sgx=false 322 integration_vfio=false 323 integration_windows=false 324 integration_live_migration=false 325 integration_rate_limiter=false 326 metrics=false 327 libc="gnu" 328 arg_vols="" 329 hypervisor="kvm" 330 exported_device="/dev/kvm" 331 while [ $# -gt 0 ]; do 332 case "$1" in 333 "-h" | "--help") { 334 cmd_help 335 exit 1 336 } ;; 337 "--unit") { unit=true; } ;; 338 "--integration") { integration=true; } ;; 339 "--integration-sgx") { integration_sgx=true; } ;; 340 "--integration-vfio") { integration_vfio=true; } ;; 341 "--integration-windows") { integration_windows=true; } ;; 342 "--integration-live-migration") { integration_live_migration=true; } ;; 343 "--integration-rate-limiter") { integration_rate_limiter=true; } ;; 344 "--metrics") { metrics=true; } ;; 345 "--libc") 346 shift 347 [[ "$1" =~ ^(musl|gnu)$ ]] || 348 die "Invalid libc: $1. Valid options are \"musl\" and \"gnu\"." 349 libc="$1" 350 ;; 351 "--volumes") 352 shift 353 arg_vols="$1" 354 ;; 355 "--hypervisor") 356 shift 357 hypervisor="$1" 358 ;; 359 "--all") { 360 cargo=true 361 unit=true 362 integration=true 363 } ;; 364 "--") { 365 shift 366 break 367 } ;; 368 *) 369 die "Unknown tests argument: $1. Please use --help for help." 370 ;; 371 esac 372 shift 373 done 374 if [[ ! ("$hypervisor" = "kvm" || "$hypervisor" = "mshv") ]]; then 375 die "Hypervisor value must be kvm or mshv" 376 fi 377 378 if [[ "$hypervisor" = "mshv" ]]; then 379 exported_device="/dev/mshv" 380 fi 381 382 if [ ! -e "${exported_device}" ] ; then 383 die "${exported_device} does not exist on the system" 384 fi 385 386 set -- '--hypervisor' "$hypervisor" "$@" 387 388 ensure_build_dir 389 ensure_latest_ctr 390 391 process_volumes_args 392 target="$(uname -m)-unknown-linux-${libc}" 393 394 if [[ "$unit" = true ]]; then 395 say "Running unit tests for $target..." 396 $DOCKER_RUNTIME run \ 397 --workdir "$CTR_CLH_ROOT_DIR" \ 398 --rm \ 399 --device $exported_device \ 400 --device /dev/net/tun \ 401 --cap-add net_admin \ 402 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 403 --env BUILD_TARGET="$target" \ 404 "$CTR_IMAGE" \ 405 ./scripts/run_unit_tests.sh "$@" || fix_dir_perms $? || exit $? 406 fi 407 408 if [ "$integration" = true ]; then 409 say "Running integration tests for $target..." 410 $DOCKER_RUNTIME run \ 411 --workdir "$CTR_CLH_ROOT_DIR" \ 412 --rm \ 413 --privileged \ 414 --security-opt seccomp=unconfined \ 415 --ipc=host \ 416 --net="$CTR_CLH_NET" \ 417 --mount type=tmpfs,destination=/tmp \ 418 --volume /dev:/dev \ 419 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 420 --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ 421 --env USER="root" \ 422 --env CH_LIBC="${libc}" \ 423 "$CTR_IMAGE" \ 424 ./scripts/run_integration_tests_"$(uname -m)".sh "$@" || fix_dir_perms $? || exit $? 425 fi 426 427 if [ "$integration_sgx" = true ]; then 428 say "Running SGX integration tests for $target..." 429 $DOCKER_RUNTIME run \ 430 --workdir "$CTR_CLH_ROOT_DIR" \ 431 --rm \ 432 --privileged \ 433 --security-opt seccomp=unconfined \ 434 --ipc=host \ 435 --net="$CTR_CLH_NET" \ 436 --mount type=tmpfs,destination=/tmp \ 437 --volume /dev:/dev \ 438 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 439 --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ 440 --env USER="root" \ 441 --env CH_LIBC="${libc}" \ 442 "$CTR_IMAGE" \ 443 ./scripts/run_integration_tests_sgx.sh "$@" || fix_dir_perms $? || exit $? 444 fi 445 446 if [ "$integration_vfio" = true ]; then 447 say "Running VFIO integration tests for $target..." 448 $DOCKER_RUNTIME run \ 449 --workdir "$CTR_CLH_ROOT_DIR" \ 450 --rm \ 451 --privileged \ 452 --security-opt seccomp=unconfined \ 453 --ipc=host \ 454 --net="$CTR_CLH_NET" \ 455 --mount type=tmpfs,destination=/tmp \ 456 --volume /dev:/dev \ 457 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 458 --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ 459 --env USER="root" \ 460 --env CH_LIBC="${libc}" \ 461 "$CTR_IMAGE" \ 462 ./scripts/run_integration_tests_vfio.sh "$@" || fix_dir_perms $? || exit $? 463 fi 464 465 if [ "$integration_windows" = true ]; then 466 say "Running Windows integration tests for $target..." 467 $DOCKER_RUNTIME run \ 468 --workdir "$CTR_CLH_ROOT_DIR" \ 469 --rm \ 470 --privileged \ 471 --security-opt seccomp=unconfined \ 472 --ipc=host \ 473 --net="$CTR_CLH_NET" \ 474 --mount type=tmpfs,destination=/tmp \ 475 --volume /dev:/dev \ 476 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 477 --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ 478 --env USER="root" \ 479 --env CH_LIBC="${libc}" \ 480 "$CTR_IMAGE" \ 481 ./scripts/run_integration_tests_windows_"$(uname -m)".sh "$@" || fix_dir_perms $? || exit $? 482 fi 483 484 if [ "$integration_live_migration" = true ]; then 485 say "Running 'live migration' integration tests for $target..." 486 $DOCKER_RUNTIME run \ 487 --workdir "$CTR_CLH_ROOT_DIR" \ 488 --rm \ 489 --privileged \ 490 --security-opt seccomp=unconfined \ 491 --ipc=host \ 492 --net="$CTR_CLH_NET" \ 493 --mount type=tmpfs,destination=/tmp \ 494 --volume /dev:/dev \ 495 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 496 --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ 497 --env USER="root" \ 498 --env CH_LIBC="${libc}" \ 499 "$CTR_IMAGE" \ 500 ./scripts/run_integration_tests_live_migration.sh "$@" || fix_dir_perms $? || exit $? 501 fi 502 503 if [ "$integration_rate_limiter" = true ]; then 504 say "Running 'rate limiter' integration tests for $target..." 505 $DOCKER_RUNTIME run \ 506 --workdir "$CTR_CLH_ROOT_DIR" \ 507 --rm \ 508 --privileged \ 509 --security-opt seccomp=unconfined \ 510 --ipc=host \ 511 --net="$CTR_CLH_NET" \ 512 --mount type=tmpfs,destination=/tmp \ 513 --volume /dev:/dev \ 514 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 515 --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ 516 --env USER="root" \ 517 --env CH_LIBC="${libc}" \ 518 "$CTR_IMAGE" \ 519 ./scripts/run_integration_tests_rate_limiter.sh "$@" || fix_dir_perms $? || exit $? 520 fi 521 522 if [ "$metrics" = true ]; then 523 say "Generating performance metrics for $target..." 524 $DOCKER_RUNTIME run \ 525 --workdir "$CTR_CLH_ROOT_DIR" \ 526 --rm \ 527 --privileged \ 528 --security-opt seccomp=unconfined \ 529 --ipc=host \ 530 --net="$CTR_CLH_NET" \ 531 --mount type=tmpfs,destination=/tmp \ 532 --volume /dev:/dev \ 533 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 534 --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ 535 --env USER="root" \ 536 --env CH_LIBC="${libc}" \ 537 "$CTR_IMAGE" \ 538 ./scripts/run_metrics.sh "$@" || fix_dir_perms $? || exit $? 539 fi 540 541 fix_dir_perms $? 542} 543 544build_container() { 545 ensure_build_dir 546 547 BUILD_DIR=/tmp/cloud-hypervisor/container/ 548 549 mkdir -p $BUILD_DIR 550 cp "$CLH_DOCKERFILE" $BUILD_DIR 551 552 [ "$(uname -m)" = "aarch64" ] && TARGETARCH="arm64" 553 [ "$(uname -m)" = "x86_64" ] && TARGETARCH="amd64" 554 555 $DOCKER_RUNTIME build \ 556 --target dev \ 557 -t $CTR_IMAGE \ 558 -f $BUILD_DIR/Dockerfile \ 559 --build-arg TARGETARCH=$TARGETARCH \ 560 $BUILD_DIR 561} 562 563cmd_build-container() { 564 while [ $# -gt 0 ]; do 565 case "$1" in 566 "-h" | "--help") { 567 cmd_help 568 exit 1 569 } ;; 570 "--") { 571 shift 572 break 573 } ;; 574 *) 575 die "Unknown build-container argument: $1. Please use --help for help." 576 ;; 577 esac 578 shift 579 done 580 581 build_container 582} 583 584cmd_shell() { 585 while [ $# -gt 0 ]; do 586 case "$1" in 587 "-h" | "--help") { 588 cmd_help 589 exit 1 590 } ;; 591 "--volumes") 592 shift 593 arg_vols="$1" 594 ;; 595 "--") { 596 shift 597 break 598 } ;; 599 *) ;; 600 601 esac 602 shift 603 done 604 ensure_build_dir 605 ensure_latest_ctr 606 process_volumes_args 607 say_warn "Starting a privileged shell prompt as root ..." 608 say_warn "WARNING: Your $CLH_ROOT_DIR folder will be bind-mounted in the container under $CTR_CLH_ROOT_DIR" 609 $DOCKER_RUNTIME run \ 610 -ti \ 611 --workdir "$CTR_CLH_ROOT_DIR" \ 612 --rm \ 613 --privileged \ 614 --security-opt seccomp=unconfined \ 615 --ipc=host \ 616 --net="$CTR_CLH_NET" \ 617 --tmpfs /tmp:exec \ 618 --volume /dev:/dev \ 619 --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ 620 --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ 621 --env USER="root" \ 622 --entrypoint bash \ 623 "$CTR_IMAGE" 624 625 fix_dir_perms $? 626} 627 628# Parse main command line args. 629# 630while [ $# -gt 0 ]; do 631 case "$1" in 632 -h | --help) { 633 cmd_help 634 exit 1 635 } ;; 636 --local) { 637 CTR_IMAGE_VERSION="local" 638 CTR_IMAGE="${CTR_IMAGE_TAG}:${CTR_IMAGE_VERSION}" 639 } ;; 640 -*) 641 die "Unknown arg: $1. Please use \`$0 help\` for help." 642 ;; 643 *) 644 break 645 ;; 646 esac 647 shift 648done 649 650# $1 is now a command name. Check if it is a valid command and, if so, 651# run it. 652# 653declare -f "cmd_$1" >/dev/null 654ok_or_die "Unknown command: $1. Please use \`$0 help\` for help." 655 656cmd=cmd_$1 657shift 658 659$cmd "$@" 660