#!/bin/bash

#This script syncs the code for the internal server issue due to data size

function code_rsync() {

       rsync_script="sync-code";

       #code for checking the md5sum for file checksum started

       echo "File integrity check started. Please wait";

       if [ -f ${rsync_script}.tar.gz.md5sum ]; then
           echo "${rsync_script}.tar.gz.md5sum file is present ${reset}"

           if md5sum --status -c ${rsync_script}.tar.gz.md5sum && echo OK; then
              echo "File integrity check was successful ${reset}";
           else
              echo "File integrity Check Failed. Please download the correct ${rsync_script}.tar.gz file ${reset}";
              exit;
           fi
       else
           echo "${rsync_script}.tar.gz.md5sum file not present. Please Download It ${reset}";
           exit;
       fi

       #code for checking the md5sum for file checksum ended

       echo -e "Extracting the files ${reset}";
       sudo tar -xvzf ${rsync_script}.tar.gz;

       sudo bash /mnt/${rsync_script}/sync_code.sh ;

       rm -r /mnt/${rsync_script} ;
}
code_rsync | tee code_rsync.log
