#!/bin/bash  

# define resource
resource=chebi

# add the glyconnect 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

wget https://ftp.ebi.ac.uk/pub/databases/chebi/flat_files/database_accession.tsv.gz &
sleep 5
wget https://ftp.ebi.ac.uk/pub/databases/chebi/archive/chebi_legacy/Flat_file_tab_delimited/chebiId_inchi.tsv &
sleep 5
wget https://ftp.ebi.ac.uk/pub/databases/chebi/flat_files/reference.tsv.gz &
sleep 5

wait # Wait until all downloads are complete
gunzip *.gz

# 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