File: //datos/www/embajadasyconsulados.procolombia.co/git.sh
#!/bin/bash
set -e
scriptname=$(basename $0)
scriptname+="."
full_path=$(realpath $0)
scriptname+=$(echo -n ${full_path} | md5sum | awk '{print $1}')
scriptname+="."
scriptname+=$(id -u)
lock="/tmp/${scriptname}.lock"
exec 200>$lock
flock -n 200 || exit 1
pid=$$
echo $pid 1>&200
## The code:
DIRREPO=public_html
ORIGIN=origin
BRANCH=$(git -C $DIRREPO rev-parse --abbrev-ref HEAD)
# Change branch and fectch data from remote
git -C $DIRREPO checkout $BRANCH
timeout --foreground -k 10 1m git -C $DIRREPO fetch $ORIGIN $BRANCH
# Have a new commit
if [ $(git -C $DIRREPO rev-parse HEAD) != $(git -C $DIRREPO rev-parse @{u}) ]; then
echo NUEVO
git -C $DIRREPO clean -df
git -C $DIRREPO reset --hard $ORIGIN/$BRANCH
timeout --foreground -k 10 3m git -C $DIRREPO pull $ORIGIN $BRANCH
fi