Created
September 16, 2015 12:17
-
-
Save yitsushi/124b293357a9f4107bab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Basic logic: | |
# Check if current user is not equal with the file owner | |
# Parse mysql parameters from app/config/parameters.ini | |
# Check differeces from origin | |
# Merge remote changes | |
# If merge says there is nothing to do then simply exit | |
# If there was SQL files then execute them | |
# Updtae Symfony stuffs | |
# Last update: 2015-08-21 (Balazs Nadasdi) | |
# Check user | |
# If current user is not equal with the owner of this script | |
# then sudo them and execute the script as the owner | |
if [ `whoami` != `ls -ld $0 | awk 'NR==1 {print $3}'` ] | |
then | |
sudo -E -u `ls -ld $0 | awk 'NR==1 {print $3}'` sh $0 | |
exit | |
fi | |
if [ "x$PIWIK_API" = "x" ] | |
then | |
echo "Permission denied! You need an API Token!" | |
exit | |
fi | |
# Parse MySQL credentials from parameters.ini (Symfony configuration) | |
mysqlCommandParameters=`cat app/config/parameters.ini | sed -e 's/^ *//g' -e 's/\(=\)"\|"$/\1/g' | awk -F'=' '{ | |
if ($1 == "database_host") { host = $2 } | |
if ($1 == "database_name") { database = $2 } | |
if ($1 == "database_user") { username = $2 } | |
if ($1 == "database_password") { password = $2 } | |
} END { print "--host="host" --user="username" --password="password" "database }'` | |
# save current git commit id (maybe useful) | |
commitId=`git rev-parse --verify HEAD` | |
# save current branch name | |
branchName=`git rev-parse --abbrev-ref HEAD` | |
# fetch origin (remote branches) | |
git fetch origin | |
# get only added/deleted files with .sql endings | |
# Add: If we diff into the past | |
# Remove: If we diff into the future | |
sqlFiles=`git diff --name-only --diff-filter=DA origin/$branchName | grep "\.sql$"` | |
# Merge remote to local | |
mergeReturn=`git merge origin/$branchName` | |
if [ "${mergeReturn}" = "Already up-to-date." ] | |
then | |
echo $mergeReturn" Quit." | |
#exit | |
fi | |
# Execute each sql file | |
for f in $sqlFiles | |
do | |
# Check if file is exists | |
if [ -f $f ] | |
then | |
mysql $mysqlCommandParameters < $f | |
fi | |
done | |
phpUrlEncode='$text = ""; while (FALSE !== ($line = fgets(STDIN))) { $text .= $line; } echo rawurlencode($text);' | |
note=`git log -n 1 --merges --branches=$branchName --format=format:'%B' | tr "\n" " " | php -r "$phpUrlEncode"` | |
curl -s "http://pwa.shopping-all.hu/index.php?module=API&\ | |
method=Annotations.add&\ | |
idSite=1&\ | |
date=`date '+%Y-%m-%d'`&\ | |
note=$note&\ | |
token_auth=$PIWIK_API" > /dev/null | |
# Update symfony | |
php ./app/console assets:install web && \ | |
php app/console cache:clear && \ | |
php app/console cache:clear --env=prod --no-debug | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment