#!/bin/bash  

# define resource
resource=tablemaker

# add the time stamped folder
cd /data/projects/glygen/downloads/$resource/

new_dir=$(date +%Y_%m_%d)
mkdir $new_dir

# download files to new folder & create symbolic links
cd /data/projects/glygen/downloads/$resource/$new_dir

curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD1127346' -H 'accept: */*' -o TD1127346.csv &
sleep 5 
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD1468274' -H 'accept: */*' -o TD1468274.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD1040297' -H 'accept: */*' -o TD1040297.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD7732158' -H 'accept: */*' -o TD7732158.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD2986138' -H 'accept: */*' -o TD2986138.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD2415036' -H 'accept: */*' -o TD2415036.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD8741863' -H 'accept: */*' -o TD8741863.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD8189974' -H 'accept: */*' -o TD8189974.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD7181079' -H 'accept: */*' -o  TD7181079.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD4951079' -H 'accept: */*' -o  TD4951079.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD1131507' -H 'accept: */*' -o  TD1131507.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD7680256' -H 'accept: */*' -o  TD7680256.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD4964642' -H 'accept: */*' -o  TD4964642.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD6640575' -H 'accept: */*' -o  TD6640575.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD2727671' -H 'accept: */*' -o  TD2727671.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD5664582' -H 'accept: */*' -o  TD5664582.csv &
sleep 5
curl -X 'GET' 'https://glygen.ccrc.uga.edu/tablemaker/api/api/public/downloadtablefordataset/TD4253352' -H 'accept: */*' -o  TD4253352.csv &
sleep 5

wait #wait until all downloads are complete

# update new folder permissions
chmod -R 775 /data/shared/glygen/downloads/$resource/$new_dir/

# create symbolic link
cd /data/projects/glygen/downloads/$resource/
rm current
ln -s $new_dir current

echo "Download Complete"