summaryrefslogtreecommitdiffstats
path: root/mkmodular
blob: ff401c40c21e51fca8843453cac6e1193305273a (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
#!/usr/bin/php
<?php
chdir(__DIR__);

$template_php = <<< EOT
---
document: modulemd
version: 2
data:
  name: remi-php
  stream: @VERSION@
  version: @DATE@
  context: 00000000
  arch: @ARCH@
  summary: PHP scripting language
  description: >-
    php @VERSION@ module
  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:
      platform: [@DIST@]
  references:
    documentation: http://php.net/
    tracker: https://bugs.php.net/
  profiles:
    default:
      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
  components:
    rpms:
      php:
        rationale: Module API.
      php-pecl-zip:
        rationale: ZIP extension
  artifacts:
    rpms:

EOT;

$template_glpi = <<< EOT
---
document: modulemd
version: 2
data:
  name: remi-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:
      platform: [@DIST@]
  references:
    documentation: https://glpi-project.org/
    tracker: https://github.com/glpi-project/glpi/issues
  profiles:
    default:
      rpms:
      - glpi
  api:
    rpms:
    - glpi
  components:
    rpms:
      glpi:
        rationale: Module API.
  artifacts:
    rpms:

EOT;

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

EOT;

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

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

	$rpms = findPackages($srce, $dest, $pat);
	$mod = str_replace(['@VERSION@', '@ARCH@', "@DATE@", "@DIST@"], [$ver, $arch, date("YmdHis"), $dist], $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__);
}

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

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