Skip to content

Instantly share code, notes, and snippets.

@4np
Created May 6, 2013 23:44
Show Gist options
  • Save 4np/5529208 to your computer and use it in GitHub Desktop.
Save 4np/5529208 to your computer and use it in GitHub Desktop.
cronjob to automatically update a piratebay proxy to the latest version
#!/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