<?php
#Where to save downloaded packages
$dir = '/tmp/packages';
#FTP server with all packages
$ftp = 'ftp://ftp6.ru.freebsd.org/pub/FreeBSD/ports/i386/packages-7.2-release/All';
#Target packages we need to retrieve
$packages = array(
'bash-3.2.48_1',
'bzip2-1.0.5',
'curl-7.19.4',
'mc-4.6.2',
'mysql-server-5.0.77_1',
'php5-mysqli-5.2.9',
'postgresql-server-8.3.7',
'vim-7.2.132',
'wget-1.11.4',
'zip-3.0'
);
#Load packages info from previously downloaded INDEX file (ftp://ftp6.ru.freebsd.org/pub/FreeBSD/ports/i386/packages-7.2-release/All/INDEX)
function get_tree() {
$handle = fopen('INDEX', 'r');
$tree = array();
while (($data = fgetcsv($handle, 0, '|')) !== FALSE) {
$tree[$data[0]] = $data[8];
}
fclose($handle);
return $tree;
}
$tree = get_tree();
#Calculate dependencies
for ($i = 0; $i < sizeof($packages); $i++) {
if (isset($tree, $packages[$i])) {
$deps = explode(' ', $tree[$packages[$i]]);
foreach ($deps as $dep) {
if (strlen($dep)>0 && !in_array($dep, $packages)) {
$packages[] = $dep;
}
}
}
}
#Downloading
foreach ($packages as $package) {
file_put_contents($dir.'/'.$package.'.tbz', file_get_contents($ftp.'/'.$package.'.tbz'));
echo "$package.tbz\n";
}
?>
17 August, 2009
Download FreeBSD packages with dependencies
Just code, no comments:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment