github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/swarm/dev/scripts/random-uploads.sh (about) 1 #!/bin/bash 2 # 3 # A script to upload random data to a swarm cluster. 4 # 5 # Example: 6 # 7 # random-uploads.sh --addr 192.168.33.101:8500 --size 40k --count 1000 8 9 set -e 10 11 ROOT="$(cd "$(dirname "$0")/../../.." && pwd)" 12 source "${ROOT}/swarm/dev/scripts/util.sh" 13 14 DEFAULT_ADDR="localhost:8500" 15 DEFAULT_UPLOAD_SIZE="40k" 16 DEFAULT_UPLOAD_COUNT="1000" 17 18 usage() { 19 cat >&2 <<USAGE 20 usage: $0 [options] 21 22 Upload random data to a Swarm cluster. 23 24 OPTIONS: 25 -a, --addr ADDR Swarm API address [default: ${DEFAULT_ADDR}] 26 -s, --size SIZE Individual upload size [default: ${DEFAULT_UPLOAD_SIZE}] 27 -c, --count COUNT Number of uploads [default: ${DEFAULT_UPLOAD_COUNT}] 28 -h, --help Show this message 29 USAGE 30 } 31 32 main() { 33 local addr="${DEFAULT_ADDR}" 34 local upload_size="${DEFAULT_UPLOAD_SIZE}" 35 local upload_count="${DEFAULT_UPLOAD_COUNT}" 36 37 parse_args "$@" 38 39 info "uploading ${upload_count} ${upload_size} random files to ${addr}" 40 41 for i in $(seq 1 ${upload_count}); do 42 info "upload ${i} / ${upload_count}:" 43 do_random_upload 44 echo 45 done 46 } 47 48 do_random_upload() { 49 curl -fsSL -X POST --data-binary "$(random_data)" "http://${addr}/bzz-raw:/" 50 } 51 52 random_data() { 53 dd if=/dev/urandom of=/dev/stdout bs="${upload_size}" count=1 2>/dev/null 54 } 55 56 parse_args() { 57 while true; do 58 case "$1" in 59 -h | --help) 60 usage 61 exit 0 62 ;; 63 -a | --addr) 64 if [[ -z "$2" ]]; then 65 fail "--addr flag requires an argument" 66 fi 67 addr="$2" 68 shift 2 69 ;; 70 -s | --size) 71 if [[ -z "$2" ]]; then 72 fail "--size flag requires an argument" 73 fi 74 upload_size="$2" 75 shift 2 76 ;; 77 -c | --count) 78 if [[ -z "$2" ]]; then 79 fail "--count flag requires an argument" 80 fi 81 upload_count="$2" 82 shift 2 83 ;; 84 *) 85 break 86 ;; 87 esac 88 done 89 90 if [[ $# -ne 0 ]]; then 91 usage 92 fail "ERROR: invalid arguments: $@" 93 fi 94 } 95 96 main "$@"