#!/bin/bash  

# define resource
resource=compound

# add the glyconnect time_stamped_folder
cd /data/projects/glygen/downloads/pubchem/$resource/

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

# download files to new folder
cd /data/projects/glygen/downloads/pubchem/$resource/$new_dir

wget https://ftp.ncbi.nlm.nih.gov/pubchem/Compound/Extras/CID-InChI-Key.gz  &
sleep 5
wget https://ftp.ncbi.nlm.nih.gov/pubchem/Compound/Extras/CID-SMILES.gz  &
sleep 5
wget https://ftp.ncbi.nlm.nih.gov/pubchem/Compound/Extras/CID-Synonym-filtered.gz  &
sleep 5

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

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

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