
Making your life easier, one keystroke at a time.
Today we will cover the basics of updating subversion via a menu driven twilio application using a php script and twiml
Requirements
- Linux Server
- Twilio Account
- Subversion
- pecl
- phpize
- svn pecl libraries
*Note: you must check your files out saving the credentials, or using the file:/// method.
Commands
apt-get install php-pear php5-dev libsvn-dev
pecl install svn
Update php.ini for web environment and cli environments and add extension in as:
extension=svn.so
Now for the code, because after all, thats why you're here.
TODO:
Update line 04 with your authorized phone number
Update line 05 with the location of your files to update
Update line 06 with the location of your subversion repository
[subversion_update_menu.php]
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$authorized_users = array("+1NNNNNNNNNN");
$production_files = "/home/production_sites/";
$repository_location = "//var/svn/production_sites/";
if(!in_array($_REQUEST['From'], $authorized_users))
{
echo ("<Response><Reject/></Response>");
} else {
$web = array();
$web['default'] = array('status','production_version','production_update');
/* Get the menu node, index, and url */
$node = $_REQUEST['node'];
$index = (int) $_REQUEST['Digits'];
$url = 'http://'.dirname($_SERVER["SERVER_NAME"].$_SERVER['PHP_SELF']).'/subversion_update_menu.php';
/* Check to make sure index is valid */
if(isset($web[$node]) || count($web[$node]) >= $index && !is_null($_REQUEST['Digits']))
$destination = $web[$node][$index];
else
$destination = NULL;
// @end snippet
echo "<Response>";
switch($destination)
{
case 'production_version' : ?>
<Say>Checking the revision number of production</Say>
<?php
$revision_number = exec("svn info ".$production_files." | tail -7 | grep \"Revision\" | grep -v \"Last\"");
$revision_number = str_replace("Revision: ", "", $revision_number);
echo "<Say>REVISION NUMBER IS: ".$revision_number."</Say>";
break;
case 'production_update' :
$production_revision = svn_update($production_files);
echo "<Say>The updated revision number of production is ".$production_revision."</Say>";
break;
case 'status' :
$revision_number = exec("svnlook history ".$repository_location." | head -3 | tail -1");
$revision_number = str_replace("/","",$revision_number);
$revision_number = str_replace(" ","",$revision_number);
$revision_log = exec("svnlook log ".$repository_location);
$svn_author = exec("svnlook author ".$repository_location);
echo "<Say>master repository revision :".$revision_number."</Say>";
echo "<Say>Last author: ".$svn_author."</Say>";
echo "<Say>Last commit message: ".$revision_log."</Say>";
break;
default: ?>
<Gather action="subversion_update_menu.php?node=default" numDigits="1">
<Say>Welcome to the Subversion Server</Say>
<Say>For the production revision, press 1</Say>
<Say>For the production update, press 2</Say>
<Say>For the repository infomation, press 0</Say>
</Gather>
<?php
break;
}
if($destination && $destination != 'status') { ?>
<Pause/>
<Say>Subversion Server System</Say>
<Redirect><?php echo 'subversion_update_menu.php' ?></Redirect>
<?php
}
?>
<Redirect>subversion_update_menu.php</Redirect>
</Response>
<?php
}
?>
Point a phone number at http://yourdomain.com/subversion_update_menu.php
Happy hacking sysadmins ;)
FearRoot.com - Developed by: Shawn Campbell
|