#!/bin/bash
DEPTH=${DEPTH:-3}
WIDTH=${WIDTH:-10}
OC_URL=${OC_URL:-https://localhost:9200}
ENDPOINT=${ENDPOINT:-/webdav}
FOLDER=${FOLDER:-w$WIDTH x d$DEPTH folders}
USER=${USER:-alan}
PASSWORD=${PASSWORD:-demo}
CURL_OPTS=${CURL_OPTS:--k}
COUNT=0
MAX=0
calc_max()
{
for i in $(seq 1 $2);
do {
MAX=$(( MAX + ($1 ** i) ))
}
done
}
calc_max $WIDTH $DEPTH
create_tree()
{
if (( $2 >= 1 )); then
for w in $(seq 1 $1);
do {
p="$3/w${w}d$2"
COUNT=$(( COUNT + 1 ))
echo "creating $COUNT/$MAX $OC_URL$ENDPOINT/$FOLDER$p"
curl -X MKCOL "$OC_URL$ENDPOINT/$FOLDER$p" -u $USER:$PASSWORD -w "%{http_code}" $CURL_OPTS || { echo "could not create collection '$OC_URL$ENDPOINT/$FOLDER$p'" >&2; exit 1; } &
create_tree $1 $(( $2 - 1 )) $p
}
done
fi
}
curl -X MKCOL "$OC_URL$ENDPOINT/$FOLDER" -u $USER:$PASSWORD -w "%{http_code}" $CURL_OPTS || { echo "could not create collection '$OC_URL$ENDPOINT/$FOLDER/'" >&2; exit 1; }
create_tree $WIDTH $DEPTH