Last active
December 27, 2015 17:39
-
-
Save stephencroberts/7363361 to your computer and use it in GitHub Desktop.
Updates the database and files of a staging server from git repo and set proper permissions
This file contains 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/bash | |
# Get the branch that was pushed | |
branch=$(git rev-parse --symbolic --abbrev-ref $1) | |
# Move to root of git repo | |
cd .. | |
unset GIT_DIR | |
# Save working directory for later | |
wd=`pwd` | |
# Master branch pushed? | |
if [[ "$branch" == *master* ]]; then | |
# Pull changes from origin | |
git pull | |
# Get the version tag | |
ver=`git tag --contains HEAD` | |
# Does the versioned sql exist? | |
if [ -r $wd/database/$ver.sql ]; then | |
echo 'Importing database changes...' | |
# Get JConfig vars | |
jconfig=httpdocs/configuration.php | |
dbname=$(grep "\$db " $jconfig | sed "s/.*\$db \= '\(.*\)'.*/\1/") | |
dbuser=$(grep "\$user " $jconfig | sed "s/.*\$user \= '\(.*\)'.*/\1/") | |
dbpass=$(grep "\$password " $jconfig | sed "s/.*\$password \= '\(.*\)'.*/\1/") | |
# Import versioned sql | |
mysql --user=$dbuser --password=$dbpass $dbname < $wd/database/$ver.sql | |
# Append versioned sql to changes.sql | |
cat $wd/database/$ver.sql >> $wd/database/changes.sql | |
fi | |
echo "Updating permissions..." | |
# Get owner and group | |
owner=$(ls -l .. | grep $(basename $wd) | awk '{print $3}') | |
group=$(ls -l .. | grep $(basename $wd) | awk '{print $4}') | |
# Set permissions | |
sudo chown -R $owner:$group $wd | |
sudo find $wd -type d -exec chmod 755 {} \; | |
sudo find $wd -type f -exec chmod 644 {} \; | |
sudo chmod -R g+swX $wd | |
sudo find . -name id_rsa -exec chmod 600 {} \; | |
keys=$(dirname $(sudo find . -name id_rsa)) | |
if [ -d $keys ]; then | |
sudo chmod 700 $keys | |
fi | |
sudo find $wd -wholename "*git/hooks/*" ! -name "*.*" -exec chmod +x {} \; | |
sudo find $wd -wholename "*digitollsync/hooks/*" ! -name "*.*" -exec chmod +x {} \; | |
elif [[ "$branch" == *develop* ]]; then | |
echo `/var/www/html/ss-test.davidccook.com/scripts/test.sh` | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment