HEX
HEX
Server: Apache/2.4.29 (Ubuntu)
System: Linux 2amigos-php74 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
User: squarehillcompany.com (1002)
PHP: 7.4.25
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhosts/yiistrap.2amigos.us/cgi-bin/deploy.cgi
#!/bin/bash
#
# Clevertech GIT Deploy Tool v0.1a
# (C)2013 Gregory Motruk (greg@clevertech.biz)
#

# Variables to edit ######################################################
PROJECT="yiistrap"                                                       # Project name, should be same as in assembla/github if you want to use HipChat notifications
ENVIRONMENT="DEV"                                                        # Environment type (INT/DEMO/PROD or STAGE/HOTFIX/PROD)
REPO_HOST="Assembla"                                                     # Where GIT repo is hosted, can be Assembla or GitHub
GIT_BRANCH="master"                                                      # Branch from where will be performed pull
GIT_URL="git@github.com:yii-twbs/yiistrap.git"                           # GIT repo URL
WORK_DIR="/var/www/html/yiistrap.2amigos.us"                             # Project home directory
MAIL_TO="greg@clevertech.biz"                                            # E-Mail address for logs
PASSWORD="yiistrap"                                                      # Password
ALLOWED_IP="184.106.216.206 109.185.125.23"                              # IP's allowed to perform deploy
##########################################################################

# Features ###############################################################
PASSWORD_CHECK="1"                                                       # Allow deploy only if correct password is supplied
LIMIT_IP="0"                                                             # Allow deploy only from specified IP's
MAIL_ENABLED="0"                                                         # Send deploy log to e-mail
CLEAN_ENABLED="0"                                                        # Clean repo before pull
LOG_ENABLED="1"                                                          # Enable daily logs
##########################################################################

# GIT commands ###########################################################
GIT_RESET="git reset --hard HEAD"                                        # Reset GIT head
GIT_CLEAN="git clean -f"                                                 # Remove all files which does not exist in repo from dirs not in .gitignore
GIT_UPDATE="git pull origin "                                            # Pull command
##########################################################################

# Other variables ########################################################
LOG="$WORK_DIR/logs/deploy-`date +%d.%m.%Y`.log"                         # Path to daily logs
TMP_LOG="$WORK_DIR/logs/last.log"                                        # Temp log path
DEPLOY_DIR="$WORK_DIR/docroot"                                           # Repo dir
PASTIE_BIN="$WORK_DIR/bin/pastie"                                        # Path to pastie executable
HIPCHAT_BIN="$WORK_DIR/bin/hipchat"                                      # Path to HipChat executable
##########################################################################

# Functions ##############################################################
clean() {
 if [ "$CLEAN_ENABLED" == "1" ]; then
  echo "--- `date '+%d.%m.%Y %T'` ($REMOTE_ADDR): Performing Clean"
  cd $DEPLOY_DIR
  $GIT_RESET
  $GIT_CLEAN
 fi
}

deploy() {
 echo "--- `date '+%d.%m.%Y %T'` ($REMOTE_ADDR): Performing Deploy"
 cd $DEPLOY_DIR
 $GIT_UPDATE $GIT_BRANCH
}

writelog() {
 if [ "$LOG_ENABLED" == "1" ]; then
  cat $TMP_LOG >> $LOG
 fi
}

mailsend() {
 if [ "$MAIL_ENABLED" == "1" ]; then
  echo "--- `date '+%d.%m.%Y %T'` ($REMOTE_ADDR): Sending Log to $MAIL_TO"
  mail -s "$PROJECT $ENVIRONMENT Deploy Log" $MAIL_TO < $TMP_LOG
 fi
}

hipchat() {
 if [ "$HIPCHAT_ENABLED" == "1" ]; then
  echo "--- `date '+%d.%m.%Y %T'` ($REMOTE_ADDR): Sending notification to HipChat"
  cd $DEPLOY_DIR
  HASH=`git whatchanged --format=oneline|head -n 1|awk '{print $1}'`
  AUTHOR=`git show $HASH|grep Author|cut -d\< -f1|sed 's/ *$//g'`
  COMMENT=`git whatchanged --format=oneline|head -n 1|cut -d\  -f2-`
  MFILES=`git whatchanged --oneline --name-status $HASH -1|grep "/"|wc -l`
  COMMENT1=""
  for i in $COMMENT; do
   t=`echo $i|cut -b1`
   l=`echo $i|cut -b2-`
   if [ "$t" == "#" ]; then
    COMMENT1="$COMMENT1 <a href=\"$ASSEMBLAT/$l\">$i</a> "
   else
    COMMENT1="$COMMENT1 $i "
   fi
  done
  COMMENT=`echo $COMMENT1|sed 's/ *$//g'`
  PBLINK=`cat $TMP_LOG|$PASTIE_BIN -p`
  if [ "$REPO_HOST" == "Assembla" ]; then
   DEP_TXT="$AUTHOR, $COMMENT, changed $MFILES files, <a href=\"$ASSEMBLAC/$HASH\">View commit</a>, <a href=\"$PBLINK\">View deploy</a>"
  fi
  if [ "$REPO_HOST" == "GitHub" ]; then
   DEP_TXT="$AUTHOR, $COMMENT, changed $MFILES files, <a href=\"$GITHUBC/$HASH\">View commit</a>, <a href=\"$PBLINK\">View deploy</a>"
  fi
  echo "$DEP_TXT" | $HIPCHAT_BIN -t $TOKEN -r $ROOM -f "Deploy-$ENVIRONMENT" -c $COLLOR > /dev/null
 fi
}

##########################################################################

echo "Content-Type: text/html"
echo
echo "<HTML><BODY>"
echo "<H3><PRE>"

if [ "$PASSWORD_CHECK" == "1" ] && [ "$QUERY_STRING" != "$PASSWORD" ]; then
 echo "--- `date '+%d.%m.%Y %T'` ($REMOTE_ADDR): Deploy could not be performed! (Wrong password)" 2>&1 | tee $TMP_LOG
 writelog
 echo "</PRE></H3>"
 echo "</BODY></HTML>"
 exit
fi

if [ "$LIMIT_IP" == "1" ] && [[ "$ALLOWED_IP" != *"$REMOTE_ADDR"* ]]; then
 echo "--- `date '+%d.%m.%Y %T'` ($REMOTE_ADDR): Deploy could not be performed! (IP is not authorized)" 2>&1 | tee $TMP_LOG
 writelog
 echo "</PRE></H3>"
 echo "</BODY></HTML>"
 exit
fi

> $TMP_LOG

echo "--- `date '+%d.%m.%Y %T'` ($REMOTE_ADDR): Start!" 2>&1 | tee -a $TMP_LOG

clean 2>&1 | tee -a $TMP_LOG
deploy 2>&1 | tee -a $TMP_LOG

echo "--- `date '+%d.%m.%Y %T'` ($REMOTE_ADDR): Finish!" 2>&1 | tee -a $TMP_LOG

mailsend
hipchat
writelog

echo "</PRE></H3>"
echo "</BODY></HTML>"