Last active
August 29, 2015 14:12
-
-
Save k3an3/b643bfdac21def96ddd4 to your computer and use it in GitHub Desktop.
Git->Webapp Update Script. Simple script to keep web site up to date with a Git Repo.
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 | |
uid=$(id -u ) | |
if [ $uid = 0 ]; then | |
echo "Error! Must not be run as root." | |
exit 0 | |
fi | |
if [ "$1" = "-h" ]; then | |
echo "syncwww v1.1.1 -- Keane O'Kelley 2015" | |
echo "Automates syncing with Github and updating the webpage" | |
echo -e "Usage: syncwww [options]\n" | |
echo "-f Reset git" | |
echo "-r Restart nginx upon completion" | |
echo "-c Force copy" | |
echo "-h Display this help page" | |
exit 0 | |
fi | |
cd ~/projectdir | |
if [ "$1" = "-f" ]; then | |
echo "Hard reset on repo..." | |
rm -rf * | |
git fetch --all | |
git reset --hard origin/master | |
fi | |
echo "Attempting to sync with GitHub..." | |
git pull | tee ~/sync.log | |
var=$(cat ~/sync.log | grep -c "Already up-to-date.") | |
error=$(cat ~/sync.log | grep -c -i error) | |
if [ $var = 0 ] && [ $error = 0 ] || [ "$1" = "-c" ]; then | |
echo "Changes detected!" | |
echo "Hot swap is a go!" | |
echo "Copying files..." | |
sudo rsync --delete -a * /path/to/www/root | |
if [ -f ~/perms ]; then | |
echo "Setting permissions..." | |
# Just another script file containing chmod and chown commands. | |
sudo ~/perms | |
fi | |
echo "Files copied." | |
if [ "$1" = "-r" ]; then | |
echo "Restarting nginx..." | |
sudo systemctl reload nginx.service | |
echo "Done." | |
fi | |
echo "Operation completed successfully." | |
else | |
echo "Nothing was changed." | |
fi | |
rm ~/sync.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment