aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorManuel Hiebel <leuhmanu@mageia.org>2021-04-03 09:31:33 +0200
committerManuel Hiebel <leuhmanu@mageia.org>2021-04-03 09:31:33 +0200
commit4eada4dec308ebea1a5c17839e5cf3f73ca78f32 (patch)
tree58495b9ced57477ca85a66223455761f24dc9f2b /lib
parentebe227967e3ac42a8eacae14a56d1ad920e333d9 (diff)
downloadfidd-4eada4dec308ebea1a5c17839e5cf3f73ca78f32.tar
fidd-4eada4dec308ebea1a5c17839e5cf3f73ca78f32.tar.gz
fidd-4eada4dec308ebea1a5c17839e5cf3f73ca78f32.tar.bz2
fidd-4eada4dec308ebea1a5c17839e5cf3f73ca78f32.tar.xz
fidd-4eada4dec308ebea1a5c17839e5cf3f73ca78f32.zip
Add netinstall to the builded catalog
Diffstat (limited to 'lib')
-rw-r--r--lib/FIDD.php110
1 files changed, 84 insertions, 26 deletions
diff --git a/lib/FIDD.php b/lib/FIDD.php
index f26f604..655c5e1 100644
--- a/lib/FIDD.php
+++ b/lib/FIDD.php
@@ -23,24 +23,25 @@ class FIDD
*
* @return boolean
*/
- public static function run($app_path, $url, $prefix)
+ public static function run($app_path, $url, $prefix, $netinstall = false)
{
$tmp_path = $app_path . '/var/tmp';
-
+
echo sprintf("rsync'ing bcd.mageia.org files from %s...\n", $url);
- if (self::rsync_mirror_files($url, $tmp_path)) {
+ if (self::rsync_mirror_files($url, $tmp_path, $netinstall)) {
echo "Failed to rsync remote ISOs...\n";
return false;
}
-
echo "fetching ISOs filesize...\n";
- $filesizes = self::rsync_get_filesizes($url);
-
+ $filesizes = self::rsync_get_filesizes($url, $netinstall);
echo "building definition file...\n";
- $info = self::build_definitions($prefix, $tmp_path, $filesizes);
-
+ if (!$netinstall) {
+ $info = self::build_definitions($prefix, $tmp_path, $filesizes);
+ } else {
+ $info = self::build_definitions_net_install($prefix, $tmp_path, $filesizes);
+ }
self::save_definitions($info, $app_path . '/var/definitions');
-
+
return true;
}
@@ -80,14 +81,18 @@ class FIDD
* @param string $url
* @param string $dir where to mirror files
*/
- private static function rsync_mirror_files($url, $dir)
+ private static function rsync_mirror_files($url, $dir, $netinstall = false)
{
+ if (!$netinstall){
$cmd = sprintf('/usr/bin/rsync -avHP --exclude=*.iso %s %s',
escapeshellarg($url),
escapeshellarg($dir));
-
+ } else {
+ $cmd = sprintf('/usr/bin/rsync -avHP --exclude=*.iso --exclude=*.img --include=i586 --include=x86_64 --include=*/install --include=*/install/images --include=*/install/images/* --exclude=* %s %s',
+ escapeshellarg($url),
+ escapeshellarg($dir));
+ }
exec($cmd, $out, $ret);
-
return $ret;
}
@@ -98,13 +103,16 @@ class FIDD
*
* @return array ["file.iso" => "size", ...]
*/
- private static function rsync_get_filesizes($url)
+ private static function rsync_get_filesizes($url, $netinstall = false)
{
- $cmd = sprintf('/usr/bin/rsync -a --list-only --no-h %s | awk \'{print $2"\t"$5}\'',
+ if (!$netinstall){
+ $cmd = sprintf('/usr/bin/rsync -a --list-only --no-h %s | awk \'{print $2"\t"$5}\'',
escapeshellarg($url));
-
+ }else{
+ $cmd = sprintf('/usr/bin/rsync -a --list-only --include=i586 --include=x86_64 --include=*/install --include=*/install/images --include=*/install/images/* --exclude=* --no-h %s | awk \'{print $2"\t"$5}\'',
+ escapeshellarg($url));
+ }
$isos = array();
-
exec($cmd, $out, $ret);
if ($ret === 0) {
foreach ($out as $line) {
@@ -112,12 +120,15 @@ class FIDD
if (count($line) > 1) {
if (trim(substr($line[1], -3, 3)) == 'iso') {
$file = explode('/', $line[1]);
- $isos[$file[1]] = formatBytes($line[0], 1);
+ if (!$netinstall) {
+ $isos[$file[1]] = formatBytes($line[0], 1);
+ } else {
+ $isos[$file[3]] = formatBytes($line[0], 1);
+ }
}
}
}
}
-
return $isos;
}
@@ -134,17 +145,13 @@ class FIDD
{
$info = array();
$isos = glob($dir . '/*');
-
+
foreach ($isos as $isodir) {
-
$data = array();
$files = glob($isodir . '/*.*');
-
foreach ($files as $f) {
-
$fi = pathinfo($f);
$ext = $fi['extension'];
-
switch ($fi['extension'])
{
case 'md5':
@@ -169,8 +176,6 @@ class FIDD
}
}
-
-
if ( count($data) == 0) {
// skip the first one
} else if (null !== ($ret = self::is_correct_name($data['file']))) {
@@ -202,6 +207,59 @@ class FIDD
}
/**
+ * Parse mirrors files in $dir and build a catalog of these.
+ *
+ * @param string $prefix
+ * @param string $dir where to look for files
+ * @param array $filesizes sizes of each .iso file
+ *
+ * @return array
+ */
+ function build_definitions_net_install($prefix, $dir, $filesizes)
+ {
+ $info = array();
+ $isos = glob($dir . '/*/install/images/');
+
+ foreach ($isos as $isodir) {
+ $data = array();
+ $files = glob($isodir . '/*.iso*');
+ foreach ($files as $f){
+ $fi = pathinfo($f);
+ $ext = $fi['extension'];
+ switch ($fi['extension'])
+ {
+ case 'md5':
+ $key = str_replace('.iso.md5', '.iso', basename($f));
+ $data['file'] = $key;
+ $data['md5'] = self::get_checksum_value($f);
+ break;
+ case 'sha3':
+ $data['sha3'] = self::get_checksum_value($f);
+ break;
+ case 'sha512':
+ $data['sha512'] = self::get_checksum_value($f);
+ break;
+ }
+ if ( count($data) == 0) {
+ // skip the first one
+ } else if (null !== ($ret = self::is_correct_name($data['file']))) {
+ $data['path'] = sprintf('%s/%s/install/images',
+ $ret['release'] == '' ? sprintf('distrib/%s', $ret['version']) : sprintf('distrib/cauldron%s', $prefix),
+ $ret['arch']
+ );
+ $data['name'] = str_replace(array('-', '.iso', 'i586', 'x86_64'), array(' ', '', '32bit', '64bit'), $data['file']);
+ $data['size'] = $filesizes[$data['file']];
+ $info[$data['file']] = $data;
+ } else {
+ $info['invalid'][] = $data;
+ }
+ }
+ }
+
+ return $info;
+ }
+
+ /**
* Extract checksum from .md5 or .sha1 file.
*
* @param string $f
@@ -233,7 +291,7 @@ class FIDD
'version' => $arr[2],
'release' => $arr[4] . $arr[5],
'variant' => $arr[7],
- 'arch' => $arr[8],
+ 'arch' => $arr[9],
'medium' => $arr[10],
'build' => $arr[12],
'ext' => $arr[13]