not entirely sure, think its all the messaging components
[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 if(file_exists("$file/repodata/repomd.xml.new")) unlink("$file/repodata/repomd.xml.new");
40 file_put_contents("$file/repodata/repomd.xml.new", $repomdxml);
41
42
43 $xml = simplexml_load_file("$file/repodata/repomd.xml.new");
44
45
46 foreach($xml as $key => $var) {
47         //echo "for key $key has:\n";
48         //print_r($var);
49         if($key == "data") {
50                 $fileloc = $var->location["href"];
51                 if(!file_exists("$file/$fileloc")) {
52                         error_log("getting $file/$fileloc  on $url/$fileloc");
53                         $dlfile = file_get_contents("$url/$fileloc");
54                         file_put_contents("$file/$fileloc", $dlfile);
55                 } else {
56                         error_log("Not getting $fileloc because we already have it");
57                 }
58         }
59 }
60
61 unlink("$file/repodata/repoupdate.lock");
62 if(file_exists("$file/repodata/repomd.xml")) {
63         unlink("$file/repodata/repomd.xml");
64 }
65 rename("$file/repodata/repomd.xml.new", "$file/repodata/repomd.xml")
66
67 // TODO: check for outdated repodata files and delete
68 ?>