summaryrefslogtreecommitdiffstats
path: root/mkmodular
blob: ffd3ff987e05136b9f8f3a7b9612d2d353ed8de4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/usr/bin/php
<?php
chdir(__DIR__);

$template_php = <<< EOT
---
document: modulemd
version: 2
data:
  name: php
  stream: remi-@VERSION@
  version: @DATE@
  context: 00000000
  arch: @ARCH@
  summary: PHP scripting language
  description: >-
    Alternative php @VERSION@ module.
    The remi-@VERSION@ stream provides more recent versions
    and more packages than default @VERSION@ stream.
  license:
    module:
    - GPLv2+
    content:
    - BSD
    - BSD and LGPLv3+
    - PHP
    - PHP and BSD
    - PHP and LGPLv2 and OpenLDAP
    - PHP and LGPLv2+
    - PHP and Zend and BSD and MIT and ASL 1.0
  dependencies:
  - buildrequires:
      platform: [@DIST@]
    requires:
@DEPS@
  references:
    documentation: http://php.net/
    tracker: https://bugs.php.net/
  profiles:
    common:
      rpms:
      - php-cli
      - php-common
      - php-fpm
      - php-json
      - php-mbstring
      - php-xml
    devel:
      rpms:
      - libzip
      - php-cli
      - php-common
      - php-devel
      - php-fpm
      - php-json
      - php-mbstring
      - php-pear
      - php-pecl-zip
      - php-process
      - php-xml
    minimal:
      rpms:
      - php-cli
      - php-common
  api:
    rpms:
    - php-fpm
  artifacts:
    rpms:

EOT;

$template_redis = <<< EOT
---
document: modulemd
version: 2
data:
  name: redis
  stream: remi-@VERSION@
  version: @DATE@
  context: 00000000
  arch: @ARCH@
  summary: Redis persistent key-value database
  description: >-
    Alternative redis @VERSION@ module.
    The remi-@VERSION@ stream provides more recent versions
    and than default @VERSION@ stream.
  license:
    module:
    - GPLv2+
    content:
    - BSD and MIT
    - CC-BY-SA
  dependencies:
  - buildrequires:
      platform: [@DIST@]
    requires:
@DEPS@
  references:
    documentation: https://redis.io/documentation
    tracker: https://github.com/antirez/redis/issues
  profiles:
    common:
      rpms:
      - redis
  api:
    rpms:
    - redis
  artifacts:
    rpms:

EOT;

$template_glpi = <<< EOT
---
document: modulemd
version: 2
data:
  name: glpi
  stream: @VERSION@
  version: @DATE@
  context: 00000000
  arch: @ARCH@
  summary: Free IT asset management software
  description: >-
    glpi @VERSION@ module
  license:
    module:
    - GPLv2+
    content:
    - GPLv2+ and GPLv3+ and MIT
  dependencies:
  - buildrequires:
      platform: [@DIST@]
    requires:
@DEPS@
  references:
    documentation: https://glpi-project.org/
    tracker: https://github.com/glpi-project/glpi/issues
  profiles:
    common:
      rpms:
      - glpi
  api:
    rpms:
    - glpi
  artifacts:
    rpms:

EOT;

$defaults = <<< EOT
---
document: modulemd-defaults
version: 1
data:
  module: php
  profiles:
    remi-7.2: [common]
    remi-7.3: [common]
...
---
document: modulemd-defaults
version: 1
data:
  module: glpi
  profiles:
    9.2: [common]
    9.3: [common]
    9.4: [common]
...
---
document: modulemd-defaults
version: 1
data:
  module: redis
  profiles:
    remi-5.0: [common]
...

EOT;

function findPackages($from, $dest, $pat) {
	$fil = '.';
	$rpms = [];
	foreach (glob("$from/$pat") as $file) {
		$info = rpminfo($file);
		$name = basename($file);
		if (!file_exists("$dest/$name")) {
			if (link($file, "$dest/$name")) {
				echo $fil;
				if (count($rpms)%64==63) {
					echo "\r";
					$fil = ($fil == '.' ? '-' : '.');
				}
			}
		}
		$rpms[] = 
			$info['Name'] . '-' . 
			($info['Epoch'] ?? '0') . ':' . 
			$info['Version'] . '-' . 
			$info['Release'] . '.' . 
			$info['Arch'];
	}
	echo "\r  " . count($rpms) . " rpms" . str_repeat(" ", 64) . "\n";
	return $rpms;
}

function genModule($srce, $dest, $pat, $ver, $arch, $deps, $template) {

	$rpms = findPackages($srce, $dest, $pat);
	$deptxt = '';
	foreach($deps as $n => $v) {
		$deptxt .= ($deptxt ? "\n" : '') . "      $n: [$v]";
	}
	$mod = str_replace(
		['@VERSION@', '@ARCH@', "@DATE@",       "@DIST@",         "@DEPS@"], 
		[$ver,        $arch,    date("YmdHis"), $deps['platform'], $deptxt], 
		$template
	);
	foreach($rpms as $rpm) {
		$mod .= "    - $rpm\n";
	}
	$mod .= "...\n";
	return $mod;
}

function cleanup($dest) {
	foreach (glob("$dest/*rpm") as $file) {
		unlink($file);
	}
}

function createRepo($dest, $mod) {
chdir($dest);

exec("mkrepo nocheck noclean");
$data = '/tmp/modules.yaml';
file_put_contents($data, $mod);
$hash = hash('sha256', $mod);
exec("modifyrepo_c --mdtype=modules $data repodata");
$arch = basename($dest);
rename($data, "$data.$arch");
echo "  in $data.$arch\n";

chdir(__DIR__);
}


if (count($_SERVER['argv'])<2 || in_array('f29', $_SERVER['argv'])) {
	$dest = 'fedora/29/modular/x86_64';
	echo "Populate $dest\n";
	cleanup($dest);
	$deps = ['platform' => 'f29'];
	$mod  = genModule('fedora/29/remi/x86_64',   $dest, 'php-*7.2*.rpm', '7.2', 'x86_64', $deps, $template_php);
	$mod .= genModule('fedora/29/php73/x86_64',  $dest, '*.rpm',         '7.3', 'x86_64', $deps, $template_php);
	$mod .= genModule('fedora/29/glpi92/x86_64', $dest, '*.rpm',         '9.2', 'x86_64', $deps, $template_glpi);
	$mod .= genModule('fedora/29/glpi93/x86_64', $dest, '*.rpm',         '9.3', 'x86_64', $deps, $template_glpi);
	$mod .= genModule('fedora/29/glpi94/x86_64', $dest, '*.rpm',         '9.4', 'x86_64', $deps, $template_glpi);
	$mod .= $defaults;
	createRepo($dest, $mod);

	$dest = 'fedora/29/modular-test/x86_64';
	echo "Populate $dest\n";
	cleanup($dest);
	$deps = ['platform' => 'f29'];
	$mod  = genModule('fedora/29/test/x86_64',   $dest, 'php-*7.2*.rpm', '7.2', 'x86_64', $deps, $template_php);
	$mod .= genModule('fedora/29/test73/x86_64', $dest, '*.rpm',         '7.3', 'x86_64', $deps, $template_php);
	$mod .= $defaults;
	createRepo($dest, $mod);

	$dest = 'fedora/29/modular/i386';
	echo "Populate $dest\n";
	cleanup($dest);
	$deps = ['platform' => 'f29'];
	$mod  = genModule('fedora/29/remi/i386',   $dest, 'php-*7.2*.rpm', '7.2', 'i386', $deps, $template_php);
	$mod .= genModule('fedora/29/php73/i386',  $dest, '*.rpm',         '7.3', 'i386', $deps, $template_php);
	$mod .= genModule('fedora/29/glpi92/i386', $dest, '*.rpm',         '9.2', 'i386', $deps, $template_glpi);
	$mod .= genModule('fedora/29/glpi93/i386', $dest, '*.rpm',         '9.3', 'i386', $deps, $template_glpi);
	$mod .= genModule('fedora/29/glpi94/i386', $dest, '*.rpm',         '9.4', 'i386', $deps, $template_glpi);
	$mod .= $defaults;
	createRepo($dest, $mod);

	$dest = 'fedora/29/modular-test/i386';
	echo "Populate $dest\n";
	cleanup($dest);
	$deps = ['platform' => 'f29'];
	$mod  = genModule('fedora/29/test/i386',   $dest, 'php-*7.2*.rpm', '7.2', 'i386', $deps, $template_php);
	$mod .= genModule('fedora/29/test73/i386', $dest, '*.rpm',         '7.3', 'i386', $deps, $template_php);
	$mod .= $defaults;
	createRepo($dest, $mod);
}

if (count($_SERVER['argv'])<2 || in_array('el8', $_SERVER['argv'])) {
	$dest = 'enterprise/8/modular-test/x86_64';
	echo "Populate $dest\n";
	cleanup($dest);
	$deps = ['platform' => 'el8', 'nginx' => '1.14', 'httpd' => '2.4'];
	$mod  = genModule('enterprise/8/test72/x86_64',  $dest, '*.rpm',         '7.2', 'x86_64', $deps, $template_php);
	$mod .= genModule('enterprise/8/test73/x86_64',  $dest, '*.rpm',         '7.3', 'x86_64', $deps, $template_php);
	$mod .= $defaults;
	createRepo($dest, $mod);

	$dest = 'enterprise/8/modular/x86_64';
	echo "Populate $dest\n";
	cleanup($dest);
	$deps = ['platform' => 'el8', 'nginx' => '1.14', 'httpd' => '2.4'];
	$mod  = genModule('enterprise/8/php72/x86_64',  $dest, '*.rpm',         '7.2', 'x86_64', $deps, $template_php);
	$mod .= genModule('enterprise/8/php73/x86_64',  $dest, '*.rpm',         '7.3', 'x86_64', $deps, $template_php);
	$mod .= genModule('enterprise/8/remi/x86_64',   $dest, 'redis*.rpm',    '5.0', 'x86_64', $deps, $template_redis);
	$deps = ['platform' => 'el8', 'php' => ''];
	$mod .= genModule('enterprise/8/glpi93/x86_64', $dest, '*.rpm',         '9.3', 'x86_64', $deps, $template_glpi);
	$mod .= genModule('enterprise/8/glpi94/x86_64', $dest, '*.rpm',         '9.4', 'x86_64', $deps, $template_glpi);
	$mod .= $defaults;
	createRepo($dest, $mod);
}