updating apt repo's now work.... apt really annoys
authorpaulr <me@pjr.cc>
Sat, 6 Aug 2011 17:16:11 +0000 (03:16 +1000)
committerpaulr <me@pjr.cc>
Sat, 6 Aug 2011 17:16:11 +0000 (03:16 +1000)
bin/updateaptrepo.php
plugins/repo.php

index 38aae68..dadd382 100644 (file)
@@ -27,10 +27,94 @@ if(file_exists("$file/update.lock")) {
        } else {
                error_log("weird problem");
        }
+       fclose($lf);
 }
-fclose($lf);
 $lf = fopen("$file/update.lock", "w");
 flock($lf, LOCK_EX|LOCK_NB);
 
+// next we go into $file/dists and open each dir
+// download "release"
+// then check every file in release against what we have... this is giong to be a nightmare
+$dh = opendir("$file/dists/");
+while(($fn = readdir($dh))!==false) {
+       if($fn != "." && $fn != "..") {
+               echo "checkin dist, $fn with $url\n";
+               $releasefile = file_get_contents("$url/dists/$fn/Release");
+               file_put_contents("$file/dists/$fn/Release.new", $releasefile);
+               if(file_exists("$file/dists/$fn/Release")) {
+                       unlink("$file/dists/$fn/Release");
+                       rename("$file/dists/$fn/Release.new", "$file/dists/$fn/Release");
+               } else {
+                       rename("$file/dists/$fn/Release.new", "$file/dists/$fn/Release");
+               }
+               
+               echo "got release file\n";
+               
+               // now open that release file and check all our ... versions and stuff, this bit sucks, i hate parsing text files
+               $relfile = fopen("$file/dists/$fn/Release", "r");
+               $continue = true;
+               $chkfile = false;
+               if($relfile) while($continue) {
+                       $line = fgets($relfile);
+                       if(feof($relfile)) $continue = false;
+                       // first try to parse a tag
+                       $tags = explode(":", $line);
+                       // check for a tag we're into
+                       if(strcasecmp($tags[0], "md5sum") == 0) {
+                               $chkfile = true;
+                               $chktype = "md5";
+                                                       
+                       } else if(strcasecmp($tags[0], "SHA1") == 0) {
+                               $chkfile = true;
+                               $chktype = "sha1";
+                               
+                       } else if(strcasecmp($tags[0], "SHA256") == 0) {
+                               $chkfile = true;
+                               $chktype = "sha256";
+                               
+                               
+                       } else if($chkfile) {
+                               //echo "in chkfile on $line\n";
+                               $line = trim($line);
+                               $lspl = preg_split("/ +/", $line);
+                               if(isset($lspl[2])) {
+                                       $sum = $lspl[0];
+                                       $size = ((int)($lspl[1]));
+                                       $distrofile = $lspl[2];
+                                       if(file_exists("$file/dists/$fn/$distrofile")) {
+                                               $updatefile = false;
+                                               $mysum = hash_file($chktype, "$file/dists/$fn/$distrofile");
+                                               $mysize = filesize("$file/dists/$fn/$distrofile");
+                                               //echo "would check $sum, $size, $distrofile against $distrofile/dists/$fn, $sum\n";
+                                               if(strtolower($mysum) == strtolower($sum)) {
+                                                       echo "file $distrofile is clean for sum\n";
+                                               } else {
+                                                       echo "File $distrofile needs updating with $sum, $mysum, $chktype, $url\n";
+                                                       $updatefile = true;
+                                               }
+                                               
+                                               if($size != $mysize) {
+                                                       echo "File $distrofile needs updating with $size, $mysize, $url\n";
+                                                       $updatefile = true;
+                                               } else {
+                                                       echo "file $distrofile is clean for size\n";
+                                               }
+                                               if($updatefile) {
+                                                       $getthisfile = file_get_contents("$url/dists/$fn/$distrofile");
+                                                       unlink("$file/dists/$fn/$distrofile");
+                                                       file_put_contents("$file/dists/$fn/$distrofile", $getthisfile);
+                                                       echo "Updated file\n";
+                                               }
+                                       }
+                               } else {
+                                       $chkfile = false;
+                               }
+                       }
+               }
+       }
+}
+fclose($lf);
+unlink("$file/update.lock");
+echo "im at an end\n";
 
 ?>
\ No newline at end of file
index 9d1de84..f794c29 100644 (file)
@@ -63,7 +63,23 @@ class GLCASRepo {
                                }
                                echo " - Expire time is ".$repo["expiretime"]." days, checking repo<br>";
                                $maxtdiff = $repo["expiretime"] * 24 * 3600;
-                               $this->updateRepo($rkey);
+                               // now we check for outdated release files
+                               $dh = opendir("$repostore/$rkey/dists/");
+                               $needsupdate = false;
+                               while(($fn = readdir($dh))!==false) {
+                                       if($fn != "." && $fn != "..") {
+                                               if(file_exists("$repostore/$rkey/dists/$fn/Release")) {
+                                                       $tdiff = time() -  filemtime("$repostore/$rkey/dists/$fn/Release");
+                                                       if($tdiff > $maxtdiff) $needsupdate = true;
+                                               }
+                                       }
+                               }
+                               if($needsupdate) {
+                                       echo " - Spawn updater<br>";
+                                       $this->updateRepo($rkey);
+                               } else {
+                                       echo " - Up to date<br>";
+                               }
                        }
                }
        }
@@ -795,6 +811,13 @@ class GLCASRepo {
                if(!file_exists("$repostore/$repokey")) {
                        mkdir("$repostore/$repokey");
                }
+               
+               if(!file_exists("$repostore/$repokey/dists/")) {
+                       mkdir("$repostore/$repokey/dists/");
+                       // no point trying to update if we have no dists directory
+                       return;
+               }
+               
 
                error_log("background apt repo update, start");
                global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;