Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 106 lines (90 sloc) 4.8 KB
#!/bin/bash
ssh-agent > /tmp/.ssh-agent.tmp 2> /dev/null;
. /tmp/.ssh-agent.tmp 1>/dev/null 2>/dev/null;
TheAgent=$(cat /tmp/.ssh-agent.tmp | grep SSH_AGENT | awk -F';' '{print $1}' | awk -F'=' '{print $2}')
ssh-add ~/.ssh/id_rsa ~/.ssh/new-prod-us-east-1.pem ~/.ssh/new-int-us-east-1.pem ~/.ssh/prod-us-east-1.pem ~/.ssh/sectest1.pem 1>/dev/null 2>/dev/null
/usr/local/bin/gfind ~/.ssh/ -regex ".*id_\S\S\S?1?" -exec ssh-add {} \; 1>/dev/null 2>/dev/null
GITPATHA="/git/artbinder"
GITPATHB="/git/wellzilla"
GITPATHC="/git/otherRepos"
GITPATHD="/git"
TMPFILE="/tmp/gitupdate"
LOGFILE="/var/log/git-update.log"
NUMPATHA=$(find $GITPATHA -type d -maxdepth 2 -iname ".git" | wc -l | xargs)
NUMPATHB=$(find $GITPATHB -type d -maxdepth 2 -iname ".git" | wc -l | xargs)
NUMPATHC=$(find $GITPATHC -type d -maxdepth 2 -iname ".git" | wc -l | xargs)
NUMPATHD=$(find $GITPATHD -type d -maxdepth 2 -iname ".git" | wc -l | xargs)
echo `date` > $LOGFILE;
TOTALCALC=$(echo $NUMPATHA + $NUMPATHB + $NUMPATHC + $NUMPATHD | bc -l)
echo "Total Repositories: ($TOTALCALC)"
echo "Starting git pulls on directories in $GITPATHA"
message="Starting git pulls on directories in $GITPATHA \n"
gfind $GITPATHA -maxdepth 2 -type d -iname ".git" -printf "%h\n" | awk -F'%' '{print "echo",$1"; git --git-dir="$1"/.git --work-tree="$1" pull --ff-only"}' | bash > $TMPFILE 2>&1
GITUPDATE=$(cat $TMPFILE | grep -c 'Already up-to-date')
cat $TMPFILE | egrep -v 'Already up-to-date.|^warning' >> $LOGFILE
UPDATED=$(expr $NUMPATHA - $GITUPDATE)
echo "25% completed. $UPDATED repos updated"
AREPOS=$(cat $TMPFILE | grep -B1 'Updating' | awk -F"$GITPATHD" '{print $2}')
if [ ${#AREPOS} -le 1 ];
then
AREPOS=$(cat $TMPFILE | grep -B1 'From github.com:' | awk -F'From github.com:' '{print $2}');
fi
echo "Starting git pulls on directories in $GITPATHB"
message="Starting git pulls on directories in $GITPATHB \n"
gfind $GITPATHB -maxdepth 2 -type d -iname ".git" -printf "%h\n" | awk -F'%' '{print "echo",$1"; git --git-dir="$1"/.git --work-tree="$1" pull --ff-only"}' | bash > $TMPFILE 2>&1
BGITUPDATE=$(cat $TMPFILE | grep -c 'Already up-to-date')
cat $TMPFILE | egrep -v 'Already up-to-date.|^warning' >> $LOGFILE
UPDATED=$(expr $NUMPATHB - $BGITUPDATE)
echo "50% completed. $UPDATED repos updated"
BREPOS=$(cat $TMPFILE | grep -B1 'Updating' | awk -F"$GITPATHD" '{print $2}')
if [ ${#BREPOS} -le 1 ];
then
BREPOS=$(cat $TMPFILE | grep -B1 'From github.com:' | awk -F'From github.com:' '{print $2}');
fi
echo "Starting git pulls on directories in $GITPATHC"
message="Starting git pulls on directories in $GITPATHC \n"
gfind $GITPATHC -maxdepth 2 -type d -iname ".git" -printf "%h\n" | awk -F'%' '{print "echo",$1"; git --git-dir="$1"/.git --work-tree="$1" pull --ff-only"}' | bash > $TMPFILE 2>&1
CGITUPDATE=$(cat $TMPFILE | grep -c 'Already up-to-date')
cat $TMPFILE | egrep -v 'Already up-to-date.|^warning' >> $LOGFILE
UPDATED=$(expr $NUMPATHC - $CGITUPDATE)
echo "75% completed. $UPDATED repos updated"
CREPOS=$(cat $TMPFILE | grep -B1 'Updating' | awk -F"$GITPATHD" '{print $2}')
if [ ${#CREPOS} -le 1 ];
then
CREPOS=$(cat $TMPFILE | grep -B1 'From github.com:' | awk -F'From github.com:' '{print $2}');
fi
echo "Starting git pulls on directories in $GITPATHD"
message="Starting git pulls on directories in $GITPATHD \n"
gfind $GITPATHD -maxdepth 2 -type d -iname ".git" -printf "%h\n" | awk -F'%' '{print "echo",$1"; git --git-dir="$1"/.git --work-tree="$1" pull --ff-only"}' | bash > $TMPFILE 2>&1
DGITUPDATE=$(cat $TMPFILE | grep -c 'Already up-to-date')
cat $TMPFILE | egrep -v 'Already up-to-date.|^warning' >> $LOGFILE
UPDATED=$(expr $NUMPATHD - $DGITUPDATE)
echo "100% completed. $UPDATED repos updated"
DREPOS=$(cat $TMPFILE | grep -B1 'Updating' | awk -F"$GITPATHD" '{print $2}')
if [ ${#DREPOS} -le 1 ];
then
DREPOS=$(cat $TMPFILE | grep -B1 'From github.com:' | awk -F'From github.com:' '{print $2}');
fi
message+="Updated repos: \n"
AUPDATED=$(expr $NUMPATHA - $GITUPDATE)
BUPDATED=$(expr $NUMPATHB - $BGITUPDATE)
CUPDATED=$(expr $NUMPATHC - $CGITUPDATE)
DUPDATED=$(expr $NUMPATHD - $DGITUPDATE)
TUPDATE=$(expr $AUPDATED + $BUPDATED + $CUPDATED + $DUPDATED)
UREPOS=$(echo $AREPOS $BREPOS $CREPOS $DREPOS | tr ' ' '\n')
message+=$UREPOS
message+="`echo $'\n '` Finished. $TUPDATE repos updated."
echo "`echo $'\n '` Finished. $TUPDATE repos updated."
if [ $TUPDATE -gt 0 ];
then
if [ ${#UREPOS} -gt 1 ];
then
LocalHostName=$(cat /etc/scripted-hostname)
echo -e $message | mail -s "Git Update - $LocalHostName" thisis@jared.nyc
echo -e $message | mail -s "Git Update - $LocalHostName" Jared
fi
fi
echo $BUPDATED | /usr/bin/awk '$1>0{print "osascript -e \"display notification \\\""$1" updated git repos. {$message}\\\" with title \\\" Git Repo Update \\\"\""}' | /bin/sh
kill -9 $TheAgent
HCS=$(curl -Ls http://hchk.io/1810517f-675a-45f9-9c19-51aee59b00c7)
echo "Healthcheck: $HCS"