#!/bin/bash
#PBS -l nodes=1:ppn=2
#PBS -l mem=10gb
#PBS -l walltime=06:00:00
#PBS -m abe
#PBS -q small

cd $PBS_O_WORKDIR/"${download_folder}"

module load 7-Zip/16.02

## md5sum
echo "$(date) Checking md5sum..."
md5sum -c "${name}".md5sum
if [ "$?" == "0" ]; then
    ## 7za
    echo "$(date) Unzipping..."
    7za x -p"${unzip_password}" "${name}".zip.001
    if [ "$?" == "0" ]; then
        if [ "${keep}" == "false" ]; then
            echo "Found 'keep_downloaded_md5sum_zip_files' option is false. Removing the downloaded md5sum and zip file(s)..."
            rm "${name}".md5sum
            rm "${name}".zip.[0-9][0-9][0-9]
        else
            echo "Found 'keep_downloaded_md5sum_zip_files' option is true. Leaving without remove the downloaded md5sum and zip file(s)..."
        fi
        echo "$(date) cpos-sftp2hpcf for ${name} has completed!"
    else
        exit 1
    fi
else
    exit 1
fi
