From 4155cb435eef3fd13b8b88f0aa74e04a52c81741 Mon Sep 17 00:00:00 2001 From: storypku Date: Tue, 24 Nov 2020 17:55:28 +0800 Subject: [PATCH] Format: shfmt {cyber,dev}_{start,into}.sh --- docker/scripts/cyber_into.sh | 9 +- docker/scripts/cyber_start.sh | 134 ++++++++++++------------ docker/scripts/dev_start.sh | 188 ++++++++++++++++++---------------- 3 files changed, 171 insertions(+), 160 deletions(-) diff --git a/docker/scripts/cyber_into.sh b/docker/scripts/cyber_into.sh index 4ca45b63868..a2f34c3586f 100755 --- a/docker/scripts/cyber_into.sh +++ b/docker/scripts/cyber_into.sh @@ -27,17 +27,16 @@ xhost +local:root 1>/dev/null 2>&1 HOST_ARCH="$(uname -m)" TARGET_ARCH="$(docker exec "${CYBER_CONTAINER}" uname -m)" - -IFS='' read -r -d '' NONROOT_SUDO_ERRMSG << EOF +IFS='' read -r -d '' NONROOT_SUDO_ERRMSG <> "${agreement_record}" - echo "${user_agreed}" >> "${agreement_record}" + echo "${tip}" >>"${agreement_record}" + echo "${user_agreed}" >>"${agreement_record}" else exit 1 fi @@ -102,7 +102,7 @@ function _target_arch_check() { } function show_usage() { -cat < Pull docker image from mirror registry based on geolocation. @@ -120,8 +120,8 @@ function stop_all_apollo_containers_for_user() { local force="$1" local running_containers running_containers="$(docker ps -a --format '{{.Names}}')" - for container in ${running_containers[*]} ; do - if [[ "${container}" =~ apollo_.*_${USER} ]] ; then + for container in ${running_containers[*]}; do + if [[ "${container}" =~ apollo_.*_${USER} ]]; then #printf %-*s 70 "Now stop container: ${container} ..." #printf "\033[32m[DONE]\033[0m\n" #printf "\033[31m[FAILED]\033[0m\n" @@ -151,50 +151,57 @@ function parse_arguments() { local shm_size="" local geo="" - while [[ $# -gt 0 ]] ; do - local opt="$1"; shift + while [[ $# -gt 0 ]]; do + local opt="$1" + shift case "${opt}" in - -g|--geo) - geo="$1"; shift - _optarg_check_for_opt "${opt}" "${geo}" - ;; - -t|--tag) - if [[ ! -z "${custom_version}" ]]; then - warning "Multiple option ${opt} specified, only the last one will take effect." - fi - custom_version="$1"; shift - _optarg_check_for_opt "${opt}" "${custom_version}" - ;; - -d|--dist) - custom_dist="$1"; shift - _optarg_check_for_opt "${opt}" "${custom_dist}" - ;; - -h|--help) - show_usage - exit 1 - ;; - -l|--local) - use_local_image=1 - ;; - -m) - target_arch="$1"; shift - _optarg_check_for_opt "${opt}" "${target_arch}" - _target_arch_check "${target_arch}" - ;; - --shm-size) - shm_size="$1"; shift - _optarg_check_for_opt "${opt}" "${shm_size}" - ;; - stop) - local force="$1"; shift - info "Now, stop all apollo containers created by ${USER} ..." - stop_all_apollo_containers_for_user "${force}" - exit 0 - ;; - *) - warning "Unknown option: $1" - exit 2 - ;; + -g | --geo) + geo="$1" + shift + _optarg_check_for_opt "${opt}" "${geo}" + ;; + -t | --tag) + if [[ ! -z "${custom_version}" ]]; then + warning "Multiple option ${opt} specified, only the last one will take effect." + fi + custom_version="$1" + shift + _optarg_check_for_opt "${opt}" "${custom_version}" + ;; + -d | --dist) + custom_dist="$1" + shift + _optarg_check_for_opt "${opt}" "${custom_dist}" + ;; + -h | --help) + show_usage + exit 1 + ;; + -l | --local) + use_local_image=1 + ;; + -m) + target_arch="$1" + shift + _optarg_check_for_opt "${opt}" "${target_arch}" + _target_arch_check "${target_arch}" + ;; + --shm-size) + shm_size="$1" + shift + _optarg_check_for_opt "${opt}" "${shm_size}" + ;; + stop) + local force="$1" + shift + info "Now, stop all apollo containers created by ${USER} ..." + stop_all_apollo_containers_for_user "${force}" + exit 0 + ;; + *) + warning "Unknown option: $1" + exit 2 + ;; esac done # End while loop @@ -218,7 +225,7 @@ function guess_arch_from_tag() { local __result="$2" local arch - IFS='-' read -ra __arr <<< "${tag}" + IFS='-' read -ra __arr <<<"${tag}" IFS=' ' # restore if [[ ${#__arr[@]} -lt 3 ]]; then warning "Unexpected image: ${tag}" @@ -262,8 +269,8 @@ function determine_target_version_and_arch() { _target_arch_check "${supposed_arch}" TARGET_ARCH="${supposed_arch}" elif [[ "${TARGET_ARCH}" != "${supposed_arch}" ]]; then - error "Target arch (${TARGET_ARCH}) doesn't match supposed arch"\ - "(${supposed_arch}) from ${version}" + error "Target arch (${TARGET_ARCH}) doesn't match supposed arch" \ + "(${supposed_arch}) from ${version}" exit 1 fi fi @@ -283,7 +290,7 @@ function geo_specific_config() { function determine_gpu_use_aarch64() { local use_gpu=0 - if lsmod | grep -q nvgpu ; then + if lsmod | grep -q nvgpu; then use_gpu=1 fi if [[ "${use_gpu}" -eq 1 ]]; then @@ -302,9 +309,9 @@ function determine_gpu_use_aarch64() { function determine_gpu_use_amd64() { # Check nvidia-driver and GPU device local nv_driver="nvidia-smi" - if [ ! -x "$(command -v ${nv_driver} )" ]; then + if [ ! -x "$(command -v ${nv_driver})" ]; then warning "No nvidia-driver found. CPU will be used" - elif [ -z "$(eval ${nv_driver} )" ]; then + elif [ -z "$(eval ${nv_driver})" ]; then warning "No GPU device found. CPU will be used." else USE_GPU_HOST=1 @@ -327,7 +334,7 @@ function determine_gpu_use_amd64() { else USE_GPU_HOST=0 warning "Cannot access GPU from within container. Please install latest Docker" \ - "and NVIDIA Container Toolkit as described by: " + "and NVIDIA Container Toolkit as described by: " warning " ${nv_docker_doc}" fi fi @@ -360,12 +367,12 @@ function setup_devices_and_mount_volumes() { 16.04) # Mount host devices into container (/dev) warning "[Deprecated] Support for Ubuntu 16.04 will be removed" \ - "in the near future. Please upgrade to ubuntu 18.04+." + "in the near future. Please upgrade to ubuntu 18.04+." if [[ "${HOST_ARCH}" == "${TARGET_ARCH}" ]]; then volumes="${volumes} -v /dev:/dev" fi ;; - 18.04|20.04|*) + 18.04 | 20.04 | *) if [[ "${HOST_ARCH}" == "${TARGET_ARCH}" ]]; then volumes="${volumes} -v /dev:/dev" fi @@ -384,7 +391,7 @@ function setup_devices_and_mount_volumes() { " fi fi - volumes="$(tr -s " " <<< "${volumes}")" + volumes="$(tr -s " " <<<"${volumes}")" eval "${__retval}='${volumes}'" } @@ -401,8 +408,8 @@ function docker_pull_if_needed() { local use_local_image="$2" if [[ ${use_local_image} -eq 1 ]]; then info "Start cyber container based on local image: ${image}" - elif docker images -a --format '{{.Repository}}:{{.Tag}}' \ - | grep -q "${image}"; then + elif docker images -a --format '{{.Repository}}:{{.Tag}}' | + grep -q "${image}"; then info "Image ${image} found locally, will be used." use_local_image=1 fi @@ -434,7 +441,7 @@ function check_multi_arch_support() { local qemu="multiarch/qemu-user-static" local refer="https://github.com/multiarch/qemu-user-static" local qemu_cmd="docker run --rm --privileged ${qemu} --reset -p yes" - if docker images --format "{{.Repository}}" |grep -q "${qemu}" ; then + if docker images --format "{{.Repository}}" | grep -q "${qemu}"; then info "Run: ${qemu_cmd}" ## docker run --rm --privileged "${qemu}" --reset -p yes >/dev/null eval "${qemu_cmd}" >/dev/null @@ -495,7 +502,7 @@ function start_cyber_container() { "${image}" \ /bin/bash - if [ $? -ne 0 ];then + if [ $? -ne 0 ]; then error "Failed to start docker container \"${CYBER_CONTAINER}\" based on image: ${image}" exit 1 fi @@ -538,10 +545,9 @@ function main() { after_run_setup ok "Congrats, you have successfully finished setting up Apollo cyber docker environment." \ - "To login into cyber container, please run the following command:" + "To login into cyber container, please run the following command:" ok " bash docker/scripts/cyber_into.sh" ok "Enjoy!" } main "$@" - diff --git a/docker/scripts/dev_start.sh b/docker/scripts/dev_start.sh index df397f1631c..c7bc2c4fd1d 100755 --- a/docker/scripts/dev_start.sh +++ b/docker/scripts/dev_start.sh @@ -54,15 +54,15 @@ MAP_VOLUMES_CONF= OTHER_VOLUMES_CONF= DEFAULT_MAPS=( - sunnyvale_big_loop - sunnyvale_loop - sunnyvale_with_two_offices - san_mateo + sunnyvale_big_loop + sunnyvale_loop + sunnyvale_with_two_offices + san_mateo ) DEFAULT_TEST_MAPS=( - sunnyvale_big_loop - sunnyvale_loop + sunnyvale_big_loop + sunnyvale_loop ) # Check whether user has agreed license agreement @@ -79,7 +79,7 @@ function check_agreement() { if [ "$USER_AGREED" = "yes" ]; then local progname="$(basename $0)" - cat "${AGREEMENT_FILE}" > "${agreement_record}" + cat "${AGREEMENT_FILE}" >"${agreement_record}" local msgtext="By specifying '-y' option when running ${progname}, \ you have agreed to the license agreement above." echo "${msgtext}" | tee -a "${agreement_record}" @@ -92,9 +92,9 @@ you have agreed to the license agreement above." echo if [[ "${user_agreed}" = "y" || "${user_agreed}" == "Y" ]]; then - cat "${AGREEMENT_FILE}" > "${agreement_record}" - echo "${tip}" >> "${agreement_record}" - echo "${user_agreed}" >> $agreement_record + cat "${AGREEMENT_FILE}" >"${agreement_record}" + echo "${tip}" >>"${agreement_record}" + echo "${user_agreed}" >>$agreement_record else exit 1 fi @@ -112,7 +112,7 @@ function _optarg_check_for_opt() { } function show_usage() { -cat <