/** NOTE: This script is used to generate the "Packages" and "Packages.gz" files that Debian-based repositories uses. It can also be used to make OPKG-repositories. */ function ipkg_parse($file) { require_once "knj/os.php"; require_once "knj/functions_knj_filesystem.php"; require_once "knj/strings.php"; $fileinfo = fileinfo($file); if (strpos($fileinfo, "gzip compressed data") !== false) { $format = "tar.gz"; } else { $format = "debian"; } $old_dir = getcwd(); $tmpdir = "./generate_packages_list_" . microtime(true); while (true) { if (file_exists($tmpdir)) { $tmpdir .= "1"; } else { break; } } if (!mkdir($tmpdir)) { throw new exception("Could not create temp-dir: " . $tmpdir); } $finfo = pathinfo($file); $cmd = "cd " . knj_string_unix_safe($tmpdir) . ";"; if ($format == "tar.gz") { $cmd .= "tar -zxmvf ../" . knj_string_unix_safe($fino["basename"]); } else { $cmd .= "ar -x ../" . knj_string_unix_safe($finfo["basename"]) . " control.tar.gz"; } $res = knj_os::shellCMD($cmd); if (strlen($res["error"]) > 0) { throw new exception(trim($res["error"])); } $res = knj_os::shellCMD("cd " . knj_string_unix_safe($tmpdir) . "; tar -zxmvf control.tar.gz"); if (strlen($res["error"]) > 0) { throw new exception(trim($res["error"])); } $res = knj_os::shellCMD("cd " . knj_string_unix_safe($tmpdir) . "; cat control"); if (strlen($res["error"]) > 0) { throw new exception(trim($res["error"])); } $control = substr($res["result"], 0, -1); $return = array(); foreach (explode("\n", $control) as $line) { if (preg_match("/^(\\S+):\\s+([\\s\\S]+)\$/", $line, $match)) { if (strlen(trim($match[2])) > 0) { $return["control"][$match[1]] = $match[2]; } } } knj_os::shellCMD("cd " . knj_string_unix_safe($old_dir)); fs_cleanDir($tmpdir, true); if (file_exists($tmpdir)) { if (!rmdir($tmpdir)) { throw new Exception("Could not remove tmp-dir."); } } return $return; }
function killSVN($dir) { $fp = opendir($dir); while (($file = readdir($fp)) !== false) { if ($file != "." && $file != "..") { if ($file == ".svn" || $file == "CVS") { fs_cleanDir($dir . "/" . $file, true); echo "Removed \"" . $dir . "/" . $file . "\".\n"; } elseif (is_dir($dir . "/" . $file)) { killSVN($dir . "/" . $file); } } } }
static function rmdir($path){ fs_cleanDir($path, true); }