Created
May 6, 2013 23:44
-
-
Save 4np/5529208 to your computer and use it in GitHub Desktop.
cronjob to automatically update a piratebay proxy to the latest version
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 | |
# usage: | |
# m h dom mon dow command | |
# * */4 * * * ~/scripts/updatePiratebayProxy > /dev/null | |
# Configuration | |
HOSTNAME=tpb.example.com | |
REPO_BASE=~ | |
DESTINATION=/etc/apache2/sites-available/example.com_tpb.conf | |
ACCESS_LOG=/var/log/apache2/example.com_tpb-access.log | |
ERROR_LOG=/var/log/apache2/example.com_tpb-error.log | |
# update the repository and patch in the ServerName | |
update() { | |
echo "updating..." | |
# pull changes | |
git pull --quiet | |
# copy new file | |
sudo cp domain.com_tpb.conf $DESTINATION | |
# change servername configuration | |
sudo sed -i "s/ServerName.*/ServerName $HOSTNAME/g" $DESTINATION | |
# change log configuration | |
sudo sed -i "s/ErrorLog.*/ErrorLog $(echo "$ERROR_LOG"|sed -e 's/\//\\\//g' -e 's/\./\\\./g')/g" $DESTINATION | |
sudo sed -i "s/CustomLog.*/CustomLog $(echo "$ERROR_LOG"|sed -e 's/\//\\\//g' -e 's/\./\\\./g') combined/g" $DESTINATION | |
# reload apache | |
sudo /etc/init.d/apache2 reload | |
} | |
# got a repo? | |
if [ ! -d $REPO_BASE/pirateBayProxy ]; then | |
echo "creating repo" | |
# clone repo | |
cd $REPO_BASE | |
git clone https://github.com/4np/pirateBayProxy.git | |
# go to the git repo | |
cd $REPO_BASE/pirateBayProxy | |
# perform update | |
update | |
else | |
# go to the git repo | |
cd $REPO_BASE/pirateBayProxy | |
# check if there are incoming changes | |
git remote update | |
# check if we need to update | |
BEHIND=`git status -uno|grep -i "is behind"|wc -l` | |
if [ $BEHIND -gt 0 ]; then | |
update | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment