this is an untested CLI script designed to grab tarballs, rpms, and zips (.tar.(gz|bz2),.tgz,.rpm,.zip, other suggestions welcome) from one dir and copies them into another. this may sound stupid, but it is rather cool because it includes so much error checking. this is my first CLI script, and there may be problems with my version of read(). i havent tested or commented it yet because i just hacked this up in half an hour at a friends house.
it requires the following to be at /usr/local/lib/php/common.shell.lib.php:
<?php
define('N',"\n"); //newline so we dont have to go into double-quotes
define('TARBALL_DIR','/winxp'); //this is where your sources are kept
define('DEST_DIR','/usr/local/src/'); //this is where you want things to go
$sdir = TARBALL_DIR; //set defaults
$ddir = DEST_DIR;
function read($length=255)
{
/*****************************\
* Grabs from stdin up to *
* $length, \n, or EOF. *
\*****************************/
if (!is_int($length) || !$length) //if length is invalid
{
$length = 255; //fall back to default
}
$f = STDIN; //stdin link
if (!$f)
{
die('Error opening STDIN. Dying.');
}
$data = fgets($f,1024); //first, get up to 1K of data
$data = str_split($data); //PHP5-only function same as preg_split with empty delimeter
$outdata = ''; //what we return
for ($i = 1; $i < $length; $i++)
{
$outdata .= str_replace(N, '', $data[$i-1]); //no newlines
}
return str_replace('\n', N, $outdata); // unless you REALLY want them...
} //end read()
function user_abort($message = 'User aborted', $allow_abort = true)
{
/*****************************\
* Echo a dying message, but *
* give the user a choice *
* (disableable) *
\*****************************/
if ($allow_abort)
{
echo 'Die?';
if (strtolower(read(1)) == 'y')
{
die($message.N);
}
else
{
echo 'Continuing script...'.N;
return 0;
}
}
else
{
echo 'Dying...'.N.N;
die($message.N);
}
}
?>
put the main script inside your PATH (eg /usr/local/bin) and you're set to go!
edit: added comments