X-Git-Url: http://git.pjr.cc/?p=glcas.git;a=blobdiff_plain;f=bin%2Fupdateaptrepo.php;fp=bin%2Fupdateaptrepo.php;h=dadd3822605a54251d7120b524c2a950eb08a9fd;hp=38aae689c10796336ae93aff2bccb7e2562b39b5;hb=143c8289c2a75a9ff8d1db6136baa56fbb8ac19f;hpb=ce6eddc1cf6b4a879b9239fec18258b99f3d739a diff --git a/bin/updateaptrepo.php b/bin/updateaptrepo.php index 38aae68..dadd382 100644 --- a/bin/updateaptrepo.php +++ b/bin/updateaptrepo.php @@ -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