#!/bin/bash
GIT_TOKEN=glpat-i1mRnqJ16Ax9AhneRDZy
FILE_URL=https://gitlab.com/api/v4/projects/31494443/repository/files/examples%2Falign%2Fcore_current/raw?ref=main
echo start download
curl --header "PRIVATE-TOKEN: $GIT_TOKEN" $FILE_URL >  core_current
RC=$?
SUCCESS=1
if [ $RC -ne 0 ] ; then
   echo git connection error
   SUCCESS=0  
else
   [[ ! -s core_current ]] && SUCCESS=0 && echo downloaded empty file

    file core_current | grep -q "ASCII text" && echo error page && SUCCESS=0  
    file core_current | grep -q "ELF 64-bit LSB shared object" && echo executive && find . -cmin -1 | grep "core_current" && echo is fresh && mv core core.old && mv core_current core && SUCCESS=1  
     
   [[ $SUCCESS -ne 1 ]] &&  echo problem to download new core_current
fi
#echo success $SUCCESS  
if  [ $SUCCESS -ne 1 ] ; then 
 exit 1
fi
