#!/bin/bash

URL="$IMG_URL_1"
CUSTOMER="$CUST"
TEMP_DIR=/tmp/tmpfs/download/
CUST_DIR=streams/
LOCAL_DOWNLOAD_DIR=/tmp/tmpfs/images/$CUSTOMER/


mkdir -p /tmp/tmpfs/download
mkdir -p /tmp/tmpfs/images
mkdir -p $LOCAL_DOWNLOAD_DIR

# Loop indefinitely
while true; do
    # download all files from webservers
    wget -q -r -np --reject-regex "\?.=.;.=.|nginx" --reject="index.html*" --no-host-directories  $URL$CUSTOMER/ -P "$TEMP_DIR"
    sleep 1
    mv $TEMP_DIR$CUST_DIR$CUSTOMER/* $LOCAL_DOWNLOAD_DIR
done
