github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/deploy/dev/utils.sh (about) 1 #!/bin/bash 2 3 exit_error() { 4 echo "Error: $1." 5 exit 1 6 } 7 8 is_number() { 9 if ! [[ "$1" =~ ^[0-9]+$ ]] ; then 10 exit_error "'$1' is not a number" 11 fi 12 } 13 14 is_boolean() { 15 if ! [[ "$1" =~ ^[yn]+$ ]] ; then 16 exit_error "input is not a 'y' or 'n'" 17 fi 18 } 19 20 is_command_available() { 21 if [[ -z $(command -v "$1") ]]; then 22 exit_error "command '$1' not available" 23 fi 24 } 25 26 # uncomment to see the commands 27 run_cmd() { 28 # set -x 29 $@ & 30 # { set +x; } 2>/dev/null 31 } 32 33 # NOTE: `AIS_BACKEND_PROVIDERS` and all other system environment variables 34 # are listed in the `env` package: 35 # https://github.com/NVIDIA/aistore/blob/main/api/env/README.md 36 37 parse_backend_providers() { 38 AIS_BACKEND_PROVIDERS="" 39 echo "Select backend providers:" 40 echo "Amazon S3: (y/n) ?" 41 read -r cld_aws 42 is_boolean "${cld_aws}" 43 echo "Google Cloud Storage: (y/n) ?" 44 read -r cld_gcp 45 is_boolean "${cld_gcp}" 46 echo "Azure: (y/n) ?" 47 read -r cld_azure 48 is_boolean "${cld_azure}" 49 50 if [[ "${cld_aws}" == "y" ]] ; then 51 AIS_BACKEND_PROVIDERS="${AIS_BACKEND_PROVIDERS} aws" 52 fi 53 if [[ "${cld_gcp}" == "y" ]] ; then 54 AIS_BACKEND_PROVIDERS="${AIS_BACKEND_PROVIDERS} gcp" 55 fi 56 if [[ "${cld_azure}" == "y" ]] ; then 57 AIS_BACKEND_PROVIDERS="${AIS_BACKEND_PROVIDERS} azure" 58 fi 59 } 60 61 create_loopbacks() { 62 echo "Loopback device size, e.g. 10G, 100M (press Enter to skip): " 63 read -r loopback_size 64 if [[ "$loopback_size" == "" || "$loopback_size" == "0" ]] ; then 65 return 66 fi 67 if ! command -v numfmt &> /dev/null; then 68 exit_error "numfmt not found (check GNU coreutils)" 69 fi 70 if ! command -v losetup &> /dev/null; then 71 exit_error "losetup not found (install mount or klibc-utils)" 72 fi 73 size=`numfmt --from=iec ${loopback_size}` || exit_error $? 74 let mbcount=$size/1048576 # IEC mebibytes 75 if [ $mbcount -lt 100 ] ; then 76 exit_error "the minimum loopback size is 100M (got ${loopback_size})" 77 fi 78 for ((i=1; i<=TEST_FSPATH_COUNT; i++)); do 79 dir=${TEST_FSPATH_ROOT:-/tmp/ais$NEXT_TIER/}mp${i} 80 mkdir -p "${dir}" 81 82 if mount | grep "${dir}" > /dev/null; then 83 continue 84 fi 85 86 sudo dd if=/dev/zero of="${dir}.img" bs=1M count=$mbcount 87 sudo losetup -fP "${dir}.img" 88 sudo mkfs.ext4 "${dir}.img" > /dev/null 89 90 device=$(sudo losetup -l | grep "${dir}.img" | awk '{print $1}') 91 sudo mount -o loop "${device}" "${dir}" 92 sudo chown -R ${USER}: "${dir}" 93 done 94 TEST_LOOPBACK_COUNT=$TEST_FSPATH_COUNT 95 } 96 97 rm_loopbacks() { 98 for mpath in $(df -h | grep "/tmp/ais${NEXT_TIER}/mp" | awk '{print $1}'); do 99 sudo umount "${mpath}" 100 done 101 102 if [[ -x "$(command -v losetup)" ]]; then 103 for mpath in $(losetup -l | grep "/tmp/ais${NEXT_TIER}/mp" | awk '{print $1}'); do 104 sudo losetup -d "${mpath}" 105 done 106 fi 107 }