HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: //datos/www/www.colombia.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