#!/bin/bash  

# define resource
resource=alliance_genome

# 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
cd /data/projects/glygen/downloads/$resource/$new_dir

# the commands followed by & are run in the background
wget --user-agent="Mozilla" https://fms.alliancegenome.org/download/DISEASE-ALLIANCE_COMBINED.tsv.gz &
sleep 5 
wget --user-agent="Mozilla" "https://fms.alliancegenome.org/download/ORTHOLOGY-ALLIANCE_COMBINED.tsv.gz" &

wait # Wait until all downloads are complete
echo "Download completed, unzipping files..."

# unzip the downloaded folder
gunzip *.gz
echo "Unzipping completed, changing folder permissions and creating softlinks..."

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

# create symbolic links to the files according to species
cd /data/projects/glygen/downloads/$resource/
rm current
ln -s $new_dir current

echo "Download is ready, process completed."
