fixed the directory making bits for the downloader...
[glcas.git] / bin / updateyumrepo.php
1 <?php
2
3 $url = "";
4 $file = "";
5 if(isset($argv[1])) {
6         $url = $argv[1];
7 }
8
9 if(isset($argv[2])) {
10         $file = $argv[2];
11 }
12
13 if($url == "" || $file == "") {
14         echo "need a url and file\n";
15         exit(0);
16 }
17
18 if(file_exists("$file/repodata/repoupdate.lock")) {
19         // try get a lock
20         $lf = fopen("$file/repodata/repoupdate.lock", "r");
21         if($lf) {
22                 $lockres = flock($lf, LOCK_EX|LOCK_NB);
23                 if(!$lockres) {
24                         error_log("flock did fail, all is right with the world a download is in progress");
25                         exit(0);
26                 }
27         } else {
28                 error_log("weird problem");
29         }
30 }
31 fclose($lf);
32 $lf = fopen("$file/repodata/repoupdate.lock", "w");
33 flock($lf, LOCK_EX|LOCK_NB);
34
35 error_log("called with $url and $file");
36
37 $actionurl = "$url/repodata/repomd.xml";
38 $repomdxml = file_get_contents($actionurl);
39 file_put_contents("$file/repodata/repomd.xml", $repomdxml);
40
41
42 $xml = simplexml_load_file("$file/repodata/repomd.xml");
43
44
45 foreach($xml as $key => $var) {
46         //echo "for key $key has:\n";
47         //print_r($var);
48         if($key == "data") {
49                 $fileloc = $var->location["href"];
50                 if(!file_exists("$file/$fileloc")) {
51                         error_log("getting $file/$fileloc  on $url/$fileloc");
52                         $dlfile = file_get_contents("$url/$fileloc");
53                         file_put_contents("$file/$fileloc", $dlfile);
54                 } else {
55                         error_log("Not getting $fileloc because we already have it");
56                 }
57         }
58 }
59
60 unlink("$file/repodata/repoupdate.lock");
61
62 ?>