List of commits:
Subject Hash Author Date (UTC)
.deb support 722ca672abf6f28109e35f3573dca7e367d3b51a Catalin(ux) M. BOIE 2022-02-16 18:39:19
compare: added rpm/deb lines 1356fb5c8e5d82356776561af4a2dcaec0d19c14 Catalin(ux) M. BOIE 2022-02-16 07:30:06
debian folder updates 45e86104b565e508c514804910cfda87a3c1239c Catalin(ux) M. BOIE 2022-02-16 07:26:09
Fix rate limit for IPv6 336d34f7eaac356688ba5c251f027aff947ce9e4 Catalin(ux) M. BOIE 2022-02-09 14:39:28
Forgot to remove a function after moving it b6fd0700cf5dde953acb0d4584a48cb404a69ab2 Catalin(ux) M. BOIE 2021-11-17 19:27:04
Prepare correctly for rgfs (missed some places) 38d255af17a72fd9f92a8c37d4fddc8f2caf023b Catalin(ux) M. BOIE 2021-11-17 18:05:01
TODO/cosmetic d4968bc1d9c8bbe3c4aba2479f3694a7a3863d0f Catalin(ux) M. BOIE 2021-11-17 18:04:36
More debug help 74f45188bffd7630d0c08648433749a3ef23c9af Catalin(ux) M. BOIE 2021-11-15 17:34:58
worker: Fixed a stupid bug leading to wrong distro upgrade command d9bc215557cd9a6f30dbc90434dc3aba46e39979 Catalin(ux) M. BOIE 2021-11-14 16:16:43
Silence an 'unpack' exception when we do not have enough bytes. add562b15d94501a0585001db526b241c251b6e6 Catalin(ux) M. BOIE 2021-11-14 11:25:01
Run struct and fixes under the same lock d046942317c73351473a18eb833318aec3f4d907 Catalin(ux) M. BOIE 2021-11-14 08:18:05
spec file small updates 7aef02df6ed5f6ce4d39cd2a926a79bcdc1a3c5a Catalin(ux) M. BOIE 2021-11-14 06:33:35
Typo b0087441b4d637c7bf6ed64b6c243ad2ec8f1493 Catalin(ux) M. BOIE 2021-11-14 06:15:00
spec: Added 'Replaces: rocketgit' to easy upgrade, fixed fixfiles c380f40fe86ddf70b99030a6f0be93d91137b909 Catalin(ux) M. BOIE 2021-11-14 06:14:25
Fixed non debug case of rg_debug_html 523f6784671e5f810b8435ad66ad21ea548219d8 Catalin(ux) M. BOIE 2021-11-14 05:58:37
Fix rate limit types 0de3ee35d0d0e46521d64a596232765fb5d618a3 Catalin(ux) M. BOIE 2021-11-14 05:58:03
commented request_slowlog_timeout 505877b567807e11f25695de58725f316f10043e Catalin(ux) M. BOIE 2021-11-13 17:32:46
systemctl git.socket rethinking 3c71e58760f6abc69db661098840c277d4fc13fb Catalin(ux) M. BOIE 2021-11-13 17:25:52
PHP FALSE verus NULL correction 42f8bc560a0ec2203f0974e203e6c33ec26aa983 Catalin(ux) M. BOIE 2021-11-13 16:31:33
.spec: some minor corrections 70c3a23f507d57c729e0d710ec99060e0e88c238 Catalin(ux) M. BOIE 2021-11-13 16:22:11
Commit 722ca672abf6f28109e35f3573dca7e367d3b51a - .deb support
Author: Catalin(ux) M. BOIE
Author date (UTC): 2022-02-16 18:39
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2022-02-16 18:39
Parent(s): 1356fb5c8e5d82356776561af4a2dcaec0d19c14
Signer:
Signing key:
Signing status: N
Tree: 0ce7066ea253a417d3b171097d1ad5bde6c1c4b7
File Lines added Lines deleted
inc/builder.inc.php 1 0
inc/gpg.inc.php 240 3
inc/rgfs.inc.php 135 0
inc/user/packages.inc.php 377 135
inc/user/packages_core.inc.php 2 0
inc/user/packages_deb.inc.php 953 0
inc/user/packages_rpm.inc.php 111 118
inc/user/pkg_map.inc.php 79 25
inc/user/pkg_repo.inc.php 91 87
inc/user/pkg_rights.inc.php 12 6
inc/user/pkg_subrepo.inc.php 55 103
inc/util2.inc.php 105 33
inc/webhooks.inc.php 1 1
inc/wh/build.inc.php 20 22
inc/wh/cloud.inc.php 2 2
inc/wh/http/matrix.inc.php 2 2
inc/wh/lambda.inc.php 1 1
inc/workers.inc.php 2 2
root/themes/default/admin/distros/list/line.html 2 2
root/themes/default/rights/list_pkgrepo/header.html 1 1
root/themes/default/rights/list_pkgrepo/line.html 1 1
root/themes/default/user/pkg/deb/add_repo_howto.html 5 0
root/themes/default/user/pkg/deb/debug_pkg_list/footer.html 0 0
root/themes/default/user/pkg/deb/debug_pkg_list/header.html 0 0
root/themes/default/user/pkg/deb/debug_pkg_list/line.html 1 0
root/themes/default/user/pkg/deb/debug_pkg_list/nodata.html 0 0
root/themes/default/user/pkg/deb/pkg_list/line.html 1 0
root/themes/default/user/pkg/deb/priv_download.html 19 0
root/themes/default/user/pkg/deb/pub_download.html 5 0
root/themes/default/user/pkg/deb/src_pkg_list/line.html 1 0
root/themes/default/user/pkg/list/line.html 1 1
root/themes/default/user/pkg/rpm/priv_download.html 1 0
root/themes/default/user/pkg/rpm/pub_download.html 1 0
root/themes/default/user/settings/packages/map/menu.html 2 2
root/themes/default/user/settings/packages/repo/list/header.html 2 0
root/themes/default/user/settings/packages/repo/list/line.html 5 1
root/themes/default/user/settings/packages/repo/menu.html 2 2
root/themes/default/user/settings/packages/subrepo/menu.html 2 2
scripts/builder.php 9 8
scripts/events.php 3 2
scripts/rgfs.php 63 134
scripts/worker.php 641 219
techdocs/Certs.txt 0 0
techdocs/rpm.txt 6 6
tests/gpg.php 9 1
tests/helpers.inc.php 3 3
tests/http.inc.php 8 5
tests/wh_build.git.sh 55 0
tests/wh_build.php 143 36
File inc/builder.inc.php changed (mode: 100644) (index a4b69e3..69b9880)
... ... function rg_builder_load_jobs($db, $where, $order, $limit)
46 46
47 47 /* /*
48 48 * Add a build job in queue * Add a build job in queue
49 * @repo_id - the charging/listing will be associated to this repo
49 50 */ */
50 51 function rg_builder_add($db, $repo_id, $prio, $d) function rg_builder_add($db, $repo_id, $prio, $d)
51 52 { {
File inc/gpg.inc.php changed (mode: 100644) (index d95f9e9..e359c64)
... ... function rg_gpg_key_gen($user_id)
21 21 $ret = array('ok' => 0); $ret = array('ok' => 0);
22 22 do { do {
23 23 // TODO: hd - how to clean it? Take care of on current access! Lock? // TODO: hd - how to clean it? Take care of on current access! Lock?
24 $hd = rg_tmp_path('gpg', 0);
24 $hd = rg_tmp_path('gpg_key_gen_hd-' . rg_id(16), 120);
25 25 $ehd = escapeshellarg($hd); $ehd = escapeshellarg($hd);
26 $kr = rg_tmp_path('gpg-kr-' . rg_id(16), 120);
26 $kr = rg_tmp_path('gpg_key_gen_kr-' . rg_id(16), 120);
27 27 $ekr = escapeshellarg($kr); $ekr = escapeshellarg($kr);
28 28 $euser_id = escapeshellarg($user_id); $euser_id = escapeshellarg($user_id);
29 29
 
... ... function rg_gpg_key_gen($user_id)
101 101
102 102 $ret['ok'] = 1; $ret['ok'] = 1;
103 103 } while (0); } while (0);
104 rg_del_tree($kr);
105 @unlink($kr . '.meta');
106 rg_del_tree($hd);
107 @unlink($hd . '.meta');
108
109 return $ret;
110 }
111
112 /*
113 * Save a keyring based on a private key (not used)
114 */
115 function rg_gpg_save_kr($out, $key)
116 {
117 rg_log_enter('gpg_save_kr');
118
119 $ret = array('ok' => 0);
120 do {
121 // TODO: hd - how to clean it? Take care of on current access! Lock?
122 $hd = rg_tmp_path('gpg_save_kr_hd-' . rg_id(16), 120);
123 $ehd = escapeshellarg($hd);
124 $eout = escapeshellarg($out);
125
126 if (!is_dir($hd)) {
127 $r = @mkdir($hd, 0700);
128 if ($r === FALSE) {
129 $ret['errmsg'] = 'cannot create gpg homedir [' . $hd . ']: '
130 . rg_php_err();
131 break;
132 }
133 }
104 134
105 @unlink($kr);
135 $base = 'gpg2'
136 . ' --no-options'
137 . ' --lock-never'
138 . ' --keyring ' . $eout
139 . ' --no-default-keyring'
140 . ' --homedir ' . $ehd;
141
142 $a = array(
143 'cmds' => array(
144 'cmd1' => array(
145 'cmd' => $base
146 . ' --import'
147 . ' --batch',
148 'out_buf' => $key
149 )
150 )
151 );
152 $r = rg_exec2($a);
153 if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) {
154 rg_log_debug('import: ' . print_r($r, TRUE));
155 $ret['errmsg'] = 'cannot import key: '
156 . $r['cmds']['cmd1']['last_errmsg']
157 . ' [' . $r['cmds']['cmd1']['err_buf'] . ']';
158 break;
159 }
160
161 $ret['ok'] = 1;
162 } while (0);
163 rg_del_tree($hd);
164 @unlink($hd . '.meta');
165
166 rg_log_exit();
167 return $ret;
168 }
169
170 /*
171 * Saves a keyring based on a private key.
172 * This is a special version of the above one, used for Debian (public keyring v4).
173 * @out - out file
174 * @key - private key
175 */
176 function rg_gpg_save_public_kr($out, $key)
177 {
178 rg_log_enter('gpg_save_public_kr');
179
180 $ret = array('ok' => 0);
181 do {
182 // TODO: hd - how to clean it? Take care of on current access! Lock?
183 $hd = rg_tmp_path('gpg_save_public_kr_home-' . rg_id(16), 120);
184 $ehd = escapeshellarg($hd);
185 $kr = rg_tmp_path('gpg-save_public_kr_kr-' . rg_id(16), 120);
186 $ekr = escapeshellarg($kr);
187
188 if (!is_dir($hd)) {
189 $r = @mkdir($hd, 0700);
190 if ($r === FALSE) {
191 $ret['errmsg'] = 'cannot create gpg homedir [' . $hd . ']: '
192 . rg_php_err();
193 break;
194 }
195 }
196
197 $base = 'gpg2'
198 . ' --no-options'
199 . ' --lock-never'
200 . ' --keyring ' . $ekr
201 . ' --no-default-keyring'
202 . ' --homedir ' . $ehd;
203
204 $a = array(
205 'cmds' => array(
206 'cmd1' => array(
207 'cmd' => $base
208 . ' --import'
209 . ' --batch',
210 'out_buf' => $key
211 )
212 )
213 );
214 $r = rg_exec2($a);
215 if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) {
216 rg_log_debug('import: ' . print_r($r, TRUE));
217 $ret['errmsg'] = 'cannot import key: '
218 . $r['cmds']['cmd1']['last_errmsg']
219 . ' [' . $r['cmds']['cmd1']['err_buf'] . ']';
220 break;
221 }
222
223 if (file_exists($out))
224 @unlink($out);
225
226 $eout = escapeshellarg($out);
227
228 $a = array(
229 'cmds' => array(
230 'cmd1' => array(
231 'cmd' => $base
232 . ' --batch'
233 . ' --export'
234 . ' --output ' . $eout
235 )
236 )
237 );
238 $r = rg_exec2($a);
239 if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) {
240 //rg_log_debug('export: ' . print_r($r, TRUE));
241 $ret['errmsg'] = 'cannot export public keyring: '
242 . $r['cmds']['cmd1']['last_errmsg']
243 . ' [' . $r['cmds']['cmd1']['err_buf'] . ']';
244 break;
245 }
246
247 $ret['ok'] = 1;
248 } while (0);
249 rg_del_tree($kr);
250 @unlink($kr . '.meta');
251 rg_del_tree($hd);
252 @unlink($hd . '.meta');
253
254 rg_log_exit();
255 return $ret;
256 }
257
258 /*
259 * Sign a file providing priv key
260 */
261 function rg_gpg_sign($out, $in, $priv_key, $extra)
262 {
263 rg_log_enter('gpg_sign');
264
265 $ret = array('ok' => 0);
266 do {
267 // TODO: hd - how to clean it? Take care of on current access! Lock?
268 $hd = rg_tmp_path('gpg_sign_hd-' . rg_id(16), 120);
269 $ehd = escapeshellarg($hd);
270 $kr = rg_tmp_path('gpg_sign_kr-' . rg_id(16), 120);
271 $ekr = escapeshellarg($kr);
272
273 if (!is_dir($hd)) {
274 $r = @mkdir($hd, 0700);
275 if ($r === FALSE) {
276 $ret['errmsg'] = 'cannot create gpg homedir [' . $hd . ']: '
277 . rg_php_err();
278 break;
279 }
280 }
281
282 $base = 'gpg2'
283 . ' --no-options'
284 . ' --lock-never'
285 . ' --keyring ' . $ekr
286 . ' --no-default-keyring'
287 . ' --homedir ' . $ehd;
288
289 $a = array(
290 'cmds' => array(
291 'cmd1' => array(
292 'cmd' => $base
293 . ' --import'
294 . ' --batch',
295 'out_buf' => $priv_key
296 )
297 )
298 );
299 $r = rg_exec2($a);
300 if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) {
301 rg_log_debug('import: ' . print_r($r, TRUE));
302 $ret['errmsg'] = 'cannot import key: '
303 . $r['cmds']['cmd1']['last_errmsg']
304 . ' [' . $r['cmds']['cmd1']['err_buf'] . ']';
305 break;
306 }
307
308 $out2 = $out . '-sign';
309 $a = array(
310 'cmds' => array(
311 'cmd1' => array(
312 'cmd' => $base
313 . ' --sign'
314 . ' ' . $extra
315 . ' --output ' . escapeshellarg($out2)
316 . ' ' . escapeshellarg($in)
317 )
318 )
319 );
320 $r = rg_exec2($a);
321 if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) {
322 rg_log_debug('sign: ' . print_r($r, TRUE));
323 $ret['errmsg'] = 'cannot sign: '
324 . $r['cmds']['cmd1']['last_errmsg']
325 . ' [' . $r['cmds']['cmd1']['err_buf'] . ']';
326 break;
327 }
328
329 $r = @rename($out2, $out);
330 if ($r === FALSE) {
331 $ret['errmsg'] = 'cannot rename: '
332 . rg_php_err();
333 break;
334 }
335
336 $ret['ok'] = 1;
337 } while (0);
338 rg_del_tree($kr);
106 339 @unlink($kr . '.meta'); @unlink($kr . '.meta');
340 rg_del_tree($hd);
341 @unlink($hd . '.meta');
107 342
343 rg_log_exit();
108 344 return $ret; return $ret;
109 345 } }
346
File inc/rgfs.inc.php added (mode: 100644) (index 0000000..b6ef290)
1 <?php
2
3 /*
4 * Helper for rgfs_validate_and_store_meta and for .deb handling
5 * Paths inside @files must be relative to @subrepo_dir.
6 * @exec - TRUE - execute remove/rename operations
7 */
8 function rg_rgfs_add_remove($subrepo_dir, $files, $exec)
9 {
10 rg_log_enter('rgfs_add_remove');
11 //rg_log_debug('files=' . print_r($files, TRUE));
12
13 $ret = array('ok' => 0);
14 $locked = FALSE;
15 do {
16 $meta_dir = $subrepo_dir . '/meta';
17 if (!is_dir($meta_dir)) {
18 $r = @mkdir($meta_dir, 0700);
19 if ($r === FALSE) {
20 $ret['errmsg'] = 'canot create meta dir: ' . rg_php_err();
21 break;
22 }
23 }
24
25 $lock_file = $meta_dir . '/lock';
26 $r = rg_lock($lock_file, RG_LOCK_BLOCK);
27 if ($r !== TRUE) {
28 $ret['errmsg'] = rg_util_error();
29 break;
30 }
31 $locked = TRUE;
32
33 $cache = array();
34 $cache_path = array();
35 foreach ($files as $i) {
36 $repo_id = $i['repo_id'];
37 $add_path = isset($i['add']) ? $i['add'] : '';
38 $remove_path = isset($i['del']) ? $i['del'] : '';
39
40 if (!isset($cache[$repo_id])) {
41 $meta_path = $meta_dir . '/' . $repo_id . '.json';
42 $data = array();
43 if (file_exists($meta_path)) {
44 $data = @file_get_contents($meta_path);
45 if ($data === FALSE) {
46 $ret['errmsg'] = 'cannot load old data: ' . rg_php_err();
47 break;
48 }
49 $data = rg_unserialize($data);
50 if ($data === FALSE) {
51 $ret['errmsg'] = 'cannot unserizalize data';
52 break;
53 }
54 }
55
56 $cache_path[$repo_id] = $meta_path;
57 $cache[$repo_id] = $data;
58 }
59
60 $old_meta = array();
61 if ((!empty($remove_path)) && isset($cache[$repo_id][$remove_path])) {
62 $old_meta = $cache[$repo_id][$remove_path];
63 //rg_log_debug('TODO unsetting cache[' . $repo_id . '][' . $remove_path . ']');
64 unset($cache[$repo_id][$remove_path]);
65 //rg_log_debug('old_meta: ' . rg_array2string($old_meta));
66 }
67
68 if (!empty($add_path)) {
69 if (!empty($old_meta)) {
70 $new_meta = $old_meta;
71 } else {
72 $new_meta = array();
73 $new_meta['ctime'] = time();
74 }
75
76 foreach ($i['meta'] as $k => $v)
77 $new_meta[$k] = $v;
78
79 $cache[$repo_id][$add_path] = $new_meta;
80 }
81
82 if (!$exec)
83 break;
84
85 if (empty($add_path)) {
86 // just a remove
87 $r = @unlink($i['root'] . '/' . $remove_path);
88 if ($r === FALSE) {
89 $ret['errmsg'] = 'cannot remove ' . $remove_path . ': ' . rg_php_err();
90 break;
91 }
92 } else if (empty($remove_path)) {
93 // Just add - nothing to do
94 } else {
95 // move
96 $d = dirname($i['root'] . '/' . $add_path);
97 if (!is_dir($d)) {
98 $r = @mkdir($d, 0700, TRUE);
99 if ($r === FALSE) {
100 $ret['errmsg'] = 'cannot mkdir ' . $d
101 . ': ' . rg_php_err();
102 break;
103 }
104 }
105
106 $r = @rename($i['root'] . '/' . $remove_path,
107 $i['root'] . '/' . $add_path);
108 if ($r === FALSE) {
109 $ret['errmsg'] = 'cannot rename ' . $remove_path
110 . ' to ' . $add_path . ': ' . rg_php_err();
111 break;
112 }
113 }
114 }
115 if (isset($ret['errmsg']))
116 break;
117
118 foreach ($cache as $_repo_id => $_info) {
119 $r = rg_save($cache_path[$_repo_id], $_info);
120 if ($r === FALSE) {
121 $ret['errmsg'] = rg_php_err();
122 break;
123 }
124 }
125 if (isset($ret['errmsg']))
126 break;
127
128 $ret['ok'] = 1;
129 } while (0);
130 if ($locked)
131 rg_unlock($lock_file);
132
133 rg_log_exit();
134 return $ret;
135 }
File inc/user/packages.inc.php changed (mode: 100644) (index bc36eb0..b3d1d1a)
... ... include_once(__DIR__ . '/pkg_repo.inc.php');
3 3 include_once(__DIR__ . '/pkg_subrepo.inc.php'); include_once(__DIR__ . '/pkg_subrepo.inc.php');
4 4 include_once(__DIR__ . '/pkg_map.inc.php'); include_once(__DIR__ . '/pkg_map.inc.php');
5 5 include_once(__DIR__ . '/packages_rpm.inc.php'); include_once(__DIR__ . '/packages_rpm.inc.php');
6 include_once(__DIR__ . '/packages_deb.inc.php');
6 7
7 8 /* /*
8 * This is called from rgfs.php to validate a creation of a path
9 * Event functions
9 10 */ */
10 function rg_packages_validate_path($db, $path, $allow_paths)
11 $_f = array(
12 'pkg_event_after_build' => 'rg_pkg_event_after_build'
13 );
14 rg_event_register_functions($_f);
15
16 /*
17 * Some chars are not allowed in package names
18 */
19 function rg_pkg_transform($type, $s)
11 20 { {
12 $ret = array('ok' => 0, 'user_path' => '');
21 if (strcmp($type, 'deb') == 0) {
22 $s2 = strtolower($s);
23 $s2 = preg_replace('/[^-a-z0-9.]/', '-', $s2);
24 $s2 = str_replace('--', '-', $s2);
25 } else if (strcmp($type, 'rpm') == 0) {
26 $s2 = preg_replace('/[^-A-Za-z0-9._]/', '-', $s);
27 }
28 rg_log_debug('pkg_transform[' . $type . ']: [' . $s . '] -> [' . $s2 . ']');
29
30 return $s2;
31 }
32
33 /*
34 * This is called after a push and before sendint the job to a builder
35 */
36 function rg_pkg_prepare_for_build($db, &$a)
37 {
38 rg_log_enter('pkg_prepare_for_build');
39 rg_log_debug('a: ' . rg_array2string_short($a));
40
41 $ret = array('ok' => 0);
13 42 do { do {
14 $r = rg_envs_tree($db, TRUE /*only enabled*/);
43 rg_pkg_prepare_for_rgfs($db, $a);
44
45 $ei = rg_env_info($a['env']);
46 $a['env_codename'] = $ei['codename'];
47
48 if (isset($a['repo_name']))
49 $a['repo_name_allowed'] = rg_pkg_transform($ei['pkg_type'],
50 $a['repo_name']);
51 $a['repo_username_allowed'] = rg_pkg_transform($ei['pkg_type'],
52 $a['repo_username']);
53
54 if (!isset($a['event_callbacks']))
55 $a['event_callbacks'] = array();
56 $a['event_callbacks'][] = 'pkg_event_after_build';
57
58 if (isset($a['pkg_subrepo_id_list'])) {
59 $r = rg_pkg_maps_prepare($db, $a);
60 if ($r['ok'] != 1) {
61 $ret['errmsg'] = $r['errmsg'];
62 break;
63 }
64 }
65
66 $r = array('ok' => 1);
67 if (strcmp($ei['pkg_type'], 'rpm') == 0) {
68 $r = rg_pkg_prepare_for_build_rpm($db, $a);
69 } else if (strcmp($ei['pkg_type'], 'deb') == 0) {
70 $r = rg_pkg_prepare_for_build_deb($db, $a);
71 }
15 72 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
16 $ret['errmsg'] = 'cannot load envs: ' . $r['errmsg'];
73 rg_log('Cannot prepare ev: ' . $r['errmsg']);
17 74 break; break;
18 75 } }
19 $d = $r['tree'];
20 76
21 $x = explode('/', $path);
22 $junk = array_shift($x); // because path starts with '/', we ignore the empty element
77 // Prio is 2 less than normal (10)
78 $r = rg_builder_add($db, $a['build_repo_id'], 8 /*prio*/, $a);
79 if ($r['ok'] != 1) {
80 $ret['errmsg'] = $r['errmsg'];
81 break;
82 }
23 83
24 $distro = array_shift($x);
25 if (!isset($d[$distro])) {
26 $ret['errmsg'] = 'invalid distro [' . $distro . ']';
84 $ret['ok'] = 1;
85 } while (0);
86
87 rg_log_exit();
88 return $ret;
89 }
90
91 /*
92 * Event called after a build is done
93 */
94 function rg_pkg_event_after_build($db, $ev)
95 {
96 rg_log_enter('pkg_event_after_build');
97 rg_log_debug('ev: ' . rg_array2string_short($ev));
98
99 $ret = FALSE;
100 do {
101 $req = $ev['job']['request'];
102 $e = $req['env'];
103 $ei = rg_env_info($e);
104
105 if (!isset($req['orig_job_id'])) {
106 rg_log_debug('TODO orig_job_id is not set, so set it to ' . $ev['job']['id']);
107 $ev['job']['request']['orig_job_id'] = $ev['job']['id'];
108 } else {
109 rg_log_debug('req[orig_job_id] is already set to ' . $req['orig_job_id']);
110 }
111
112 $r = array('ok' => 1);
113 if (strcmp($ei['pkg_type'], 'rpm') == 0) {
114 $r = rg_pkg_after_build_rpm($db, $ev);
115 } else if (strcmp($ei['pkg_type'], 'deb') == 0) {
116 $r = rg_pkg_after_build_deb($db, $ev);
117 }
118 if ($r['ok'] != 1) {
119 rg_log('error: ' . $r['errmsg']);
120 break;
121 }
122
123 $ret = array();
124 } while (0);
125
126 rg_log_exit();
127 return $ret;
128 }
129
130 /*
131 * Validate path for Debian
132 * Example x: [11]/[main]
133 */
134 function rg_packages_validate_path_deb($distro, &$x, $m)
135 {
136 rg_log_enter('packages_validate_path_deb');
137 //rg_log_debug('x: ' . print_r($x, TRUE));
138
139 $ret = array('ok' => 0);
140 do {
141 $codename = array_shift($x);
142 $major = rg_env_codename2major($distro, $codename);
143 if (!isset($m[$major])) {
144 $ret['errmsg'] = 'invalid codename [' . $codename . ']'
145 . ' for distro ' . $distro;
146 break;
147 }
148
149 if (empty($x)) {
150 $ret['ok'] = 1;
27 151 break; break;
28 152 } }
29 153
154 $junk_main = array_shift($x);
155
30 156 if (empty($x)) { if (empty($x)) {
31 157 $ret['ok'] = 1; $ret['ok'] = 1;
32 158 break; break;
33 159 } }
34 160
161 $binary_or_source = array_shift($x);
162
163 $ret['ok'] = 1;
164 } while (0);
165
166 rg_log_exit();
167 return $ret;
168 }
169
170 /*
171 * Validate path for Fedora/CentOS/CentOS Stream
172 */
173 function rg_packages_validate_path_rpm($distro, &$x, $m)
174 {
175 rg_log_enter('packages_validate_path_rpm');
176
177 $ret = array('ok' => 0);
178 do {
35 179 $major = array_shift($x); $major = array_shift($x);
36 if (!isset($d[$distro]['versions'][$major])) {
180 if (!isset($m[$major])) {
37 181 $ret['errmsg'] = 'invalid major [' . $major . ']'; $ret['errmsg'] = 'invalid major [' . $major . ']';
38 182 break; break;
39 183 } }
 
... ... function rg_packages_validate_path($db, $path, $allow_paths)
44 188 } }
45 189
46 190 $arch = array_shift($x); $arch = array_shift($x);
47 if (!isset($d[$distro]['versions'][$major]['archs'][$arch])) {
191 if (!isset($m[$major]['archs'][$arch])) {
48 192 $ret['errmsg'] = 'invalid arch [' . $arch . ']'; $ret['errmsg'] = 'invalid arch [' . $arch . ']';
49 193 break; break;
50 194 } }
 
... ... function rg_packages_validate_path($db, $path, $allow_paths)
54 198 break; break;
55 199 } }
56 200
57 if (strcmp($d[$distro]['pkg_type'], 'rpm') != 0) {
58 $ret['errmsg'] = 'unsupported pkg type';
59 break;
60 }
61
62 201 $type = array_shift($x); $type = array_shift($x);
63 202 $allow = array('os', 'debug', 'src'); $allow = array('os', 'debug', 'src');
64 203 if (!in_array($type, $allow)) { if (!in_array($type, $allow)) {
 
... ... function rg_packages_validate_path($db, $path, $allow_paths)
66 205 break; break;
67 206 } }
68 207
208 $ret['ok'] = 1;
209 } while (0);
210
211 rg_log_exit();
212 return $ret;
213 }
214
215 /*
216 * This is called from rgfs.php to validate the creation of a path
217 */
218 function rg_packages_validate_path($db, $path, $allow_paths)
219 {
220 rg_log_enter('packages_validate_path: path=' . $path);
221
222 $ret = array('ok' => 0, 'user_path' => '');
223 do {
224 $r = rg_envs_tree($db, TRUE /*only enabled*/);
225 if ($r['ok'] != 1) {
226 $ret['errmsg'] = 'cannot load envs: ' . $r['errmsg'];
227 break;
228 }
229 $d = $r['tree'];
230
231 $x = explode('/', $path);
232 $junk = array_shift($x); // because path starts with '/', we ignore the empty element
233
234 $distro = array_shift($x);
235 if (!isset($d[$distro])) {
236 $ret['errmsg'] = 'invalid distro [' . $distro . ']';
237 break;
238 }
239
240 if (empty($x)) {
241 $ret['ok'] = 1;
242 break;
243 }
244
245 $m = $d[$distro]['versions'];
246 switch ($d[$distro]['pkg_type']) {
247 case 'rpm': $r = rg_packages_validate_path_rpm($distro, $x, $m); break;
248 case 'deb': $r = rg_packages_validate_path_deb($distro, $x, $m); break;
249 default: $r = array('ok' => 0, 'errmsg' => 'yet unsupported distro'
250 . ' (' . $distro . ')'); break;
251 }
252 if ($r['ok'] != 1) {
253 $ret['errmsg'] = $r['errmsg'];
254 break;
255 }
256
69 257 if (empty($x)) { if (empty($x)) {
70 258 $ret['ok'] = 1; $ret['ok'] = 1;
71 259 break; break;
 
... ... function rg_packages_validate_path($db, $path, $allow_paths)
76 264 $match = FALSE; $match = FALSE;
77 265 $next1 = array_shift($x); $next1 = array_shift($x);
78 266 $next2 = !empty($x) ? array_shift($x) : ''; $next2 = !empty($x) ? array_shift($x) : '';
267 $next3 = !empty($x) ? array_shift($x) : '';
79 268 foreach ($allow_paths as $i) { foreach ($allow_paths as $i) {
80 rg_log_debug('[' . $next1 . ']/[' . $next2 . '] vs [' . $i['next1'] . ']/[' . $i['next2'] . ']');
269 rg_log_debug('testing [' . $next1 . ']/[' . $next2 . ']/[' . $next3 . ']'
270 . ' vs [' . $i['next1'] . ']/[' . $i['next2'] . ']/[' . $i['next3'] . ']');
81 271
82 272 if (preg_match('/^' . $i['next1'] . '$/uD', $next1) !== 1) if (preg_match('/^' . $i['next1'] . '$/uD', $next1) !== 1)
83 273 continue; continue;
 
... ... function rg_packages_validate_path($db, $path, $allow_paths)
86 276 && preg_match('/^' . $i['next2'] . '$/uD', $next2) !== 1) && preg_match('/^' . $i['next2'] . '$/uD', $next2) !== 1)
87 277 continue; continue;
88 278
279 if (!empty($next3)
280 && preg_match('/^' . $i['next3'] . '$/uD', $next3) !== 1)
281 continue;
282
89 283 $match = TRUE; $match = TRUE;
90 284 break; break;
91 285 } }
92 286 if (!$match) { if (!$match) {
93 $ret['errmsg'] = 'not allowed path [' . $next1 . ']/[' . $next2 . ']';
287 $ret['errmsg'] = 'not allowed path [' . $next1 . ']'
288 . '/[' . $next2 . ']/[' . $next3 . ']';
94 289 break; break;
95 290 } }
96 291
97 292 $ret['ok'] = 1; $ret['ok'] = 1;
98 293 } while (0); } while (0);
99 294
295 rg_log_exit();
100 296 return $ret; return $ret;
101 297 } }
102 298
103 299 function rg_packages_get_link($db, $a) function rg_packages_get_link($db, $a)
104 300 { {
105 if (strcmp($a['distro_pkg_type'], 'rpm') == 0)
301 if (strcmp($a['pkg_type'], 'rpm') == 0)
106 302 return rg_packages_rpm_get_link($db, $a); return rg_packages_rpm_get_link($db, $a);
107 303
304 if (strcmp($a['pkg_type'], 'deb') == 0)
305 return rg_packages_deb_get_link($db, $a);
306
108 307 return FALSE; return FALSE;
109 308 } }
110 309
 
... ... function rg_packages_get_link($db, $a)
113 312 */ */
114 313 function rg_packages_howto($a, $user, $repo_name, $meta) function rg_packages_howto($a, $user, $repo_name, $meta)
115 314 { {
116 if (strcmp($a['distro_pkg_type'], 'rpm') == 0)
315 if (strcmp($a['pkg_type'], 'rpm') == 0)
117 316 return rg_packages_rpm_howto($a, $user, $repo_name, $meta); return rg_packages_rpm_howto($a, $user, $repo_name, $meta);
317 else if (strcmp($a['pkg_type'], 'deb') == 0)
318 return rg_packages_deb_howto($a, $user, $repo_name, $meta);
118 319
119 320 return 'TODO'; return 'TODO';
120 321 } }
 
... ... function rg_packages_howto($a, $user, $repo_name, $meta)
125 326 function rg_packages_meta_split($meta) function rg_packages_meta_split($meta)
126 327 { {
127 328 $ret = array(); $ret = array();
329
128 330 foreach ($meta as $path => $i) { foreach ($meta as $path => $i) {
129 $a = explode('/', $path, 5);
130 $distro = $a[1];
131 $major = $a[2];
132 $arch = $a[3];
133 $rest = $a[4];
331 if (isset($i['env'])) { // new way
332 $ei = rg_env_info($i['env']);
333 $distro = $ei['distro'];
334 $major = $ei['major'];
335 $arch = $ei['arch'];
336
337 $a = explode('/', $path);
338 $c = count($a);
339 $rest = $a[$c - 1];
340 } else { // old way
341 $a = explode('/', $path, 5);
342 $distro = $a[1];
343 $major = $a[2];
344 $arch = $a[3];
345
346 $rest = $a[4];
347 }
134 348
135 349 if (!isset($ret[$distro])) if (!isset($ret[$distro]))
136 350 $ret[$distro] = array(); $ret[$distro] = array();
 
... ... function rg_packages_meta_split($meta)
154 368 */ */
155 369 function rg_packages_are_available($a, $repo_id) function rg_packages_are_available($a, $repo_id)
156 370 { {
157 rg_log_enter_ml('packages_are_available: '
371 rg_log_enter('packages_are_available:'
158 372 . ' pr=' . $a['pkg_repo_info']['id'] . ' pr=' . $a['pkg_repo_info']['id']
159 373 . ' psr=' . $a['pkg_subrepo_info']['id'] . ' psr=' . $a['pkg_subrepo_info']['id']
160 374 . ' repo_id=' . $repo_id); . ' repo_id=' . $repo_id);
161 375
162 376 $ret = FALSE; $ret = FALSE;
163 377 do { do {
164 $d = '/var/lib/rocketgit/pkg_repos'
378 $d = '/var/lib/rocketgit/pkg_repos' // TODO: replace with the global variable
165 379 . '/' . $a['pkg_repo_info']['id'] . '/' . $a['pkg_repo_info']['id']
166 380 . '/' . $a['pkg_subrepo_info']['id']; . '/' . $a['pkg_subrepo_info']['id'];
167 381 $f = $d . '/meta/' . $repo_id . '.json'; $f = $d . '/meta/' . $repo_id . '.json';
 
... ... function rg_packages_are_available($a, $repo_id)
172 386 } }
173 387
174 388 $u = rg_unserialize($c); $u = rg_unserialize($c);
175 if ($u === FALSE)
389 if ($u === FALSE) {
390 rg_internal_error('canot unserialize ' . $c);
176 391 break; // TODO: return a temporary error? break; // TODO: return a temporary error?
392 }
393 rg_log_debug('Loaded ' . count($u) . ' entries');
394 //rg_log_debug('Loaded from file ' . $f . ': ' . print_r($u, TRUE));
177 395
178 396 // Load more info about files (size and nlink) // Load more info about files (size and nlink)
179 397 foreach ($u as $subpath => &$i) { foreach ($u as $subpath => &$i) {
398 if (strstr($subpath, '/+pending/')) {
399 unset($u[$subpath]);
400 continue;
401 }
402
180 403 $s = @stat($d . $subpath); $s = @stat($d . $subpath);
181 404 if ($s === FALSE) { if ($s === FALSE) {
182 rg_log('cannot stat ' . $d . '/' . $subpath);
405 //rg_log_debug('cannot stat ' . $d . $subpath); // TODO: what to do with this?
183 406 unset($u[$subpath]); unset($u[$subpath]);
184 407 continue; continue;
185 408 } }
 
... ... function rg_packages_are_available($a, $repo_id)
191 414 unset($i); unset($i);
192 415
193 416 $ret = rg_packages_meta_split($u); $ret = rg_packages_meta_split($u);
194 rg_log_debug('meta: ' . print_r($ret, TRUE));
417 //rg_log_debug('return: ' . print_r($ret, TRUE));
195 418 } while (0); } while (0);
196 419
197 420 rg_log_exit(); rg_log_exit();
 
... ... function rg_packages_prepare_meta(&$m, $repo_url)
231 454 } }
232 455
233 456 /* /*
234 * Returns a tree table with all available repositories+distro+major+arch
457 * Returns a tree with all available repositories+distro+major+arch
235 458 * for @uid. * for @uid.
236 459 * TODO: get rid of $rg? * TODO: get rid of $rg?
237 460 */ */
238 function rg_packages_info($db, $uid, $rg, $needed_flags)
461 function rg_packages_info($db, $uid, $rg)
239 462 { {
240 rg_log_enter('packages_info needed_flags=' . $needed_flags);
463 rg_log_enter('packages_info');
241 464
242 465 $ret = array('ok' => 0); $ret = array('ok' => 0);
243 466 do { do {
244 467 $ui_page = rg_ui_page(); $ui_page = rg_ui_page();
245 468 //rg_log_debug('ui_page: ' . print_r($ui_page, TRUE)); //rg_log_debug('ui_page: ' . print_r($ui_page, TRUE));
246 469
470 // If user can edit ('E') the repo, she should be able to see job details
471 $can_see_details = 0;
472 if ($ui_page['uid'] > 0) {
473 $obj_id = $rg['ri']['repo_id'];
474 $r = rg_rights_allow2($db, 'repo', $obj_id, 'E', '');
475 $can_see_details = ($r === TRUE) ? 1 : 0;
476 }
477 rg_log_debug('can_see_details=' . $can_see_details);
478
247 479 // Load available pkg repos for an uid (including global ones) // Load available pkg repos for an uid (including global ones)
248 480 $repo_list = rg_pkg_repo_list($db, $uid); $repo_list = rg_pkg_repo_list($db, $uid);
249 481 if ($repo_list === FALSE) { if ($repo_list === FALSE) {
 
... ... function rg_packages_info($db, $uid, $rg, $needed_flags)
252 484 } }
253 485 //rg_log_debug('pkg_repo_list returned: ' . print_r($repo_list, TRUE)); //rg_log_debug('pkg_repo_list returned: ' . print_r($repo_list, TRUE));
254 486
255 // Filter repo_list based by @flags/rights
487 // Filter repo_list based by rights
256 488 foreach ($repo_list as $pri => &$ri) { foreach ($repo_list as $pri => &$ri) {
257 $skip = FALSE;
258 $nf = $needed_flags;
259 while (1) {
260 $f = substr($nf, 0, 1);
261 if (empty($f))
262 break;
263
264 if (strstr($ri['flags'], $f) === FALSE) {
265 rg_log_debug('skip ' . $ri['name']
266 . ' because it does not contain flag ' . $f);
267 $skip = TRUE;
268 break;
269 }
270 $nf = substr($nf, 1);
271 }
272 if ($skip && rg_pkg_has_rights($db, $ri, $rg, 'A'))
273 $skip = FALSE;
274 if ($skip) {
275 unset($repo_list[$pri]);
276 continue;
277 }
278
279 489 // We do not need this variables // We do not need this variables
280 490 unset($ri['gpg_priv_key']); unset($ri['gpg_priv_key']);
281 491 unset($ri['gpg_pub_key']); unset($ri['gpg_pub_key']);
282 492 unset($ri['rgfs_key']); unset($ri['rgfs_key']);
283 493
284 if ($ri['uid'] > 0) { // is a user repo
285 $ui = rg_user_info($db, $ri['uid'], '', '');
286 if ($ui['exists'] != 1) {
287 rg_internal_error('user missing for a repo');
288 unset($repo_list[$pri]);
289 continue;
290 }
291 $repo_list[$pri]['username'] = $ui['username'];
292 }
494 rg_pkg_repo_cosmetic($db, $repo_list[$pri]);
293 495
294 496 $repo_list[$pri]['subrepos'] = array(); $repo_list[$pri]['subrepos'] = array();
497
498 if ($ri['uid'] == 0) // public pkg repo?
499 continue;
500
501 if (strstr($ri['flags'], 'P')) // pkg repo is public
502 continue;
503
504 if (rg_pkg_has_rights($db, $ri, 'A'))
505 continue;
506
507 unset($repo_list[$pri]);
295 508 } }
296 509 unset($ri); unset($ri);
297 510
 
... ... function rg_packages_info($db, $uid, $rg, $needed_flags)
318 531 } }
319 532 unset($subrepo_list); unset($subrepo_list);
320 533
534 $r = rg_envs_tree($db, TRUE);
535 if ($r['ok'] != 1) {
536 $ret['errmsg'] = $r['errmsg'];
537 break;
538 }
539 $envs = $r['tree'];
540 //rg_log_debug('TODO: envs: ' . print_r($envs, TRUE));
541
321 542 $ret['ok'] = 1; $ret['ok'] = 1;
322 543 $ret['list'] = array(); $ret['list'] = array();
323 544 $a = array(); $a = array();
 
... ... function rg_packages_info($db, $uid, $rg, $needed_flags)
332 553 $list_subrepo = array(); $list_subrepo = array();
333 554 foreach ($subrepos as $pkg_subrepo_id => $sri) { foreach ($subrepos as $pkg_subrepo_id => $sri) {
334 555 rg_log_enter('pkg_subrepo_id: ' . $pkg_subrepo_id . ' [' . $sri['name'] . ']'); rg_log_enter('pkg_subrepo_id: ' . $pkg_subrepo_id . ' [' . $sri['name'] . ']');
335 rg_log_debug('sri[distro_info]: ' . print_r($sri['distro_info'], TRUE));
336
337 if (empty($sri['distro_info'])) {
338 rg_log_debug('empty sri distros => skip it');
339 rg_log_exit();
340 continue;
341 }
342 $distros = rg_distro_info2tree($sri['distro_info']);
556 //rg_log_debug('sri[distro_info]: ' . print_r($sri['distro_info'], TRUE));
343 557
344 558 $a['pkg_subrepo_info'] = $sri; $a['pkg_subrepo_info'] = $sri;
345 559
346 // If we are on /opt/pkg_repos, we do not have a repo
560 // If we are on /op/pkg_repos, we do not have a repo
347 561 if ($ui_page['uid'] > 0) if ($ui_page['uid'] > 0)
348 562 $meta = rg_packages_are_available($a, $rg['ri']['repo_id']); $meta = rg_packages_are_available($a, $rg['ri']['repo_id']);
349 563
350 564 $list_distro = array(); $list_distro = array();
351 foreach ($distros as $distro => $per_distro) {
352 rg_log_enter('distro ' . $distro);
353
354 $env_info = rg_env_info($distro);
565 foreach ($envs as $distro => $per_distro) {
566 $versions = $per_distro['versions']; unset($per_distro['versions']);
355 567 $a['distro'] = $distro; $a['distro'] = $distro;
568 $a['pkg_type'] = $per_distro['pkg_type'];
356 569
357 570 $list_major = array(); $list_major = array();
358 foreach ($per_distro['versions'] as $major => $per_major) {
359 rg_log_enter('major: ' . $major);
360
571 foreach ($versions as $major => $per_major) {
361 572 $a['major'] = $major; $a['major'] = $major;
573 $a['codename'] = rg_env_major2codename($distro, $major);
362 574
363 575 $list_arch = array(); $list_arch = array();
364 576 foreach ($per_major['archs'] as $arch => $per_arch) { foreach ($per_major['archs'] as $arch => $per_arch) {
365 rg_log_enter('arch ' . $arch);
577 $e = $distro . '-' . $major . '-' . $arch;
366 578
579 if (!isset($sri['distro_info'][$e])) {
580 //rg_log_debug('distro_info[' . $e . '] is missing; skip');
581 continue;
582 }
583 $di = $sri['distro_info'][$e];
584
585 if (strcmp($per_distro['pkg_type'], 'rpm') == 0) {
586 if (!isset($di['dotrepo'])) {
587 //rg_log_debug('dotrepo is missing; skip');
588 continue;
589 }
590 } else if (strcmp($per_distro['pkg_type'], 'deb') == 0) {
591 if (!isset($di['has_packages'])) {
592 //rg_log_debug('has_packages is missing; skip');
593 continue;
594 }
595 }
596
597 $m = FALSE;
367 598 if ($ui_page['uid'] > 0) { if ($ui_page['uid'] > 0) {
368 if (empty($meta[$distro][$major][$arch])) {
369 rg_log_debug('skip arch ' . $arch
370 . ' because meta[distro][major][arch] is empty');
371 rg_log_exit();
599 if (!isset($meta[$distro][$major])) {
600 //rg_log_debug('meta[' . $distro . ']'
601 // . '[' . $major . '] is not set; skip');
372 602 continue; continue;
373 603 } }
374 604
375 $m = $meta[$distro][$major][$arch];
376 } else {
377 $m = FALSE;
605 $m = $meta[$distro][$major];
606
607 if (empty($m[$arch])) {
608 //rg_log_debug('m[' . $arch . '] is not set; skip');
609 continue;
610 }
611
612 $m = $m[$arch];
378 613 } }
379 614
615 rg_log_enter($e);
616 //if ($m !== FALSE) rg_log_debug('meta: ' . print_r($m, TRUE));
617
380 618 $a['arch'] = $arch; $a['arch'] = $arch;
381 foreach ($per_arch as $k => $v)
382 $a[$k] = $v;
619 $a['env'] = $e;
620
383 621 $r = rg_packages_get_link($db, $a); $r = rg_packages_get_link($db, $a);
384 $a['dotrepo_pkg_name'] = $r['dotrepo_pkg_name'];
385 $a['dotrepo_pkg_url'] = $r['dotrepo_pkg_url'];
622 foreach ($r as $k => $v)
623 $a[$k] = $v;
386 624
387 625 if ($ui_page['uid'] > 0) { if ($ui_page['uid'] > 0) {
388 626 $_user = $ui_page['username']; $_user = $ui_page['username'];
 
... ... function rg_packages_info($db, $uid, $rg, $needed_flags)
390 628 $repo_url = rg_re_repopage($ui_page, $_repo_name); $repo_url = rg_re_repopage($ui_page, $_repo_name);
391 629
392 630 // Filter meta // Filter meta
393 $p = $_user . '+' . $_repo_name . '-';
394 $p_len = strlen($p);
395 $m2 = array();
396 631 foreach ($m as $f => $i) { foreach ($m as $f => $i) {
397 $f2 = basename($f);
398 if (strncmp($f2, $p, $p_len) != 0) {
399 rg_log_debug('no match [' . $f2 . '] [' . $p . ']');
632 if (strstr($f, '/+pending/')) {
633 unset($m[$f]);
400 634 continue; continue;
401 635 } }
402
403 $i['f2'] = $f2;
404 $m2[$f] = $i;
405 636 } }
406 $m = $m2;
407 637 if (empty($m)) { if (empty($m)) {
408 638 rg_log_debug('empty meta after filtering'); rg_log_debug('empty meta after filtering');
409 639 rg_log_exit(); rg_log_exit();
 
... ... function rg_packages_info($db, $uid, $rg, $needed_flags)
415 645 $_repo_name = ''; $_repo_name = '';
416 646 } }
417 647
648 $a['can_see_details'] = $can_see_details;
418 649 $list_arch[$arch] = array( $list_arch[$arch] = array(
419 650 'howto' => rg_packages_howto($a, $_user, $_repo_name, $m), 'howto' => rg_packages_howto($a, $_user, $_repo_name, $m),
420 'meta' => $m
421 );
651 'meta' => $m);
422 652 rg_log_exit(); rg_log_exit();
423 653 } }
424 654 if (!empty($list_arch)) if (!empty($list_arch))
425 655 $list_major[$major] = $list_arch; $list_major[$major] = $list_arch;
426 rg_log_exit();
427 656 } }
428 657 if (!empty($list_major)) if (!empty($list_major))
429 658 $list_distro[$distro] = $list_distro[$distro] =
430 array('info' => $env_info, 'list' => $list_major);
431 rg_log_exit();
659 array('info' => $per_distro, 'list' => $list_major);
432 660 } }
433 661 if (!empty($list_distro)) if (!empty($list_distro))
434 662 $list_subrepo[$pkg_subrepo_id] = $list_subrepo[$pkg_subrepo_id] =
435 663 array('info' => $sri, 'list' => $list_distro); array('info' => $sri, 'list' => $list_distro);
436 664 rg_log_exit(); rg_log_exit();
437 665 } }
438 if (!empty($list_subrepo))
439 $list[$pkg_repo_id] =
666 if (!empty($list_subrepo)) {
667 isset($list[$global]) || $list[$global] = array();
668 $list[$global][$pkg_repo_id] =
440 669 array('info' => $ri, 'list' => $list_subrepo); array('info' => $ri, 'list' => $list_subrepo);
670 }
441 671 rg_log_exit(); rg_log_exit();
442 672 } }
443 if (!empty($list))
444 $ret['list'][$global] = $list;
673 $ret['list'] = $list;
445 674 } while (0); } while (0);
446 675
447 676 rg_log_exit(); rg_log_exit();
 
... ... function rg_packages_repo_page($db, $rg)
462 691 // TODO: We must switch to normal rights check! // TODO: We must switch to normal rights check!
463 692 $ui_page = rg_ui_page(); $ui_page = rg_ui_page();
464 693 $uid = $ui_page['uid']; $uid = $ui_page['uid'];
465 $ui_login = rg_ui_login();
466 $flags = $ui_login['uid'] == $uid ? '' : 'P';
467 694
468 $r = rg_packages_info($db, $uid, $rg, $flags);
695 $r = rg_packages_info($db, $uid, $rg);
469 696 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
470 697 $rg['errmsg'] = $r['errmsg']; $rg['errmsg'] = $r['errmsg'];
471 698 $ret = rg_template('internal_err.html', $rg, TRUE /*xss*/); $ret = rg_template('internal_err.html', $rg, TRUE /*xss*/);
472 699 break; break;
473 700 } }
474 rg_log_debug('packages_info returned: ' . print_r($r['list'], TRUE));
701 //rg_log_debug('packages_info returned: ' . print_r($r['list'], TRUE));
702 rg_debug_html_set('pkg_info', $r['list']);
475 703
476 704 if (empty($r['list'])) { if (empty($r['list'])) {
477 705 $ret = rg_template('user/pkg/no_packages.html', $rg, TRUE /*xss*/); $ret = rg_template('user/pkg/no_packages.html', $rg, TRUE /*xss*/);
 
... ... function rg_packages_repo_page($db, $rg)
482 710 foreach ($r['list'] as $global => $per_type) { foreach ($r['list'] as $global => $per_type) {
483 711 $ret .= '<details open><summary>Type: <b>' . ($global == 1 ? 'Global' : 'User') . '</b></summary>'; $ret .= '<details open><summary>Type: <b>' . ($global == 1 ? 'Global' : 'User') . '</b></summary>';
484 712 foreach ($per_type as $pkg_repo_id => $per_repo) { foreach ($per_type as $pkg_repo_id => $per_repo) {
485 // TODO: remove this: rg_pkg_repo_cosmetic($per_repo['info']);
486 713 $ret .= '<details open>' $ret .= '<details open>'
487 714 . '<summary>Repo: <b>' . rg_xss_safe($per_repo['info']['name']) . '</b>' . '<summary>Repo: <b>' . rg_xss_safe($per_repo['info']['name']) . '</b>'
488 715 . ' - ' . (strstr($per_repo['info']['flags'], 'P') ? 'public' : 'private') . ' - ' . (strstr($per_repo['info']['flags'], 'P') ? 'public' : 'private')
 
... ... function rg_packages_repo_page($db, $rg)
491 718 foreach ($per_repo['list'] as $pkg_subrepo_id => $per_subrepo) { foreach ($per_repo['list'] as $pkg_subrepo_id => $per_subrepo) {
492 719 $ret .= '<details open><summary>Subrepo: <b>' . rg_xss_safe($per_subrepo['info']['name']) . '</b></summary>'; $ret .= '<details open><summary>Subrepo: <b>' . rg_xss_safe($per_subrepo['info']['name']) . '</b></summary>';
493 720 foreach ($per_subrepo['list'] as $distro => $per_distro) { foreach ($per_subrepo['list'] as $distro => $per_distro) {
494 $ret .= '<details open><summary>Distribution: <b>' . rg_xss_safe($per_distro['info']['distro_nice']) . '</b></summary>';
721 $ret .= '<details open><summary>Distribution: <b>' . rg_xss_safe($per_distro['info']['nice']) . '</b></summary>';
495 722 foreach ($per_distro['list'] as $major => $per_major) { foreach ($per_distro['list'] as $major => $per_major) {
496 $ret .= '<details open><summary>Major version: <b>' . rg_xss_safe($major) . '</b></summary>';
723 $codename = rg_env_major2codename($distro, $major);
724 $add = strcmp($codename, $major) == 0 ? '' : ' (' . rg_xss_safe($codename) . ')';
725 $ret .= '<details open><summary>Major version: <b>' . rg_xss_safe($major) . '</b>' . $add . '</summary>';
497 726 foreach ($per_major as $arch => $per_arch) { foreach ($per_major as $arch => $per_arch) {
498 727 $ret .= '<details open><summary>Architecture: <b>' . rg_xss_safe($arch) . '</b></summary>'; $ret .= '<details open><summary>Architecture: <b>' . rg_xss_safe($arch) . '</b></summary>';
499 728 $ret .= $per_arch['howto']; $ret .= $per_arch['howto'];
 
... ... function rg_packages_high_level($db, &$rg, $paras)
525 754 rg_log_enter('packages_high_level'); rg_log_enter('packages_high_level');
526 755
527 756 $ret = ''; $ret = '';
528 while (1) {
757 do {
529 758 $op = empty($paras) ? 'repo' : array_shift($paras); $op = empty($paras) ? 'repo' : array_shift($paras);
530 759 $rg['menu2']['packages'] = array($op => 1); $rg['menu2']['packages'] = array($op => 1);
531 760
 
... ... function rg_packages_high_level($db, &$rg, $paras)
545 774
546 775 $rg['HTML:menu_level2'] = $rg['HTML:menu_level2'] =
547 776 rg_template('user/settings/packages/menu.html', $rg, TRUE /*xss*/); rg_template('user/settings/packages/menu.html', $rg, TRUE /*xss*/);
548
549 break;
550 }
777 } while (0);
551 778
552 779 rg_log_exit(); rg_log_exit();
553 780 rg_prof_end('packages_high_level'); rg_prof_end('packages_high_level');
 
... ... function rg_packages_web($db, $rg, $paras, $pass)
583 810 break; break;
584 811 } }
585 812 $distros = $r['tree']; $distros = $r['tree'];
586 rg_log_debug('distros: ' . rg_array2string($distros));
813 //rg_log_debug('distros: ' . rg_array2string($distros));
587 814
588 815 if (!isset($distros[$a['distro']])) { if (!isset($distros[$a['distro']])) {
589 816 rg_log('unsupported distro [' . $a['distro'] . ']'); rg_log('unsupported distro [' . $a['distro'] . ']');
 
... ... function rg_packages_web($db, $rg, $paras, $pass)
592 819 break; break;
593 820 } }
594 821 $di = $distros[$a['distro']]; $di = $distros[$a['distro']];
822 //rg_log_debug('di: ' . print_r($di, TRUE));
595 823
596 if (strcmp($di['pkg_type'], 'rpm') != 0) {
597 rg_log('unsupported pkg repo type');
598 header($rg['proto'] . ' 404 unsupported pkg repo type');
599 echo 'unsupported pkg repo type' . "\n";
824 if (strcmp($di['pkg_type'], 'rpm') == 0) {
825 $a['major'] = preg_replace('/[^0-9]/', '', @array_shift($paras));
826 $a['arch'] = preg_replace('/[^-_0-9a-zA-Z]/', '', @array_shift($paras));
827 $a['type'] = @array_shift($paras);
828 $a['path'] = implode('/', $paras);
829
830 rg_packages_rpm_helper($db, $rg, $a);
600 831 break; break;
601 832 } }
602 833
603 $a['major'] = preg_replace('/[^0-9]/', '', @array_shift($paras));
604 $a['arch'] = preg_replace('/[^-_0-9a-zA-Z]/', '', @array_shift($paras));
605 $a['type'] = @array_shift($paras);
606 $a['path'] = implode('/', $paras);
834 if (strcmp($di['pkg_type'], 'deb') == 0) {
835 rg_log_debug('paras: ' . rg_array2string_short($paras));
836 $x = @array_shift($paras);
837 if (strcmp($x, 'dists') == 0) { // eg dists/buster/InRelease
838 $a['codename'] = @array_shift($paras); // example: 'buster'
839 } else { // eg buster/pool/main/c/a/catab+rgfs_0.1_amd64.deb
840 $a['codename'] = $x;
841 }
842 $a['path'] = implode('/', $paras);
843
844 rg_packages_deb_helper($db, $rg, $a);
845 break;
846 }
607 847
608 rg_packages_rpm_helper($db, $rg, $a);
848 rg_log('unsupported pkg repo type');
849 header($rg['proto'] . ' 404 unsupported pkg repo type');
850 echo 'unsupported pkg repo type' . "\n";
609 851 } while (0); } while (0);
610 852
611 853 rg_log_exit(); rg_log_exit();
File inc/user/packages_core.inc.php changed (mode: 100644) (index e065ce6..1c13071)
... ... function rg_pkg_prepare_for_rgfs($db, &$a)
10 10 $_r = rg_state_get($db, $k); $_r = rg_state_get($db, $k);
11 11 if ($_r !== FALSE) { if ($_r !== FALSE) {
12 12 rg_log('DEBUG: a[' . $k . '] set to ' . $_r); rg_log('DEBUG: a[' . $k . '] set to ' . $_r);
13 if (isset($a[$k]) && (strcmp($a[$k], $_r) == 0))
14 rg_internal_error('rgfs was already set!');
13 15 $a[$k] = $_r; $a[$k] = $_r;
14 16 } else { } else {
15 17 rg_log($k . ' is not defined'); rg_log($k . ' is not defined');
File inc/user/packages_deb.inc.php added (mode: 100644) (index 0000000..580521b)
1 <?php
2 require_once(__DIR__ . '/../events.inc.php');
3 require_once(__DIR__ . '/../mime.inc.php');
4 require_once(__DIR__ . '/../rgfs.inc.php');
5 require_once(__DIR__ . '/packages_core.inc.php');
6
7 /*
8 * Event functions
9 */
10 //$_f = array(
11 // 'pkg_generate_dotrepo_deb_callback' => 'rg_pkg_event_generate_dotrepo_deb_callback',
12 // 'pkg_generate_dotrepo_deb' => 'rg_pkg_event_generate_dotrepo_deb'
13 //);
14 //rg_event_register_functions($_f);
15
16 /*
17 * This is called after a push and before sendint the job to a builder
18 */
19 function rg_pkg_prepare_for_build_deb($db, &$a)
20 {
21 rg_log_enter('pkg_prepare_for_build_deb');
22
23 $ret = array('ok' => 0);
24 do {
25 $ret['ok'] = 1;
26 } while (0);
27
28 rg_log_exit();
29 return $ret;
30 }
31
32 /*
33 * Called from rg_pkg_event_build_done
34 */
35 function rg_pkg_after_build_deb($db, $ev)
36 {
37 rg_log_enter('pkg_after_build_deb');
38 rg_log_debug('ev: ' . rg_array2string_short($ev));
39
40 $ret = array('ok' => 0);
41 do {
42 // Clean not needed stuff
43 unset($ev['head']);
44 unset($ev['repo_name']); unset($ev['repo_name_allowed']);
45 unset($ev['repo_username']); unset($ev['repo_username_allowed']);
46
47 $req = $ev['job']['request'];
48 $s = $ev['status'];
49
50 $ei = rg_env_info($req['env']);
51
52 // First, we deal with user pkg repos (debs are signed with user key)
53 foreach ($req['pkg_subrepos'] as $pkg_subrepo_id => $junk) {
54 rg_log_debug('pkg_subrepo_id ' . $pkg_subrepo_id);
55
56 // Dirty repos can be the global ones only // TODO: can happen?
57 if (in_array($pkg_subrepo_id, $s['pkg_subrepo_dirty'])) {
58 rg_log_debug('subrepo is marked dirty, skip this step');
59 continue;
60 }
61
62 $sri = rg_pkg_subrepo_info($db, $req['uid'], $pkg_subrepo_id);
63 if ($sri['exists'] != 1) {
64 $ret['errmsg'] = $sri['errmsg'];
65 break;
66 }
67
68 $ri = rg_pkg_repo_info($db, $req['uid'], $sri['pkg_repo_id']);
69 if ($ri['exists'] != 1) {
70 $ret['errmsg'] = $ri['errmsg'];
71 break;
72 }
73
74 $repo_dir = '/var/lib/rocketgit/pkg_repos'
75 . '/' . $ri['id'];
76 $subrepo_dir = $repo_dir
77 . '/' . $pkg_subrepo_id;
78 $distro_dir = $ei['distro'] . '/' . $ei['codename'];
79 $dir = $subrepo_dir . '/' . $distro_dir;
80
81 $r = rg_gpg_save_public_kr($dir . '/keyring.gpg',
82 $ri['gpg_pub_key']);
83 if ($r['ok'] != 1) {
84 $ret['errmsg'] = $r['errmsg'];
85 break;
86 }
87
88 rg_log_debug('TODO job[id]=' . $ev['job']['id'] . ' req[orig_job_id]=' . $req['orig_job_id']);
89 $r = rg_packages_deb_repo_update($db, $subrepo_dir,
90 $distro_dir, $ei['codename'], $req['orig_job_id'],
91 $ev['job']['repo_id'], $req['env'], $ri, $sri);
92 if ($r['ok'] != 1) {
93 $ret['errmsg'] = $r['errmsg'];
94 break;
95 }
96
97 // Mark the environment as 'available'
98 $di = array($req['env'] => array('has_packages' => 1));
99 $r = rg_pkg_subrepo_update_distro_info($db,
100 $req['uid'], $pkg_subrepo_id, $di);
101 if ($r['ok'] != 1) {
102 $ret['errmsg'] = $r['errmsg'];
103 break;
104 }
105 }
106 if (isset($ret['errmsg']))
107 break;
108
109 if (empty($s['pkg_subrepo_dirty'])) {
110 $ret['ok'] = 1;
111 break;
112 }
113
114 // Now, we deal with pkg repositories which need .deb signing
115
116 $a = array();
117 $a['worker_must_be_global'] = 1; // for security reasons
118 $a['exec'] = array();
119 $a['source'] = 'pkg_after_build_deb';
120 $a['uid'] = 0;
121 $a['repo_id'] = $req['repo_id'];
122 $a['repo_uid'] = $req['repo_uid'];
123 $a['repo_username'] = $req['repo_username'];
124 $a['head'] = $req['head'];
125 $a['orig_job_id'] = $req['orig_job_id'];
126 $a['log_sid'] = $req['log_sid'];
127 $a['pkg_subrepo_id_list'] = $s['pkg_subrepo_dirty'];
128 $a['env'] = $req['env'];
129 $a['build_repo_id'] = $req['build_repo_id']; // this is NOT a meta repo operation like on rpm
130
131 $r = rg_pkg_prepare_for_build($db, $a);
132 if ($r['ok'] != 1) {
133 $ret['errmsg'] = $r['errmsg'];
134 break;
135 }
136
137 $ret['ok'] = 1;
138 } while (0);
139
140 rg_log_exit();
141 return $ret;
142 }
143
144 /*
145 * Helper for 'packages_deb'
146 */
147 function rg_packages_deb_helper($db, $rg, $a)
148 {
149 rg_log_enter('packages_deb_helper');
150 rg_log_debug('a: ' . print_r($a, TRUE));
151
152 do {
153 if (!empty($a['username'])) {
154 $ui = rg_user_info($db, 0, $a['username'], '');
155 if ($ui['exists'] != 1) {
156 rg_log('invalid user ' . $a['username']);
157 header($rg['proto'] . ' 404 Not found');
158 echo 'invalid user' . "\n";
159 break;
160 }
161 $uid = $ui['uid'];
162 } else {
163 $uid = 0;
164 }
165
166 // TODO: this must be in generic code; but we may be missing user?
167 $ri = rg_pkg_repo_info_by_name($db, $uid, $a['pkg_repo_name']);
168 if ($ri['exists'] != 1) {
169 rg_log('Cannot find pkg repo ' . $a['pkg_repo_name']);
170 header($rg['proto'] . ' 404 Not found');
171 echo 'invalid repo' . "\n";
172 break;
173 }
174
175 $sri = rg_pkg_subrepo_info_by_name($db, $uid,
176 $ri['id'], $a['pkg_subrepo_name']);
177 if ($sri['exists'] != 1) {
178 rg_log('Cannot find pkg subrepo ' . $a['pkg_subrepo_name']);
179 header($rg['proto'] . ' 404 Not found');
180 echo 'invalid subrepo' . "\n";
181 break;
182 }
183
184 // TODO: should be this in generic code?
185 if (!strstr($ri['flags'], 'P')) { // pkg repo is private
186 if (!rg_pkg_has_rights($db, $ri, 'A')) {
187 if (strcmp($a['sent_pass'], $ri['password']) != 0) {
188 rg_log('provided password is not correct!');
189 header($rg['proto'] . ' 404 Not found');
190 echo 'pkg repository not found or you do not'
191 . ' have access' . "\n";
192 break;
193 }
194 }
195 }
196
197 $subrepo_dir = '/var/lib/rocketgit/pkg_repos'
198 . '/' . $ri['id']
199 . '/' . $sri['id'];
200 $distro_dir = $a['distro'] . '/' . $a['codename'];
201 rg_log_debug('subrepo_dir=' . $subrepo_dir);
202 rg_log_debug('distro_dir=' . $distro_dir);
203 $dir = $subrepo_dir . '/' . $distro_dir;
204
205 if ($ri['uid'] == 0) {
206 $type_and_owner = 'main';
207 $global_and_user = 'global';
208 } else {
209 rg_pkg_repo_cosmetic($db, $ri);
210 $type_and_owner = 'user/' . $ri['owner'];
211 $global_and_user = 'user-' . $ri['owner'];
212 }
213
214 if (strcmp($a['path'], 'keyring') == 0) {
215 $f = @file_get_contents($dir . '/keyring.gpg');
216 if ($f === FALSE) {
217 rg_log('Cannot load key file: ' . rg_php_err());
218 header($rg['proto'] . ' 500 Internal server error');
219 echo 'error loading key file' . "\n";
220 break;
221 }
222 $len = strlen($f);
223 $file = 'rocketgit-' . $global_and_user . '-' . $ri['name'] . '.gpg';
224
225 header('Content-Length: ' . $len);
226 header('Content-Type: application/octet-stream');
227 header('Content-Disposition: attachment; filename="' . $file . '"'); // TODO: escape
228 echo $f;
229
230 rg_stats_conns_set('bytes_out', $len);
231 break;
232 } else if (strcmp($a['path'], 'auth') == 0) {
233 $url = rg_base_url($db, '', '')
234 . '/op/pkgrepo'
235 . '/' . $type_and_owner
236 . '/' . $ri['name'];
237 $url = str_replace('http://', '', $url);
238 $url = str_replace('https://', '', $url);
239 $f = 'machine ' . $url . ' login rg password ' . $ri['password'];
240 $len = strlen($f);
241 $file = 'rocketgit-' . $global_and_user . '-' . $ri['name'] . '.conf';
242
243 header('Content-Length: ' . $len);
244 header('Content-Type: text/plain');
245 header('Content-Disposition: attachment; filename="' . $file . '"'); // TODO: escape
246 echo $f;
247
248 rg_stats_conns_set('bytes_out', $len);
249 break;
250 }
251
252 // TODO: this function should return the size to not do an extra stat
253 $r = rg_path_validate($dir, $a['path']);
254 if ($r === FALSE) {
255 rg_security_violation_no_exit('path=' . $a['path']);
256 header($rg['proto'] . ' 404 Not found');
257 echo 'invalid file' . "\n";
258 break;
259 }
260
261 $s = @stat($dir . '/' . $a['path']);
262 if ($s === FALSE) {
263 rg_log('Cannot stat file: ' . rg_php_err());
264 header($rg['proto'] . ' 500 Internal server error');
265 echo 'missing file' . "\n";
266 break;
267 }
268
269 header('Content-Length: ' . $s['size']);
270
271 $ext = strrchr($a['path'], '.');
272 $ct = rg_content_type_by_ext($ext);
273 header('Content-Type: ' . $ct);
274 $r = @readfile($dir . '/' . $a['path']);
275
276 if ($r === FALSE) {
277 rg_log('Cannot send file: ' . rg_php_err());
278 header($rg['proto'] . ' 404 Not found');
279 echo 'missing file' . "\n";
280 break;
281 }
282
283 rg_stats_conns_set('bytes_out', $r);
284 } while (0);
285
286 rg_log_exit();
287 }
288
289 /*
290 * Builds a link to a pkg repo
291 */
292 function rg_packages_deb_get_link($db, $a)
293 {
294 //rg_log_debug('get_link: a: ' . rg_array2string($a));
295
296 $ret = array();
297
298 // Both pkg repo and subrepo names cannot contain '+' and '-'.
299
300 if ($a['pkg_repo_info']['uid'] == 0)
301 $type_and_owner = 'main';
302 else
303 $type_and_owner = 'user/' . $a['pkg_repo_info']['owner'];
304
305 $x = rg_base_url($db, '', '')
306 . '/op/pkgrepo'
307 . '/' . $type_and_owner
308 . '/' . $a['pkg_repo_info']['name']
309 . '/' . $a['pkg_subrepo_info']['name']
310 . '/' . $a['distro'];
311
312 $ret['keyring_url'] = $x . '/' . $a['codename'] . '/keyring';
313 $ret['auth_url'] = $x . '/' . $a['codename'] . '/auth';
314 $ret['repo_url'] = $x;
315 $ret['repo_codename'] = $a['codename'];
316 $ret['repo_components'] = 'main';
317
318 return $ret;
319 }
320
321 /*
322 * Instructions on how to install a package
323 * TODO: Showing the details of other packages versions has no place here!
324 */
325 function rg_packages_deb_howto($a, $user, $repo_name, $meta)
326 {
327 //rg_log_debug('packages_deb_howto: a: ' . rg_array2string_short($a));
328 //rg_log_debug('packages_deb_howto: meta: ' . rg_array2string_short($meta));
329
330 $private = !strstr($a['pkg_repo_info']['flags'], 'P');
331
332 $pkg_list = array();
333 $src_pkg_list = array();
334 $debug_pkg_list = array();
335 $other = '';
336 if ($meta !== FALSE) {
337 $other .= "\n";
338 $other .= '<details><summary>Details about all versions</summary>' . "\n";
339 $other .= '<table><tr><th>Name</th><th>Size</th><th>Head</th><th>Date (UTC)</th>';
340 if ($a['can_see_details'] == 1)
341 $other .= '<th>Job</th><th>Worker</th><th>Copies</th>';
342 $other .= '</tr>' . "\n";
343 foreach ($meta as $f => $i) {
344 $other .= '<tr><td>' . rg_xss_safe($f) . '</td>'
345 . '<td>' . $i['size_nice'] . '</td>';
346
347 $other .= '<td>' . $i['head_link'] . '</td>'
348 . '<td>' . gmdate('Y-m-d H:i', $i['ctime']) . '</td>';
349
350 if ($a['can_see_details'] == 1)
351 $other .= '<td>' . rg_xss_safe($i['job_id']) . '</td>'
352 . '<td>' . rg_xss_safe($i['worker_name']) . '</td>'
353 . '<td>' . $i['nlink'] . '</td>';
354
355 $other .= '</tr>' . "\n";
356
357 if (isset($i['source_pkg_name'])) {
358 $src_pkg_list[] = array('name' => $i['source_pkg_name']);
359 } else if (isset($i['real_pkg_name'])) {
360 $last7 = substr($i['real_pkg_name'], -7);
361 if (strcmp($last7, '-dbgsym') == 0)
362 $debug_pkg_list[] = array('name' => $i['real_pkg_name']);
363 else
364 $pkg_list[] = array('name' => $i['real_pkg_name']);
365 }
366 }
367 $other .= '</table>';
368 $other .= '</details>';
369 }
370
371 $rg = array();
372
373 $global_and_user = ($a['pkg_repo_info']['uid'] == 0) ? '' : ('user-' . $user . '-');
374
375 // Seems I cannot use '+' (.list file is ignored)
376 $a['list_file'] = $global_and_user
377 . $a['pkg_repo_info']['name']
378 . '-' . $a['pkg_subrepo_info']['name'];
379 $a['auth_file'] = $global_and_user . $a['pkg_repo_info']['name'];
380 $a['gpg_file'] = $global_and_user . $a['pkg_repo_info']['name'];
381 $a['user'] = $user;
382 $a['repo_name'] = $repo_name;
383 $a['cmd'] = 'apt install'; // TODO: move this in distro array!
384 $a['src_cmd'] = 'apt source'; // TODO: move this in distro array!
385 $a['HTML:other'] = $other;
386 $rg['pkg'] = $a;
387
388 $rg['HTML:pkg_list'] = rg_template_table('user/pkg/deb/pkg_list', $pkg_list, $rg);
389 $rg['HTML:src_pkg_list'] = rg_template_table('user/pkg/deb/src_pkg_list',
390 $src_pkg_list, $rg);
391 $rg['HTML:debug_pkg_list'] = rg_template_table('user/pkg/deb/debug_pkg_list',
392 $debug_pkg_list, $rg);
393
394 $howto = rg_template('user/pkg/deb/add_repo_howto.html', $rg, TRUE /*xss*/);
395 $rg['HTML:add_repo_howto'] = trim($howto);
396
397 if ($private) {
398 // We cannot do it like with the private pkg repo.
399 // We do not want to put the password on the screen.
400 return rg_template('user/pkg/deb/priv_download.html',
401 $rg, TRUE /*xss*/);
402 } else {
403 return rg_template('user/pkg/deb/pub_download.html',
404 $rg, TRUE /*xss*/);
405 }
406 }
407
408 /*
409 * Saves a debian file
410 */
411 // TODO - do we need to sort it?
412 function rg_deb_save($dst, $a)
413 {
414 rg_log_enter('deb_save: dst=' . $dst);
415
416 $ret = array('ok' => 0);
417 do {
418 $c = '';
419 $add_pi = '';
420 foreach ($a as $pkg => $pi) {
421 $c .= $add_pi;
422 foreach ($pi as $k => $v) {
423 //rg_log_debug('k ' . $k . ' v:' . print_r($v, TRUE));
424 $c .= $k . ':';
425 if (is_array($v)) {
426 $add = ' ';
427 foreach ($v as $line) {
428 if (!empty($line))
429 $c .= $add . $line;
430 $add = "\n" . ' ';
431 }
432 } else {
433 $c .= ' ' . $v;
434 }
435 $c .= "\n";
436 }
437
438 $add_pi = "\n";
439 }
440
441 $r = @file_put_contents($dst, $c);
442 if ($r === FALSE) {
443 $ret['errmsg'] = 'cannot save';
444 break;
445 }
446
447 $ret['size'] = strlen($c);
448 $ret['sha256'] = hash('sha256', $c);
449 $ret['ok'] = 1;
450 } while (0);
451
452 rg_log_exit();
453 return $ret;
454 }
455
456 /*
457 * Loads a debian 'key: value file
458 */
459 function rg_deb_load($f)
460 {
461 $ret = array('ok' => 0, 'c' => array());
462 do {
463 $c = @file_get_contents($f);
464 if ($c === FALSE) {
465 $ret['errmsg'] = 'cannot load file';
466 break;
467 }
468
469 $e = explode("\n", $c);
470 foreach ($e as $line) {
471 if (empty($line))
472 continue;
473
474 if (strncmp($line, ' ', 1) == 0) { // continuation
475 if (!is_array($ret['c'][$prev_k]))
476 $ret['c'][$prev_k] = array($ret['c'][$prev_k]);
477 $ret['c'][$prev_k][] = substr($line, 1);
478 continue;
479 }
480 $p = explode(':', $line, 2);
481 if (!isset($p[1])) {
482 rg_log_debug(' line without : [' . $line . ']');
483 continue;
484 }
485 $k = rtrim($p[0]);
486 $ret['c'][$k] = ltrim($p[1]);
487 $prev_k = $k;
488 }
489
490 $ret['ok'] = 1;
491 } while (0);
492
493 return $ret;
494 }
495
496 /*
497 * Creates/updates a Debian repository subdir (source, binary-amd64 etc.)
498 * ri and sri seems to not be used!
499 */
500 function rg_packages_deb_repo_update_subdir($subrepo_dir, $distro_dir,
501 $subdir, $codename, $job_id, $repo_id, $env)
502 {
503 rg_log_enter('packages_deb_repo_update_subdir: job_id=' . $job_id
504 . ' subdir=' . $subdir);
505
506 $ret = array('ok' => 0, 'files_changed' => array());
507 do {
508 rg_log_debug('subrepo_dir=' . $subrepo_dir);
509 rg_log_debug('distro_dir=' . $distro_dir);
510
511 $dir = $subrepo_dir . '/' . $distro_dir;
512
513 $s = $dir . '/main/' . $subdir;
514 $pool = $dir . '/pool/main';
515 $jd = $s . '/+pending/' . $job_id;
516
517 // Check +pending dir and integrate it
518 if (!is_dir($s . '/+pending/' . $job_id)) {
519 rg_log_debug('+pending dir not found');
520 $ret['ok'] = 1;
521 break;
522 }
523
524 // Creating Release file
525 // We regenerate it any time to generate the hash
526 $f = $s . '/Release';
527 $arch = str_replace('binary-', '', $subdir);
528
529 $c = ''
530 . 'Archive: stable' . "\n"
531 . 'Origin: RocketGit' . "\n"
532 . 'Label: RocketGit' . "\n"
533 . 'Version: 1' . "\n"
534 . 'Component: main' . "\n"
535 . 'Architecture: ' . $arch . "\n";
536 $r = rg_save_plain($f, $c);
537 if ($r === FALSE) {
538 $ret['errmsg'] = 'cannot save Release file';
539 break;
540 }
541
542 $k = $subdir . '/Release';
543 $ret['files_changed'][$k] = array(
544 'sha256' => hash('sha256', $c),
545 'size' => strlen($c)
546 );
547
548 // list.json is used to keep the information about the packages
549 // to be able to generate Sources/Packages files.
550 if (file_exists($s . '/list.json')) {
551 $r = @file_get_contents($s . '/list.json');
552 if ($r === FALSE) {
553 $ret['errmsg'] = 'cannot load list.json';
554 break;
555 }
556 $list = @json_decode($r, TRUE, 20);
557 if (empty($list)) {
558 $ret['errmsg'] = 'error loading json';
559 break;
560 }
561 } else {
562 $list = array();
563 }
564
565 if (strcmp($subdir, 'source') == 0) {
566 // Info is loaded from .dsc files
567 $si = $s . '/Sources';
568 $si_short = $subdir . '/Sources';
569 $ext = '.*\.dsc$';
570 } else {
571 $si = $s . '/Packages';
572 $si_short = $subdir . '/Packages';
573 $ext = '.*\.deb$';
574 }
575
576 $to_add_remove = array();
577 $to_delete = array();
578
579 $r = rg_dir_load_pattern($jd, $ext);
580 if ($r === FALSE) {
581 $ret['errmsg'] = 'cannot load +pending/job_id files';
582 break;
583 }
584 //rg_log_debug('files matching [' . $ext . ']: ' . print_r($r, TRUE));
585
586 foreach ($r as $f) {
587 rg_log_debug('f: ' . $f);
588
589 $u1 = substr($f, 0, 1);
590 $u2 = substr($f, 1, 1);
591 $d = $pool . '/' . $u1 . '/' . $u2;
592
593 // Loading control file
594 if (strcmp($subdir, 'source') == 0) {
595 $r = rg_deb_load($jd . '/' . $f);
596 } else {
597 $r = rg_deb_load($jd . '/' . $f . 'c'); // .debc file
598
599 $to_add_remove[] = array(
600 'root' => $subrepo_dir,
601 'del' => rg_dir_cut($jd, $subrepo_dir) . '/' . $f . 'c',
602 'repo_id' => $repo_id);
603 }
604 if ($r['ok'] != 1) {
605 $ret['errmsg'] = 'cannot load control file for ' . $f;
606 continue;
607 }
608 $c = $r['c'];
609 //rg_log_debug('loaded control file: ' . print_r($c, TRUE));
610
611 // Unset some old things
612 unset($c['Checksums-Sha1']);
613
614 $a = array();
615 $meta = array('env' => $env);
616 if (strcmp($subdir, 'source') == 0) {
617 $a['Package'] = $c['Source'];
618 $a['Directory'] = $codename . '/pool/main/' . $u1 . '/' . $u2;
619 } else {
620 $a['Package'] = $c['Package'];
621 $a['Filename'] = $codename . '/pool/main/' . $u1 . '/' . $u2 . '/' . $f;
622 $meta['real_pkg_name'] = $c['Package']; // this is used in 'apt instal ...'
623 }
624
625 $l = array('Version', 'Maintainer',
626 'Architecture', 'Description',
627 'Homepage', 'Section', 'Priority');
628
629 // TODO: Description: is missing from force-bind, but in Sources-big it exists.
630 if (strcmp($subdir, 'source') == 0) {
631 $l[] = 'Binary';
632 $l[] = 'Build-Depends';
633 $l[] = 'Standards-Version';
634 $l[] = 'Format';
635 $l[] = 'Files';
636 $l[] = 'Vcs-Browser';
637 $l[] = 'Vcs-Git';
638 $l[] = 'Checksums-Sha256';
639
640 foreach ($l as $k)
641 if (isset($c[$k]))
642 $a[$k] = $c[$k];
643
644 $a['Priority'] = 'source';
645
646 // Add .dsc file to the 'Sources' file (sh256)
647 $r = rg_hash_load('sha256', $jd . '/' . $f);
648 if ($r['ok'] != 1) {
649 $ret['errmsg'] = $r['errmsg'];
650 break;
651 }
652 $a['Checksums-Sha256'][] = $r['hash'] . ' ' . $r['size'] . ' ' . $f;
653
654 // We must move all listed files (before adding .dsc file)
655 foreach ($a['Checksums-Sha256'] as $_line) {
656 $_line = trim($_line);
657 if (empty($_line))
658 continue;
659
660 $meta2 = $meta;
661 $_ext = substr($_line, -4);
662 if (strcmp($_ext, '.dsc') == 0)
663 $meta2['source_pkg_name'] = $a['Package'];
664
665 $_x = explode(' ', $_line, 3);
666 $to_add_remove[] = array(
667 'root' => $subrepo_dir,
668 'del' => rg_dir_cut($jd, $subrepo_dir) . '/' . $_x[2],
669 'add' => rg_dir_cut($d, $subrepo_dir) . '/' . $_x[2],
670 'repo_id' => $repo_id,
671 'meta' => $meta2);
672 }
673
674 // Add .dsc file to the 'Sources' file (md5)
675 $r = rg_hash_load('md5', $jd . '/' . $f);
676 if ($r['ok'] != 1) {
677 $ret['errmsg'] = $r['errmsg'];
678 break;
679 }
680 $a['Files'][] = $r['hash'] . ' ' . $r['size'] . ' ' . $f;
681 } else {
682 $l[] = 'Source';
683 $l[] = 'Depends';
684 $l[] = 'Pre-Depends';
685 $l[] = 'Installed-Size';
686 $l[] = 'Multi-Arch';
687
688 foreach ($l as $k)
689 if (isset($c[$k]))
690 $a[$k] = $c[$k];
691
692 $r = rg_hash_load('sha256', $jd . '/' . $f);
693 if ($r['ok'] != 1) {
694 $ret['errmsg'] = $r['errmsg'];
695 break;
696 }
697 $a['SHA256'] = $r['hash'];
698 $a['Size'] = $r['size'];
699
700 $to_add_remove[] = array(
701 'repo_id' => $repo_id,
702 'root' => $subrepo_dir,
703 'del' => rg_dir_cut($jd, $subrepo_dir) . '/' . $f,
704 'add' => rg_dir_cut($d, $subrepo_dir) . '/' . $f,
705 'meta' => $meta);
706 }
707
708 $list[$f] = $a;
709 }
710 if (isset($ret['errmsg']))
711 break;
712
713 $to_delete[] = $jd;
714
715 if (!empty($list)) {
716 rg_log_debug('saving list: ' . print_r($list, TRUE));
717 $r = @rg_save($s . '/list.json', $list);
718 if ($r === FALSE) {
719 $ret['errmsg'] = 'canot save list.json';
720 break;
721 }
722 }
723
724 // TODO: if we rename it and something crashes, we cannot recover: suffix c is present, but the deb not
725 $r = rg_rgfs_add_remove($subrepo_dir, $to_add_remove, TRUE /*exec*/);
726 if ($r['ok'] != 1) {
727 $ret['errmsg'] = $r['errmsg'];
728 break;
729 }
730
731 $r = rg_deb_save($si, $list);
732 if ($r['ok'] != 1) {
733 $ret['errmsg'] = $r['errmsg'];
734 break;
735 }
736 $ret['files_changed'][$si_short] = array(
737 'sha256' => $r['sha256'],
738 'size' => $r['size']
739 );
740
741 $r = rg_xz_compress($si, '--keep --force -6 --quiet'); // TODO: should we generate also the sha256?
742 if ($r['ok'] != 1) {
743 $ret['errmsg'] = $r['errmsg'];
744 break;
745 }
746 $r = rg_hash_load('sha256', $si . '.xz');
747 if ($r['ok'] != 1) {
748 $ret['errmsg'] = $r['errmsg'];
749 break;
750 }
751 $ret['files_changed'][$si_short . '.xz'] = array(
752 'sha256' => $r['hash'],
753 'size' => $r['size']
754 );
755
756 foreach ($to_delete as $i)
757 rg_del_tree($i);
758
759 $ret['ok'] = 1;
760 } while (0);
761 isset($ret['errmsg']) && rg_log_debug('ERROR: ' . $ret['errmsg']);
762
763 rg_log_exit();
764 return $ret;
765 }
766
767 /*
768 * Create InRelease(.xz) file(s)
769 */
770 function rg_packages_deb_create_inrelease($dir, $codename, $ri, $archs,
771 $files_changed)
772 {
773 rg_log_enter('packages_deb_create_inrelease');
774 rg_log_debug('files_changed: ' . print_r($files_changed, TRUE));
775
776 $ret = array('ok' => 0);
777 do {
778 // Loading info about files, if exists
779 $files = array();
780 while (file_exists($dir . '/InRelease.json')) {
781 if (empty($files_changed)) {
782 rg_log_debug('no file changed, skip');
783 $ret['ok'] = 1;
784 break;
785 }
786
787 $c = @file_get_contents($dir . '/InRelease.json');
788 if ($c !== FALSE) {
789 $files = @json_decode($c, TRUE, 20);
790 if (!empty($files))
791 break;
792 }
793
794 // We need to reload it
795 $subdirs = array('.');
796 foreach ($archs as $a) {
797 if (strcmp($a, 'source') == 0) {
798 $subdirs[] = 'source';
799 continue;
800 }
801
802 $subdirs[] = 'binary-' . $a;
803 }
804
805 foreach ($subdirs as $subdir) {
806 $d = $dir . '/main/' . $subdir;
807
808 $r = rg_dir_load_pattern($d, '(Packages|Sources)(\.xz)?$');
809 if ($r === FALSE) {
810 $ret['errmsg'] = 'cannot load subdir ' . $d;
811 break;
812 }
813
814 foreach ($r as $f) {
815 rg_log_debug($subdir . ' file ' . $f);
816
817 $r = rg_hash_load('sha256', $d . '/' . $f);
818 if ($r['ok'] != 1) {
819 $ret['errmsg'] = $r['errmsg'];
820 break;
821 }
822
823 $k = $subdir . '/' . $f;
824 $files[$k] = array(
825 'size' => $r['size'],
826 'sha256' => $r['hash']
827 );
828 }
829 if (isset($ret['errmsg']))
830 break;
831 }
832 break;
833 }
834 if (isset($ret['errmsg']))
835 break;
836
837 $files = rg_array_merge($files, '', $files_changed);
838 //rg_log_debug('files final: ' . print_r($files, TRUE));
839
840 $r = rg_save($dir . '/InRelease.json', $files);
841 if ($r === FALSE) {
842 $ret['errmsg'] = 'cannot save json file';
843 break;
844 }
845
846 $archs_without_source = $archs;
847 unset($archs_without_source['source']);
848
849 $out = ''
850 . 'Origin: Debian' . "\n"
851 . 'Label: Debian' . "\n"
852 . 'Suite: stable' . "\n"
853 . 'Version: 11.1' . "\n"
854 . 'Codename: ' . $codename . "\n"
855 // . '#Changelogs: https://metadata.ftp-master.debian.org/changelogs/@CHANGEPATH@_changelog' . "\n"
856 . 'Date: ' . gmdate(DATE_RFC2822) . "\n"
857 // . '#Acquire-By-Hash: no' . "\n"
858 . 'No-Support-for-Architecture-all: Packages' . "\n" // TODO: What is this?
859 . 'Architectures: ' . implode(' ', $archs_without_source) . "\n"
860 . 'Components: main' . "\n"
861 . 'Description: Debian repo at RocketGit' . "\n"
862 . 'SHA256:' . "\n";
863
864 foreach ($files as $file => $i)
865 $out .= ' ' . $i['sha256'] . ' '
866 . str_pad($i['size'], 12, ' ', STR_PAD_LEFT)
867 . ' main/' . $file . "\n";
868
869 $r = rg_save_plain($dir . '/InRelease.pre_sign', $out);
870 if ($r === FALSE) {
871 $ret['errmsg'] = 'cannot save InRelease.pre_sign file';
872 break;
873 }
874
875 $r = rg_gpg_sign($dir . '/InRelease', $dir . '/InRelease.pre_sign',
876 $ri['gpg_priv_key'], '--clear-sign');
877 if ($r['ok'] != 1) {
878 rg_log('Cannot sign InRelease file: ' . $r['errmsg']);
879 break;
880 }
881
882 @unlink($dir . '/InRelease.pre_sign');
883
884 $ret['ok'] = 1;
885 } while (0);
886
887 rg_log_exit();
888 return $ret;
889 }
890
891 /*
892 * Creates/updates a Debian repository
893 */
894 function rg_packages_deb_repo_update($db, $subrepo_dir, $distro_dir, $codename,
895 $job_id, $repo_id, $env, $ri, $sri)
896 {
897 rg_log_enter('packages_deb_repo_update: job_id=' . $job_id);
898
899 $ret = array('ok' => 0);
900 do {
901 $dir = $subrepo_dir . '/' . $distro_dir;
902
903 $files_changed = array();
904
905 // Locking TODO
906
907 // Gather architectures
908 $subdirs = rg_dir_load_pattern($dir . '/main', '^binary-.*');
909 if ($subdirs === FALSE) {
910 $ret['errmsg'] = 'cannot load subdirs';
911 break;
912 }
913 $subdirs[] = 'source';
914 //rg_log_debug('subdirs final: ' . print_r($subdirs, TRUE));
915
916 $archs = array();
917 foreach ($subdirs as $subdir) {
918 if (!is_dir($dir . '/main/' . $subdir)) {
919 rg_log_debug($subdir . ' does not exists; ignore it');
920 continue;
921 }
922
923 $archs[] = str_replace('binary-', '', $subdir);
924
925 $r = rg_packages_deb_repo_update_subdir($subrepo_dir,
926 $distro_dir, $subdir, $codename, $job_id,
927 $repo_id, $env);
928 if ($r['ok'] != 1) {
929 $ret['errmsg'] = $r['errmsg'];
930 break;
931 }
932 if (!empty($r['files_changed']))
933 $files_changed = rg_array_merge($files_changed,
934 '', $r['files_changed']);
935 }
936 if (isset($ret['errmsg']))
937 break;
938
939 // Create main/i18n/Translation-en.xz
940
941 $r = rg_packages_deb_create_inrelease($dir, $codename,
942 $ri, $archs, $files_changed);
943 if ($r['ok'] != 1) {
944 $ret['errmsg'] = $r['errmsg'];
945 break;
946 }
947
948 $ret['ok'] = 1;
949 } while (0);
950
951 rg_log_exit();
952 return $ret;
953 }
File inc/user/packages_rpm.inc.php changed (mode: 100644) (index 803219f..cdf24bc)
... ... require_once(__DIR__ . '/packages_core.inc.php');
7 7 * Event functions * Event functions
8 8 */ */
9 9 $_f = array( $_f = array(
10 'pkg_generate_dotrepo_rpm_callback' => 'rg_pkg_event_generate_dotrepo_rpm_callback',
11 10 'pkg_generate_dotrepo_rpm' => 'rg_pkg_event_generate_dotrepo_rpm' 'pkg_generate_dotrepo_rpm' => 'rg_pkg_event_generate_dotrepo_rpm'
12 11 ); );
13 12 rg_event_register_functions($_f); rg_event_register_functions($_f);
14 13
15 14 /* /*
16 * Called when a dotrepo was done
17 * TODO: what happens when there is an error building the dotrepo?
15 * This is called after a push and before sendint the job to a builder
18 16 */ */
19 function rg_pkg_event_generate_dotrepo_rpm_callback($db, $ev)
17 function rg_pkg_prepare_for_build_rpm($db, &$a)
20 18 { {
21 rg_log_enter('pkg_event_generate_dotrepo_rpm_callback');
22 //rg_log_debug('req: ' . rg_array2string($ev['job']['request']));
19 rg_log_enter('pkg_prepare_for_build_rpm');
23 20
24 $ret = FALSE;
21 $ret = array('ok' => 0);
25 22 do { do {
26 $req = $ev['job']['request'];
27
28 $err = FALSE;
29 foreach ($req['rpm_repo_files'] as $pkg_subrepo_id => $junk) {
30 $sri = $req['pkg_subrepos'][$pkg_subrepo_id];
31 $ver = $sri['version'];
32 $di = array($req['env'] => array('dotrepo' => $ver));
33 $r = rg_pkg_subrepo_update_distro_info($db,
34 $req['uid'], $pkg_subrepo_id, $di);
35 if ($r['ok'] != 1) {
36 $err = TRUE;
37 break;
38 }
39 }
40 if ($err)
23 $r = rg_pkg_prepare_for_dotrepo($db, $a);
24 if ($r['ok'] != 1) {
25 $ret['errmsg'] = $r['errmsg'];
41 26 break; break;
42
43 $ret = array();
44
45 $s = $ev['status'];
46 //rg_log_debug('status: ' . rg_array2string($s));
47 if (!empty($s['pkg_subrepo_dirty'])) {
48 rg_log_debug('trigger ev pkg_subrepo_regenerate');
49 $a = array(
50 'category' => 'pkg_subrepo_regenerate',
51 'prio' => 100,
52 'uid' => 0,
53 'repo_id' => $req['repo_id'],
54 'repo_username' => $req['repo_username'],
55 'head' => $req['head'],
56 'orig_job_id' => $ev['job']['id'],
57 'log_sid' => $req['log_sid'],
58 'pkg_subrepo_id_list' => $s['pkg_subrepo_dirty'],
59 'env' => $req['env']
60 );
61 $ret[] = $a;
62 27 } }
28
29 $ret['ok'] = 1;
63 30 } while (0); } while (0);
64 31
65 32 rg_log_exit(); rg_log_exit();
 
... ... function rg_pkg_event_generate_dotrepo_rpm_callback($db, $ev)
68 35
69 36 /* /*
70 37 * Prepares 'ev' for dotrepo building. * Prepares 'ev' for dotrepo building.
71 * Helper for rg_pkg_subrepo_event_regenerate and
72 * rg_pkg_event_generate_dotrepo_rpm.
73 * TODO: add a generic function which will call this function for rpm.
74 38 */ */
75 39 function rg_pkg_prepare_for_dotrepo($db, &$ev) function rg_pkg_prepare_for_dotrepo($db, &$ev)
76 40 { {
77 41 rg_log_enter('pkg_prepare_for_dotrepo'); rg_log_enter('pkg_prepare_for_dotrepo');
42 rg_log_debug('TODO: check if distro_info is passed here, to remove it below');
43 rg_log_debug('ev: ' . print_r($ev, TRUE));
78 44
79 45 $ret = array('ok' => 0); $ret = array('ok' => 0);
80 46 do { do {
 
... ... function rg_pkg_prepare_for_dotrepo($db, &$ev)
83 49 $ret['errmsg'] = $r['errmsg']; $ret['errmsg'] = $r['errmsg'];
84 50 break; break;
85 51 } }
86 rg_log_debug('tree: ' . print_r($r['tree'], TRUE));
52 //rg_log_debug('tree: ' . print_r($r['tree'], TRUE));
87 53
88 54 if (!rg_envs_tree_is_enabled($r['tree'], $ev['env'])) { if (!rg_envs_tree_is_enabled($r['tree'], $ev['env'])) {
89 55 rg_log_debug('env ' . $ev['env'] . ' is not enabled in rg_envs_tree!'); rg_log_debug('env ' . $ev['env'] . ' is not enabled in rg_envs_tree!');
 
... ... function rg_pkg_prepare_for_dotrepo($db, &$ev)
91 57 break; break;
92 58 } }
93 59
94 $ti = rg_envs_tree_info($r['tree'], $ev['env']);
95 if (strcmp($ti['pkg_type'], 'rpm') != 0) {
96 $ret['ok'] = 1;
97 break;
98 }
99
100 60 rg_log_debug('adding rpm_repo_files...'); rg_log_debug('adding rpm_repo_files...');
101 61 $files = array(); $files = array();
102 62 foreach ($ev['pkg_maps'] as $mi) { foreach ($ev['pkg_maps'] as $mi) {
 
... ... function rg_pkg_prepare_for_dotrepo($db, &$ev)
105 65 $pkg_repo_id = $sri['pkg_repo_id']; $pkg_repo_id = $sri['pkg_repo_id'];
106 66
107 67 $ri = $ev['pkg_repos'][$pkg_repo_id]; $ri = $ev['pkg_repos'][$pkg_repo_id];
108 //rg_log_debug('ri: ' . rg_array2string($ri));
109 68 if ($ev['uid'] != $ri['uid']) { if ($ev['uid'] != $ri['uid']) {
110 69 rg_log_debug('we cannot build this' rg_log_debug('we cannot build this'
111 70 . ' dotrepo because pkg_repo_uid(' . $ri['uid'] . ' dotrepo because pkg_repo_uid(' . $ri['uid']
 
... ... function rg_pkg_prepare_for_dotrepo($db, &$ev)
124 83 } }
125 84 } }
126 85
127 // TODO: replace $di (used above) with below $d?
128 $di = rg_env_info($ev['env']);
129
86 $ei = rg_env_info($ev['env']);
130 87 $r = rg_packages_rpm_add_dotrepo_files($db, $ev['uid'], $r = rg_packages_rpm_add_dotrepo_files($db, $ev['uid'],
131 $pkg_subrepo_id, $di['distro']);
88 $pkg_subrepo_id, $ei['distro']);
132 89 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
133 90 $ret['errmsg'] = $r['errmsg']; $ret['errmsg'] = $r['errmsg'];
134 91 break; break;
 
... ... function rg_pkg_prepare_for_dotrepo($db, &$ev)
138 95 } }
139 96 $ev['rpm_repo_files'] = $files; $ev['rpm_repo_files'] = $files;
140 97
141 $ev['event_callbacks'] = array('pkg_generate_dotrepo_rpm_callback');
142
143 $ev['exec']['prepare_rpms'] = 1;
144 $ev['exec']['copy_to_rgfs'] = 1;
98 $ev['exec']['prepare_pkgs'] = 1;
145 99
146 100 $ret['ok'] = 1; $ret['ok'] = 1;
147 101 } while (0); } while (0);
 
... ... function rg_pkg_prepare_for_dotrepo($db, &$ev)
151 105 } }
152 106
153 107 /* /*
154 * This is called when a (sub)repo is created/updated to generate the dotrepo rpm.
155 * It is also called when the first package is added to a pkg subrepo.
108 * This is called when a (sub)repo is created/updated to generate the dotrepo rpm
109 * (pkg_subrepo_event_edit).
110 * TODO: this duplicates some code with build_send_one/rg_pkg_prepare_for_build
156 111 */ */
157 112 function rg_pkg_event_generate_dotrepo_rpm($db, $ev) function rg_pkg_event_generate_dotrepo_rpm($db, $ev)
158 113 { {
159 114 rg_log_enter('pkg_event_generate_dotrepo_rpm'); rg_log_enter('pkg_event_generate_dotrepo_rpm');
160 rg_log_debug('ev: ' . rg_array2string($ev));
115 rg_log_debug('ev: ' . rg_array2string_short($ev));
116 rg_log_debug('TODO: is repo_uid still defined?');
161 117
162 118 $ret = FALSE; $ret = FALSE;
163 119 do { do {
164 // Clean not needed stuff
165 unset($ev['head']);
166 unset($ev['repo_id']);
167 unset($ev['repo_username']);
168
169 120 $ev['exec'] = array(); $ev['exec'] = array();
121
170 122 // For security: we do not want to allow a malformed repo. // For security: we do not want to allow a malformed repo.
171 123 $ev['worker_must_be_global'] = 1; $ev['worker_must_be_global'] = 1;
172 124
173 $ev['pkg_maps'] = array();
174 $ev['pkg_repos'] = array();
175 $ev['pkg_subrepos'] = array();
125 $ev['build_repo_id'] = 0;
176 126
177 $pkg_subrepo_id = $ev['pkg_subrepo_id'];
178 $sri = rg_pkg_subrepo_info($db, $ev['uid'], $pkg_subrepo_id);
179 if ($sri['ok'] != 1)
127 $r = rg_pkg_prepare_for_build($db, $ev);
128 if ($r['ok'] != 1) {
129 rg_log('Error: ' . $r['errmsg']);
130 $ret = FALSE;
180 131 break; break;
181 $ev['pkg_subrepos'][$pkg_subrepo_id] = $sri;
132 }
182 133
183 $pkg_repo_id = $sri['pkg_repo_id'];
184 $ri = rg_pkg_repo_info($db, $ev['uid'], $pkg_repo_id);
185 if ($ri['ok'] != 1)
186 break;
187 $ev['pkg_repos'][$pkg_repo_id] = $ri;
134 $ret = array();
135 } while (0);
188 136
189 // Fake pkg_maps
190 $ev['pkg_maps'][] = array(
191 'pkg_subrepo_id' => $pkg_subrepo_id,
192 'flags' => ''
193 );
137 rg_log_exit();
138 return $ret;
139 }
194 140
195 rg_pkg_prepare_for_rgfs($db, $ev);
141 /*
142 * This is called after a job is done
143 */
144 function rg_pkg_after_build_rpm($db, $ev)
145 {
146 rg_log_enter('pkg_after_build_rpm');
196 147
197 $r = rg_pkg_prepare_for_dotrepo($db, $ev);
198 if ($r['ok'] != 1) {
199 rg_log('Cannot prepare ev: ' . $r['errmsg']);
148 $ret = array('ok' => 0);
149 do {
150 $req = $ev['job']['request'];
151
152 foreach ($req['rpm_repo_files'] as $pkg_subrepo_id => $junk) {
153 $sri = $req['pkg_subrepos'][$pkg_subrepo_id]; // TODO: should we trust these or we should reload them?
154 $ver = $sri['version'];
155 $di = array($req['env'] => array('dotrepo' => $ver));
156 $r = rg_pkg_subrepo_update_distro_info($db,
157 $req['uid'], $pkg_subrepo_id, $di);
158 if ($r['ok'] != 1) {
159 $ret['errmsg'] = $r['errmsg'];
160 break;
161 }
162 }
163
164 $s = $ev['status'];
165 //rg_log_debug('status: ' . rg_array2string_short($s));
166 if (empty($s['pkg_subrepo_dirty'])) {
167 $ret['ok'] = 1;
200 168 break; break;
201 169 } }
202 170
203 // Prio is 2 less than normal (10)
204 $r = rg_builder_add($db, 0 /*repo_id*/, 8 /*prio*/, $ev);
171 $a = array();
172 $a['worker_must_be_global'] = 1; // for security reasons
173 $a['exec'] = array();
174 $a['source'] = 'pkg_after_build_rpm';
175 $a['uid'] = 0;
176 $a['repo_id'] = $req['repo_id'];
177 $a['repo_uid'] = $req['repo_uid'];
178 $a['repo_username'] = $req['repo_username'];
179 $a['head'] = $req['head'];
180 $a['orig_job_id'] = $req['orig_job_id'];
181 $a['log_sid'] = $req['log_sid'];
182 $a['pkg_subrepo_id_list'] = $s['pkg_subrepo_dirty'];
183 $a['env'] = $req['env'];
184 $a['build_repo_id'] = 0; // this is meta repo operation
185
186 $r = rg_pkg_prepare_for_build($db, $a);
205 187 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
206 rg_log('Cannot add builder job: ' . $r['errmsg']);
207 $ret = FALSE;
188 $ret['errmsg'] = $r['errmsg'];
208 189 break; break;
209 190 } }
210 191
211 $ret = array();
192 $ret['ok'] = 1;
212 193 } while (0); } while (0);
213 194
214 195 rg_log_exit(); rg_log_exit();
 
... ... function rg_packages_rpm_helper($db, $rg, $a)
331 312
332 313 // TODO: should be this in generic code? // TODO: should be this in generic code?
333 314 if (!strstr($ri['flags'], 'P')) { // pkg repo is private if (!strstr($ri['flags'], 'P')) { // pkg repo is private
334 if (!rg_pkg_has_rights($db, $ri, $rg, 'A')) {
315 if (!rg_pkg_has_rights($db, $ri, 'A')) {
335 316 if (strcmp($a['sent_pass'], $ri['password']) != 0) { if (strcmp($a['sent_pass'], $ri['password']) != 0) {
336 317 rg_log('provided password is not correct!'); rg_log('provided password is not correct!');
337 318 header($rg['proto'] . ' 404 Not found'); header($rg['proto'] . ' 404 Not found');
 
... ... function rg_packages_rpm_helper($db, $rg, $a)
390 371 */ */
391 372 function rg_packages_rpm_get_link($db, $a) function rg_packages_rpm_get_link($db, $a)
392 373 { {
393 //rg_log_debug('get_link: a: ' . rg_array2string($a));
374 //rg_log_debug('get_link: a: ' . rg_array2string_short($a));
375 //rg_log_debug('get_link: a: ' . print_r($a, TRUE));
394 376
395 377 $ret = array(); $ret = array();
396 378
397 379 // Both pkg repo and subrepo names cannot contain '+' and '-'. // Both pkg repo and subrepo names cannot contain '+' and '-'.
398 380
399 381 if ($a['pkg_repo_info']['uid'] == 0) { if ($a['pkg_repo_info']['uid'] == 0) {
400 $type_and_username = 'main';
401 $username = '';
382 $type_and_owner = 'main';
383 $owner = '';
402 384 } else { } else {
403 $type_and_username = 'user/' . $a['pkg_repo_info']['username'];
404 $username = $a['pkg_repo_info']['username'] . '-';
385 $type_and_owner = 'user/' . $a['pkg_repo_info']['owner'];
386 $owner = $a['pkg_repo_info']['owner'] . '-';
405 387 } }
406 388
407 $ret['dotrepo_pkg_name'] = 'rocketgit-' . $username
389 $env = $a['env'];
390 $di = $a['pkg_subrepo_info']['distro_info'][$env];
391
392 $ret['dotrepo_pkg_name'] = 'rocketgit-' . $owner
408 393 . $a['pkg_repo_info']['name'] . $a['pkg_repo_info']['name']
409 394 . '-' . $a['pkg_subrepo_info']['name'] . '-' . $a['pkg_subrepo_info']['name']
410 . '-' . $a['pkg_repo_info']['version'] . '.' . $a['dotrepo']
395 . '-' . $a['pkg_repo_info']['version'] . '.' . $di['dotrepo']
411 396 . '-1.noarch.rpm'; . '-1.noarch.rpm';
412 397
413 398 $ret['dotrepo_pkg_url'] = rg_base_url($db, '', '') $ret['dotrepo_pkg_url'] = rg_base_url($db, '', '')
414 399 . '/op/pkgrepo' . '/op/pkgrepo'
415 . '/' . $type_and_username
400 . '/' . $type_and_owner
416 401 . '/' . $a['pkg_repo_info']['name'] . '/' . $a['pkg_repo_info']['name']
417 402 . '/' . $a['pkg_subrepo_info']['name'] . '/' . $a['pkg_subrepo_info']['name']
418 403 . '/' . $a['distro'] . '/' . $a['distro']
 
... ... function rg_packages_rpm_add_dotrepo_files($db, $uid, $pkg_subrepo_id, $distro)
437 422 do { do {
438 423 $sri = rg_pkg_subrepo_info($db, $uid, $pkg_subrepo_id); $sri = rg_pkg_subrepo_info($db, $uid, $pkg_subrepo_id);
439 424 if ($sri['exists'] != 1) { if ($sri['exists'] != 1) {
440 $ret['errmsg'] = 'cannot find subrepo ' . $pkg_subrepo_id;
425 $ret['errmsg'] = $sri['errmsg'];
441 426 break; break;
442 427 } }
443 428
444 429 $pri = rg_pkg_repo_info($db, $uid, $sri['pkg_repo_id']); $pri = rg_pkg_repo_info($db, $uid, $sri['pkg_repo_id']);
445 430 if ($pri['exists'] != 1) { if ($pri['exists'] != 1) {
446 $ret['errmsg'] = 'cannot find repo ' . $sri['pkg_repo_id'];
431 $ret['errmsg'] = $pri['errmsg'];
447 432 break; break;
448 433 } }
449 434
 
... ... function rg_packages_rpm_add_dotrepo_files($db, $uid, $pkg_subrepo_id, $distro)
507 492
508 493 /* /*
509 494 * Instructions on how to install a package * Instructions on how to install a package
510 * TODO: Showing the details of older packages has no place here!
495 * TODO: Showing the details of other packages versions has no place here!
511 496 */ */
512 497 function rg_packages_rpm_howto($a, $user, $repo_name, $meta) function rg_packages_rpm_howto($a, $user, $repo_name, $meta)
513 498 { {
514 rg_log_debug('packages_rpm_howto: a: ' . print_r($a, TRUE));
499 rg_log_debug('packages_rpm_howto: a: ' . rg_array2string_short($a));
500 //rg_log_debug('meta: ' . print_r($meta, TRUE));
515 501
516 502 $private = !strstr($a['pkg_repo_info']['flags'], 'P'); $private = !strstr($a['pkg_repo_info']['flags'], 'P');
517 503
518 504 $other = ''; $other = '';
519 if ($meta) {
505 if ($meta !== FALSE) {
520 506 $other .= "\n"; $other .= "\n";
521 507 $other .= '<details><summary>Details about all versions</summary>' . "\n"; $other .= '<details><summary>Details about all versions</summary>' . "\n";
522 $other .= '<table><tr><th>Name</th><th>Size</th><th>Copies</th><th>Job</th><th>Head</th><th>Worker</th><th>Date (UTC)</th></tr>' . "\n";
508 $other .= '<table><tr><th>Name</th><th>Size</th><th>Head</th><th>Date (UTC)</th>';
509 if ($a['can_see_details'] == 1)
510 $other .= '<th>Job</th><th>Worker</th><th>Copies</th>';
511 $other .= '</tr>' . "\n";
523 512 foreach ($meta as $f => $i) { foreach ($meta as $f => $i) {
524 513 $other .= '<tr><td>' . rg_xss_safe($f) . '</td>' $other .= '<tr><td>' . rg_xss_safe($f) . '</td>'
525 . '<td>' . $i['size_nice'] . '</td>'
526 . '<td>' . $i['nlink'] . '</td>'
527 . '<td>' . rg_xss_safe($i['job_id']) . '</td>'
528 . '<td>' . $i['head_link'] . '</td>'
514 . '<td>' . $i['size_nice'] . '</td>';
515
516 $other .= '<td>' . $i['head_link'] . '</td>'
517 . '<td>' . gmdate('Y-m-d H:i', $i['ctime']) . '</td>';
518
519 if ($a['can_see_details'] == 1)
520 $other .= '<td>' . rg_xss_safe($i['job_id']) . '</td>'
529 521 . '<td>' . rg_xss_safe($i['worker_name']) . '</td>' . '<td>' . rg_xss_safe($i['worker_name']) . '</td>'
530 . '<td>' . gmdate('Y-m-d H:i', $i['ctime']) . '</td>'
531 . '</tr>' . "\n";
522 . '<td>' . $i['nlink'] . '</td>';
523
524 $other .= '</tr>' . "\n";
532 525 } }
533 526 $other .= '</table>'; $other .= '</table>';
534 527 $other .= '</details>'; $other .= '</details>';
 
... ... function rg_packages_rpm_howto($a, $user, $repo_name, $meta)
551 544 if ($private) { if ($private) {
552 545 // We cannot do it like with the private pkg repo. // We cannot do it like with the private pkg repo.
553 546 // We do not want to put the password on the screen. // We do not want to put the password on the screen.
554 return rg_template('user/pkg/redhat/priv_download.html',
547 return rg_template('user/pkg/rpm/priv_download.html',
555 548 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
556 549 } else { } else {
557 return rg_template('user/pkg/redhat/pub_download.html',
550 return rg_template('user/pkg/rpm/pub_download.html',
558 551 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
559 552 } }
560 553 } }
File inc/user/pkg_map.inc.php changed (mode: 100644) (index ac751e1..f006ba7)
... ... function rg_pkg_map_event_add($db, $ev)
29 29 { {
30 30 rg_prof_start('pkg_map_event_add'); rg_prof_start('pkg_map_event_add');
31 31 rg_log_enter('pkg_map_event_add'); rg_log_enter('pkg_map_event_add');
32 rg_log_ml('ev: ' . print_r($ev ,TRUE));
32 rg_log_debug('ev: ' . rg_array2string_short($ev));
33 33
34 34 $ret = FALSE; $ret = FALSE;
35 35 do { do {
 
... ... function rg_pkg_map_event_edit($db, $ev)
45 45 { {
46 46 rg_prof_start('pkg_map_event_edit'); rg_prof_start('pkg_map_event_edit');
47 47 rg_log_enter('pkg_map_event_edit'); rg_log_enter('pkg_map_event_edit');
48 rg_log_ml('ev: ' . print_r($ev ,TRUE));
48 rg_log_debug('ev: ' . rg_array2string_short($ev));
49 49
50 50 $ret = FALSE; $ret = FALSE;
51 51 do { do {
 
... ... function rg_pkg_maps_list($db, $uid)
188 188 rg_prof_start('pkg_maps_list'); rg_prof_start('pkg_maps_list');
189 189 rg_log_enter('pkg_maps_list'); rg_log_enter('pkg_maps_list');
190 190
191 $ret = FALSE;
191 $ret = array('ok' => 0);
192 192 while (1) { while (1) {
193 193 $k = 'uid::' . $uid . '::pkg_maps'; $k = 'uid::' . $uid . '::pkg_maps';
194 194
 
... ... function rg_pkg_maps_list($db, $uid)
202 202 . ' ORDER BY prio, itime DESC'; . ' ORDER BY prio, itime DESC';
203 203 $res = rg_sql_query_params($db, $sql, $params); $res = rg_sql_query_params($db, $sql, $params);
204 204 if ($res === FALSE) { if ($res === FALSE) {
205 rg_pkg_maps_set_error('cannot get packages map list');
205 $ret['errmsg'] = 'cannot select packages map list';
206 206 break; break;
207 207 } }
208 208
209 $ret = array();
209 $ret = array('ok' => 1, 'list' => array());
210 210 while (($row = rg_sql_fetch_array($res))) { while (($row = rg_sql_fetch_array($res))) {
211 211 $id = $row['id']; $id = $row['id'];
212 $ret[$id] = $row;
212 $ret['list'][$id] = $row;
213 213 } }
214 214 rg_sql_free_result($res); rg_sql_free_result($res);
215 215
 
... ... function rg_pkg_maps_info($db, $uid, $id)
234 234 $ret['ok'] = 0; $ret['ok'] = 0;
235 235 $ret['exists'] = 0; $ret['exists'] = 0;
236 236 while (1) { while (1) {
237 $list = rg_pkg_maps_list($db, $uid);
238 if ($list === FALSE)
237 $r = rg_pkg_maps_list($db, $uid);
238 if ($r['ok'] != 1) {
239 $ret['errmsg'] = $r['errmsg'];
239 240 break; break;
241 }
242 $list = $r['list'];
240 243
241 244 $ret['ok'] = 1; $ret['ok'] = 1;
242 245
 
... ... function rg_pkg_maps_get($db, $uid, $repo_name, $ref)
262 265 { {
263 266 $ret = array('ok' => 0); $ret = array('ok' => 0);
264 267 do { do {
265 $ml = rg_pkg_maps_list($db, $uid);
266 if ($ml === FALSE)
268 $r = rg_pkg_maps_list($db, $uid);
269 if ($r['ok'] != 1) {
270 $ret['errmsg'] = $r['errmsg'];
267 271 break; break;
272 }
273 $ml = $r['list'];
268 274
269 275 $maps = array(); $maps = array();
270 276 $repos = array(); $repos = array();
271 277 $subrepos = array(); $subrepos = array();
272 $err = FALSE;
273 278 foreach ($ml as $id => $info) { foreach ($ml as $id => $info) {
274 279 if (!empty($info['repo'])) { if (!empty($info['repo'])) {
275 280 $r = @preg_match('`' . $info['repo'] . '`uD', $repo_name); $r = @preg_match('`' . $info['repo'] . '`uD', $repo_name);
276 281 if ($r === FALSE) { if ($r === FALSE) {
277 282 $ret['errmsg'] = 'repo name regex error'; $ret['errmsg'] = 'repo name regex error';
278 $err = TRUE;
279 283 break; break;
280 284 } }
281 285 if ($r !== 1) if ($r !== 1)
 
... ... function rg_pkg_maps_get($db, $uid, $repo_name, $ref)
286 290 $r = @preg_match('`' . $info['ref'] . '`uD', $ref); $r = @preg_match('`' . $info['ref'] . '`uD', $ref);
287 291 if ($r === FALSE) { if ($r === FALSE) {
288 292 $ret['errmsg'] = 'ref regex error'; $ret['errmsg'] = 'ref regex error';
289 $err = TRUE;
290 293 break; break;
291 294 } }
292 295 if ($r !== 1) if ($r !== 1)
 
... ... function rg_pkg_maps_get($db, $uid, $repo_name, $ref)
300 303 if (!isset($subrepos[$si])) { if (!isset($subrepos[$si])) {
301 304 $r = rg_pkg_subrepo_info($db, $uid, $si); $r = rg_pkg_subrepo_info($db, $uid, $si);
302 305 if ($r['exists'] != 1) { if ($r['exists'] != 1) {
303 $ret['errmsg'] = 'non existing pkg subrepo ' . $si;
304 $err = TRUE;
306 $ret['errmsg'] = $r['errmsg'];
305 307 break; break;
306 308 } }
307 309 $subrepos[$si] = $r; $subrepos[$si] = $r;
 
... ... function rg_pkg_maps_get($db, $uid, $repo_name, $ref)
311 313 if (!isset($repos[$ri])) { if (!isset($repos[$ri])) {
312 314 $r = rg_pkg_repo_info($db, $uid, $ri); $r = rg_pkg_repo_info($db, $uid, $ri);
313 315 if ($r['exists'] != 1) { if ($r['exists'] != 1) {
314 $ret['errmsg'] = 'non existing pkg repo ' . $ri;
315 $err = TRUE;
316 $ret['errmsg'] = $r['errmsg'];
316 317 break; break;
317 318 } }
318 319 $repos[$ri] = $r; $repos[$ri] = $r;
 
... ... function rg_pkg_maps_get($db, $uid, $repo_name, $ref)
323 324 'flags' => $info['flags'] 'flags' => $info['flags']
324 325 ); );
325 326 } }
326 if ($err)
327 if (isset($ret['errmsg']))
327 328 break; break;
328 329
329 330 $ret['pkg_maps'] = $maps; $ret['pkg_maps'] = $maps;
 
... ... function rg_pkg_maps_get($db, $uid, $repo_name, $ref)
335 336 return $ret; return $ret;
336 337 } }
337 338
339 /*
340 * Prepares pkg_maps based on a list of pkg subrepo ids and stores it in @a
341 */
342 function rg_pkg_maps_prepare($db, &$a)
343 {
344 rg_log_enter('pkg_maps_prepare');
345 rg_log_debug('a: ' . print_r($a, TRUE));
346
347 $ret = array('ok' => 0);
348 do {
349 // Cleans previous list
350 $a['pkg_maps'] = array();
351 $a['pkg_repos'] = array();
352 $a['pkg_subrepos'] = array();
353
354 foreach ($a['pkg_subrepo_id_list'] as $pkg_subrepo_id) {
355 $sri = rg_pkg_subrepo_info($db, $a['repo_uid'], $pkg_subrepo_id);
356 if ($sri['exists'] != 1) {
357 $ret['errmsg'] = $sri['errmsg'];
358 break;
359 }
360 $a['pkg_subrepos'][$pkg_subrepo_id] = $sri;
361
362 $pkg_repo_id = $sri['pkg_repo_id'];
363 $ri = rg_pkg_repo_info($db, $a['repo_uid'], $pkg_repo_id);
364 if ($ri['exists'] != 1) {
365 $ret['errmsg'] = $ri['errmsg'];
366 break;
367 }
368 $a['pkg_repos'][$pkg_repo_id] = $ri;
369
370 // Fake pkg_maps
371 $a['pkg_maps'][] = array(
372 'pkg_subrepo_id' => $pkg_subrepo_id,
373 'flags' => ''
374 );
375 }
376 if (isset($ret['errmsg']))
377 break;
378
379 unset($a['pkg_subrepo_id_list']);
380
381 $ret['ok'] = 1;
382 } while (0);
383
384 rg_log_exit();
385 return $ret;
386 }
387
338 388 /* /*
339 389 * High-level function for rg_pkg_maps_list * High-level function for rg_pkg_maps_list
340 390 */ */
 
... ... function rg_pkg_maps_list_high_level($db, $rg)
347 397 $errmsg = array(); $errmsg = array();
348 398
349 399 $ui_login = rg_ui_login(); $ui_login = rg_ui_login();
350 $list = rg_pkg_maps_list($db, $ui_login['uid']);
351 if ($list === FALSE) {
352 $rg['errmsg'] = rg_pkg_maps_error();
400 $r = rg_pkg_maps_list($db, $ui_login['uid']);
401 if ($r['ok'] != 1) {
402 $rg['errmsg'] = $r['errmsg'];
353 403 $ret .= rg_template('user/settings/packages/map/list_err.html', $ret .= rg_template('user/settings/packages/map/list_err.html',
354 404 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
355 405 break; break;
356 406 } }
407 $list = $r['list'];
357 408 rg_pkg_maps_cosmetic_list($db, $list); rg_pkg_maps_cosmetic_list($db, $list);
358 409
359 410 $xlist = rg_var_str('delete_list'); $xlist = rg_var_str('delete_list');
 
... ... function rg_pkg_maps_high_level($db, &$rg, $paras)
534 585 rg_log_enter('pkg_maps_high_level paras:' . rg_array2string($paras)); rg_log_enter('pkg_maps_high_level paras:' . rg_array2string($paras));
535 586
536 587 $ret = ''; $ret = '';
537 while (1) {
588 do {
589 $old_url = $rg['url'];
590 $rg['url'] .= '/map';
591
538 592 $op = empty($paras) ? 'list' : array_shift($paras); $op = empty($paras) ? 'list' : array_shift($paras);
539 $rg['menu3']['packages']['map'] = array($op => 1);
593 $rg['menu3']['packages']['map'] = $op;
540 594
541 595 switch ($op) { switch ($op) {
542 596 case 'add': case 'add':
 
... ... function rg_pkg_maps_high_level($db, &$rg, $paras)
553 607 rg_template('user/settings/packages/map/menu.html', rg_template('user/settings/packages/map/menu.html',
554 608 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
555 609
556 break;
557 }
610 $rg['url'] = $old_url;
611 } while (0);
558 612
559 613 rg_log_exit(); rg_log_exit();
560 614 rg_prof_end('pkg_maps_high_level'); rg_prof_end('pkg_maps_high_level');
File inc/user/pkg_repo.inc.php changed (mode: 100644) (index 3891e39..19a7ec5)
... ... function rg_pkg_repo_event_gen_gpg_key($db, $ev)
46 46 { {
47 47 rg_prof_start('pkg_repo_event_gen_gpg_key'); rg_prof_start('pkg_repo_event_gen_gpg_key');
48 48 rg_log_enter('pkg_repo_event_gen_gpg_key'); rg_log_enter('pkg_repo_event_gen_gpg_key');
49 rg_log_ml('ev: ' . print_r($ev ,TRUE));
49 rg_log_debug('ev: ' . rg_array2string_short($ev));
50 50
51 51 $ret = FALSE; $ret = FALSE;
52 52 do { do {
 
... ... function rg_pkg_repo_event_add($db, $ev)
86 86 { {
87 87 rg_prof_start('pkg_repo_event_add'); rg_prof_start('pkg_repo_event_add');
88 88 rg_log_enter('pkg_repo_event_add'); rg_log_enter('pkg_repo_event_add');
89 rg_log_ml('ev: ' . print_r($ev ,TRUE));
89 rg_log_debug('ev: ' . rg_array2string_short($ev));
90 90
91 91 $ret = array(); $ret = array();
92 92 do { do {
 
... ... function rg_pkg_repo_event_edit($db, $ev)
104 104 { {
105 105 rg_prof_start('pkg_repo_event_edit'); rg_prof_start('pkg_repo_event_edit');
106 106 rg_log_enter('pkg_repo_event_edit'); rg_log_enter('pkg_repo_event_edit');
107 rg_log_ml('ev: ' . print_r($ev ,TRUE));
107 rg_log_debug('ev: ' . rg_array2string_short($ev));
108 108
109 109 $ev['uid'] = $ev['info']['uid']; $ev['uid'] = $ev['info']['uid'];
110 110 $ev['pkg_repo_id'] = $ev['info']['id']; $ev['pkg_repo_id'] = $ev['info']['id'];
 
... ... function rg_pkg_repo_edit($db, $d)
203 203 $row = rg_sql_fetch_array($res); $row = rg_sql_fetch_array($res);
204 204 rg_sql_free_result($res); rg_sql_free_result($res);
205 205
206 if (!isset($row['id'])) {
207 rg_pkg_repo_set_error('cannot insert/update packages'
208 . ' repo (uid mismatch?)');
209 break;
210 }
211
206 212 $d['id'] = $row['id']; $d['id'] = $row['id'];
207 213 $ev = array( $ev = array(
208 214 'category' => $orig_id == 0 ? 'pkg_repo_add' : 'pkg_repo_edit', 'category' => $orig_id == 0 ? 'pkg_repo_add' : 'pkg_repo_edit',
 
... ... function rg_pkg_repo_remove($db, $uid, $list)
254 260 $ret = FALSE; $ret = FALSE;
255 261 $rollback = 0; $rollback = 0;
256 262 while (1) { while (1) {
263 // Security check - a user may delete others' ids
264 $err = FALSE;
265 foreach ($list as $id => $junk) {
266 $pri = rg_pkg_repo_info($db, $uid, $id);
267 if ($pri['exists'] != 1) {
268 rg_pkg_repo_set_error('invalid id');
269 $err = TRUE;
270 break;
271 }
272 if (!rg_pkg_has_rights($db, $pri, 'D')) {
273 rg_pkg_repo_set_error('invalid id');
274 $err = TRUE;
275 break;
276 }
277 }
278 if ($err)
279 break;
280
257 281 if (rg_sql_begin($db) !== TRUE) { if (rg_sql_begin($db) !== TRUE) {
258 282 rg_pkg_repo_set_error('start transaction failed'); rg_pkg_repo_set_error('start transaction failed');
259 283 break; break;
 
... ... function rg_pkg_repo_remove($db, $uid, $list)
266 290 $sql_list = implode(', ', $my_list); $sql_list = implode(', ', $my_list);
267 291
268 292 $sql = ' DELETE FROM pkg_maps' $sql = ' DELETE FROM pkg_maps'
269 . ' WHERE pkg_repo_id IN (' . $sql_list . ')';
293 . ' WHERE pkg_subrepo_id IN'
294 . ' (SELECT id FROM pkg_subrepos'
295 . ' WHERE pkg_repo_id IN (' . $sql_list . '))';
270 296 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
271 297 if ($res === FALSE) { if ($res === FALSE) {
272 298 rg_pkg_repo_set_error('cannot remove packages mapping (query error)'); rg_pkg_repo_set_error('cannot remove packages mapping (query error)');
 
... ... function rg_pkg_repo_remove($db, $uid, $list)
316 342 return $ret; return $ret;
317 343 } }
318 344
319 function rg_pkg_repo_cosmetic(&$row)
345 function rg_pkg_repo_cosmetic($db, &$row)
320 346 { {
321 347 if (isset($row['itime'])) if (isset($row['itime']))
322 348 $row['itime_nice'] = gmdate('Y-m-d H:i', $row['itime']); $row['itime_nice'] = gmdate('Y-m-d H:i', $row['itime']);
 
... ... function rg_pkg_repo_cosmetic(&$row)
327 353
328 354 $row['disk_used'] = rg_1024($row['disk_used_mb'] * 1024 * 1024); $row['disk_used'] = rg_1024($row['disk_used_mb'] * 1024 * 1024);
329 355
356 $row['owner'] = rg_user_nice($db, $row['uid']);
357
330 358 //rg_log_debug('pkg_repo_cosmetic: ' . print_r($row, TRUE)); //rg_log_debug('pkg_repo_cosmetic: ' . print_r($row, TRUE));
331 359 } }
332 360
333 function rg_pkg_repo_cosmetic_list(&$a)
361 function rg_pkg_repo_cosmetic_list($db, &$a)
334 362 { {
335 363 foreach ($a as $id => &$row) foreach ($a as $id => &$row)
336 rg_pkg_repo_cosmetic($row);
364 rg_pkg_repo_cosmetic($db, $row);
337 365 } }
338 366
339 367 /* /*
 
... ... function rg_pkg_repo_info($db, $uid, $id)
418 446 $ret['ok'] = 1; $ret['ok'] = 1;
419 447
420 448 $id = sprintf('%u', $id); $id = sprintf('%u', $id);
421 if (!isset($list[$id]))
449 if (!isset($list[$id])) {
450 $ret['errmsg'] = 'pkg repo ' . $id . ' does not exists';
422 451 break; break;
452 }
423 453
424 454 $ret = array_merge($ret, $list[$id]); $ret = array_merge($ret, $list[$id]);
425 455 $ret['exists'] = 1; $ret['exists'] = 1;
 
... ... function rg_pkg_repo_info_by_name($db, $uid, $name)
439 469 rg_prof_start('pkg_repo_info_by_name'); rg_prof_start('pkg_repo_info_by_name');
440 470 rg_log_enter('pkg_repo_info_by_name: uid=' . $uid . ' name=' . $name); rg_log_enter('pkg_repo_info_by_name: uid=' . $uid . ' name=' . $name);
441 471
442 $ret = array();
443 $ret['ok'] = 0;
444 $ret['exists'] = 0;
472 $ret = array('ok' => 0, 'exists' => 0);
445 473 do { do {
446 474 $list = rg_pkg_repo_list($db, $uid); $list = rg_pkg_repo_list($db, $uid);
447 475 if ($list === FALSE) if ($list === FALSE)
 
... ... function rg_pkg_repo_select($db, $name, $uid, $pkg_repo_id, $strict)
492 520 return $ret; return $ret;
493 521 } }
494 522
495 /*
496 * Security validation; return TRUE if the list is valid
497 */
498 function rg_pkg_repo_list_valid($db_list, $web_list)
499 {
500 foreach ($web_list as $id => $junk) {
501 if (!isset($db_list[$id])) {
502 rg_security_violation_no_exit('user tried to delete others ids');
503 return FALSE;
504 }
505 }
506
507 return TRUE;
508 }
509
510 523 /* /*
511 524 * High-level function for rg_pkg_repo_list * High-level function for rg_pkg_repo_list
512 525 */ */
 
... ... function rg_pkg_repo_list_high_level($db, $rg, $paras)
519 532 $errmsg = array(); $errmsg = array();
520 533
521 534 $ui_login = rg_ui_login(); $ui_login = rg_ui_login();
522 $strict_list = rg_pkg_repo_list_one($db, $ui_login['uid']);
535 $strict_list = rg_pkg_repo_list_one($db, $ui_login['uid']); // rename this to ..._no_global?
523 536 if ($strict_list === FALSE) { if ($strict_list === FALSE) {
524 537 $rg['errmsg'] = rg_pkg_repo_error(); $rg['errmsg'] = rg_pkg_repo_error();
525 538 $ret .= rg_template('user/settings/packages/repo/list_err.html', $ret .= rg_template('user/settings/packages/repo/list_err.html',
 
... ... function rg_pkg_repo_list_high_level($db, $rg, $paras)
534 547 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
535 548 break; break;
536 549 } }
537 rg_pkg_repo_cosmetic_list($list);
550 rg_pkg_repo_cosmetic_list($db, $list);
538 551
539 552 $xlist = rg_var_str('delete_list'); $xlist = rg_var_str('delete_list');
540 553 while (!empty($xlist)) { while (!empty($xlist)) {
 
... ... function rg_pkg_repo_list_high_level($db, $rg, $paras)
545 558 if (!rg_token_valid($db, $rg, 'pkg_repo_list', FALSE)) if (!rg_token_valid($db, $rg, 'pkg_repo_list', FALSE))
546 559 $del_errmsg[] = 'invalid token; try again.'; $del_errmsg[] = 'invalid token; try again.';
547 560
548 // Security check - a user may delete others' ids
549 if (!rg_pkg_repo_list_valid($strict_list, $xlist))
550 $del_errmsg[] = rg_template('user/settings/packages/repo/id_invalid.html',
551 $rg, TRUE /*xss*/);
552
553 561 if (empty($del_errmsg)) { if (empty($del_errmsg)) {
554 562 $r = rg_pkg_repo_remove($db, $ui_login['uid'], $xlist); $r = rg_pkg_repo_remove($db, $ui_login['uid'], $xlist);
555 563 if ($r !== TRUE) if ($r !== TRUE)
 
... ... function rg_pkg_repo_edit_high_level($db, &$rg, $op, $paras)
591 599
592 600 $rg['pi'] = array(); $rg['pi'] = array();
593 601 $rg['pi']['id'] = isset($paras[0]) ? sprintf('%u', $paras[0]) : 0; $rg['pi']['id'] = isset($paras[0]) ? sprintf('%u', $paras[0]) : 0;
602 if ($rg['pi']['id'] > 0) {
603 $rg['pi'] = rg_pkg_repo_info($db, $ui_login['uid'],
604 $rg['pi']['id']);
605 if ($rg['pi']['ok'] != 1) {
606 $ret .= rg_template_blind('internal_err.html');
607 return $ret;
608 }
609 if ($rg['pi']['exists'] != 1) {
610 $m = rg_template_blind('user/settings/packages/repo/id_invalid.html');
611 $ret .= rg_warning($m);
612 return $ret;
613 }
614
615 if (!rg_pkg_has_rights($db, $rg['pi'], 'E')) {
616 $m = rg_template_blind('user/settings/packages/repo/id_invalid.html');
617 $ret .= rg_warning($m);
618 return $ret;
619 }
620
621 rg_pkg_repo_cosmetic($db, $rg['pi']);
622 }
594 623
595 624 $errmsg = array(); $errmsg = array();
596 625 $load_form = TRUE; $load_form = TRUE;
597 626 while ($rg['doit'] == 0) { while ($rg['doit'] == 0) {
598 if ($rg['pi']['id'] > 0) {
599 $rg['pi'] = rg_pkg_repo_info($db, $ui_login['uid'],
600 $rg['pi']['id']);
601 if ($rg['pi']['ok'] != 1) {
602 $ret .= rg_template_blind('internal_err.html');
603 $load_form = FALSE;
604 break;
605 }
606
607 if ($rg['pi']['exists'] != 1) {
608 $m = rg_template_blind('user/settings/packages/repo/id_invalid.html');
609 $ret .= rg_warning($m);
610 $load_form = FALSE;
611 break;
612 }
613
614 rg_pkg_repo_cosmetic($rg['pi']);
615 } else {
627 if ($rg['pi']['id'] == 0) {
616 628 // Defaults // Defaults
617 629 $rg['pi']['name'] = ''; $rg['pi']['name'] = '';
618 630 $rg['pi']['flags'] = 'P'; $rg['pi']['flags'] = 'P';
 
... ... function rg_pkg_repo_edit_high_level($db, &$rg, $op, $paras)
632 644 if (!rg_token_valid($db, $rg, 'pkg_repo_edit_hl', FALSE)) if (!rg_token_valid($db, $rg, 'pkg_repo_edit_hl', FALSE))
633 645 $errmsg[] = 'invalid token; try again'; $errmsg[] = 'invalid token; try again';
634 646
635 if (empty($rg['pi']['name']))
647 if (empty($rg['pi']['name'])) {
636 648 $errmsg[] = rg_template( $errmsg[] = rg_template(
637 649 'user/settings/packages/repo/name_empty.html', 'user/settings/packages/repo/name_empty.html',
638 650 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
651 break;
652 }
639 653
640 654 if (rg_chars_allow($rg['pi']['name'], '\pL\pN.', $invalid) !== 1) { if (rg_chars_allow($rg['pi']['name'], '\pL\pN.', $invalid) !== 1) {
641 655 $rg['pi']['name_invalid'] = $invalid; $rg['pi']['name_invalid'] = $invalid;
642 656 $errmsg[] = rg_template( $errmsg[] = rg_template(
643 657 'user/settings/packages/repo/name_invalid.html', 'user/settings/packages/repo/name_invalid.html',
644 658 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
659 break;
645 660 } }
646 661
647 if ($rg['pi']['id'] > 0) {
648 $i = rg_pkg_repo_info($db, $ui_login['uid'],
649 $rg['pi']['id']);
650 if ($i['exists'] != 1)
651 $errmsg[] = rg_template(
652 'user/settings/packages/repo/id_invalid.html',
653 $rg, TRUE /*xss*/);
654 } else {
655 $ri = rg_pkg_repo_info_by_name($db, $ui_login['uid'],
656 $rg['pi']['name']);
657 if ($ri === FALSE) {
658 $rg['errmsg'] = rg_pkg_repo_error();
659 $errmsg[] = rg_template('internal_err.html', $rg, TRUE /*xss*/);
660 } else if ($ri['exists'] == 1) {
661 $errmsg[] = rg_template('user/settings/packages/repo/name_duplicate.html',
662 $rg, TRUE /*xss*/);
663 }
664 }
665
666 if (empty($errmsg)) {
667 // We operate as uid 0 on pkg_repos if we are an admin.
668 $rg['pi']['uid'] = $ui_login['is_admin'] == 1 ?
669 0 : $ui_login['uid'];
670 $rg['pi']['flags'] = $rg['pi']['public'] == 1 ? 'P' : '';
671 $r = rg_pkg_repo_edit($db, $rg['pi']);
672 if ($r === FALSE) {
673 $rg['err_detail'] = rg_pkg_repo_error();
674 $errmsg[] = rg_template(
675 'user/settings/packages/repo/add_edit_err.html',
676 $rg, TRUE /*xss*/);
677 }
662 $ri = rg_pkg_repo_info_by_name($db, $ui_login['uid'],
663 $rg['pi']['name']);
664 if ($ri['exists'] == 1) {
665 $errmsg[] = rg_template('user/settings/packages/repo/name_duplicate.html',
666 $rg, TRUE /*xss*/);
667 break;
678 668 } }
679 669
680 if (empty($errmsg)) {
681 $ret .= rg_template('user/settings/packages/repo/add_ok.html',
670 // We operate as uid 0 on pkg_repos if we are an admin.
671 $rg['pi']['uid'] = $ui_login['is_admin'] == 1 ?
672 0 : $ui_login['uid'];
673 $rg['pi']['flags'] = $rg['pi']['public'] == 1 ? 'P' : '';
674 $r = rg_pkg_repo_edit($db, $rg['pi']);
675 if ($r === FALSE) {
676 $rg['err_detail'] = rg_pkg_repo_error();
677 $errmsg[] = rg_template(
678 'user/settings/packages/repo/add_edit_err.html',
682 679 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
683 $load_form = FALSE;
680 break;
684 681 } }
685 682
683 $ret .= rg_template('user/settings/packages/repo/add_ok.html',
684 $rg, TRUE /*xss*/);
685 $load_form = FALSE;
686 686 break; break;
687 687 } }
688 688
 
... ... function rg_pkg_repo_high_level($db, &$rg, $paras)
706 706
707 707 $ret = ''; $ret = '';
708 708 while (1) { while (1) {
709 $old_url = $rg['url'];
710 $rg['url'] .= '/repo';
711
709 712 $op = empty($paras) ? 'list' : array_shift($paras); $op = empty($paras) ? 'list' : array_shift($paras);
710 $rg['menu3']['packages']['repo'] = array($op => 1);
713 $rg['menu3']['packages']['repo'] = $op;
711 714
712 715 switch ($op) { switch ($op) {
713 716 case 'add': case 'add':
 
... ... function rg_pkg_repo_high_level($db, &$rg, $paras)
728 731 rg_template('user/settings/packages/repo/menu.html', rg_template('user/settings/packages/repo/menu.html',
729 732 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
730 733
734 $rg['url'] = $old_url;
731 735 break; break;
732 736 } }
733 737
File inc/user/pkg_rights.inc.php changed (mode: 100644) (index 7947a57..6af87a2)
... ... require_once(__DIR__ . '/pkg_repo.inc.php');
6 6
7 7 $rights = array( $rights = array(
8 8 'A' => 'Access pkg repo', 'A' => 'Access pkg repo',
9 'E' => 'Edit pkg repo',
10 'D' => 'Delete pkg repo',
9 11 'G' => 'Grant rights', 'G' => 'Grant rights',
10 'R' => 'Revoke rights'
12 'g' => 'Revoke rights'
11 13 ); );
12 14 rg_rights_register('pkgrepo', $rights, 'A', rg_rights_register('pkgrepo', $rights, 'A',
13 15 FALSE, FALSE); FALSE, FALSE);
 
... ... function rg_pkg_rights_high_level($db, $rg, $paras)
21 23 rg_log_enter('pkg_rights_high_level paras:' . rg_array2string($paras)); rg_log_enter('pkg_rights_high_level paras:' . rg_array2string($paras));
22 24
23 25 do { do {
26 $rg['url'] .= '/rights';
27
24 28 if (empty($paras)) { if (empty($paras)) {
25 29 $m = rg_template_blind('user/settings/packages/repo/id_invalid.html'); $m = rg_template_blind('user/settings/packages/repo/id_invalid.html');
26 30 $ret = rg_warning($m); $ret = rg_warning($m);
 
... ... function rg_pkg_rights_high_level($db, $rg, $paras)
30 34 $pkg_repo_id = intval($paras[0]); $pkg_repo_id = intval($paras[0]);
31 35 $ui_page = rg_ui_page(); $ui_page = rg_ui_page();
32 36 $rg['pkg_repo_info'] = rg_pkg_repo_info($db, $ui_page['uid'], $pkg_repo_id); $rg['pkg_repo_info'] = rg_pkg_repo_info($db, $ui_page['uid'], $pkg_repo_id);
33 if ($rg['pkg_repo_info']['ok'] != 1) {
37 if ($rg['pkg_repo_info']['exists'] != 1) {
34 38 $ret = rg_template_blind('internal_err.html'); $ret = rg_template_blind('internal_err.html');
35 39 break; break;
36 40 } }
37 41
42 $rg['url'] .= '/' . $pkg_repo_id;
43
38 44 $ret = rg_template('user/settings/packages/repo/rights_head.html', $ret = rg_template('user/settings/packages/repo/rights_head.html',
39 45 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
40 46
 
... ... function rg_pkg_rights_high_level($db, $rg, $paras)
50 56 break; break;
51 57 } }
52 58
53 rg_pkg_repo_cosmetic($rg['pkg_repo_info']);
59 rg_pkg_repo_cosmetic($db, $rg['pkg_repo_info']);
60 //rg_log_debug('TODO: rg: ' . print_r($rg, TRUE));
54 61
55 62 $owner = $rg['pkg_repo_info']['uid']; $owner = $rg['pkg_repo_info']['uid'];
56 63
57 64 $type = 'pkgrepo'; $type = 'pkgrepo';
58 65 $obj_id = $pkg_repo_id; $obj_id = $pkg_repo_id;
59 $ret .= rg_rights_high_level($db, $rg, $type, $type, $owner,
60 $obj_id);
66 $ret .= rg_rights_high_level($db, $rg, $type, $type, $owner, $obj_id);
61 67 } while (0); } while (0);
62 68
63 69 rg_log_exit(); rg_log_exit();
 
... ... function rg_pkg_rights_high_level($db, $rg, $paras)
69 75 * Returns true if the login user has rights over this pkg repo * Returns true if the login user has rights over this pkg repo
70 76 * @pri - pkg_repo info * @pri - pkg_repo info
71 77 */ */
72 function rg_pkg_has_rights($db, $pri, $rg, $rights)
78 function rg_pkg_has_rights($db, $pri, $rights)
73 79 { {
74 80 $x = array(); $x = array();
75 81 $x['obj_id'] = $pri['id']; $x['obj_id'] = $pri['id'];
File inc/user/pkg_subrepo.inc.php changed (mode: 100644) (index 50accda..7b83216)
... ... function rg_pkg_subrepo_error()
23 23 $_f = array( $_f = array(
24 24 'pkg_subrepo_add' => 'rg_pkg_subrepo_event_add', 'pkg_subrepo_add' => 'rg_pkg_subrepo_event_add',
25 25 'pkg_subrepo_edit' => 'rg_pkg_subrepo_event_edit', 'pkg_subrepo_edit' => 'rg_pkg_subrepo_event_edit',
26 'pkg_subrepo_regenerate' => 'rg_pkg_subrepo_event_regenerate',
27 26 'pkg_subrepo_pkg_repo_changed' => 'rg_pkg_subrepo_event_pkg_repo_changed' 'pkg_subrepo_pkg_repo_changed' => 'rg_pkg_subrepo_event_pkg_repo_changed'
28 27 ); );
29 28 rg_event_register_functions($_f); rg_event_register_functions($_f);
 
... ... function rg_pkg_subrepo_event_add($db, $ev)
35 34 return $ret; return $ret;
36 35 } }
37 36
37 /*
38 * Called by: 'pkg_subrepo_event_pkg_repo_changed' and 'pkg_subrepo_edit'
39 */
38 40 function rg_pkg_subrepo_event_edit($db, $ev) function rg_pkg_subrepo_event_edit($db, $ev)
39 41 { {
40 42 rg_log_enter('pkg_subrepo_event_edit'); rg_log_enter('pkg_subrepo_event_edit');
43 rg_log_debug('list: ' . rg_array2string($ev['pkg_subrepo_id_list']));
41 44
42 45 $ret = FALSE; $ret = FALSE;
43 46 do { do {
44 $sri = rg_pkg_subrepo_info($db, $ev['uid'], $ev['pkg_subrepo_id']);
45 if ($sri['ok'] != 1)
46 break;
47
48 47 $a = $ev; $a = $ev;
49 48 $a['category'] = 'pkg_generate_dotrepo_rpm'; $a['category'] = 'pkg_generate_dotrepo_rpm';
50 49 $a['force_regenerate_dotrepo'] = 1; $a['force_regenerate_dotrepo'] = 1;
51 50
52 $ret = array();
53 $di = $sri['distro_info'];
54 foreach ($di as $env => $info) {
55 // We do not need to generate dotrepo for never generated subrepos.
56 // We wait for the first packet in the repo to trigger it.
57 if (!isset($info['dotrepo'])) {
58 rg_log_debug('env ' . $env . ' never had a dotrepo; skip it');
59 continue;
60 }
61
62 rg_log_debug('env ' . $env . ' needs rebuilding of'
63 . ' dotrepo because ver was incremented');
64 $a['env'] = $env;
65 $ret[] = $a;
66 }
67 } while (0);
68
69 rg_log_exit();
70 return $ret;
71 }
72
73 /*
74 * This is trigger by the addition of some user packages to
75 * a global repository.
76 * It is called from 'rgfs'.
77 */
78 function rg_pkg_subrepo_event_regenerate($db, $ev)
79 {
80 rg_log_enter('pkg_subrepo_event_regenerate');
81
82 $ret = FALSE;
83 do {
84 $ev['source'] = 'pkg_subrepo_event_regenerate';
85
86 $ev['exec'] = array();
87
88 $ev['uid'] = 0;
89
90 $ev['pkg_maps'] = array();
91 $ev['pkg_repos'] = array();
92 $ev['pkg_subrepos'] = array();
93
94 $err = FALSE;
51 // We try to group the changes by arch, to start fewer machines
52 $per_env = array();
95 53 foreach ($ev['pkg_subrepo_id_list'] as $pkg_subrepo_id) { foreach ($ev['pkg_subrepo_id_list'] as $pkg_subrepo_id) {
96 54 $sri = rg_pkg_subrepo_info($db, $ev['uid'], $pkg_subrepo_id); $sri = rg_pkg_subrepo_info($db, $ev['uid'], $pkg_subrepo_id);
97 if ($sri['ok'] != 1) {
98 $err = TRUE;
55 if ($sri['exists'] != 1)
99 56 break; break;
100 }
101 $ev['pkg_subrepos'][$pkg_subrepo_id] = $sri;
102 57
103 $pkg_repo_id = $sri['pkg_repo_id'];
104 $ri = rg_pkg_repo_info($db, $ev['uid'], $pkg_repo_id);
105 if ($ri['ok'] != 1) {
106 $err = TRUE;
107 break;
58 // TODO: I think for Debian we should do nothing
59 $di = $sri['distro_info'];
60 foreach ($di as $env => $info) {
61 // We do not need to generate dotrepo for never generated subrepos.
62 // We wait for the first packet in the repo to trigger it.
63 if (!isset($info['dotrepo'])) {
64 rg_log_debug('env ' . $env . ' never had a dotrepo; skip it');
65 continue;
66 }
67
68 rg_log_debug('env ' . $env . ' needs rebuilding of'
69 . ' dotrepo because ver was incremented');
70 if (!isset($per_env[$env]))
71 $per_env[$env] = array();
72 $per_env[$env] = $pkg_repo_id;
108 73 } }
109 $ev['pkg_repos'][$pkg_repo_id] = $ri;
110
111 // Fake pkg_maps
112 $ev['pkg_maps'][] = array(
113 'pkg_subrepo_id' => $pkg_subrepo_id,
114 'flags' => ''
115 );
116 }
117 if ($err)
118 break;
119
120 unset($ev['pkg_subrepo_id_list']);
121
122 rg_pkg_prepare_for_rgfs($db, $ev);
123
124 $r = rg_pkg_prepare_for_dotrepo($db, $ev);
125 if ($r['ok'] != 1) {
126 rg_log('Cannot prepare ev: ' . $r['errmsg']);
127 break;
128 74 } }
129 75
130 $r = rg_builder_add($db, $ev['repo_id'], $ev['prio'], $ev);
131 if ($r['ok'] != 1) {
132 rg_log($r['errmsg']);
133 break;
134 }
76 rg_log_debug('per_env: ' . print_r($per_env, TRUE));
135 77
136 78 $ret = array(); $ret = array();
137 79
138 //$ret[] = $ev;
139 // TODO: Then, from cron, we gather all dirty subrepos and regenerate all of them.
140 // TODO: Check all major/arch for '+pending' folder.
141 // TODO: Should we just return an array with 'category' = builder_add'?
142 // TODO: Else, why we have an event here?!
80 foreach ($per_env as $env => $list) {
81 $a['env'] = $env;
82 $a['pkg_subrepo_id_list'] = $list;
83 $ret[] = $a;
84 }
143 85 } while (0); } while (0);
144 86
145 87 rg_log_exit(); rg_log_exit();
 
... ... function rg_pkg_subrepo_event_regenerate($db, $ev)
147 89 } }
148 90
149 91 /* /*
150 * This is trigger by the edit of a pkg_repo (NOT subrepo)
92 * This is triggered by the edit of a pkg_repo (NOT subrepo)
151 93 */ */
152 94 function rg_pkg_subrepo_event_pkg_repo_changed($db, $ev) function rg_pkg_subrepo_event_pkg_repo_changed($db, $ev)
153 95 { {
 
... ... function rg_pkg_subrepo_event_pkg_repo_changed($db, $ev)
157 99 if ($list === FALSE) if ($list === FALSE)
158 100 break; break;
159 101
160 foreach ($list as $id => $info) {
102 $ev['source'] = 'pkg_subrepo_event_pkg_repo_changed';
103 $ev['category'] = 'pkg_subrepo_edit';
104 $ev['pkg_subrepo_id_list'] = array();
105
106 // For each affected subrepo...
107 foreach ($list as $pkg_subrepo_id => $info) {
161 108 if ($info['pkg_repo_id'] != $ev['pkg_repo_id']) if ($info['pkg_repo_id'] != $ev['pkg_repo_id'])
162 109 continue; continue;
163 110
164 $a = $ev;
165 $a['category'] = 'pkg_subrepo_edit';
166 $a['pkg_subrepo_id'] = $id;
167 $ret[] = $a;
111 $ev['pkg_subrepo_id_list'][] = $pkg_subrepo_id;
168 112 } }
113
114 $ret[] = $ev;
169 115 } while (0); } while (0);
170 116
171 117 return $ret; return $ret;
 
... ... function rg_pkg_subrepo_update_distro_info($db, $uid, $pkg_subrepo_id, $di)
222 168 { {
223 169 rg_log_enter('pkg_subrepo_update_distro_info'); rg_log_enter('pkg_subrepo_update_distro_info');
224 170 rg_log_debug('di: ' . rg_array2string($di)); rg_log_debug('di: ' . rg_array2string($di));
171
225 172 $ret = array('ok' => 0); $ret = array('ok' => 0);
226 173 do { do {
227 174 $sri = rg_pkg_subrepo_info($db, $uid, $pkg_subrepo_id); $sri = rg_pkg_subrepo_info($db, $uid, $pkg_subrepo_id);
228 if ($sri['ok'] != 1) {
175 if ($sri['exists'] != 1) {
229 176 $ret['errmsg'] = $sri['errmsg']; $ret['errmsg'] = $sri['errmsg'];
230 177 break; break;
231 178 } }
 
... ... function rg_pkg_subrepo_edit($db, $uid, $d)
343 290 'pkg_subrepo_add' : 'pkg_subrepo_edit', 'pkg_subrepo_add' : 'pkg_subrepo_edit',
344 291 'prio' => 100, 'prio' => 100,
345 292 'uid' => $uid, 'uid' => $uid,
346 'pkg_subrepo_id' => $d['id']
293 'pkg_subrepo_id_list' => array($d['id'])
347 294 ); );
348 295 $r = rg_event_add($db, $ev); $r = rg_event_add($db, $ev);
349 296 if ($r !== TRUE) { if ($r !== TRUE) {
 
... ... function rg_pkg_subrepo_cosmetic($db, &$row)
457 404 if ($pkg_repo_info['exists'] != 1) { if ($pkg_repo_info['exists'] != 1) {
458 405 $row['pkg_repo_info'] = array('name' => 'error'); $row['pkg_repo_info'] = array('name' => 'error');
459 406 } else { } else {
460 rg_pkg_repo_cosmetic($pkg_repo_info);
407 rg_pkg_repo_cosmetic($db, $pkg_repo_info);
461 408 $row['pkg_repo_info'] = $pkg_repo_info; $row['pkg_repo_info'] = $pkg_repo_info;
462 409 } }
463 410 } }
 
... ... function rg_pkg_subrepo_info($db, $uid, $id)
556 503 $ret = array(); $ret = array();
557 504 $ret['ok'] = 0; $ret['ok'] = 0;
558 505 $ret['exists'] = 0; $ret['exists'] = 0;
559 while (1) {
506 do {
560 507 $list = rg_pkg_subrepo_list($db, $uid); $list = rg_pkg_subrepo_list($db, $uid);
561 508 if ($list === FALSE) if ($list === FALSE)
562 509 break; break;
 
... ... function rg_pkg_subrepo_info($db, $uid, $id)
564 511 $ret['ok'] = 1; $ret['ok'] = 1;
565 512
566 513 $id = sprintf('%d', $id); $id = sprintf('%d', $id);
567 if (!isset($list[$id]))
514 if (!isset($list[$id])) {
515 $ret['errmsg'] = 'pkg subrepo ' . $id . ' does not exists';
568 516 break; break;
517 }
569 518
570 519 $ret = array_merge($ret, $list[$id]); $ret = array_merge($ret, $list[$id]);
571 520 $ret['exists'] = 1; $ret['exists'] = 1;
572 break;
573 }
521 } while (0);
574 522
575 523 rg_log_exit(); rg_log_exit();
576 524 rg_prof_end('pkg_subrepo_info'); rg_prof_end('pkg_subrepo_info');
 
... ... function rg_pkg_subrepo_high_level($db, &$rg, $paras)
852 800 rg_log_enter('pkg_subrepo_high_level paras:' . rg_array2string($paras)); rg_log_enter('pkg_subrepo_high_level paras:' . rg_array2string($paras));
853 801
854 802 $ret = ''; $ret = '';
855 while (1) {
803 do {
804 $old_url = $rg['url'];
805 $rg['url'] .= '/subrepo';
806
856 807 $op = empty($paras) ? 'list' : array_shift($paras); $op = empty($paras) ? 'list' : array_shift($paras);
857 $rg['menu3']['packages']['subrepo'] = array($op => 1);
808 $rg['menu3']['packages']['subrepo'] = $op;
858 809
859 810 switch ($op) { switch ($op) {
860 811 case 'add': case 'add':
 
... ... function rg_pkg_subrepo_high_level($db, &$rg, $paras)
871 822 $rg['HTML:menu_level3'] = $rg['HTML:menu_level3'] =
872 823 rg_template('user/settings/packages/subrepo/menu.html', rg_template('user/settings/packages/subrepo/menu.html',
873 824 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
874 break;
875 }
825
826 $rg['url'] = $old_url;
827 } while (0);
876 828
877 829 rg_log_exit(); rg_log_exit();
878 830 rg_prof_end('pkg_subrepo_high_level'); rg_prof_end('pkg_subrepo_high_level');
File inc/util2.inc.php changed (mode: 100644) (index c2e63c3..3c0752f)
... ... function rg_env_enable($db, $list)
66 66 } }
67 67
68 68 /* /*
69 * Returns some info about an 'env'
69 * Returns info based on distro name
70 */
71 function rg_env_distro_info($distro)
72 {
73 $ret = array();
74
75 if (strcmp($distro, 'fedora') == 0) {
76 $ret['nice'] = 'Fedora Linux';
77 $ret['pkg_type'] = 'rpm';
78 } else if (strcmp($distro, 'centos') == 0) {
79 $ret['nice'] = 'CentOS';
80 $ret['pkg_type'] = 'rpm';
81 } else if (strcmp($distro, 'debian') == 0) {
82 $ret['nice'] = 'Debian';
83 $ret['pkg_type'] = 'deb';
84 } else if (strcmp($distro, 'rocky') == 0) {
85 $ret['nice'] = 'Rocky Linux';
86 $ret['pkg_type'] = 'rpm';
87 } else if (strcmp($distro, 'archlinux') == 0) {
88 $ret['nice'] = 'ArchLinux';
89 $ret['pkg_type'] = 'apk?';
90 } else if (strcmp($distro, 'opensuse') == 0) {
91 $ret['nice'] = 'OpenSuse';
92 $ret['pkg_type'] = 'rpm';
93 } else if (strcmp($distro, 'ubuntu') == 0) {
94 $ret['nice'] = 'Ubuntu';
95 $ret['pkg_type'] = 'deb';
96 } else {
97 $ret['nice'] = $distro;
98 $ret['pkg_type'] = '?';
99 }
100
101 return $ret;
102 }
103
104 /*
105 * Returns a codename based on major
106 */
107 function rg_env_major2codename($distro, $major)
108 {
109 if (strcmp($distro, 'debian') == 0) {
110 switch ($major) {
111 case 13: return 'trixie';
112 case 12: return 'bookworm';
113 case 11: return 'bullseye';
114 case 10: return 'buster';
115 case 9: return 'stretch';
116 case 8: return 'jessie';
117 }
118 } else if (strcmp($distro, 'ubuntu') == 0) {
119 if (strcmp($major, '20.04') == 0) {
120 return 'focal'; // fossa
121 } else if (strcmp($major, '20.10') == 0) {
122 return 'groovy'; // gorilla
123 } else if (strcmp($major, '21.04') == 0) {
124 return 'hirsute'; // hippo
125 } else if (strcmp($major, '21.10') == 0) {
126 return 'impish'; // indri
127 } else if (strcmp($major, '22.04') == 0) {
128 return 'jammy'; // jellyfish
129 }
130 }
131
132 return sprintf('%u', $major);
133 }
134
135 /*
136 * Returns a major based on codename
137 */
138 function rg_env_codename2major($distro, $codename)
139 {
140 if (strcmp($distro, 'debian') == 0) {
141 switch ($codename) {
142 case 'trixie': return '13'; break;
143 case 'bookworm': return '12'; break;
144 case 'bullseye': return '11'; break;
145 case 'buster': return '10'; break;
146 case 'stretch': return '9'; break;
147 case 'jessie': return '8'; break;
148 }
149 } else if (strcmp($distro, 'ubuntu') == 0) {
150 switch ($codename) {
151 case 'focal': return '20.04'; break;
152 case 'groovy': return '20.10'; break;
153 case 'hirsute': return '21.04'; break;
154 case 'impish': return '21.10'; break;
155 case 'jammy': return '22.04'; break;
156 }
157 }
158
159 return '-';
160 }
161
162 /*
163 * Returns some info about an 'env' (distro-major-arch)
70 164 */ */
71 165 function rg_env_info($env) function rg_env_info($env)
72 166 { {
 
... ... function rg_env_info($env)
79 173 if (isset($p[2])) if (isset($p[2]))
80 174 $ret['arch'] = $p[2]; $ret['arch'] = $p[2];
81 175
82 if (strcmp($ret['distro'], 'fedora') == 0) {
83 $ret['distro_nice'] = 'Fedora Linux';
84 $ret['distro_pkg_type'] = 'rpm';
85 } else if (strcmp($ret['distro'], 'centos') == 0) {
86 $ret['distro_nice'] = 'CentOS';
87 $ret['distro_pkg_type'] = 'rpm';
88 } else if (strcmp($ret['distro'], 'debian') == 0) {
89 $ret['distro_nice'] = 'Debian';
90 $ret['distro_pkg_type'] = 'deb';
91 } else if (strcmp($ret['distro'], 'rocky') == 0) {
92 $ret['distro_nice'] = 'Rocky Linux';
93 $ret['distro_pkg_type'] = 'rpm';
94 } else if (strcmp($ret['distro'], 'archlinux') == 0) {
95 $ret['distro_nice'] = 'ArchLinux';
96 $ret['distro_pkg_type'] = 'apk?';
97 } else if (strcmp($ret['distro'], 'opensuse') == 0) {
98 $ret['distro_nice'] = 'OpenSuse';
99 $ret['distro_pkg_type'] = 'rpm';
100 } else if (strcmp($ret['distro'], 'ubuntu') == 0) {
101 $ret['distro_nice'] = 'Ubuntu';
102 $ret['distro_pkg_type'] = 'deb';
103 } else {
104 $ret['distro_nice'] = $ret['distro'];
105 $ret['distro_pkg_type'] = '?';
106 }
176 $r = rg_env_distro_info($ret['distro']);
177 foreach ($r as $k => $v)
178 $ret[$k] = $v;
179
180 $ret['codename'] = rg_env_major2codename($ret['distro'], $ret['major']);
107 181
108 182 return $ret; return $ret;
109 183 } }
 
... ... function rg_distro_info2tree($list)
137 211
138 212 function rg_distro_sort_func($a, $b) function rg_distro_sort_func($a, $b)
139 213 { {
140 $x = strcmp($a['distro_nice'], $b['distro_nice']);
214 $x = strcmp($a['nice'], $b['nice']);
141 215 if ($x != 0) if ($x != 0)
142 216 return $x; return $x;
143 217
 
... ... function rg_envs_tree($db, $only_enabled)
183 257 $distro = $ei['distro']; $distro = $ei['distro'];
184 258 if (!isset($ret['tree'][$distro])) if (!isset($ret['tree'][$distro]))
185 259 $ret['tree'][$distro] = array( $ret['tree'][$distro] = array(
186 'pkg_type' => $ei['distro_pkg_type'],
187 'nice' => $ei['distro_nice'],
188 'versions' => array()
189 );
260 'pkg_type' => $ei['pkg_type'],
261 'nice' => $ei['nice'],
262 'versions' => array());
190 263
191 264 $major = $ei['major']; $major = $ei['major'];
192 265 if (!isset($ret['tree'][$distro]['versions'][$major])) if (!isset($ret['tree'][$distro]['versions'][$major]))
193 266 $ret['tree'][$distro]['versions'][$major] = array( $ret['tree'][$distro]['versions'][$major] = array(
194 'archs' => array()
195 );
267 'archs' => array());
196 268
197 269 $arch = $ei['arch']; $arch = $ei['arch'];
198 270 if (!isset($ret['tree'][$distro]['versions'][$major]['archs'][$arch])) if (!isset($ret['tree'][$distro]['versions'][$major]['archs'][$arch]))
File inc/webhooks.inc.php changed (mode: 100644) (index 42a9ac3..5f12ed3)
... ... rg_event_register_functions($rg_wh_functions);
16 16 function rg_wh_send($db, $ev) function rg_wh_send($db, $ev)
17 17 { {
18 18 rg_log_enter('wh_send'); rg_log_enter('wh_send');
19 rg_log_debug('ev: ' . print_r($ev, TRUE));
19 rg_log_debug('ev: ' . rg_array2string_short($ev));
20 20
21 21 $ret = array(); $ret = array();
22 22 do { do {
File inc/wh/build.inc.php changed (mode: 100644) (index 69dae5a..bf9dc8e)
2 2 require_once(__DIR__ . '/../events.inc.php'); require_once(__DIR__ . '/../events.inc.php');
3 3 require_once(__DIR__ . '/../builder.inc.php'); require_once(__DIR__ . '/../builder.inc.php');
4 4 require_once(__DIR__ . '/core.inc.php'); require_once(__DIR__ . '/core.inc.php');
5 require_once(__DIR__ . '/../user/pkg_map.inc.php');
6 require_once(__DIR__ . '/../user/packages_rpm.inc.php');
5 require_once(__DIR__ . '/../user/packages.inc.php');
7 6
8 7 $_f = array( $_f = array(
9 8 'wh_build_send' => 'rg_wh_build_send', 'wh_build_send' => 'rg_wh_build_send',
 
... ... function rg_wh_build_job_done($db, $ev)
20 19 { {
21 20 rg_prof_start('wh_build_job_done'); rg_prof_start('wh_build_job_done');
22 21 rg_log_enter('wh_build_job_done'); rg_log_enter('wh_build_job_done');
23 //rg_log_enter_ml('DEBUG: ev: ' . rg_array2string($ev));
22 rg_log_debug('ev: ' . rg_array2string_short($ev));
24 23
25 24 $job = $ev['job']; $job = $ev['job'];
26 25 $req = isset($job['request']) ? $job['request'] : $job; $req = isset($job['request']) ? $job['request'] : $job;
 
... ... function rg_wh_build_job_done($db, $ev)
73 72 } }
74 73 } while (0); } while (0);
75 74
76 //rg_log_debug('ret: ' . rg_array2string($ret));
75 //rg_log_debug('ret: ' . rg_array2string_short($ret));
77 76
78 77 rg_log_exit(); rg_log_exit();
79 78 rg_prof_end('wh_build_job_done'); rg_prof_end('wh_build_job_done');
 
... ... function rg_wh_build_job_done($db, $ev)
82 81
83 82 /* /*
84 83 * Helper for rg_wh_build_send * Helper for rg_wh_build_send
84 * We have to do some things here because the push generates a generic event
85 * (think http post) and this is the last chance to prepare it.
85 86 */ */
86 87 function rg_wh_build_send_one($db, $ev) function rg_wh_build_send_one($db, $ev)
87 88 { {
88 89 rg_prof_start('wh_build_send_one'); rg_prof_start('wh_build_send_one');
89 //rg_log_debug('wh_build_send_one: event: ' . rg_array2string($ev));
90 rg_log_enter('wh_build_send_one');
91 //rg_log_debug('wh_build_send_one: ev: ' . rg_array2string_short($ev));
90 92
91 93 $ret = FALSE; $ret = FALSE;
92 94 $last_output = ''; $last_output = '';
 
... ... function rg_wh_build_send_one($db, $ev)
102 104
103 105 $a = $ev['wh']['idata']; $a = $ev['wh']['idata'];
104 106 $a['repo_id'] = $ev['ri']['repo_id']; $a['repo_id'] = $ev['ri']['repo_id'];
107 $a['repo_uid'] = $ev['ri']['repo_uid'];
108 $a['repo_name'] = $ri['name'];
105 109 $a['repo_username'] = $ev['ri']['repo_username']; $a['repo_username'] = $ev['ri']['repo_username'];
106 110 $a['hook_id'] = $ev['wh']['id']; $a['hook_id'] = $ev['wh']['id'];
107 111 $a['uid'] = $ev['ui_login']['uid']; $a['uid'] = $ev['ui_login']['uid'];
 
... ... function rg_wh_build_send_one($db, $ev)
115 119 $a['log_sid'] = $ev['log_sid']; $a['log_sid'] = $ev['log_sid'];
116 120 $a['packages'] = $ev['packages']; $a['packages'] = $ev['packages'];
117 121 // TODO: pass e-mail notification // TODO: pass e-mail notification
122 $a['exec'] = array();
118 123
119 124 $r = rg_pkg_maps_get($db, $a['uid'], $ri['name'], $r = rg_pkg_maps_get($db, $a['uid'], $ri['name'],
120 125 $a['refname_short']); $a['refname_short']);
 
... ... function rg_wh_build_send_one($db, $ev)
127 132 $a['pkg_repos'] = $r['pkg_repos']; $a['pkg_repos'] = $r['pkg_repos'];
128 133 $a['pkg_subrepos'] = $r['pkg_subrepos']; $a['pkg_subrepos'] = $r['pkg_subrepos'];
129 134
130 rg_pkg_prepare_for_rgfs($db, $a);
135 $a['build_repo_id'] = $ev['ri']['repo_id'];
131 136
132 $a['exec'] = array();
133 $a['exec']['prepare_rpms'] = 1;
134 $a['exec']['copy_to_rgfs'] = 1;
137 $a['exec']['prepare_pkgs'] = 1;
135 138
136 $r = rg_pkg_prepare_for_dotrepo($db, $a);
137 if ($r['ok'] != 1) {
138 rg_log('Cannot prepare ev: ' . $r['errmsg']);
139 break;
140 }
141
142 // Call the function
143 $r = rg_builder_add($db, $ev['ri']['repo_id'], 10 /*prio*/, $a);
139 $r = rg_pkg_prepare_for_build($db, $a);
144 140 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
141 rg_log('Error: ' . $r['errmsg']);
145 142 $last_output .= $r['errmsg']; $last_output .= $r['errmsg'];
146 143 break; break;
147 144 } }
 
... ... function rg_wh_build_send_one($db, $ev)
154 151 rg_wh_set_last_output($db, $ev['ui_login']['uid'], $ev['wh']['id'], rg_wh_set_last_output($db, $ev['ui_login']['uid'], $ev['wh']['id'],
155 152 substr($last_output, 0, 4096)); substr($last_output, 0, 4096));
156 153
154 rg_log_exit();
157 155 rg_prof_end('wh_build_send_one'); rg_prof_end('wh_build_send_one');
158 156 return $ret; return $ret;
159 157 } }
 
... ... function rg_wh_build_send_one($db, $ev)
164 162 function rg_wh_build_send($db, $ev) function rg_wh_build_send($db, $ev)
165 163 { {
166 164 rg_prof_start('wh_build_send'); rg_prof_start('wh_build_send');
167 rg_log_ml('wh_build_send: event: ' . rg_array2string($ev));
165 rg_log_debug('wh_build_send: ev: ' . rg_array2string_short($ev));
168 166
169 167 $ret = array(); $ret = array();
170 168
 
... ... function rg_wh_build_send($db, $ev)
191 189 } }
192 190
193 191 if (isset($ev['ri']['name']) if (isset($ev['ri']['name'])
194 && !rg_repo_compare_refs($wh['repo'], $ev['ri']['name'])) {
192 && !rg_wh_repo_match($wh['repo'], $ev['ri']['name'])) {
195 193 rg_log_debug('hook is not for this repo'); rg_log_debug('hook is not for this repo');
196 194 continue; continue;
197 195 } }
 
... ... function rg_wh_build_fill_vars(&$rg)
298 296 $a['packages'] = trim(rg_var_str('wh::idata::packages')); $a['packages'] = trim(rg_var_str('wh::idata::packages'));
299 297 $a['packages'] = str_replace(';', ' ', $a['packages']); $a['packages'] = str_replace(';', ' ', $a['packages']);
300 298 $a['packages'] = str_replace(',', ' ', $a['packages']); $a['packages'] = str_replace(',', ' ', $a['packages']);
301 $a['packages'] = str_replace('\r', ' ', $a['packages']);
302 $a['packages'] = str_replace('\n', ' ', $a['packages']);
303 $a['packages'] = str_replace('\t', ' ', $a['packages']);
299 $a['packages'] = str_replace("\r", ' ', $a['packages']);
300 $a['packages'] = str_replace("\n", ' ', $a['packages']);
301 $a['packages'] = str_replace("\t", ' ', $a['packages']);
304 302
305 303 $rg['wh']['idata'] = $a; $rg['wh']['idata'] = $a;
306 304
File inc/wh/cloud.inc.php changed (mode: 100644) (index 8ad7324..29081fe)
... ... function rg_wh_cloud_send($db, $ev)
124 124 continue; continue;
125 125 } }
126 126
127 if (!rg_repo_compare_refs($wh['repo'], $ev['ri']['name'])) {
128 rg_log('hook is not for this ref');
127 if (!rg_wh_repo_match($wh['repo'], $ev['ri']['name'])) {
128 rg_log('hook is not for this repo');
129 129 continue; continue;
130 130 } }
131 131
File inc/wh/http/matrix.inc.php changed (mode: 100644) (index 178f368..3e17adc)
... ... function rg_wh_matrix_fill_vars(&$rg, &$junk)
15 15 function rg_wh_matrix_send($db, $ev) function rg_wh_matrix_send($db, $ev)
16 16 { {
17 17 rg_log_enter('wh_matrix_send'); rg_log_enter('wh_matrix_send');
18 //rg_log_debug('wh_matrix_send: ev: ' . rg_array2string($ev));
18 //rg_log_debug('wh_matrix_send: ev: ' . rg_array2string_short($ev));
19 19
20 20 $ret = FALSE; $ret = FALSE;
21 21 while (1) { while (1) {
 
... ... function rg_wh_matrix_send($db, $ev)
76 76
77 77 // message // message
78 78 // https://matrix.org/docs/spec/client_server/latest#id320 // https://matrix.org/docs/spec/client_server/latest#id320
79 rg_log_debug('now, sending the message ev: ' . rg_array2string($ev));
79 rg_log_debug('now, sending the message ev: ' . rg_array2string_short($ev));
80 80 $ev2 = $ev; $ev2 = $ev;
81 81 $ev2['wh']['idata']['url'] .= '/_matrix/client/r0/rooms/' $ev2['wh']['idata']['url'] .= '/_matrix/client/r0/rooms/'
82 82 . rawurlencode($ev2['wh']['idata']['room']) . rawurlencode($ev2['wh']['idata']['room'])
File inc/wh/lambda.inc.php changed (mode: 100644) (index 27d451e..9ae06b9)
... ... function rg_wh_lambda_send($db, $ev)
89 89 } }
90 90
91 91 if (isset($ev['ri']['name']) if (isset($ev['ri']['name'])
92 && !rg_repo_compare_refs($wh['repo'], $ev['ri']['name'])) {
92 && !rg_wh_repo_match($wh['repo'], $ev['ri']['name'])) {
93 93 rg_log_debug('hook is not for this repo'); rg_log_debug('hook is not for this repo');
94 94 continue; continue;
95 95 } }
File inc/workers.inc.php changed (mode: 100644) (index 2ce8cc0..ccc2336)
... ... function rg_worker_cosmetic_one(&$row)
80 80 $row['last_connect_nice'] = 'n/a'; $row['last_connect_nice'] = 'n/a';
81 81 else else
82 82 $row['last_connect_nice'] = gmdate('Y-m-d H:i', $row['last_connect_nice'] = gmdate('Y-m-d H:i',
83 $row['last_connect']);
83 intval($row['last_connect']));
84 84
85 85 if (empty($row['env'])) { if (empty($row['env'])) {
86 86 $row['HTML:envs_nice'] = 'n/a'; $row['HTML:envs_nice'] = 'n/a';
 
... ... function rg_worker_add($db, $uid, $a)
273 273 $params['uname'] = ''; $params['uname'] = '';
274 274 $params['host'] = ''; $params['host'] = '';
275 275 $params['arch'] = ''; $params['arch'] = '';
276 $params['last_connect'] = '';
276 $params['last_connect'] = 0;
277 277 $params['last_ip'] = ''; $params['last_ip'] = '';
278 278
279 279 $sql = 'INSERT INTO workers (itime, uid, name' $sql = 'INSERT INTO workers (itime, uid, name'
File root/themes/default/admin/distros/list/line.html changed (mode: 100644) (index c054037..d3b2463)
1 1 <tr> <tr>
2 2 <td><input id="@@env@@" type="checkbox" name="list[@@env@@]" @@if(@@enabled@@ == 1){{checked}} /></td> <td><input id="@@env@@" type="checkbox" name="list[@@env@@]" @@if(@@enabled@@ == 1){{checked}} /></td>
3 <td>@@distro_nice@@</td>
3 <td>@@nice@@</td>
4 4 <td>@@major@@</td> <td>@@major@@</td>
5 5 <td>@@arch@@</td> <td>@@arch@@</td>
6 <td>@@distro_pkg_type@@</td>
6 <td>@@pkg_type@@</td>
7 7 </tr> </tr>
8 8
File root/themes/default/rights/list_pkgrepo/header.html changed (mode: 100644) (index ca45be0..5a9d487)
1 1 @@list_errmsg@@ @@list_errmsg@@
2 2
3 <form method="post" action="@@url_repo@@/admin/repo_rights" class="form_table">
3 <form method="post" action="@@url@@" class="form_table">
4 4 <input type="hidden" name="delete" value="1" /> <input type="hidden" name="delete" value="1" />
5 5 <input type="hidden" name="token" value="@@rg_form_token@@" /> <input type="hidden" name="token" value="@@rg_form_token@@" />
6 6
File root/themes/default/rights/list_pkgrepo/line.html changed (mode: 100644) (index a1da39f..3917502)
7 7 <td>@@ip_nice@@</td> <td>@@ip_nice@@</td>
8 8 <td>@@rights_text@@</td> <td>@@rights_text@@</td>
9 9 <td><small>@@description_nlbr@@</small></td> <td><small>@@description_nlbr@@</small></td>
10 <td>@@if(@@can_be_deleted@@ == 1){{<a href="/op/settings/packages/repo/rights/@@pkg_repo_info::id@@/?edit_id=@@right_id@@"><span class="but">Edit</span></a>}}{{N/A}}</td>
10 <td>@@if(@@can_be_deleted@@ == 1){{<a href="@@url@@/?edit_id=@@right_id@@"><span class="but">Edit</span></a>}}{{N/A}}</td>
11 11 </tr> </tr>
File root/themes/default/user/pkg/deb/add_repo_howto.html added (mode: 100644) (index 0000000..384d371)
1 echo "deb [signed-by=/usr/share/keyrings/rocketgit-@@pkg::gpg_file@@.gpg] @@pkg::repo_url@@ @@pkg::repo_codename@@ @@pkg::repo_components@@" &gt; /etc/apt/sources.list.d/rocketgit-@@pkg::list_file@@.list
2 echo "deb-src [signed-by=/usr/share/keyrings/rocketgit-@@pkg::gpg_file@@.gpg] @@pkg::repo_url@@ @@pkg::repo_codename@@ @@pkg::repo_components@@" &gt;&gt; /etc/apt/sources.list.d/rocketgit-@@pkg::list_file@@.list
3
4 apt update
5 @@pkg_list@@@@debug_pkg_list@@@@src_pkg_list@@
File root/themes/default/user/pkg/deb/debug_pkg_list/footer.html copied from file root/themes/default/user/pkg/deb/pkg_list/footer.html (similarity 100%)
File root/themes/default/user/pkg/deb/debug_pkg_list/header.html copied from file root/themes/default/user/pkg/deb/pkg_list/header.html (similarity 100%)
File root/themes/default/user/pkg/deb/debug_pkg_list/line.html added (mode: 100644) (index 0000000..8370e57)
1 @@pkg::cmd@@ @@ESCAPE_SHELL_ARG:name@@ # if you need to install the debug package
File root/themes/default/user/pkg/deb/debug_pkg_list/nodata.html copied from file root/themes/default/doc/demo/toc/nodata.html (similarity 100%)
File root/themes/default/user/pkg/deb/pkg_list/line.html changed (mode: 100644) (index e69de29..9381746)
1 @@pkg::cmd@@ @@ESCAPE_SHELL_ARG:name@@
File root/themes/default/user/pkg/deb/priv_download.html added (mode: 100644) (index 0000000..12bb708)
1 <a href="@@pkg::auth_url@@"><span class="but">Download auth info</span></a>
2 <a href="@@pkg::keyring_url@@"><span class="but">Download keyring</span></a>
3
4 <div class="term"># Press the download buttons above and save the files.
5 # Then, copy them to all machines where you want to access this repository:
6 cp rocketgit-@@pkg::gpg_file@@.gpg /usr/share/keyrings/
7 cp rocketgit-@@pkg::auth_file@@.conf /etc/apt/auth.conf.d/
8 chmod go= /etc/apt/auth.conf.d/rocketgit-*.conf
9
10 @@add_repo_howto@@</div>
11
12 @@pkg::other@@
13
14
15
16
17
18
19
File root/themes/default/user/pkg/deb/pub_download.html added (mode: 100644) (index 0000000..1441b72)
1 <div class="term">wget -O /usr/share/keyrings/rocketgit-@@pkg::gpg_file@@.gpg @@pkg::keyring_url@@
2 @@add_repo_howto@@</div>
3
4 @@pkg::other@@
5
File root/themes/default/user/pkg/deb/src_pkg_list/line.html added (mode: 100644) (index 0000000..474517d)
1 @@pkg::src_cmd@@ @@ESCAPE_SHELL_ARG:name@@ # if you need to download the source package
File root/themes/default/user/pkg/list/line.html changed (mode: 100644) (index 43d476c..a72ed15)
3 3 <td>@@if(@@pkg_repo_info::public@@ == 1){{Public}}{{Private}}</td> <td>@@if(@@pkg_repo_info::public@@ == 1){{Public}}{{Private}}</td>
4 4 <td>@@pkg_repo_info::name@@</td> <td>@@pkg_repo_info::name@@</td>
5 5 <td>@@pkg_subrepo_info::name@@</td> <td>@@pkg_subrepo_info::name@@</td>
6 <td>@@distro_nice@@</td>
6 <td>@@nice@@</td>
7 7 <td>@@major@@</td> <td>@@major@@</td>
8 8 <td>@@arch@@</td> <td>@@arch@@</td>
9 9 <td> <td>
File root/themes/default/user/pkg/rpm/priv_download.html changed (mode: 100644) (index 79815a1..314b2bc)
5 5 <div class="term"># Press the <b>Download</b> button above, copy the rpm to any machine you want, and then: <div class="term"># Press the <b>Download</b> button above, copy the rpm to any machine you want, and then:
6 6 @@pkg::cmd@@ install @@ESCAPE_SHELL_ARG:pkg::dotrepo_pkg_name@@ @@pkg::cmd@@ install @@ESCAPE_SHELL_ARG:pkg::dotrepo_pkg_name@@
7 7 @@if("@@pkg::user@@" != ""){{ @@if("@@pkg::user@@" != ""){{
8
8 9 @@pkg::cmd@@ install @@ESCAPE_SHELL_ARG:pkg::user_repo_name@@ @@pkg::cmd@@ install @@ESCAPE_SHELL_ARG:pkg::user_repo_name@@
9 10 }} }}
10 11 </div> </div>
File root/themes/default/user/pkg/rpm/pub_download.html changed (mode: 100644) (index 9cadafc..5f92419)
1 1 <div class="term">@@pkg::cmd@@ install <a href="@@pkg::dotrepo_pkg_url@@/@@pkg::dotrepo_pkg_name@@">@@pkg::dotrepo_pkg_url@@/@@pkg::dotrepo_pkg_name@@</a> <div class="term">@@pkg::cmd@@ install <a href="@@pkg::dotrepo_pkg_url@@/@@pkg::dotrepo_pkg_name@@">@@pkg::dotrepo_pkg_url@@/@@pkg::dotrepo_pkg_name@@</a>
2 2 @@if("@@pkg::user@@" != ""){{ @@if("@@pkg::user@@" != ""){{
3
3 4 @@pkg::cmd@@ install @@ESCAPE_SHELL_ARG:pkg::user_repo_name@@ @@pkg::cmd@@ install @@ESCAPE_SHELL_ARG:pkg::user_repo_name@@
4 5 }} }}
5 6 </div> </div>
File root/themes/default/user/settings/packages/map/menu.html changed (mode: 100644) (index 5619f8f..34ca20b)
1 1 <div class="menu menu3"> <div class="menu menu3">
2 2 <ul> <ul>
3 <li@@if(@@menu3::packages::map::list@@ == 1){{ class="selected"}}><a href="/op/settings/packages/map/list">List</a></li>
4 <li@@if(@@menu3::packages::map::add@@ == 1){{ class="selected"}}><a href="/op/settings/packages/map/add">Add</a></li>
3 <li@@if(@@menu3::packages::map@@ == list){{ class="selected"}}><a href="/op/settings/packages/map/list">List</a></li>
4 <li@@if(@@menu3::packages::map@@ == add){{ class="selected"}}><a href="/op/settings/packages/map/add">Add</a></li>
5 5 </ul> </ul>
6 6 </div> </div>
File root/themes/default/user/settings/packages/repo/list/header.html changed (mode: 100644) (index f6812b2..2708de0)
9 9 <thead> <thead>
10 10 <tr> <tr>
11 11 <th>Select</th> <th>Select</th>
12 <th>ID</th>
12 13 <th>Name</th> <th>Name</th>
14 <th>Type</th>
13 15 <th>Public?</th> <th>Public?</th>
14 16 <th>Version</th> <th>Version</th>
15 17 <th>Insert date (UTC)</th> <th>Insert date (UTC)</th>
File root/themes/default/user/settings/packages/repo/list/line.html changed (mode: 100644) (index 00913fa..565ddf6)
1 1 <tr> <tr>
2 <td><input type="checkbox" name="delete_list[@@id@@]" /></td>
2 <td>@@if(@@uid@@ != 0){{<input type="checkbox" name="delete_list[@@id@@]" />}}{{-}}</td>
3 <td>@@id@@</td>
3 4 <td>@@name@@</td> <td>@@name@@</td>
5 <td>@@if(@@uid@@ == 0){{Global}}{{User}}</td>
4 6 <td>@@public_nice@@</td> <td>@@public_nice@@</td>
5 7 <td>@@version@@</td> <td>@@version@@</td>
6 8 <td>@@itime_nice@@</td> <td>@@itime_nice@@</td>
7 9 <td>@@disk_used@@</td> <td>@@disk_used@@</td>
8 10 <td> <td>
11 @@if(@@uid@@ != 0){{
9 12 <a href="/op/settings/packages/repo/edit/@@id@@"><span class="but">Edit</span></a> <a href="/op/settings/packages/repo/edit/@@id@@"><span class="but">Edit</span></a>
13 }}
10 14 @@if(@@public@@ == 0){{ @@if(@@public@@ == 0){{
11 15 <a href="/op/settings/packages/repo/rights/@@id@@"><span class="but">Rights</span></a> <a href="/op/settings/packages/repo/rights/@@id@@"><span class="but">Rights</span></a>
12 16 }} }}
File root/themes/default/user/settings/packages/repo/menu.html changed (mode: 100644) (index 75066a3..7353f68)
1 1 <div class="menu menu3"> <div class="menu menu3">
2 2 <ul> <ul>
3 <li@@if(@@menu3::packages::repo::list@@ == 1){{ class="selected"}}><a href="/op/settings/packages/repo/list">List</a></li>
4 <li@@if(@@menu3::packages::repo::add@@ == 1){{ class="selected"}}><a href="/op/settings/packages/repo/add">Add</a></li>
3 <li@@if(@@menu3::packages::repo@@ == list){{ class="selected"}}><a href="/op/settings/packages/repo/list">List</a></li>
4 <li@@if(@@menu3::packages::repo@@ == add){{ class="selected"}}><a href="/op/settings/packages/repo/add">Add</a></li>
5 5 </ul> </ul>
6 6 </div> </div>
File root/themes/default/user/settings/packages/subrepo/menu.html changed (mode: 100644) (index c002788..d3aa156)
1 1 <div class="menu menu3"> <div class="menu menu3">
2 2 <ul> <ul>
3 <li@@if(@@menu3::packages::subrepo::list@@ == 1){{ class="selected"}}><a href="/op/settings/packages/subrepo/list">List</a></li>
4 <li@@if(@@menu3::packages::subrepo::add@@ == 1){{ class="selected"}}><a href="/op/settings/packages/subrepo/add">Add</a></li>
3 <li@@if(@@menu3::packages::subrepo@@ == list){{ class="selected"}}><a href="/op/settings/packages/subrepo/list">List</a></li>
4 <li@@if(@@menu3::packages::subrepo@@ == add){{ class="selected"}}><a href="/op/settings/packages/subrepo/add">Add</a></li>
5 5 </ul> </ul>
6 6 </div> </div>
File scripts/builder.php changed (mode: 100644) (index 6312f0d..3d49cf6)
... ... function xdispatch($key, $data)
695 695 } }
696 696
697 697 /* /*
698 * Returns TRUE if we should try to continue finding a worker.
699 * Returns FALSE if we should not continue.
698 * Process a job.
699 * Returns TRUE if we should try to continue with the next job in queue.
700 * Returns FALSE if we should not.
700 701 */ */
701 702 function rg_process_job($db, &$job) function rg_process_job($db, &$job)
702 703 { {
 
... ... function rg_process_job($db, &$job)
709 710 //rg_log($jid . ': job is already assigned to' //rg_log($jid . ': job is already assigned to'
710 711 // . ' worker [' . $job['worker_name'] . ']' // . ' worker [' . $job['worker_name'] . ']'
711 712 // . ' (id ' . $job['worker_id'] . '); skip it'); // . ' (id ' . $job['worker_id'] . '); skip it');
712 return FALSE;
713 return TRUE;
713 714 } }
714 715
715 716 // Should we delay because of a previous fail? // Should we delay because of a previous fail?
716 717 if (isset($job['next_try']) && ($job['next_try'] > time())) { if (isset($job['next_try']) && ($job['next_try'] > time())) {
717 718 rg_log_debug($jid . ': job is suspended till ' rg_log_debug($jid . ': job is suspended till '
718 719 . date('Y-m-d H:i:s', $job['next_try'])); . date('Y-m-d H:i:s', $job['next_try']));
719 return FALSE;
720 return TRUE;
720 721 } }
721 722
722 723 rg_log_ml($jid . ': processing job...'); rg_log_ml($jid . ': processing job...');
 
... ... function rg_process_job($db, &$job)
731 732 $workers_list = rg_worker_list_all($db, $req['uid']); $workers_list = rg_worker_list_all($db, $req['uid']);
732 733 if ($workers_list === FALSE) { if ($workers_list === FALSE) {
733 734 rg_log($jid . ': cannot load workers list: ' . rg_worker_error()); rg_log($jid . ': cannot load workers list: ' . rg_worker_error());
734 $job['next_try'] = time() + 60;
735 return TRUE;
735 $job['next_try'] = time() + 30;
736 return FALSE;
736 737 } }
737 738 //rg_log_debug('workers list: ' . rg_array2string($workers_list)); //rg_log_debug('workers list: ' . rg_array2string($workers_list));
738 739
 
... ... function rg_process_job($db, &$job)
820 821 // duplicate work // duplicate work
821 822 rg_log($key . ': ' . $jid . ': job sent to worker [' . $name . ']'); rg_log($key . ': ' . $jid . ': job sent to worker [' . $name . ']');
822 823 rg_log_debug('sent job: ' . rg_array2string($job2)); rg_log_debug('sent job: ' . rg_array2string($job2));
823 return FALSE;
824 return TRUE;
824 825 } }
825 826 unset($i); unset($i);
826 827
 
... ... $jobs = array();
855 856 $state_dir = $rg_state_dir . '/builder'; $state_dir = $rg_state_dir . '/builder';
856 857 $saved_jobs = rg_load_files($state_dir, 'job-[0-9]*.ser', 'id'); $saved_jobs = rg_load_files($state_dir, 'job-[0-9]*.ser', 'id');
857 858 if (!empty($saved_jobs)) if (!empty($saved_jobs))
858 rg_log_ml('Jobs loaded from dir: ' . rg_array2string($saved_jobs));
859 rg_log_debug('Jobs loaded from dir: ' . rg_array2string_short($saved_jobs));
859 860
860 861 rg_sql_app('rg-builder'); rg_sql_app('rg-builder');
861 862 $db = rg_sql_open($rg_sql); $db = rg_sql_open($rg_sql);
File scripts/events.php changed (mode: 100644) (index 0e91311..653a380)
... ... require_once($INC . "/fixes.inc.php");
27 27 require_once($INC . "/plan.inc.php"); require_once($INC . "/plan.inc.php");
28 28 require_once($INC . "/apikeys.inc.php"); require_once($INC . "/apikeys.inc.php");
29 29 require_once($INC . "/admin.inc.php"); require_once($INC . "/admin.inc.php");
30 require_once($INC . '/user/packages.inc.php');
30 31 require_once($INC . "/ver.php"); require_once($INC . "/ver.php");
31 32
32 33 function rg_destroy($key) function rg_destroy($key)
 
... ... do {
129 130 // check machine load - if too big we will delay // check machine load - if too big we will delay
130 131 $load = rg_load(); $load = rg_load();
131 132 if ($load > 500) { // TODO: make the limit configurable if ($load > 500) { // TODO: make the limit configurable
132 rg_log("Load too big (' . $load . ' > 200)!'
133 . ' Skip queue processing.");
133 rg_log('Load too big (' . $load . ' > 200)!'
134 . ' Skip queue processing.');
134 135 break; break;
135 136 } }
136 137
File scripts/rgfs.php changed (mode: 100644) (index ef70564..38bcf64)
... ... require_once(__DIR__ . '/../inc/prof.inc.php');
17 17 require_once(__DIR__ . '/../inc/user.inc.php'); require_once(__DIR__ . '/../inc/user.inc.php');
18 18 require_once(__DIR__ . '/../inc/fixes.inc.php'); require_once(__DIR__ . '/../inc/fixes.inc.php');
19 19 require_once(__DIR__ . '/../inc/ver.php'); require_once(__DIR__ . '/../inc/ver.php');
20 require_once(__DIR__ . '/../inc/rgfs.inc.php');
20 21 require_once(__DIR__ . '/../inc/user/packages.inc.php'); require_once(__DIR__ . '/../inc/user/packages.inc.php');
21 22
22 23 define('RGFS_EPERM', 1); define('RGFS_EPERM', 1);
 
... ... function rgfs_validate($path, &$s)
88 89 break; break;
89 90 } }
90 91
91 $allow_paths = array();
92
93 if (isset($s['vars']['allow_any_write'])) {
94 $allow_paths[] = array(
95 'next1' => '.*',
96 'next2' => '.*'
97 );
98 } else {
99 // This is needed when copying pkgs to the global repo
100 $allow_paths[] = array(
101 'next1' => '\+pending',
102 'next2' => $s['vars']['allow_username']
103 );
104
105 // This is needed when a user builds its pkgs and repo
106 /*
107 $allow_paths[] = array(
108 'next1' => $s['vars']['allow_username'],
109 'next2' => '.*'
110 );
111
112 if (isset($s['vars']['allow_create_repo'])) {
113 $allow_paths[] = array(
114 'next1' => '\.?repodata.*',
115 'next2' => '.*'
116 );
117
118 $allow_paths[] = array(
119 'next1' => 'drpms',
120 'next2' => '.*'
121 );
122 }
123 TODO: not needed anymore */
124
125 rg_log_debug('allow_paths: ' . rg_array2string($allow_paths));
126 }
127
128 $r = rg_packages_validate_path($s['db'], $path, $allow_paths);
92 $r = rg_packages_validate_path($s['db'], $path, $s['allow_paths']);
129 93 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
130 94 $ret['errmsg'] = $r['errmsg']; $ret['errmsg'] = $r['errmsg'];
131 95 break; break;
 
... ... function rgfs_validate_and_store_meta($add_path, $remove_path, &$s)
145 109 { {
146 110 rg_log_enter('validate_and_store_meta: add_path=[' . $add_path . ']' rg_log_enter('validate_and_store_meta: add_path=[' . $add_path . ']'
147 111 . ' remove_path=' . $remove_path . ']'); . ' remove_path=' . $remove_path . ']');
148 //rg_log_debug('s[vars]: ' . rg_array2string($s['vars']));
112 //rg_log_debug('s[vars]: ' . rg_array2string_short($s['vars']));
149 113
150 $locked = FALSE;
151 114 $a = $s['vars']; $a = $s['vars'];
152 115 $ret = array('ok' => 0); $ret = array('ok' => 0);
153 116 do { do {
 
... ... function rgfs_validate_and_store_meta($add_path, $remove_path, &$s)
177 140 } }
178 141
179 142 if (preg_match('/\/\.?repodata($|\.old.*|\/)/', $add_path) === 1) { if (preg_match('/\/\.?repodata($|\.old.*|\/)/', $add_path) === 1) {
180 rg_log_debug('meta ignore ' . $add_path);
143 //rg_log_debug('meta ignore ' . $add_path);
181 144 $ret['ok'] = 1; $ret['ok'] = 1;
182 145 break; break;
183 146 } }
184 if (preg_match('/\/drpms($|\/)/', $add_path) === 1) {
185 rg_log_debug('meta ignore ' . $add_path);
147 if (preg_match('/\/drpms($|\/)/', $add_path) === 1) { // TODO: we should not ignore these files
148 //rg_log_debug('meta ignore ' . $add_path);
186 149 $ret['ok'] = 1; $ret['ok'] = 1;
187 150 break; break;
188 151 } }
189 152
190 $meta_dir = $s['dir'] . '/meta';
191 if (!is_dir($meta_dir)) {
192 $r = @mkdir($meta_dir, 0700);
193 if ($r === FALSE) {
194 $ret['errmsg'] = 'canot create meta dir: ' . rg_php_err();
195 break;
196 }
197 }
198
199 $lock_file = 'rgfs-' . $a['pkg_repo_id']
200 . '-' . $a['pkg_subrepo_id']
201 . '-' . $a['repo_id'] . '.lock';
202 $r = rg_lock($lock_file, RG_LOCK_BLOCK);
203 if ($r !== TRUE) {
204 $ret['errmsg'] = rg_util_error();
205 break;
206 }
207 $locked = TRUE;
208
209 $meta_path = $meta_dir . '/' . $a['repo_id'] . '.json';
210 $data = array();
211 if (file_exists($meta_path)) {
212 $data = @file_get_contents($meta_path);
213 if ($data === FALSE) {
214 $ret['errmsg'] = 'cannot load old data: ' . rg_php_err();
215 break;
216 }
217 $data = rg_unserialize($data);
218 if ($data === FALSE) {
219 $ret['errmsg'] = 'cannot unserizalize data';
220 break;
221 }
222 }
223
224 $old_meta = array();
225 if ((!empty($remove_path)) && isset($data[$remove_path])) {
226 $old_meta = $data[$remove_path];
227 unset($data[$remove_path]);
228 //rg_log_debug('old_meta: ' . rg_array2string($old_meta));
229 }
230
231 if (!empty($add_path)) {
232 if (!empty($old_meta)) {
233 $meta = $old_meta;
234 } else {
235 $meta['job_id'] = $a['job_id'];
236 $meta['head'] = $a['head'];
237 $meta['ctime'] = time();
238 $meta['worker_name'] = $a['worker_name'];
239 }
240 $data[$add_path] = $meta;
241 }
242
243 $r = rg_save($meta_path, $data);
244 if ($r === FALSE) {
245 $ret['errmsg'] = rg_php_err();
153 $meta = array('job_id' => $a['job_id'],
154 'env' => $a['env'],
155 'head' => $a['head'],
156 'worker_name' => $a['worker_name']);
157 $files = array();
158 $files[] = array('repo_id' => $a['repo_id'], 'add' => $add_path,
159 'del' => $remove_path, 'meta' => $meta);
160 $r = rg_rgfs_add_remove($s['dir'], $files, FALSE);
161 if ($r['ok'] != 1) {
162 $ret['errmsg'] = $r['errmsg'];
246 163 break; break;
247 164 } }
248 165
249 166 $ret['ok'] = 1; $ret['ok'] = 1;
250 167 } while (0); } while (0);
251 if ($locked)
252 rg_unlock($lock_file);
253 168
254 169 rg_log_exit(); rg_log_exit();
255 170 return $ret; return $ret;
 
... ... function xdispatch_one($key, $tlv)
331 246
332 247 $pri = rg_pkg_repo_info($s['db'], $a['uid'], $a['pkg_repo_id']); $pri = rg_pkg_repo_info($s['db'], $a['uid'], $a['pkg_repo_id']);
333 248 if ($pri['exists'] != 1) { if ($pri['exists'] != 1) {
334 debug($key, 'Cannot find the pkg repo ' . $a['pkg_repo_id'] . '!');
249 debug($key, $pri['errmsg']);
335 250 rg_conn_shutdown($key, 2); rg_conn_shutdown($key, 2);
336 251 return; return;
337 252 } }
 
... ... function xdispatch_one($key, $tlv)
355 270
356 271 $sri = rg_pkg_subrepo_info($s['db'], $a['uid'], $a['pkg_subrepo_id']); $sri = rg_pkg_subrepo_info($s['db'], $a['uid'], $a['pkg_subrepo_id']);
357 272 if ($sri['exists'] != 1) { if ($sri['exists'] != 1) {
358 debug($key, 'Cannot find the pkg subrepo ' . $a['pkg_subrepo_id'] . '!');
273 debug($key, $sri['errmsg']);
359 274 rg_conn_shutdown($key, 2); rg_conn_shutdown($key, 2);
360 275 return; return;
361 276 } }
 
... ... function xdispatch_one($key, $tlv)
392 307 } }
393 308 $a['repo_uid'] = $ri['uid']; // TODO: propagate it to worker script $a['repo_uid'] = $ri['uid']; // TODO: propagate it to worker script
394 309 $a['repo_username'] = $repo_ui['username']; $a['repo_username'] = $repo_ui['username'];
395 //$a['allow_username'] = $repo_ui['username'];
396
397 //if (($a['uid'] > 0) && (strcmp($pri['uid'], $a['uid']) == 0))
398 // $a['allow_create_repo'] = 1;
399 // TODO: not used anymore
400 } else {
401 // repo_id='': we are building a dotrepo
402 //if ($a['uid'] == $a['pkg_repo_uid']) {
403 // $a['allow_any_write'] = 1;
404 //} else if ($a['uid'] > 0) {
405 // $a['allow_username'] = $a['job_username'];
406 //}
407 310 } }
408 311
409 if ($a['uid'] == $a['pkg_repo_uid']) {
312 $s['allow_paths'] = array();
313 if ($a['uid'] == 0) {
314 $a['allow_any_write'] = 1;
315 rg_log_debug('job_uid == 0 => allow any write');
316
317 $s['allow_paths'][] = array(
318 'next1' => '.*',
319 'next2' => '.*',
320 'next3' => '.*');
321 } else if ($a['uid'] == $a['pkg_repo_uid']) {
410 322 $a['allow_any_write'] = 1; $a['allow_any_write'] = 1;
411 323 rg_log_debug('job_uid == pkg_repo_uid => allow any write'); rg_log_debug('job_uid == pkg_repo_uid => allow any write');
324
325 $s['allow_paths'][] = array(
326 'next1' => '.*',
327 'next2' => '.*',
328 'next3' => '.*');
412 329 } else { } else {
413 330 $a['allow_username'] = $a['job_username']; $a['allow_username'] = $a['job_username'];
414 331 rg_log_debug('job_uid != pkg_repo_uid => allow_username=job_username'); rg_log_debug('job_uid != pkg_repo_uid => allow_username=job_username');
332
333 // rpm: This is needed when copying pkgs to the global repo
334 $s['allow_paths'][] = array(
335 'next1' => '\+pending',
336 'next2' => $a['allow_username'],
337 'next3' => '.*');
338
339 // deb: This is needed for Debian
340 $s['allow_paths'][] = array(
341 'next1' => '\+pending',
342 'next2' => $a['job_id'],
343 'next3' => '.*'); // pkg name can change because of not allowed chars
415 344 } }
345 rg_log_debug('allow_paths: ' . rg_array2string($s['allow_paths']));
416 346
417 347 $s['dir'] = '/var/lib/rocketgit/pkg_repos/' $s['dir'] = '/var/lib/rocketgit/pkg_repos/'
418 348 . $a['pkg_repo_id'] . '/' . $a['pkg_subrepo_id']; . $a['pkg_repo_id'] . '/' . $a['pkg_subrepo_id'];
 
... ... function xdispatch_one($key, $tlv)
427 357 } }
428 358
429 359 debug($key, 'connection is authenticated'); debug($key, 'connection is authenticated');
430 debug($key, 'DEBUG: end: a: ' . rg_array2string($a));
360 debug($key, 'DEBUG: a: ' . rg_array2string($a));
431 361 $s['vars'] = $a; $s['vars'] = $a;
432 362 $s['allow'] = 1; $s['allow'] = 1;
433 363 } }
 
... ... function xdispatch_one($key, $tlv)
927 857 } }
928 858
929 859 $p .= pack('N', strlen($p2)) . $p2; $p .= pack('N', strlen($p2)) . $p2;
930 rg_conn_enq($key, $p);
931 860 //debug($key, ' DEBUG: p: ' . $p); //debug($key, ' DEBUG: p: ' . $p);
861 rg_conn_enq($key, $p);
932 862 } }
933 863
934 864 /* /*
 
... ... function xdispatch($key, $data)
941 871
942 872 $s = &$rg_conns[$key]; $s = &$rg_conns[$key];
943 873
944 $ret = 0;
874 $used = 0;
945 875
946 876 if (!isset($s['ws_done'])) { if (!isset($s['ws_done'])) {
947 877 //debug($key, 'DEBUG: data [pre ws]: ' . $data); //debug($key, 'DEBUG: data [pre ws]: ' . $data);
 
... ... function xdispatch($key, $data)
949 879 if ($pos === FALSE) if ($pos === FALSE)
950 880 return 0; return 0;
951 881 $s['ws_done'] = 1; $s['ws_done'] = 1;
952 $ret = $pos + 4;
882 $used = $pos + 4;
953 883
954 884 rg_conn_enq($key, "HTTP/1.1 101 Switching Protocols\r\n" rg_conn_enq($key, "HTTP/1.1 101 Switching Protocols\r\n"
955 885 . "Server: websocket1\r\n" . "Server: websocket1\r\n"
 
... ... function xdispatch($key, $data)
959 889 . "\r\n"); . "\r\n");
960 890 } }
961 891
962 $len = strlen($data);
963 //debug($key, 'DEBUG: data[' . ($len - $ret) . ']: ' . substr($data, $ret));
892 $data_len = strlen($data);
893 //debug($key, 'DEBUG: data[' . ($data_len - $used) . ']: ' . substr($data, $used));
964 894 while (1) { while (1) {
965 if ($len - $ret == 0)
966 break;
967
968 895 if (!isset($s['tlv']['type'])) { if (!isset($s['tlv']['type'])) {
969 896 // Type + length // Type + length
970 if ($len < 5) {
971 //debug($key, ' DEBUG: Not enough data to parse type+length [' . ($len - $ret) . ']');
897 if ($data_len - $used < 1 + 2) {
898 //debug($key, ' DEBUG: Not enough data to parse type+length [' . ($data_len - $used) . ']');
972 899 break; break;
973 900 } }
974 $x = @unpack('Ctype/nlen', $data, $ret);
901 $x = @unpack('Ctype/nlen', $data, $used);
975 902 if ($x === FALSE) // TODO: what can we do here? if ($x === FALSE) // TODO: what can we do here?
976 903 break; break;
977 904 //debug($key, 'DEBUG: unpack TL: ' . rg_array2string($x)); //debug($key, 'DEBUG: unpack TL: ' . rg_array2string($x));
978 905 $s['tlv']['type'] = $x['type']; $s['tlv']['type'] = $x['type'];
979 906 $s['tlv']['len'] = $x['len']; $s['tlv']['len'] = $x['len'];
980 $ret += 3;
907 $used += 3;
981 908 } }
982 909
983 if (strlen($data) < $s['tlv']['len'])
910 if ($data_len - $used < $s['tlv']['len'])
984 911 break; break;
985 912
986 $s['tlv']['data'] = substr($data, $ret, $s['tlv']['len']);
987 $ret += $s['tlv']['len'];
913 $s['tlv']['data'] = substr($data, $used, $s['tlv']['len']);
914 $used += $s['tlv']['len'];
988 915 xdispatch_one($key, $s['tlv']); xdispatch_one($key, $s['tlv']);
989 916 $s['tlv'] = array(); $s['tlv'] = array();
990 917 } }
991 918
992 //debug($key, ' Returning ' . $ret);
993 return $ret;
919 //debug($key, ' Returning ' . $used);
920 return $used;
994 921 } }
995 922
996 923
 
... ... if ($db === FALSE) {
1013 940 if (rg_struct_ok($db) === FALSE) if (rg_struct_ok($db) === FALSE)
1014 941 exit(0); exit(0);
1015 942
943 rg_debug_set(rg_state_get($db, 'debug'));
944
1016 945 // Prepare socket // Prepare socket
1017 946 $af = strstr($rg_fs_bind, '.') ? AF_INET : AF_INET6; $af = strstr($rg_fs_bind, '.') ? AF_INET : AF_INET6;
1018 947 $socket = @socket_create($af, SOCK_STREAM, SOL_TCP); $socket = @socket_create($af, SOCK_STREAM, SOL_TCP);
File scripts/worker.php changed (mode: 100644) (index 31a44da..f7790f9)
... ... function load_config_file($file)
106 106 if (strncmp($value, '/', 1) != 0) if (strncmp($value, '/', 1) != 0)
107 107 $value = dirname($file) . '/' . $value; $value = dirname($file) . '/' . $value;
108 108 load_config_file($value); load_config_file($value);
109 } else if (strcmp($var, 'debug') == 0) {
110 rg_debug_set(intval($value));
109 111 } else { } else {
110 112 $conf[$var] = $value; $conf[$var] = $value;
111 113 $last_parent = FALSE; $last_parent = FALSE;
 
... ... function load_config($file)
238 240 $i['pkg_cmd'] = 'apt --assume-yes --ignore-hold' $i['pkg_cmd'] = 'apt --assume-yes --ignore-hold'
239 241 . ' --allow-downgrades --allow-remove-essential' . ' --allow-downgrades --allow-remove-essential'
240 242 . ' --allow-change-held-packages' . ' --allow-change-held-packages'
241 . ' -o Dpkg::Options::=--force-confnew install';
243 . ' -o Dpkg::Options::=--force-confnew install'
244 . ' --no-install-recommends';
242 245 } else if (strcasecmp($x, 'fedora') == 0) { } else if (strcasecmp($x, 'fedora') == 0) {
243 246 $i['pkg_cmd'] = 'dnf -y install'; $i['pkg_cmd'] = 'dnf -y install';
244 247 } else if (strcasecmp($x, 'rocky') == 0) { } else if (strcasecmp($x, 'rocky') == 0) {
245 248 $i['pkg_cmd'] = 'dnf -y install'; $i['pkg_cmd'] = 'dnf -y install';
249 } else if (strcasecmp($x, 'centos_stream') == 0) {
250 $i['pkg_cmd'] = 'dnf -y install';
246 251 } else if (strcasecmp($x, 'centos') == 0) { } else if (strcasecmp($x, 'centos') == 0) {
247 252 if ($y > 7) if ($y > 7)
248 253 $i['pkg_cmd'] = 'dnf -y install'; $i['pkg_cmd'] = 'dnf -y install';
 
... ... function load_config($file)
252 257 $i['pkg_cmd'] = 'zypper --non-interactive install'; $i['pkg_cmd'] = 'zypper --non-interactive install';
253 258 } else if (strcasecmp($x, 'archlinux') == 0) { } else if (strcasecmp($x, 'archlinux') == 0) {
254 259 $i['pkg_cmd'] = 'pacman --sync --refresh --noconfirm --needed'; $i['pkg_cmd'] = 'pacman --sync --refresh --noconfirm --needed';
260 } else if (strcasecmp($x, 'alpine') == 0) {
261 $i['pkg_cmd'] = 'apk --force add';
255 262 } else { } else {
256 263 rg_log('Error! I do not know how to install packages on ' . $x rg_log('Error! I do not know how to install packages on ' . $x
257 264 . ' (name ' . $name . '). Ignore it.'); . ' (name ' . $name . '). Ignore it.');
 
... ... function load_config($file)
282 289 if (!isset($conf['libvirtd_group'])) if (!isset($conf['libvirtd_group']))
283 290 $conf['libvirtd_group'] = 'qemu'; $conf['libvirtd_group'] = 'qemu';
284 291
285 rg_log_ml('conf: ' . rg_array2string($conf));
292 rg_log_ml('conf: ' . rg_array2string_short($conf));
286 293 } }
287 294
288 295 /* /*
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
376 383 . "\n" . "\n"
377 384 . '# Export global variables' . "\n" . '# Export global variables' . "\n"
378 385 . 'export job_id=' . escapeshellarg($job['id']) . "\n" . 'export job_id=' . escapeshellarg($job['id']) . "\n"
379 . 'export repo_username=' . escapeshellarg(isset($job['repo_username']) ? $job['repo_username'] : '') . "\n"
386 . 'export orig_job_id=' . escapeshellarg(isset($job['orig_job_id']) ? $job['orig_job_id'] : $job['id']) . "\n"
387 . 'export repo_name=' . (isset($job['repo_name']) ? escapeshellarg($job['repo_name']) : '') . "\n"
388 . 'export repo_name_allowed='
389 . (isset($job['repo_name_allowed'])
390 ? escapeshellarg($job['repo_name_allowed']) : '${repo_name}') . "\n"
391 . 'export repo_username=' . (isset($job['repo_username']) ? escapeshellarg($job['repo_username']) : '') . "\n"
392 . 'export repo_username_allowed='
393 . (isset($job['repo_username_allowed']) ?
394 escapeshellarg($job['repo_username_allowed']) : '${repo_username}') . "\n"
380 395 . 'export job_uid=' . (isset($job['uid']) ? $job['uid'] : '') . "\n" . 'export job_uid=' . (isset($job['uid']) ? $job['uid'] : '') . "\n"
381 396 . 'export job_url=' . (isset($job['url']) ? $job['url'] : '') . "\n" . 'export job_url=' . (isset($job['url']) ? $job['url'] : '') . "\n"
382 397 . 'export job_head=' . (isset($job['head']) ? $job['head'] : '') . "\n" . 'export job_head=' . (isset($job['head']) ? $job['head'] : '') . "\n"
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
384 399 . 'export env_distro=' . escapeshellarg($job['env_distro']) . "\n" . 'export env_distro=' . escapeshellarg($job['env_distro']) . "\n"
385 400 . 'export env_major=' . escapeshellarg($job['env_major']) . "\n" . 'export env_major=' . escapeshellarg($job['env_major']) . "\n"
386 401 . 'export env_arch=' . escapeshellarg($job['env_arch']) . "\n" . 'export env_arch=' . escapeshellarg($job['env_arch']) . "\n"
402 . 'export env_codename=' . (isset($job['env_codename']) ? escapeshellarg($job['env_codename']) : '') . "\n"
387 403 . 'export rg_pkg_cmd="' . $env['pkg_cmd'] . '"' . "\n" . 'export rg_pkg_cmd="' . $env['pkg_cmd'] . '"' . "\n"
388 404 . '# Debian/Ubuntu stuff' . "\n" . '# Debian/Ubuntu stuff' . "\n"
389 405 . 'export DEBIAN_FRONTEND=noninteractive' . "\n" . 'export DEBIAN_FRONTEND=noninteractive' . "\n"
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
398 414 . 'export RGFS_name=' . 'wj' . $job['id'] . "\n" . 'export RGFS_name=' . 'wj' . $job['id'] . "\n"
399 415 . 'export RGFS_head=' . escapeshellarg($job['head']) . "\n" . 'export RGFS_head=' . escapeshellarg($job['head']) . "\n"
400 416 . 'export RGFS_repo_id=' . escapeshellarg($job['repo_id']) . "\n" . 'export RGFS_repo_id=' . escapeshellarg($job['repo_id']) . "\n"
401 . 'export RGFS_uid=' . escapeshellarg($job['uid']) . "\n"
402 . 'export RGFS_job_id=' . escapeshellarg($job['id']) . "\n"
417 . 'export RGFS_uid=${job_uid}' . "\n"
418 . 'export RGFS_job_id=${orig_job_id}' . "\n"
403 419 . 'export RGFS_env=' . escapeshellarg($job['env']) . "\n" . 'export RGFS_env=' . escapeshellarg($job['env']) . "\n"
404 420 . 'export RGFS_worker_id=' . escapeshellarg($job['worker_id']) . "\n" . 'export RGFS_worker_id=' . escapeshellarg($job['worker_id']) . "\n"
405 421 . 'export RGFS_worker_name=' . escapeshellarg($job['worker_name']) . "\n" . 'export RGFS_worker_name=' . escapeshellarg($job['worker_name']) . "\n"
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
426 442 . "\n" . "\n"
427 443 . 'E=0; E_CMD=""' . "\n" . 'E=0; E_CMD=""' . "\n"
428 444 . "\n" . "\n"
429 . 'function rg_notify()' . "\n"
430 . '{' . "\n"
431 . ' echo "M${@}" > /dev/virtio-ports/rgw &' . "\n" // TODO: CentOS 7, for example, returns "Resource busy"
432 . ' echo "M${@}" >> /mnt/status/history' . "\n"
433 . '}' . "\n"
434 . "\n"
435 . 'function rg_notify_err()' . "\n"
436 . '{' . "\n"
437 . ' echo "E${@}" > /dev/virtio-ports/rgw &' . "\n"
438 . ' echo "E${@}" >> /mnt/status/history' . "\n"
439 . '}' . "\n"
440 . "\n"
441 . 'function rg_notify_warn()' . "\n"
442 . '{' . "\n"
443 . ' echo "W${@}" > /dev/virtio-ports/rgw &' . "\n"
444 . ' echo "W${@}" >> /mnt/status/history' . "\n"
445 . '}' . "\n"
446 . "\n"
447 445 . 'rg_log_prefix=""' . "\n" . 'rg_log_prefix=""' . "\n"
448 446 . 'function xecho()' . "\n" . 'function xecho()' . "\n"
449 447 . '{' . "\n" . '{' . "\n"
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
453 451 . 'function rg_log_push()' . "\n" . 'function rg_log_push()' . "\n"
454 452 . '{' . "\n" . '{' . "\n"
455 453 . ' [ "${1}" = "" ] || rg_notify "${1}"' . "\n" . ' [ "${1}" = "" ] || rg_notify "${1}"' . "\n"
456 . ' [ "${1}" = "" ] || xecho "${1} [`date`]"' . "\n"
457 454 . ' rg_log_prefix+=" "' . "\n" . ' rg_log_prefix+=" "' . "\n"
458 455 . '}' . "\n" . '}' . "\n"
459 456 . "\n" . "\n"
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
463 460 . ' rg_log_prefix=${rg_log_prefix:2}' . "\n" . ' rg_log_prefix=${rg_log_prefix:2}' . "\n"
464 461 . '}' . "\n" . '}' . "\n"
465 462 . "\n" . "\n"
466 . 'function rg_op_basic()' . "\n"
463 . 'function rg_notify()' . "\n"
464 . '{' . "\n"
465 . ' xecho "${@} [$(date)]"' . "\n"
466 . ' echo "M${@} [$(date)]" > /dev/virtio-ports/rgw 2>/dev/null' . "\n" // TODO: CentOS 7, for example, returns "Resource busy"; not only CentOS7. Also Debian 11
467 . ' echo "M${@} [$(date)]" >> /mnt/status/history' . "\n"
468 . '}' . "\n"
469 . "\n"
470 . 'function rg_notify_err()' . "\n"
471 . '{' . "\n"
472 . ' xecho "${@} [$(date)]"' . "\n"
473 . ' echo "E${@} [$(date)]" > /dev/virtio-ports/rgw 2>/dev/null' . "\n"
474 . ' echo "E${@} [$(date)]" >> /mnt/status/history' . "\n"
475 . '}' . "\n"
476 . "\n"
477 . 'function rg_notify_warn()' . "\n"
478 . '{' . "\n"
479 . ' xecho "${@}"' . "\n"
480 . ' echo "W${@} [$(date)]" > /dev/virtio-ports/rgw 2>/dev/null' . "\n"
481 . ' echo "W${@} [$(date)]" >> /mnt/status/history' . "\n"
482 . '}' . "\n"
483 . "\n"
484 . 'function rg_op_basic()' . "\n" // TODO: we have a problem here: errors are not sent to rg_notify!
467 485 . '{' . "\n" . '{' . "\n"
468 486 . ' E_CMD=${@}' . "\n" . ' E_CMD=${@}' . "\n"
469 . ' xecho " X: ${E_CMD}" 1>&2' . "\n" // we do not want to interfere with user redirection (rg_op cmd > out)
470 . ' "${@}" 2>~/rg_op.err' . "\n"
487 . ' rg_notify " X: ${E_CMD}" 1>&2' . "\n" // we do not want to interfere with user redirection (rg_op cmd > out)
488 . ' "${@}" 2>/tmp/rg_op_${USER}.err' . "\n"
471 489 . ' E=${?}' . "\n" . ' E=${?}' . "\n"
472 . ' [ -r ~/rg_op.err ] \\' . "\n"
473 . ' && sed -e "s|^|${rg_log_prefix} |" ~/rg_op.err 1>&2' . "\n"
490 . ' (' . "\n"
474 491 . ' if [ "${E}" != "0" ]; then' . "\n" . ' if [ "${E}" != "0" ]; then' . "\n"
475 . ' xecho " Cannot execute [${E_CMD}] [E=${E}]" 1>&2' . "\n"
492 . ' rg_notify_err " Cannot execute [E=${E}]"' . "\n"
493 . ' rg_notify_err $(sed -e "s|^|${rg_log_prefix} |" /tmp/rg_op_${USER}.err)' . "\n"
476 494 . ' fi' . "\n" . ' fi' . "\n"
495 . ' ) 1>&2' . "\n"
477 496 . ' return ${E}' . "\n" . ' return ${E}' . "\n"
478 497 . '}' . "\n" . '}' . "\n"
479 498 . "\n" . "\n"
480 . 'function rg_op()' . "\n"
499 . 'function rg_op()' . "\n" // The output will be captured by the caller
481 500 . '{' . "\n" . '{' . "\n"
482 501 . ' rg_op_basic "${@}"' . "\n" . ' rg_op_basic "${@}"' . "\n"
483 502 . ' return ${E}' . "\n" . ' return ${E}' . "\n"
484 503 . '}' . "\n" . '}' . "\n"
485 504 . "\n" . "\n"
486 . '# No output redirect version - the output will not be captured by the caller' . "\n"
487 . 'function rg_op_s()' . "\n"
505 . 'function rg_op_s()' . "\n" // The output will not be captured by the caller' . "\n"
488 506 . '{' . "\n" . '{' . "\n"
489 . ' rg_op_basic "${@}" >~/rg_op.out' . "\n"
490 . ' sed -e "s|^|${rg_log_prefix} |" ~/rg_op.out' . "\n"
507 . ' rg_op_basic "${@}" | sed -e "s|^|${rg_log_prefix} |"' . "\n"
491 508 . ' return ${E}' . "\n" . ' return ${E}' . "\n"
492 509 . '}' . "\n" . '}' . "\n"
493 510 . "\n" . "\n"
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
510 527 . ' local dir=${1}; shift' . "\n" . ' local dir=${1}; shift' . "\n"
511 528 . ' local pkg_list_file=${1}; shift' . "\n" . ' local pkg_list_file=${1}; shift' . "\n"
512 529 . "\n" . "\n"
513 . ' xecho "rg_rpm_sign: pkg_list_file=${pkg_list_file} key=repo_id-${pkg_repo_id} dir=${dir} [`date`]"' . "\n"
530 . ' rg_notify "rg_rpm_sign: pkg_list_file=${pkg_list_file} key=repo_id-${pkg_repo_id} dir=${dir} [`date`]"' . "\n"
514 531 . ' if [ ! -s "${pkg_list_file}" ]; then' . "\n" . ' if [ ! -s "${pkg_list_file}" ]; then' . "\n"
515 . ' xecho " No packages available."' . "\n"
532 . ' rg_notify " No packages available."' . "\n"
516 533 . ' return 0' . "\n" . ' return 0' . "\n"
517 534 . ' fi' . "\n" . ' fi' . "\n"
518 535 . ' if [ ! -d "${dir}" ]; then' . "\n" . ' if [ ! -d "${dir}" ]; then' . "\n"
519 . ' xecho " Dir ${dir} not found."' . "\n"
536 . ' rg_notify " Dir ${dir} not found."' . "\n"
520 537 . ' return 0' . "\n" . ' return 0' . "\n"
521 538 . ' fi' . "\n" . ' fi' . "\n"
522 539 . "\n" . "\n"
523 540 . ' local old_dir=${PWD}' . "\n" . ' local old_dir=${PWD}' . "\n"
524 . ' xecho "rg_rpm_sign: switching to [${dir}]"' . "\n"
525 541 . ' cd "${dir}"' . "\n" . ' cd "${dir}"' . "\n"
542 . ' rg_notify "Signing in dir ${dir}:" $(< "${pkg_list_file}")' . "\n"
526 543 . ' rg_op_s rpmsign --define "_gpg_name repo_id-${pkg_repo_id}" \\' . "\n" . ' rg_op_s rpmsign --define "_gpg_name repo_id-${pkg_repo_id}" \\' . "\n"
527 544 . ' --define "_gpg_sign_cmd_extra_args --no-autostart --batch" \\' . "\n" . ' --define "_gpg_sign_cmd_extra_args --no-autostart --batch" \\' . "\n"
528 545 . ' --resign $(< "${pkg_list_file}") </dev/null' . "\n" . ' --resign $(< "${pkg_list_file}") </dev/null' . "\n"
529 546 . ' cd "${old_dir}"' . "\n" . ' cd "${old_dir}"' . "\n"
547 . ' rg_notify "Signing done (E=${E})"' . "\n"
530 548 . ' return ${E}' . "\n" . ' return ${E}' . "\n"
531 549 . '}' . "\n" . '}' . "\n"
532 550 . "\n" . "\n"
533 . 'function rg_create_list()' . "\n"
551 . 'function rg_deb_extract_control()' . "\n"
534 552 . '{' . "\n" . '{' . "\n"
535 553 . ' local dir=${1}; shift' . "\n" . ' local dir=${1}; shift' . "\n"
554 . "\n"
555 . ' rg_notify "rg_deb_extract_control: dir=[${dir}]"' . "\n"
556 . ' if [ ! -d "${dir}" ]; then' . "\n"
557 . ' rg_notify " dir does not exists."; return 0' . "\n"
558 . ' fi' . "\n"
559 . ' local old_dir=${PWD}' . "\n"
560 . ' cd "${dir}"' . "\n"
561 . ' while read file; do' . "\n"
562 . ' [ "${file}" = "" ] && continue' . "\n"
563 . ' rg_notify " Extracting control from ${file}"' . "\n"
564 . ' if [ "${env_distro}" = "ubuntu" ]; then' . "\n"
565 . ' cf="control.tar.zst"' . "\n"
566 . ' tar_opts="--zstd"' . "\n"
567 . ' else' . "\n"
568 . ' cf="control.tar.xz"' . "\n"
569 . ' tar_opts="--xz"' . "\n"
570 . ' fi' . "\n"
571 . ' ar x "${file}" ${cf}' . "\n"
572 . ' if [ "${?}" != "0" ]; then' . "\n"
573 . ' rg_notify_err " Cannot extract control.tar.xz"' . "\n"
574 . ' E=1; break' . "\n"
575 . ' fi' . "\n"
576 . ' [ "${E}" = "0" ] || break' . "\n"
577 . "\n"
578 . ' tar xf ${cf} ${tar_opts} ./control' . "\n"
579 . ' if [ "${?}" != "0" ]; then' . "\n"
580 . ' rg_notify_err " Cannot extract ./control"' . "\n"
581 . ' E=1; break' . "\n"
582 . ' fi' . "\n"
583 . ' [ "${E}" = "0" ] || break' . "\n"
584 . "\n"
585 . ' rm -f ${cf}' . "\n"
586 . ' mv control "${file}c"' . "\n" // here is build .debc and .ddebc files
587 . ' if [ "${?}" != "0" ]; then' . "\n"
588 . ' rg_notify_err " Cannot rename"' . "\n"
589 . ' E=1; break' . "\n"
590 . ' fi' . "\n"
591 . ' [ "${E}" = "0" ] || break' . "\n"
592 . ' done < <(ls *.deb *.ddeb)' . "\n"
593 . ' cd "${old_dir}"' . "\n"
594 . ' return ${E}' . "\n"
595 . '}' . "\n"
596 . "\n"
597 . 'function rg_deb_sign()' . "\n"
598 . '{' . "\n"
599 . ' local pkg_repo_id=${1}; shift' . "\n"
600 . ' local dir=${1}; shift' . "\n"
536 601 . ' local pkg_list_file=${1}; shift' . "\n" . ' local pkg_list_file=${1}; shift' . "\n"
537 602 . "\n" . "\n"
538 . ' xecho "rg_create_list: pkg_list_file=${pkg_list_file} dir=${dir} [`date`]"' . "\n"
603 . ' rg_notify "rg_deb_sign: pkg_list_file=${pkg_list_file} key=repo_id-${pkg_repo_id} dir=${dir} [`date`]"' . "\n"
604 . ' if [ ! -s "${pkg_list_file}" ]; then' . "\n"
605 . ' rg_notify " No packages available."' . "\n"
606 . ' return 0' . "\n"
607 . ' fi' . "\n"
539 608 . ' if [ ! -d "${dir}" ]; then' . "\n" . ' if [ ! -d "${dir}" ]; then' . "\n"
540 . ' xecho " Dir ${dir} not found."' . "\n"
609 . ' rg_notify " Dir ${dir} not found."' . "\n"
541 610 . ' return 0' . "\n" . ' return 0' . "\n"
542 611 . ' fi' . "\n" . ' fi' . "\n"
543 . ' export dir' . "\n"
544 . ' (cd "${dir}"; find . -type f -iname "*.rpm") > "${pkg_list_file}"' . "\n"
612 . "\n"
613 . ' local old_dir=${PWD}' . "\n"
614 . ' cd "${dir}"' . "\n"
615 . ' rg_notify "Signing in dir ${dir}:" $(< "${pkg_list_file}")' . "\n"
616 . ' rg_op_s dpkg-sig --verbose -k repo_id-${pkg_repo_id} \\' . "\n"
617 . ' --sign rg --verbose \\' . "\n"
618 . ' $(< "${pkg_list_file}") </dev/null' . "\n"
619 . ' cd "${old_dir}"' . "\n"
620 . ' rg_notify "Signing done (E=${E})"' . "\n"
621 . ' return ${E}' . "\n"
622 . '}' . "\n"
623 . "\n"
624 . 'function rg_rpm_create_list()' . "\n"
625 . '{' . "\n"
626 . ' local dir=${1}; shift' . "\n"
627 . ' local pkg_list_file=${1}; shift' . "\n"
628 . "\n"
629 . ' rg_notify "rg_rpm_create_list: pkg_list_file=${pkg_list_file} dir=${dir} [`date`]"' . "\n"
630 . ' if [ ! -d "${dir}" ]; then' . "\n"
631 . ' rg_notify_err " Dir ${dir} not found."' . "\n"
632 . ' return 0' . "\n"
633 . ' fi' . "\n"
634 . ' (cd "${dir}"; find . -type f -name "*.rpm") > "${pkg_list_file}"' . "\n"
635 . ' if [ ! -s "${pkg_list_file}" ]; then' . "\n"
636 . ' rg_notify " No files!"' . "\n"
637 . ' return 0' . "\n"
638 . ' fi' . "\n"
639 . ' rg_notify " content:" $(< "${pkg_list_file}")' . "\n"
640 . '}' . "\n"
641 . "\n"
642 . 'function rg_deb_create_deb_list()' . "\n"
643 . '{' . "\n"
644 . ' local dir=${1}; shift' . "\n"
645 . ' local pkg_list_file=${1}; shift' . "\n"
646 . "\n"
647 . ' rg_notify "rg_deb_create_deb_list: pkg_list_file=${pkg_list_file} dir=${dir} [`date`]"' . "\n"
648 . ' if [ ! -d "${dir}" ]; then' . "\n"
649 . ' rg_notify " Dir ${dir} not found."' . "\n"
650 . ' return 0' . "\n"
651 . ' fi' . "\n"
652 . ' (cd "${dir}"; find . -type f -name "*.deb" -o -name "*.ddeb") > "${pkg_list_file}"' . "\n"
545 653 . ' if [ ! -s "${pkg_list_file}" ]; then' . "\n" . ' if [ ! -s "${pkg_list_file}" ]; then' . "\n"
546 . ' xecho " No files!"' . "\n"
654 . ' rg_notify " No files!"' . "\n"
547 655 . ' return 0' . "\n" . ' return 0' . "\n"
548 656 . ' fi' . "\n" . ' fi' . "\n"
549 . ' xecho " content: "`cat "${pkg_list_file}"`' . "\n"
657 . ' rg_notify " content:" $(< "${pkg_list_file}")' . "\n"
658 . '}' . "\n"
659 . "\n"
660 . 'function rg_create_list()' . "\n"
661 . '{' . "\n"
662 . ' local dir=${1}; shift' . "\n"
663 . ' local file=${1}; shift' . "\n"
664 . "\n"
665 . ' rg_notify "rg_create_list: file=${file} dir=${dir} [`date`]"' . "\n"
666 . ' if [ ! -d "${dir}" ]; then' . "\n"
667 . ' rg_notify " Dir ${dir} not found."' . "\n"
668 . ' return 0' . "\n"
669 . ' fi' . "\n"
670 . ' (cd "${dir}"; find . -type f | grep -v "\.list\$") > "${file}"' . "\n"
671 . ' if [ ! -s "${file}" ]; then' . "\n"
672 . ' rg_notify " No files!"' . "\n"
673 . ' return 0' . "\n"
674 . ' fi' . "\n"
675 . ' rg_notify " content:" $(< "${file}")' . "\n"
550 676 . '}' . "\n" . '}' . "\n"
551 677 . "\n" . "\n"
552 678 . 'function rg_rpm_createrepo()' . "\n" . 'function rg_rpm_createrepo()' . "\n"
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
556 682 . ' local pkg_list_file=${1}; shift' . "\n" . ' local pkg_list_file=${1}; shift' . "\n"
557 683 . ' local oldpackagedirs=${1}; shift' . "\n" . ' local oldpackagedirs=${1}; shift' . "\n"
558 684 . "\n" . "\n"
559 . ' xecho "rg_rpm_createrepo dir=${dir} pkg_list_file=${pkg_list_file} oldpackagedirs=${oldpackagedirs} [`date`]"' . "\n"
685 . ' rg_notify "rg_rpm_createrepo dir=${dir} pkg_list_file=${pkg_list_file} oldpackagedirs=${oldpackagedirs} [`date`]"' . "\n"
560 686 . ' rm -rf "${dir}/.repodata"' . "\n" . ' rm -rf "${dir}/.repodata"' . "\n"
561 687 . "\n" . "\n"
562 688 . ' local extra_paras=""' . "\n" . ' local extra_paras=""' . "\n"
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
566 692 . "\n" . "\n"
567 693 . ' local old_dir="${PWD}"' . "\n" . ' local old_dir="${PWD}"' . "\n"
568 694 . ' cd "${dir}"' . "\n" . ' cd "${dir}"' . "\n"
569 . ' xecho " Switch to dir ${dir}"' . "\n"
570 . ' xecho "DEBUG: Files:"' . "\n"
695 . ' rg_notify " Switch to dir ${dir}"' . "\n"
696 . ' rg_notify "DEBUG: Files:"' . "\n"
571 697 . ' find .' . "\n" . ' find .' . "\n"
572 698 . ' rg_op_s createrepo -v --update ${extra_paras} \\' . "\n" . ' rg_op_s createrepo -v --update ${extra_paras} \\' . "\n"
573 699 . ' --recycle-pkglist \\' . "\n" . ' --recycle-pkglist \\' . "\n"
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
582 708 . ' return ${E}' . "\n" . ' return ${E}' . "\n"
583 709 . '}' . "\n" . '}' . "\n"
584 710 . "\n" . "\n"
585 . 'function rg_extract_rpm_info()' . "\n"
711 . 'function rg_rpm_extract_info()' . "\n"
586 712 . '{' . "\n" . '{' . "\n"
587 713 . ' local dir=${1}; shift' . "\n" . ' local dir=${1}; shift' . "\n"
588 714 . "\n" . "\n"
589 715 . ' rg_notify "Extracting .spec info"' . "\n" . ' rg_notify "Extracting .spec info"' . "\n"
590 . ' xecho "rg_extract_rpm_info: dir=${dir} [`date`]"' . "\n"
716 . ' rg_notify "rg_rpm_extract_info: dir=${dir} [`date`]"' . "\n"
591 717 . ' spec_file=`find "${dir}" -iname \'*.spec\' -type f -printf "%d %p\n" | sort -n | head -n1 | awk \'{print $2}\'`' . "\n" . ' spec_file=`find "${dir}" -iname \'*.spec\' -type f -printf "%d %p\n" | sort -n | head -n1 | awk \'{print $2}\'`' . "\n"
592 718 . ' if [ "${spec_file}" = "" ]; then' . "\n" . ' if [ "${spec_file}" = "" ]; then' . "\n"
593 . ' xecho " Cannot find any .spec file in ${dir}!"' . "\n"
594 . ' ls -l "${dir}"' . "\n"
719 . ' rg_notify " Cannot find any .spec file in ${dir}!"' . "\n"
595 720 . ' return' . "\n" . ' return' . "\n"
596 721 . ' fi' . "\n" . ' fi' . "\n"
597 722 . "\n" . "\n"
598 723 . ' spec_file_base=`basename "${spec_file}"`' . "\n" . ' spec_file_base=`basename "${spec_file}"`' . "\n"
599 . ' xecho " .spec file: ${spec_file} basename=[${spec_file_base}]."' . "\n"
724 . ' rg_notify " .spec file: ${spec_file} basename=[${spec_file_base}]."' . "\n"
600 725 . "\n" . "\n"
601 . ' xecho " Extracting info about version"' . "\n"
602 . ' spec_name=`grep ^Name: "${spec_file}" | cut -d: -f2| tr -d " \t\r\n"`' . "\n"
603 . ' spec_ver=`grep ^Version: "${spec_file}" | cut -d: -f2 | tr -d " \t\r\n"`' . "\n"
604 . ' spec_rel=`grep ^Release: "${spec_file}" | cut -d: -f2 | tr -d " \t\r\n"`' . "\n"
605 . ' spec_deps=`rpmspec --parse "${spec_file}" | grep ^BuildRequires | cut -d: -f2 | tr ",\t\r\n" " "`' . "\n"
606 . ' xecho " DEBUG: name=${spec_name}, ver=${spec_ver}, rel=${spec_rel}"' . "\n"
726 . ' rg_notify " Extracting info..."' . "\n"
727 . ' pkg_name=`grep ^Name: "${spec_file}" | cut -d: -f2| tr -d " \t\r\n"`' . "\n"
728 . ' pkg_ver=`grep ^Version: "${spec_file}" | cut -d: -f2 | tr -d " \t\r\n"`' . "\n"
729 . ' pkg_rel=`grep ^Release: "${spec_file}" | cut -d: -f2 | tr -d " \t\r\n"`' . "\n"
730 . ' pkg_deps=`rpmspec --parse "${spec_file}" | grep ^BuildRequires | cut -d: -f2- | tr ",\t\r\n" " "`' . "\n"
731 . ' rg_notify " DEBUG: name=${pkg_name}, ver=${pkg_ver}, rel=${pkg_rel}"' . "\n"
732 . ' echo' . "\n"
733 . '}' . "\n"
734 . "\n"
735 . 'function rg_deb_extract_info()' . "\n"
736 . '{' . "\n"
737 . ' local dir=${1}; shift' . "\n"
738 . "\n"
739 . ' rg_notify "Extracting deb info dir=${dir}"' . "\n"
740 . ' control_file=`find "${dir}" -iname control -type f -printf "%d %p\n" | sort -n | head -n1 | awk \'{print $2}\'`' . "\n"
741 . ' if [ "${control_file}" = "" ]; then' . "\n"
742 . ' rg_notify_err " Cannot find any control file in ${dir}!"' . "\n"
743 . ' return' . "\n"
744 . ' fi' . "\n"
745 . "\n"
746 . ' rg_notify " Extracting info..."' . "\n"
747 . ' pkg_name=$(grep ^Source: "${control_file}" | cut -d: -f2| tr -d " \t\r\n")' . "\n"
748 . ' pkg_deps=$(grep ^Depends: "${control_file}" | cut -d: -f2- | tr ",\t\r\n" " " | sed -e \'s/\${[^}]*}//g\')' . "\n"
749 . ' rg_notify " DEBUG: name=${pkg_name}"' . "\n"
607 750 . ' echo' . "\n" . ' echo' . "\n"
608 751 . '}' . "\n" . '}' . "\n"
609 752 . "\n" . "\n"
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
613 756 . "\n" . "\n"
614 757 . ' rg_log_push "rg_build_dotrepo dir=${dir}"' . "\n" . ' rg_log_push "rg_build_dotrepo dir=${dir}"' . "\n"
615 758 . ' while [ 1 ]; do' . "\n" . ' while [ 1 ]; do' . "\n"
616 . ' rg_extract_rpm_info "${dir}"' . "\n"
617 . ' if [ "${spec_name}" = "" ]; then' . "\n"
618 . ' xecho "Malformed .spec file?"' . "\n"
759 . ' rg_rpm_extract_info "${dir}"' . "\n"
760 . ' if [ "${pkg_name}" = "" ]; then' . "\n"
761 . ' rg_notify "Malformed .spec file?"' . "\n"
619 762 . ' E=1' . "\n" . ' E=1' . "\n"
620 763 . ' break' . "\n" . ' break' . "\n"
621 764 . ' fi' . "\n" . ' fi' . "\n"
622 765 . "\n" . "\n"
623 . ' local dst_tar_gz="/mnt/rpmbuild/SOURCES/${spec_name}-${spec_ver}.tar.gz"' . "\n"
766 . ' local dst_tar_gz="/mnt/rpmbuild/SOURCES/${pkg_name}-${pkg_ver}.tar.gz"' . "\n"
624 767 . ' local dst_spec="/mnt/rpmbuild/SPECS/${spec_file_base}"' . "\n" . ' local dst_spec="/mnt/rpmbuild/SPECS/${spec_file_base}"' . "\n"
625 . ' local xecho "DEBUG: dst_spec=${dst_spec}."' . "\n"
768 . ' local rg_notify "DEBUG: dst_spec=${dst_spec}."' . "\n"
626 769 . "\n" . "\n"
627 . ' xecho "Creating tar archive [${dst_tar_gz}]"' . "\n"
628 . ' rg_op_s tar czf "${dst_tar_gz}" --transform "s:^:./${spec_name}-${spec_ver}/:g" \\' . "\n"
770 . ' rg_notify "Creating tar archive [${dst_tar_gz}]"' . "\n"
771 . ' rg_notify "Creating tar"' . "\n"
772 . ' rg_op_s tar czf "${dst_tar_gz}" --transform "s:^:./${pkg_name}-${pkg_ver}/:g" \\' . "\n"
629 773 . ' -C "${dir}" . || break' . "\n" . ' -C "${dir}" . || break' . "\n"
630 774 . "\n" . "\n"
631 . ' xecho "Copying spec file [${spec_file}] -> [${dst_spec}]"' . "\n"
775 . ' rg_notify "Copying spec file [${spec_file}] -> [${dst_spec}]"' . "\n"
632 776 . ' rg_cp "${spec_file}" "${dst_spec}"' . "\n" . ' rg_cp "${spec_file}" "${dst_spec}"' . "\n"
633 777 . "\n" . "\n"
634 . ' xecho "Making only binary packages"' . "\n"
778 . ' rg_notify "Making only binary packages"' . "\n"
779 . ' rg_notify "Creating rpm"' . "\n"
635 780 . ' rg_op_s rpmbuild --define "_topdir /mnt/rpmbuild" \\' . "\n" . ' rg_op_s rpmbuild --define "_topdir /mnt/rpmbuild" \\' . "\n"
636 781 . ' -bb "${dst_spec}" || break' . "\n" . ' -bb "${dst_spec}" || break' . "\n"
637 782 . ' break' . "\n" . ' break' . "\n"
 
... ... function start_worker_build_tools($job, &$reason, &$reason2)
643 788 . 'function rg_build_rpm()' . "\n" . 'function rg_build_rpm()' . "\n"
644 789 . '{' . "\n" . '{' . "\n"
645 790 . ' local dir=${1}; shift' . "\n" . ' local dir=${1}; shift' . "\n"
646 . "\n"
791 . "\n"
647 792 . ' rg_log_push "rg_build_rpm: dir=${dir}"' . "\n" . ' rg_log_push "rg_build_rpm: dir=${dir}"' . "\n"
648 793 . ' while [ 1 ]; do' . "\n" . ' while [ 1 ]; do' . "\n"
649 . ' rg_extract_rpm_info "${dir}"' . "\n"
650 . ' if [ "${spec_name}" = "" ]; then' . "\n"
651 . ' xecho "Malformed .spec file?"' . "\n"
794 . ' rg_rpm_extract_info "${dir}"' . "\n"
795 . ' if [ "${pkg_name}" = "" ]; then' . "\n"
796 . ' rg_notify_err "Malformed .spec file?"' . "\n"
652 797 . ' E=1' . "\n" . ' E=1' . "\n"
653 798 . ' break' . "\n" . ' break' . "\n"
654 799 . ' fi' . "\n" . ' fi' . "\n"
655 . ' local dst_tar_gz="/mnt/rpmbuild/SOURCES/${repo_username}+${spec_name}-${spec_ver}.tar.gz"' . "\n"
800 . ' local dst_tar_gz="/mnt/rpmbuild/SOURCES/${repo_username}+${pkg_name}-${pkg_ver}.tar.gz"' . "\n"
656 801 . ' local dst_spec="/mnt/rpmbuild/SPECS/${repo_username}+${spec_file_base}"' . "\n" . ' local dst_spec="/mnt/rpmbuild/SPECS/${repo_username}+${spec_file_base}"' . "\n"
657 . "\n"
658 . ' xecho "Creating archive from git repo [${dst_tar_gz}]"' . "\n"
802 . "\n"
803 . ' rg_notify "Creating archive from git repo [${dst_tar_gz}]"' . "\n"
804 . ' rg_notify "Creating tar"' . "\n"
659 805 . ' rg_op_s git -C "${dir}" archive -v \\' . "\n" . ' rg_op_s git -C "${dir}" archive -v \\' . "\n"
660 . ' --prefix "./${repo_username}+${spec_name}-${spec_ver}/" \\' . "\n"
806 . ' --prefix "./${repo_username}+${pkg_name}-${pkg_ver}/" \\' . "\n"
661 807 . ' -o "${dst_tar_gz}" rgw || break' . "\n" . ' -o "${dst_tar_gz}" rgw || break' . "\n"
662 . "\n"
663 . ' xecho "Processing spec file [${spec_file}] -> [${dst_spec}]"' . "\n"
808 . "\n"
809 . ' rg_notify "Processing spec file [${spec_file}] -> [${dst_spec}]"' . "\n"
664 810 . ' rg_op sed -r -e "s|^Name:(\s*)(.*)(\s*)|Name:\1${repo_username}+\2\3|" \\' . "\n" . ' rg_op sed -r -e "s|^Name:(\s*)(.*)(\s*)|Name:\1${repo_username}+\2\3|" \\' . "\n"
665 811 . ' "${spec_file}" > "${dst_spec}" || break' . "\n" . ' "${spec_file}" > "${dst_spec}" || break' . "\n"
666 . "\n"
667 . ' xecho "Making source and binary packages"' . "\n"
812 . "\n"
813 . ' rg_notify "Making source and binary packages"' . "\n"
814 . ' rg_notify "Creating source and binary packages"' . "\n"
668 815 . ' rg_op_s rpmbuild --define "_topdir /mnt/rpmbuild" \\' . "\n" . ' rg_op_s rpmbuild --define "_topdir /mnt/rpmbuild" \\' . "\n"
669 816 . ' -ba "${dst_spec}" || break' . "\n" . ' -ba "${dst_spec}" || break' . "\n"
670 817 . ' break' . "\n" . ' break' . "\n"
671 818 . ' done' . "\n" . ' done' . "\n"
672 819 . ' rg_log_pop' . "\n" . ' rg_log_pop' . "\n"
673 820 . ' return ${E}' . "\n" . ' return ${E}' . "\n"
674 . '}' . "\n\n"
821 . '}' . "\n"
822 . "\n"
823 . 'function rg_build_deb()' . "\n"
824 . '{' . "\n"
825 . ' local dir=${1}; shift' . "\n"
826 . "\n"
827 . ' rg_log_push "rg_build_deb: dir=${dir}"' . "\n"
828 . ' local old_dir="${PWD}"' . "\n"
829 . ' cd "${dir}"' . "\n"
830 . ' while [ 1 ]; do' . "\n"
831 . ' rg_deb_extract_info "${dir}"' . "\n"
832 . ' if [ "${pkg_name}" = "" ]; then' . "\n"
833 . ' rg_notify_err "Malformed debian/control file?"' . "\n"
834 . ' E=1' . "\n"
835 . ' break' . "\n"
836 . ' fi' . "\n"
837 . "\n"
838 . ' rg_notify "Processing control file"' . "\n"
839 . ' # Changing Source: and Package: to prepend the user name' . "\n"
840 . ' rg_op sed -i -r \\' . "\n"
841 . ' -e "s#(Source|Package):(\s*)(.*)#\1:\2${repo_username_allowed}+\3#" \\' . "\n"
842 . ' "debian/control" || break' . "\n"
843 . ' rg_op sed -i -r \\' . "\n"
844 . ' -e "s#^(\S+.*)\$#${repo_username_allowed}+\1#" \\' . "\n"
845 . ' "debian/changelog" || break' . "\n"
846 . "\n"
847 . ' rg_notify "Creating source and binary packages"' . "\n"
848 . ' rg_op_s dpkg-buildpackage --no-check-builddeps \\' . "\n"
849 . ' -uc -us || break' . "\n"
850 . ' # Because Ubuntu generates .ddeb files we need to rename them' . "\n"
851 . ' cd ..' . "\n"
852 . ' while read f; do' . "\n"
853 . ' rg_notify "Renaming ${f} to ${f%.ddeb}.deb..."' . "\n"
854 . ' mv -fv "${f}" "${f%.ddeb}.deb"' . "\n"
855 . ' done < <(ls *.ddeb 2>/dev/null)' . "\n"
856 . ' break' . "\n"
857 . ' done' . "\n"
858 . ' cd "${old_dir}"' . "\n"
859 . ' xecho "Done E=${E}"' . "\n"
860 . ' rg_log_pop' . "\n"
861 . ' return ${E}' . "\n"
862 . '}' . "\n"
863 . "\n"
675 864 . 'mkdir -p /mnt/status' . "\n" . 'mkdir -p /mnt/status' . "\n"
676 . 'touch /mnt/status/history' . "\n"
677 . 'chmod a+w /mnt/status/history' . "\n\n";
865 . 'touch /mnt/status/history 2>/dev/null' . "\n"
866 . 'chmod a+w /mnt/status/history 2>/dev/null' . "\n\n";
678 867
679 868 $f = $job['main'] . '/root/build_tools.sh'; $f = $job['main'] . '/root/build_tools.sh';
680 869 $r = @file_put_contents($f, $s); $r = @file_put_contents($f, $s);
 
... ... function start_worker_build_rpms($job, $conf, &$reason, &$reason2)
709 898 . "\n" . "\n"
710 899 . 'source /mnt/build_tools.sh' . "\n" . 'source /mnt/build_tools.sh' . "\n"
711 900 . "\n" . "\n"
712 . 'env_distro=' . escapeshellarg($job['env_distro']) . "\n"
713 . 'env_major=' . escapeshellarg($job['env_major']) . "\n"
714 . 'env_arch=' . escapeshellarg($job['env_arch']) . "\n"
715 . "\n"
716 . 'mkdir -p /mnt/rpmbuild/{SOURCES,SPECS}' . "\n";
717
718 if (isset($job['repo_username']))
719 $s .= 'repo_username=' . escapeshellarg($job['repo_username']) . "\n";
720
721 $s .= ''
901 . 'id' . "\n"
902 . 'mkdir -p /mnt/rpmbuild/{SOURCES,SPECS}' . "\n"
722 903 . "\n" . "\n"
723 904 . 'while [ 1 ]; do' . "\n"; . 'while [ 1 ]; do' . "\n";
724 905
725 906 if (isset($job['url'])) if (isset($job['url']))
726 $s .= ' rg_build_rpm /mnt/target || break' . "\n";
907 $s .= ' rg_build_rpm /mnt/target/source || break' . "\n";
727 908
728 909 if (isset($job['rpm_repo_files'])) if (isset($job['rpm_repo_files']))
729 910 foreach ($job['rpm_repo_files'] as $pkg_subrepo_id => $junk) foreach ($job['rpm_repo_files'] as $pkg_subrepo_id => $junk)
 
... ... function start_worker_build_rpms($job, $conf, &$reason, &$reason2)
731 912
732 913 $s .= '' $s .= ''
733 914 . ' break' . "\n" . ' break' . "\n"
734 . 'done' . "\n";
915 . 'done' . "\n"
916 . 'exit ${E}' . "\n";
735 917
736 918 $f = $job['main'] . '/root/build_rpms.sh'; $f = $job['main'] . '/root/build_rpms.sh';
737 919 $r = @file_put_contents($f, $s); $r = @file_put_contents($f, $s);
 
... ... function start_worker_build_rpms($job, $conf, &$reason, &$reason2)
751 933 return TRUE; return TRUE;
752 934 } }
753 935
936 /*
937 * Building debs script
938 */
939 function start_worker_build_debs($job, $conf, &$reason, &$reason2)
940 {
941 //rg_log_debug('job: ' . print_r($job, TRUE));
942 //rg_log_debug('conf: ' . print_r($conf, TRUE));
943
944 $env = $conf['env'][$job['env']];
945
946 $s = ''
947 . '#!/bin/bash' . "\n"
948 . "\n"
949 . 'source /mnt/build_tools.sh' . "\n"
950 . "\n"
951 . 'id' . "\n"
952 . 'while [ 1 ]; do' . "\n";
953
954 if (isset($job['url']))
955 $s .= ' rg_build_deb /mnt/target/source || break' . "\n";
956
957 $s .= ''
958 . ' break' . "\n"
959 . 'done' . "\n"
960 . 'exit ${E}' . "\n";
961
962 $f = $job['main'] . '/root/build_debs.sh';
963 $r = @file_put_contents($f, $s);
964 if ($r === FALSE) {
965 $reason = 'cannot save ' . $f;
966 $reason2 = 'cannot save ' . $f . ': ' . rg_php_err();
967 return FALSE;
968 }
969
970 $r = @chmod($f, 0755);
971 if ($r === FALSE) {
972 $reason = 'cannot chmod ' . $f;
973 $reason2 = 'cannot chmod ' . $f . ': (' . rg_php_err() . ')';
974 return FALSE;
975 }
976
977 return TRUE;
978 }
979
754 980 /* /*
755 981 * Building rgfs building script * Building rgfs building script
756 982 * This is temporary, till we will have it on the main rocketgit repo. * This is temporary, till we will have it on the main rocketgit repo.
 
... ... function start_worker_build_rgfs($job, &$reason, &$reason2)
760 986 $s = '' $s = ''
761 987 . '#!/bin/bash' . "\n" . '#!/bin/bash' . "\n"
762 988 . "\n" . "\n"
989 . 'source /mnt/build_tools.sh' . "\n"
990 . "\n"
763 991 . 'set -e' . "\n" . 'set -e' . "\n"
764 992 . "\n" . "\n"
993 . 'rg_notify "Starting rgfs building"' . "\n"
994 . "\n"
765 995 . 'if [ -x /usr/bin/rgfs ]; then' . "\n" . 'if [ -x /usr/bin/rgfs ]; then' . "\n"
766 . ' echo "rgfs binary already exists. Exit."' . "\n"
996 . ' rg_notify "rgfs binary already exists. Exit."' . "\n"
767 997 . ' exit 0' . "\n" . ' exit 0' . "\n"
768 998 . 'fi' . "\n" . 'fi' . "\n"
769 999 . "\n" . "\n"
 
... ... function start_worker_build_rgfs($job, &$reason, &$reason2)
771 1001 . 'cd rgfs' . "\n" . 'cd rgfs' . "\n"
772 1002 . './configure' . "\n" . './configure' . "\n"
773 1003 . 'make' . "\n" . 'make' . "\n"
774 . 'make install' . "\n";
1004 . 'make install' . "\n"
1005 . 'rg_notify "rgfs building done"' . "\n";
775 1006
776 1007 $f = $job['main'] . '/root/build_rgfs.sh'; $f = $job['main'] . '/root/build_rgfs.sh';
777 1008 $r = @file_put_contents($f, $s); $r = @file_put_contents($f, $s);
 
... ... function start_worker_build_repo($job, $conf, &$reason, &$reason2)
846 1077 $s = '' $s = ''
847 1078 . '#!/bin/bash' . "\n" . '#!/bin/bash' . "\n"
848 1079 . "\n" . "\n"
849 . 'source /mnt/build_tools.sh' . "\n";
850
851 $s .= "\n"
852 . 'xecho "`date`"' . "\n"
853 . 'xecho "I: job_id=${job_id} job_uid=${job_uid} repo_username=${repo_username}"' . "\n"
854 . 'xecho "I: distro=${env_distro} major=${env_major} arch=${env_arch}"' . "\n"
1080 . 'source /mnt/build_tools.sh' . "\n"
1081 . 'id' . "\n"
1082 . "\n"
1083 . 'rg_notify "I: job_id=${job_id} orig_job_id=${orig_job_id} job_uid=${job_uid} repo_username=${repo_username}"' . "\n"
1084 . 'rg_notify "I: distro=${env_distro} major=${env_major} arch=${env_arch}"' . "\n"
1085 . 'rg_notify "I: do_sensitive_ops=$(do_sensitive_ops)"' . "\n"
855 1086 . "\n" . "\n"
856 1087 . 'while [ 1 ]; do' . 'while [ 1 ]; do'
857 1088 . ' echo ' . "\n" . ' echo ' . "\n"
858 . ' rg_log_push "Locating package files in /mnt/rpmbuild"' . "\n"
859 . ' files=`find /mnt/rpmbuild -type f -iname "*.rpm" -o -iname "*.deb" | head -n1`' . "\n"
1089 . ' case "${env_distro}" in' . "\n"
1090 . ' fedora|centos|rocky) sp="/mnt/rpmbuild"; name="*.rpm" ;;' . "\n"
1091 . ' debian|ubuntu) sp="/mnt/target"; name="*.deb" ;;' . "\n"
1092 . ' *) break ;;' . "\n"
1093 . ' esac' . "\n"
1094 . ' rg_log_push "Locating package files in ${sp}"' . "\n"
1095 . ' files=$(find ${sp} -type f -iname "${name}" 2>/dev/null | head -n1)' . "\n"
860 1096 . ' if [ "${files}" = "" ]; then' . "\n" . ' if [ "${files}" = "" ]; then' . "\n"
861 . ' xecho "Not found."' . "\n"
1097 . ' rg_notify "Not found."' . "\n"
862 1098 . ' else' . "\n" . ' else' . "\n"
863 . ' xecho "Found ["${files}"]"' . "\n"
1099 . ' rg_notify "Found ["${files}"]"' . "\n"
864 1100 . ' fi' . "\n" . ' fi' . "\n"
865 1101 . ' rg_log_pop' . "\n" . ' rg_log_pop' . "\n"
866 1102 . "\n"; . "\n";
 
... ... function start_worker_build_repo($job, $conf, &$reason, &$reason2)
868 1104 if ($keys > 0) if ($keys > 0)
869 1105 $s .= '' $s .= ''
870 1106 . ' echo ' . "\n" . ' echo ' . "\n"
871 . ' xecho "Importing ' . $keys . ' key(s)"' . "\n"
1107 . ' rg_notify "Importing ' . $keys . ' key(s)"' . "\n"
872 1108 . ' rg_op_s gpg --import /mnt/build2/gpg_priv_key_*.asc || break' . "\n" . ' rg_op_s gpg --import /mnt/build2/gpg_priv_key_*.asc || break' . "\n"
873 1109 . ' # Signing something for test' . "\n" . ' # Signing something for test' . "\n"
874 1110 . ' rm -f /tmp/rg-sign-junk' . "\n" . ' rm -f /tmp/rg-sign-junk' . "\n"
875 1111 . ' rg_op_s gpg --output /tmp/rg-sign-junk --no-autostart --batch \\' . "\n" . ' rg_op_s gpg --output /tmp/rg-sign-junk --no-autostart --batch \\' . "\n"
876 1112 . ' --armour --sign /etc/hosts || break' . "\n" . ' --armour --sign /etc/hosts || break' . "\n"
877 1113 . ' # list supported configuration' . "\n" . ' # list supported configuration' . "\n"
1114 . ' rg_notify "GPG supported configuration:"' . "\n"
878 1115 . ' gpg --with-colons --list-config' . "\n"; . ' gpg --with-colons --list-config' . "\n";
879 1116
880 1117 $s .= "\n" $s .= "\n"
881 1118 . ' declare -A rgfs_mounted=()' . "\n"; . ' declare -A rgfs_mounted=()' . "\n";
882 1119
883 if (isset($job['exec']['prepare_rpms']))
1120 if (isset($job['exec']['prepare_pkgs']))
884 1121 $s .= "\n" $s .= "\n"
885 1122 . ' echo' . "\n" . ' echo' . "\n"
886 . ' rg_log_push "== prepare rpms phase ====="' . "\n"
1123 . ' rg_log_push "== prepare pkgs phase ====="' . "\n"
887 1124 . ' case "${env_distro}" in' . "\n" . ' case "${env_distro}" in' . "\n"
888 1125 . ' fedora|centos|rocky)' . "\n" . ' fedora|centos|rocky)' . "\n"
1126 . ' src0="/mnt/rpmbuild"' . "\n"
1127 . ' src1="${src0}/RPMS"' . "\n"
1128 . ' src2="${src0}/SRPMS"' . "\n"
1129 . "\n"
889 1130 . ' for i in debug src os; do' . "\n" . ' for i in debug src os; do' . "\n"
890 . ' src0="/mnt/rpmbuild"' . "\n"
891 . ' src1="${src0}/RPMS"' . "\n"
892 . ' src2="${src0}/SRPMS"' . "\n"
893 . "\n"
894 1131 . ' rg_log_push "== ${i} ====="' . "\n" . ' rg_log_push "== ${i} ====="' . "\n"
895 1132 . ' for pkg_repo_id in ${pkg_repos_list}; do' . "\n" . ' for pkg_repo_id in ${pkg_repos_list}; do' . "\n"
896 1133 . ' pkg_repo_uid=${pri2uid[${pkg_repo_id}]}' . "\n" . ' pkg_repo_uid=${pri2uid[${pkg_repo_id}]}' . "\n"
897 1134 . ' rg_log_push "== pkg_repo_id ${pkg_repo_id} [uid ${pkg_repo_uid}] ====="' . "\n" . ' rg_log_push "== pkg_repo_id ${pkg_repo_id} [uid ${pkg_repo_uid}] ====="' . "\n"
898 1135 . ' dir="/mnt/build2/rpms/${pkg_repo_id}/${i}"' . "\n" . ' dir="/mnt/build2/rpms/${pkg_repo_id}/${i}"' . "\n"
899 1136 . ' if [ "`do_sensitive_ops`" = "1" ]; then' . "\n" . ' if [ "`do_sensitive_ops`" = "1" ]; then' . "\n"
900 . ' xecho "DEBUG: do_sensitive_ops==1: do not add username"' . "\n"
1137 . ' rg_notify "DEBUG: do_sensitive_ops==1: do not add username"' . "\n"
901 1138 . ' udir="${dir}"' . "\n" . ' udir="${dir}"' . "\n"
902 1139 . ' else' . "\n" . ' else' . "\n"
903 . ' xecho "DEBUG: do_sensitive_ops!=1: add username"' . "\n"
1140 . ' rg_notify "DEBUG: do_sensitive_ops!=1: add username"' . "\n"
904 1141 . ' udir="${dir}/${repo_username}"' . "\n" . ' udir="${dir}/${repo_username}"' . "\n"
905 1142 . ' fi' . "\n" . ' fi' . "\n"
906 . "\n"
907 . ' xecho "Copying RPMs to ${udir}"' . "\n"
1143 . "\n"
1144 . ' rg_notify "Copying RPMs to ${udir}"' . "\n"
908 1145 . ' rg_op_s mkdir -p "${udir}" || break' . "\n" . ' rg_op_s mkdir -p "${udir}" || break' . "\n"
909 1146 . ' case ${i} in' . "\n" . ' case ${i} in' . "\n"
910 1147 . ' debug)' . "\n" . ' debug)' . "\n"
 
... ... function start_worker_build_repo($job, $conf, &$reason, &$reason2)
931 1168 . ' done' . "\n" . ' done' . "\n"
932 1169 . ' rg_log_pop' . "\n" . ' rg_log_pop' . "\n"
933 1170 . ' [ "${E}" = "0" ] || break' . "\n" . ' [ "${E}" = "0" ] || break' . "\n"
934 . "\n"
1171 . "\n"
935 1172 . ' # We must remove debug packages after copy, else we will copy them also in "os" dir' . "\n" . ' # We must remove debug packages after copy, else we will copy them also in "os" dir' . "\n"
936 1173 . ' if [ "${i}" = "debug" ]; then' . "\n" . ' if [ "${i}" = "debug" ]; then' . "\n"
937 1174 . ' rm -f "${src1}"/*/*-debuginfo-*.rpm' . "\n" . ' rm -f "${src1}"/*/*-debuginfo-*.rpm' . "\n"
 
... ... function start_worker_build_repo($job, $conf, &$reason, &$reason2)
939 1176 . ' fi' . "\n" . ' fi' . "\n"
940 1177 . ' done' . "\n" . ' done' . "\n"
941 1178 . ' ;;' . "\n" . ' ;;' . "\n"
942 . ' *) xecho "Unsupported distro!"; E=1 ;;' . "\n"
1179 . "\n"
1180 . ' debian|ubuntu)' . "\n" // TODO: we should check if no package found and return error
1181 . ' src0="/mnt/target"' . "\n"
1182 . ' rg_deb_extract_control "${src0}" || break' . "\n"
1183 . ' for i in source binary-all binary-${env_arch}; do' . "\n"
1184 . ' rg_log_push "== ${i} ====="' . "\n"
1185 . ' for pkg_repo_id in ${pkg_repos_list}; do' . "\n"
1186 . ' pkg_repo_uid=${pri2uid[${pkg_repo_id}]}' . "\n"
1187 . ' rg_log_push "== pkg_repo_id ${pkg_repo_id} [uid ${pkg_repo_uid}] ====="' . "\n"
1188 . ' dir="/mnt/build2/debs/${pkg_repo_id}/${i}"' . "\n"
1189 . "\n"
1190 . ' copy_add=""' . "\n"
1191 . ' case ${i} in' . "\n"
1192 . ' source)' . "\n"
1193 . ' list=$(ls "${src0}"/*.tar.* "${src0}"/*.dsc "${src0}"/*.diff.gz)' . "\n"
1194 . ' copy_add=" --link"' . "\n"
1195 . ' ;;' . "\n"
1196 . ' binary-all)' . "\n"
1197 . ' list=$(ls "${src0}"/*_all.debc "${src0}"/*_all.deb)' . "\n"
1198 . ' ;;' . "\n"
1199 . ' binary-${env_arch})' . "\n"
1200 . ' list=$(ls "${src0}"/*_${env_arch}.deb "${src0}"/*_${env_arch}.debc)' . "\n"
1201 . ' list+=" "$(ls "${src0}"/*_${env_arch}.ddeb "${src0}"/*_${env_arch}.ddebc)' . "\n"
1202 . ' ;;' . "\n"
1203 . ' esac 2>/dev/null' . "\n"
1204 . ' if [ "${list}" != "" ]; then' . "\n"
1205 . ' rg_notify "Copying files from ${src0} to ${dir}"' . "\n"
1206 . ' ls -l "${src0}"' . "\n"
1207 . ' rg_op_s mkdir -p "${dir}" || break' . "\n"
1208 . ' for f in ${list}; do' . "\n"
1209 . ' rg_notify "Copying ${f}..."' . "\n"
1210 . ' rg_cp -v ${copy_add} "${f}" "${dir}/"' . "\n"
1211 . ' done' . "\n"
1212 . ' fi' . "\n"
1213 . ' rg_log_pop' . "\n"
1214 . ' [ "${E}" = "0" ] || break' . "\n"
1215 . ' done' . "\n"
1216 . ' rg_log_pop' . "\n"
1217 . ' [ "${E}" = "0" ] || break' . "\n"
1218 . ' done' . "\n"
1219 . ' rg_log_pop' . "\n"
1220 . ' [ "${E}" = "0" ] || break' . "\n"
1221 . ' ;;' . "\n"
1222 . "\n"
1223 . ' *) rg_notify_err "Unsupported distro!"; E=0 ;;' . "\n" // TODO: should we return 0? What about supported case? We should not fail the build job! Only if user wants that!
943 1224 . ' esac' . "\n" . ' esac' . "\n"
944 1225 . ' rg_log_pop' . "\n" . ' rg_log_pop' . "\n"
945 1226 . ' [ "${E}" = "0" ] || break' . "\n\n"; . ' [ "${E}" = "0" ] || break' . "\n\n";
946 1227
947 if (isset($job['exec']['prepare_rpms']))
1228 if (isset($job['exec']['prepare_pkgs']))
948 1229 foreach ($job['pkg_repos'] as $pkg_repo_id => $info) foreach ($job['pkg_repos'] as $pkg_repo_id => $info)
949 1230 $s .= "\n" $s .= "\n"
950 1231 . ' pkg_repo_id=' . $pkg_repo_id . "\n" . ' pkg_repo_id=' . $pkg_repo_id . "\n"
 
... ... function start_worker_build_repo($job, $conf, &$reason, &$reason2)
957 1238 . ' rg_log_push "== ${i} ====="' . "\n" . ' rg_log_push "== ${i} ====="' . "\n"
958 1239 . ' dir="/mnt/build2/rpms/${pkg_repo_id}/${i}"' . "\n" . ' dir="/mnt/build2/rpms/${pkg_repo_id}/${i}"' . "\n"
959 1240 . ' pkg_list_file="${dir}/pkg.list"' . "\n" . ' pkg_list_file="${dir}/pkg.list"' . "\n"
960 . "\n"
961 . ' rg_create_list "${dir}" "${pkg_list_file}" || break' . "\n"
962 . "\n"
963 . ' if [ "`do_sensitive_ops`" != "1" ]; then' . "\n"
964 . ' xecho "DEBUG: do_sensitive_ops!=1: skip rpm signing"' . "\n"
965 . ' else' . "\n"
966 . ' xecho "DEBUG: do_sensitive_ops==1: do signing"' . "\n"
967 . ' rg_rpm_sign ${pkg_repo_id} "${dir}" "${pkg_list_file}" || break' . "\n"
968 . ' fi' . "\n"
1241 . "\n"
1242 . ' while [ 1 ]; do' . "\n"
1243 . ' rg_rpm_create_list "${dir}" "${pkg_list_file}" || break' . "\n"
1244 . "\n"
1245 . ' if [ "`do_sensitive_ops`" != "1" ]; then' . "\n"
1246 . ' rg_notify "DEBUG: do_sensitive_ops!=1: skip rpm signing"' . "\n"
1247 . ' else' . "\n"
1248 . ' rg_notify "DEBUG: do_sensitive_ops==1: do signing"' . "\n"
1249 . ' rg_rpm_sign ${pkg_repo_id} "${dir}" "${pkg_list_file}" || break' . "\n"
1250 . ' fi' . "\n"
1251 . ' break' . "\n"
1252 . ' done' . "\n"
969 1253 . ' rg_log_pop' . "\n" . ' rg_log_pop' . "\n"
970 . ' done' . "\n"
971 . ' ;;' . "\n"
972 . ' *) xecho "Unsupported distro!"; E=1 ;;' . "\n"
1254 . ' done ;;' . "\n"
1255 . "\n"
1256 . ' debian|ubuntu)' . "\n"
1257 . ' pdir="/mnt/build2/debs/${pkg_repo_id}"' . "\n"
1258 . ' for i in source binary-all binary-${env_arch}; do' . "\n"
1259 . ' rg_log_push "== ${i} ====="' . "\n"
1260 . ' dir="${pdir}/${i}"' . "\n"
1261 . ' pkg_list_file="${dir}.pkg.list"' . "\n"
1262 . ' copy_list_file="${dir}.copy.list"' . "\n"
1263 . "\n"
1264 . ' while [ 1 ]; do' . "\n"
1265 . ' rg_deb_create_deb_list "${dir}" "${pkg_list_file}" || break' . "\n"
1266 . ' rg_create_list "${dir}" "${copy_list_file}" || break' . "\n"
1267 . ' [ -s "${pkg_list_file}" ] || break' . "\n"
1268 . "\n"
1269 . ' if [ "`do_sensitive_ops`" != "1" ]; then' . "\n"
1270 . ' rg_notify "DEBUG: do_sensitive_ops!=1: skip .deb signing"' . "\n"
1271 . ' else' . "\n"
1272 . ' rg_notify "DEBUG: do_sensitive_ops==1: do signing"' . "\n"
1273 . ' rg_deb_sign ${pkg_repo_id} "${dir}" "${pkg_list_file}" || break' . "\n"
1274 . ' fi' . "\n"
1275 . ' break' . "\n"
1276 . ' done' . "\n"
1277 . ' rg_log_pop' . "\n"
1278 . ' done ;;' . "\n"
1279 . "\n"
1280 . ' *) rg_notify_err "Unsupported distro!"; E=0 ;;' . "\n"
973 1281 . ' esac' . "\n" . ' esac' . "\n"
974 1282 . ' rg_log_pop' . "\n" . ' rg_log_pop' . "\n"
975 1283 . ' [ "${E}" = "0" ] || break' . "\n\n"; . ' [ "${E}" = "0" ] || break' . "\n\n";
976 1284
1285 if (isset($job['rgfs_server']))
977 1286 foreach ($job['pkg_maps'] as $junk => $info) { foreach ($job['pkg_maps'] as $junk => $info) {
978 1287 $pkg_subrepo_id = $info['pkg_subrepo_id']; $pkg_subrepo_id = $info['pkg_subrepo_id'];
979 1288 $si = $job['pkg_subrepos'][$pkg_subrepo_id]; $si = $job['pkg_subrepos'][$pkg_subrepo_id];
980 1289 $pkg_repo_id = $si['pkg_repo_id']; $pkg_repo_id = $si['pkg_repo_id'];
981 1290 $ri = $job['pkg_repos'][$pkg_repo_id]; $ri = $job['pkg_repos'][$pkg_repo_id];
982 if (!isset($job['rgfs_server'])) {
983 $s .= '# rgfs not set' . "\n";
984 continue;
985 }
986 1291 $s .= "\n" $s .= "\n"
987 1292 . ' export pkg_repo_id=' . $pkg_repo_id . "\n" . ' export pkg_repo_id=' . $pkg_repo_id . "\n"
988 1293 . ' export pkg_repo_uid=' . $ri['uid'] . "\n" . ' export pkg_repo_uid=' . $ri['uid'] . "\n"
989 1294 . ' export pkg_subrepo_id=' . $pkg_subrepo_id . "\n" . ' export pkg_subrepo_id=' . $pkg_subrepo_id . "\n"
990 1295 . "\n" . "\n"
991 1296 . ' echo' . "\n" . ' echo' . "\n"
992 . ' rg_log_push "== rgfs phase pkg_repo_id=${pkg_repo_id} pkg_subrepo_id=${pkg_subrepo_id} ====="' . "\n"
993 . ' xecho "Mounting rgfs pkg_repo_id/pkg_subrepo_id=${pkg_repo_id}/${pkg_subrepo_id}"' . "\n"
1297 . ' rg_log_push "== rgfs phase pkg_repo_id=${pkg_repo_id} pkg_repo_uid=${pkg_repo_uid} pkg_subrepo_id=${pkg_subrepo_id} ====="' . "\n"
994 1298 . ' export RGFS_LOG="/mnt/build2/rgfs/rgfs-${pkg_repo_id}-${pkg_subrepo_id}.log"' . "\n" . ' export RGFS_LOG="/mnt/build2/rgfs/rgfs-${pkg_repo_id}-${pkg_subrepo_id}.log"' . "\n"
995 1299 . ' export RGFS_pkg_repo_id=${pkg_repo_id}' . "\n" . ' export RGFS_pkg_repo_id=${pkg_repo_id}' . "\n"
996 1300 . ' export RGFS_pkg_subrepo_id=${pkg_subrepo_id}' . "\n" . ' export RGFS_pkg_subrepo_id=${pkg_subrepo_id}' . "\n"
 
... ... function start_worker_build_repo($job, $conf, &$reason, &$reason2)
999 1303 . ' mkdir -p "${dir}"' . "\n" . ' mkdir -p "${dir}"' . "\n"
1000 1304 . ' # -s -> disable multithreading - not supported and not needed' . "\n" . ' # -s -> disable multithreading - not supported and not needed' . "\n"
1001 1305 . ' # Please note, we cannot run strace on rgfs!' . "\n" . ' # Please note, we cannot run strace on rgfs!' . "\n"
1306 . ' rg_notify "Mounting rgfs pkg_repo_id/pkg_subrepo_id=${pkg_repo_id}/${pkg_subrepo_id}"' . "\n"
1002 1307 . ' rg_op_s /usr/bin/rgfs -s -o kernel_cache -o auto_cache \\' . "\n" . ' rg_op_s /usr/bin/rgfs -s -o kernel_cache -o auto_cache \\' . "\n"
1003 1308 . ' -o noforget -o use_ino "${dir}" || break' . "\n" . ' -o noforget -o use_ino "${dir}" || break' . "\n"
1004 1309 . ' rgfs_mounted[${pkg_repo_id}-${pkg_subrepo_id}]=1' . "\n" . ' rgfs_mounted[${pkg_repo_id}-${pkg_subrepo_id}]=1' . "\n"
1005 1310 . "\n" . "\n"
1006 1311 . ' rgfs_subrepo_root="/mnt/build2/rgfs/${pkg_repo_id}/${pkg_subrepo_id}"' . "\n" . ' rgfs_subrepo_root="/mnt/build2/rgfs/${pkg_repo_id}/${pkg_subrepo_id}"' . "\n"
1007 . ' xecho "DEBUG: env_distro=${env_distro}"' . "\n"
1008 1312 . ' case "${env_distro}" in' . "\n" . ' case "${env_distro}" in' . "\n"
1009 1313 . ' fedora|centos|rocky)' . "\n" . ' fedora|centos|rocky)' . "\n"
1010 1314 . ' for i in os debug src; do' . "\n" . ' for i in os debug src; do' . "\n"
 
... ... function start_worker_build_repo($job, $conf, &$reason, &$reason2)
1020 1324 . "\n" . "\n"
1021 1325 . ' if [ "${job_uid}" = "0" ]; then' . "\n" . ' if [ "${job_uid}" = "0" ]; then' . "\n"
1022 1326 . ' if [ -d "${rgfs}/+pending" ]; then' . "\n" . ' if [ -d "${rgfs}/+pending" ]; then' . "\n"
1023 . ' xecho "DEBUG: dir +pending found"' . "\n"
1024 . ' rg_create_list "${rgfs}/+pending" "${pkg_pend_list_file}" || break' . "\n"
1327 . ' rg_notify "DEBUG: dir +pending found"' . "\n"
1328 . ' rg_rpm_create_list "${rgfs}/+pending" "${pkg_pend_list_file}" || break' . "\n"
1025 1329 . ' else' . "\n" . ' else' . "\n"
1026 . ' xecho "DEBUG: dir +pending does not exists."' . "\n"
1330 . ' rg_notify "DEBUG: dir +pending does not exists."' . "\n"
1027 1331 . ' fi' . "\n" . ' fi' . "\n"
1028 1332 . ' fi' . "\n" . ' fi' . "\n"
1029 1333 . "\n" . "\n"
1030 1334 . ' if [ ! -s "${pkg_list_file}" ] && [ ! -s "${pkg_pend_list_file}" ]; then' . "\n" . ' if [ ! -s "${pkg_list_file}" ] && [ ! -s "${pkg_pend_list_file}" ]; then' . "\n"
1031 . ' xecho "pkg_list_file/pkg_pend_list_file are both empty; continue"' . "\n"
1335 . ' rg_notify "pkg_list_file/pkg_pend_list_file are both empty; continue"' . "\n"
1032 1336 . ' rg_log_pop' . "\n" . ' rg_log_pop' . "\n"
1033 1337 . ' continue' . "\n" . ' continue' . "\n"
1034 1338 . ' fi' . "\n" . ' fi' . "\n"
 
... ... function start_worker_build_repo($job, $conf, &$reason, &$reason2)
1038 1342 . ' while read file; do' . "\n" . ' while read file; do' . "\n"
1039 1343 . ' [ "${file}" = "" ] && continue' . "\n" . ' [ "${file}" = "" ] && continue' . "\n"
1040 1344 . ' if [ -r "${rgfs}/${file}" ]; then' . "\n" . ' if [ -r "${rgfs}/${file}" ]; then' . "\n"
1041 . ' xecho "- ${rgfs}/${file}"' . "\n"
1345 . ' rg_notify "- ${rgfs}/${file}"' . "\n"
1042 1346 . ' continue' . "\n" . ' continue' . "\n"
1043 1347 . ' fi' . "\n" . ' fi' . "\n"
1044 . ' xecho "+ ${rgfs}/${file}"' . "\n"
1348 . ' rg_notify "+ ${rgfs}/${file}"' . "\n"
1045 1349 . ' echo "${file}" >> ${pkg_filter_list_file}' . "\n" . ' echo "${file}" >> ${pkg_filter_list_file}' . "\n"
1046 1350 . ' done < <(cat "${pkg_list_file}"; echo; cat "${pkg_pend_list_file}"; echo)' . "\n" . ' done < <(cat "${pkg_list_file}"; echo; cat "${pkg_pend_list_file}"; echo)' . "\n"
1047 1351 . ' rg_log_pop' . "\n" . ' rg_log_pop' . "\n"
1048 1352 . "\n" . "\n"
1049 1353 . ' if [ "${job_uid}" = "0" ]; then' . "\n" . ' if [ "${job_uid}" = "0" ]; then' . "\n"
1050 1354 . ' if [ -d "${rgfs}/+pending" ]; then' . "\n" . ' if [ -d "${rgfs}/+pending" ]; then' . "\n"
1051 . ' xecho "+pending dir exists"' . "\n"
1355 . ' rg_notify "+pending dir exists"' . "\n"
1052 1356 . ' rg_rpm_sign ${pkg_repo_id} "${rgfs}/+pending" "${pkg_pend_list_file}" || break' . "\n" . ' rg_rpm_sign ${pkg_repo_id} "${rgfs}/+pending" "${pkg_pend_list_file}" || break' . "\n"
1053 1357 . ' for username in `(cd "${rgfs}/+pending"; ls)`; do' . "\n" . ' for username in `(cd "${rgfs}/+pending"; ls)`; do' . "\n"
1054 1358 . ' mkdir -p "${rgfs}/${username}"' . "\n" . ' mkdir -p "${rgfs}/${username}"' . "\n"
 
... ... function start_worker_build_repo($job, $conf, &$reason, &$reason2)
1058 1362 . ' [ "${E}" = "0" ] || break' . "\n" . ' [ "${E}" = "0" ] || break' . "\n"
1059 1363 . ' rg_op_s rmdir "${rgfs}/+pending" || break' . "\n" . ' rg_op_s rmdir "${rgfs}/+pending" || break' . "\n"
1060 1364 . ' else' . "\n" . ' else' . "\n"
1061 . ' xecho "+pending dir not found"' . "\n"
1365 . ' rg_notify "+pending dir not found"' . "\n"
1062 1366 . ' fi' . "\n" . ' fi' . "\n"
1063 . ' fi' . "\n";
1064
1065 // TODO: job_uid -> repo_uid (everywhere)?
1066
1067 if (isset($job['exec']['copy_to_rgfs']))
1068 $s .= "\n"
1069 . ' xecho "exec:copy_to_rgfs"' . "\n"
1367 . ' fi' . "\n"
1368 . "\n"
1369 . ' rg_notify "copy_to_rgfs"' . "\n"
1070 1370 . ' if [ -s "${pkg_list_file}" ]; then' . "\n" . ' if [ -s "${pkg_list_file}" ]; then' . "\n"
1071 1371 . ' rg_log_push "Copying packages from ${rpms_dir} to ${rgfs}"' . "\n" . ' rg_log_push "Copying packages from ${rpms_dir} to ${rgfs}"' . "\n"
1072 . ' rg_op_s mkdir -p "${rgfs}" || break' . "\n"
1073 1372 . ' if [ "${job_uid}" = "${pkg_repo_uid}" ]; then' . "\n" . ' if [ "${job_uid}" = "${pkg_repo_uid}" ]; then' . "\n"
1373 . ' rg_op_s mkdir -p "${rgfs}" || break' . "\n"
1074 1374 . ' rg_cp -av "${rpms_dir}"/*.rpm "${rgfs}/" || break' . "\n" . ' rg_cp -av "${rpms_dir}"/*.rpm "${rgfs}/" || break' . "\n"
1075 1375 . ' else' . "\n" // TODO: shouldn't I copy directly to ${rgfs}/${repo_username} if do_sensitive_ops==1? Seems it cannot happen! when we are uid 0, we do not need to copy! . ' else' . "\n" // TODO: shouldn't I copy directly to ${rgfs}/${repo_username} if do_sensitive_ops==1? Seems it cannot happen! when we are uid 0, we do not need to copy!
1076 1376 . ' # "+" is used because it is not allowed in username' . "\n" . ' # "+" is used because it is not allowed in username' . "\n"
 
... ... function start_worker_build_repo($job, $conf, &$reason, &$reason2)
1078 1378 . ' rg_cp -av "${rpms_dir}/${repo_username}"/*.rpm "${rgfs}/+pending/${repo_username}/" || break' . "\n" . ' rg_cp -av "${rpms_dir}/${repo_username}"/*.rpm "${rgfs}/+pending/${repo_username}/" || break' . "\n"
1079 1379 . ' fi' . "\n" . ' fi' . "\n"
1080 1380 . "\n" . "\n"
1081 . ' if [ "`do_sensitive_ops`" != "1" ]; then' . "\n"
1082 . ' xecho "Triggering the rebuild of subrepo"' . "\n"
1083 . ' echo "${pkg_subrepo_id}" >> /mnt/build2/pkg_subrepo_dirty' . "\n" // TODO: Shouldn't be done by rgfs?
1381 . ' if [ "$(do_sensitive_ops)" != "1" ]; then' . "\n"
1382 . ' rg_notify "Triggering the rebuild of subrepo"' . "\n"
1383 . ' echo "${pkg_subrepo_id}" >> /mnt/build2/pkg_subrepo_dirty' . "\n"
1084 1384 . ' fi' . "\n" . ' fi' . "\n"
1085 1385 . ' rg_log_pop' . "\n" . ' rg_log_pop' . "\n"
1086 1386 . ' else' . "\n" . ' else' . "\n"
1087 . ' xecho "No packages in pkg_list_file."' . "\n"
1387 . ' rg_notify "No packages in pkg_list_file."' . "\n"
1088 1388 . ' fi'. "\n" . ' fi'. "\n"
1089 1389 . "\n" . "\n"
1090 1390 . ' if [ "`do_sensitive_ops`" = "1" ]; then' . "\n" . ' if [ "`do_sensitive_ops`" = "1" ]; then' . "\n"
1091 1391 . ' rg_rpm_createrepo "${env_distro}" "${rgfs}" \\' . "\n" . ' rg_rpm_createrepo "${env_distro}" "${rgfs}" \\' . "\n"
1092 1392 . ' "${pkg_filter_list_file}" "${repo_username}" || break' . "\n" . ' "${pkg_filter_list_file}" "${repo_username}" || break' . "\n"
1093 . ' fi' . "\n";
1094
1095 $s .= "\n"
1393 . ' fi' . "\n"
1096 1394 . ' rg_log_pop' . "\n" . ' rg_log_pop' . "\n"
1097 . ' done ;;' . "\n"
1098 . ' *) xecho "Unsupported distro!"; E=1 ;;' . "\n"
1395 . ' done' . "\n"
1396 . ' ;;' . "\n"
1397 . "\n"
1398 . ' debian|ubuntu)' . "\n"
1399 . ' for i in source binary-all binary-${env_arch}; do' . "\n"
1400 . ' rgfs="${rgfs_subrepo_root}/${env_distro}/${env_codename}/main/${i}"' . "\n"
1401 . ' debs_dir="/mnt/build2/debs/${pkg_repo_id}/${i}"' . "\n"
1402 . ' pkg_list_file="${debs_dir}.pkg.list"' . "\n"
1403 . ' list_file="${debs_dir}.copy.list"' . "\n"
1404 . "\n"
1405 . ' rg_log_push "== ${i} ====="' . "\n"
1406 . ' while [ -s "${list_file}" ]; do' . "\n"
1407 . ' rg_notify "Copying files from ${debs_dir} to ${rgfs}"' . "\n"
1408 . ' # "+" is used because it is not allowed in username' . "\n"
1409 . ' rg_op_s mkdir -p "${rgfs}/+pending/${job_id}" || break' . "\n"
1410 . ' rg_cp -av "${debs_dir}"/* "${rgfs}/+pending/${job_id}/" || break' . "\n"
1411 . ' if [ "$(do_sensitive_ops)" != "1" ]; then' . "\n"
1412 . ' rg_notify "Triggering the rebuild of subrepo"' . "\n"
1413 . ' echo "${pkg_subrepo_id}" >> /mnt/build2/pkg_subrepo_dirty' . "\n"
1414 . ' fi' . "\n"
1415 . ' break' . "\n"
1416 . ' done'. "\n"
1417 . ' while [ "${job_uid}" = "0" ]; do' . "\n"
1418 . ' [ "${orig_job_id}" = "" ] && break' . "\n"
1419 . ' pkg_sign_file="/tmp/pkg.sign.list"' . "\n"
1420 . ' rg_deb_create_deb_list "${rgfs}/+pending/${orig_job_id}" "${pkg_sign_file}" || break' . "\n"
1421 . ' [ -s "${pkg_sign_file}" ] || break' . "\n"
1422 . ' rg_deb_sign ${pkg_repo_id} "${rgfs}/+pending/${orig_job_id}" "${pkg_sign_file}" || break' . "\n"
1423 . ' break' . "\n"
1424 . ' done' . "\n"
1425 . ' rg_log_pop' . "\n"
1426 . ' [ "${E}" = "0" ] || break' . "\n"
1427 . ' done' . "\n"
1428 . ' ;;' . "\n"
1429 . "\n"
1430 . ' *) rg_notify_err "Unsupported distro!"; E=0 ;;' . "\n"
1099 1431 . ' esac' . "\n" . ' esac' . "\n"
1100 . ' [ "${E}" = "0" ] || break' . "\n"
1101 1432 . "\n" . "\n"
1102 1433 . ' if [ "${rgfs_mounted[${pkg_repo_id}-${pkg_subrepo_id}]}" = "1" ]; then' . "\n" . ' if [ "${rgfs_mounted[${pkg_repo_id}-${pkg_subrepo_id}]}" = "1" ]; then' . "\n"
1103 . ' xecho "Unmounting rgfs"' . "\n"
1434 . ' rg_notify "Unmounting rgfs"' . "\n"
1104 1435 . ' umount "/mnt/build2/rgfs/${pkg_repo_id}/${pkg_subrepo_id}"' . "\n" . ' umount "/mnt/build2/rgfs/${pkg_repo_id}/${pkg_subrepo_id}"' . "\n"
1436 . ' rg_notify "Unmounting rgfs done"' . "\n"
1105 1437 . ' fi' . "\n" . ' fi' . "\n"
1106 . ' rg_log_pop' . "\n";
1438 . ' rg_log_pop' . "\n"
1439 . ' [ "${E}" = "0" ] || break' . "\n";
1107 1440 } }
1108 1441
1109 1442 $s .= "\n" $s .= "\n"
1110 . ' xecho "Done [E=${E}] [`date`]"' . "\n"
1111 1443 . ' break' . "\n" . ' break' . "\n"
1112 1444 . 'done' . "\n" . 'done' . "\n"
1445 . 'rg_notify "Done [E=${E}]"' . "\n"
1113 1446 . 'exit ${E}' . "\n"; . 'exit ${E}' . "\n";
1114 1447
1115 1448 $f = $job['main'] . '/root/build_repo.sh'; $f = $job['main'] . '/root/build_repo.sh';
 
... ... function start_worker($job)
1269 1602
1270 1603 $out_dir = $job['main'] . '/root/target'; $out_dir = $job['main'] . '/root/target';
1271 1604
1605 $r = @mkdir($out_dir, 0775);
1606 if ($r === FALSE) {
1607 $reason = 'cannot create root/target dir';
1608 $reason2 = 'cannot create root/target dir (' . rg_php_err() . ')';
1609 break;
1610 }
1611
1272 1612 if (isset($job['rpm_repo_files'])) { if (isset($job['rpm_repo_files'])) {
1273 1613 $err = FALSE; $err = FALSE;
1274 1614 foreach ($job['rpm_repo_files'] as $pkg_subrepo_id => $files) { foreach ($job['rpm_repo_files'] as $pkg_subrepo_id => $files) {
1275 1615 rg_log_debug('Storing dotrepo files for subrepo ' . $pkg_subrepo_id); rg_log_debug('Storing dotrepo files for subrepo ' . $pkg_subrepo_id);
1276 1616 $_out_dir = $out_dir . '-dotrepo-' . $pkg_subrepo_id; $_out_dir = $out_dir . '-dotrepo-' . $pkg_subrepo_id;
1277 1617 foreach ($files as $f => $c) { foreach ($files as $f => $c) {
1278 $r = rg_create_dirs($_out_dir . '/' . $f);
1618 $r = rg_create_dirs($_out_dir . '/' . $f, 0700);
1279 1619 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
1280 1620 $reason = 'cannot create dir'; $reason = 'cannot create dir';
1281 1621 $reason2 = 'cannot create dir: ' . $r['errmsg']; $reason2 = 'cannot create dir: ' . $r['errmsg'];
 
... ... function start_worker($job)
1314 1654 //TODO . ' --shallow-submodules' //TODO . ' --shallow-submodules'
1315 1655 . ' --no-checkout' . ' --no-checkout'
1316 1656 . ' ' . escapeshellarg($job['url']) . ' ' . escapeshellarg($job['url'])
1317 . ' ' . $emain . '/root/target';
1657 . ' ' . $emain . '/root/target/source';
1318 1658 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE); $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
1319 1659 rg_log_debug('clone: ' . print_r($r, TRUE)); rg_log_debug('clone: ' . print_r($r, TRUE));
1320 1660 @file_put_contents($job['main'] . '/root/T_clone', time() - $_s); @file_put_contents($job['main'] . '/root/T_clone', time() - $_s);
 
... ... function start_worker($job)
1332 1672 $s .= 'export RG_LABELS=/mnt/status/RG_LABELS' . "\n\n"; $s .= 'export RG_LABELS=/mnt/status/RG_LABELS' . "\n\n";
1333 1673
1334 1674 // build.sh: secrets // build.sh: secrets
1675 $s .= '# Secrets' . "\n";
1335 1676 if (isset($job['secrets']) && !empty($job['secrets'])) { if (isset($job['secrets']) && !empty($job['secrets'])) {
1336 $s .= '# Secrets' . "\n";
1337 1677 foreach ($job['secrets'] as $i => $info) { foreach ($job['secrets'] as $i => $info) {
1338 1678 if (empty($info['name'])) if (empty($info['name']))
1339 1679 continue; continue;
 
... ... function start_worker($job)
1343 1683 $s .= "\n"; $s .= "\n";
1344 1684 } }
1345 1685
1346 $s .= 'cd /mnt/target' . "\n\n";
1686 $s .= 'cd /mnt/target/source' . "\n\n";
1347 1687
1348 // To be able to run 'configure' without './'
1688 // To be able to run 'configure' without './...'
1349 1689 $s .= 'export PATH="${PATH}:."' . "\n\n"; $s .= 'export PATH="${PATH}:."' . "\n\n";
1350 1690
1351 1691 if (!isset($job['cmds'])) if (!isset($job['cmds']))
 
... ... function start_worker($job)
1406 1746 rg_log_debug('packages: ' . $job['packages'] . '.'); rg_log_debug('packages: ' . $job['packages'] . '.');
1407 1747 $p_i_cmd .= 'rg_notify "Installing webhook specified packages"' . "\n"; $p_i_cmd .= 'rg_notify "Installing webhook specified packages"' . "\n";
1408 1748
1749 // In some versions, we did not replaced \n\r\t correctly. Do it here
1750 $job['packages'] = preg_replace('/\s/', ' ', $job['packages']);
1751
1409 1752 $pkgs = explode(' ', $job['packages']); $pkgs = explode(' ', $job['packages']);
1410 1753 $p_i_cmd .= '> /mnt/packages.log' . "\n"; $p_i_cmd .= '> /mnt/packages.log' . "\n";
1411 1754
 
... ... function start_worker($job)
1414 1757 . 'p=' . escapeshellarg($p) . "\n" . 'p=' . escapeshellarg($p) . "\n"
1415 1758 . 'if [[ ${p} =~ :// ]]; then' . "\n" . 'if [[ ${p} =~ :// ]]; then' . "\n"
1416 1759 . ' rg_notify_warn "We do not allow remote packages for security reasons"' . "\n" . ' rg_notify_warn "We do not allow remote packages for security reasons"' . "\n"
1760 . 'elif [ -r "/etc/rgw/pkg/${p}" ]; then' . "\n"
1761 . ' rg_notify "Package ${p} was already installed by rgw"' . "\n"
1417 1762 . 'else' . "\n" . 'else' . "\n"
1418 1763 . ' rg_notify "Installing package ${p}"' . "\n" . ' rg_notify "Installing package ${p}"' . "\n"
1419 . ' echo "=== ${p} ==="' . "\n"
1420 1764 . ' ${rg_pkg_cmd} "${p}"' . "\n" . ' ${rg_pkg_cmd} "${p}"' . "\n"
1421 1765 . 'fi' . "\n" . 'fi' . "\n"
1422 1766 . 'echo; echo' . "\n" . 'echo; echo' . "\n"
 
... ... function start_worker($job)
1432 1776 if ($r === FALSE) if ($r === FALSE)
1433 1777 break; break;
1434 1778
1779 $r = start_worker_build_debs($job, $conf, $reason, $reason2);
1780 if ($r === FALSE)
1781 break;
1782
1435 1783 $r = start_worker_build_rgfs($job, $reason, $reason2); $r = start_worker_build_rgfs($job, $reason, $reason2);
1436 1784 if ($r === FALSE) if ($r === FALSE)
1437 1785 break; break;
 
... ... function start_worker($job)
1457 1805 . 'mkdir -p /mnt/var/tmp && chmod 1777 /mnt/var/tmp' . "\n" . 'mkdir -p /mnt/var/tmp && chmod 1777 /mnt/var/tmp' . "\n"
1458 1806 . 'mount --bind /mnt/var/tmp /var/tmp' . "\n" . 'mount --bind /mnt/var/tmp /var/tmp' . "\n"
1459 1807 . "\n" . "\n"
1460 . 'mkdir -p /mnt/target /mnt/rpmbuild /mnt/status' . "\n"
1461 . 'chown -R build:build /mnt/target* /mnt/rpmbuild /mnt/status' . "\n"
1808 . 'mkdir -p /mnt/rpmbuild /mnt/status' . "\n"
1809 . 'chown -R build:build /mnt/target /mnt/rpmbuild /mnt/status' . "\n"
1462 1810 . 'mkdir -p /mnt/build2' . "\n" . 'mkdir -p /mnt/build2' . "\n"
1463 1811 . 'chown -R build2:build2 /mnt/build2; chmod go= /mnt/build2' . "\n" . 'chown -R build2:build2 /mnt/build2; chmod go= /mnt/build2' . "\n"
1464 1812 . 'echo "PATH=${PATH}"' . "\n" . 'echo "PATH=${PATH}"' . "\n"
 
... ... function start_worker($job)
1486 1834 . 'sysctl kernel.dmesg_restrict=1' . "\n" . 'sysctl kernel.dmesg_restrict=1' . "\n"
1487 1835 . "\n" . "\n"
1488 1836 . '# Disabling root login' . "\n" . '# Disabling root login' . "\n"
1489 . 'chage -E 0 root' . "\n"
1837 //TODO . 'chage -E 0 root' . "\n"
1490 1838 . 'if [ "${?}" != "0" ]; then' . "\n" . 'if [ "${?}" != "0" ]; then' . "\n"
1491 1839 . ' ERR="cannot disable root account"' . "\n" . ' ERR="cannot disable root account"' . "\n"
1492 1840 . 'fi' . "\n" . 'fi' . "\n"
 
... ... function start_worker($job)
1505 1853 . ' if [ "${job_url}" != "" ]; then' . "\n" . ' if [ "${job_url}" != "" ]; then' . "\n"
1506 1854 . ' rg_notify "Checkout..."' . "\n" . ' rg_notify "Checkout..."' . "\n"
1507 1855 . ' echo; echo "`date`: Checkout"' . "\n" . ' echo; echo "`date`: Checkout"' . "\n"
1508 . ' su - build -c "cd /mnt/target && git branch -f rgw ${job_head} && git checkout --force rgw" >/mnt/status/checkout 2>&1' . "\n"
1856 . ' su - build -c "cd /mnt/target/source && git branch -f rgw ${job_head} && git checkout --force rgw" >/mnt/status/checkout 2>&1' . "\n"
1509 1857 . ' if [ "${?}" != "0" ]; then' . "\n" . ' if [ "${?}" != "0" ]; then' . "\n"
1510 1858 . ' sleep 3' . "\n" . ' sleep 3' . "\n"
1511 1859 . ' continue' . "\n" . ' continue' . "\n"
 
... ... function start_worker($job)
1514 1862 . ' fi' . "\n" . ' fi' . "\n"
1515 1863 . ' fi' . "\n" . ' fi' . "\n"
1516 1864 . "\n" . "\n"
1517 . ' # Extract .spec file info' . "\n"
1518 . ' rg_extract_rpm_info /mnt/target' . "\n"
1519 . ' if [ "${spec_deps}" != "" ]; then' . "\n"
1520 . ' echo; echo "`date`: Installing dependencies [${spec_deps}]"' . "\n"
1521 . ' for p in ${spec_deps}; do' . "\n"
1865 . ' case ${env_distro} in' . "\n"
1866 . ' fedora|centos|rocky)' . "\n"
1867 . ' rg_rpm_extract_info /mnt/target/source ;;' . "\n"
1868 . ' debian|ubuntu)' . "\n"
1869 . ' rg_deb_extract_info /mnt/target/source ;;' . "\n"
1870 . ' esac' . "\n"
1871 . "\n"
1872 . ' if [ "${pkg_deps}" != "" ]; then' . "\n"
1873 . ' echo; echo "`date`: Installing dependencies [${pkg_deps}]"' . "\n"
1874 . ' for p in ${pkg_deps}; do' . "\n"
1522 1875 . ' if [[ ${p} =~ :// ]]; then' . "\n" . ' if [[ ${p} =~ :// ]]; then' . "\n"
1523 . ' rg_notify_warn "We do not allow remote packages for security reasons"' . "\n" // TODO: the net is already disabled
1876 . ' rg_notify_warn "We do not allow remote packages for security reasons"' . "\n" // TODO: the net is already disabled; only for user!
1524 1877 . ' continue' . "\n" . ' continue' . "\n"
1525 1878 . ' fi' . "\n" . ' fi' . "\n"
1526 . ' rg_notify "Installing package ${p}"' . "\n"
1527 . ' ${rg_pkg_cmd} "${p}" 2>/tmp/install_pkg.err' . "\n"
1528 . ' [ "${?}" = "0" ] || rg_notify_warn "Cannot install ${p}: "$(< /tmp/install_pkg.err)' . "\n"
1879 . ' if [ -r "/etc/rgw/pkg/${p}" ]; then' . "\n"
1880 . ' rg_notify "Package ${p} was already installed by rgw"' . "\n"
1881 . ' else' . "\n"
1882 . ' rg_notify "Installing package ${p}"' . "\n"
1883 . ' ${rg_pkg_cmd} "${p}" 2>/tmp/install_pkg.err' . "\n"
1884 . ' [ "${?}" = "0" ] || rg_notify_warn "Cannot install ${p}: "$(< /tmp/install_pkg.err)' . "\n"
1885 . ' fi' . "\n"
1529 1886 . ' done' . "\n" . ' done' . "\n"
1530 1887 . ' fi' . "\n" . ' fi' . "\n"
1531 1888 . "\n" . "\n"
 
... ... function start_worker($job)
1542 1899 . ' break' . "\n" . ' break' . "\n"
1543 1900 . ' fi' . "\n" . ' fi' . "\n"
1544 1901 . "\n" . "\n"
1545 . ' rg_notify "Starting build_rpms.sh script"' . "\n"
1546 . ' echo; echo "`date`: Running build_rpms.sh script"' . "\n"
1547 . ' date +%s > /mnt/T_RPMS_START' . "\n"
1548 . ' su - build -c "bash /mnt/build_rpms.sh" &>/mnt/status/build_rpms.log' . "\n"
1902 . ' rg_notify "Starting build_rpms/debs.sh script"' . "\n"
1903 . ' echo; echo "`date`: Running build_rpms/debs.sh script"' . "\n"
1904 . ' date +%s > /mnt/T_MKPKGS_START' . "\n" // TODO: not exposed
1905 . ' case ${env_distro} in' . "\n"
1906 . ' fedora|centos|rocky)' . "\n" // TODO: pass 'rpm' not the distro? Same for 'deb'.
1907 . ' chown -Rv build:build /mnt/target-dotrepo-*' . "\n"
1908 . ' su - build -c "bash /mnt/build_rpms.sh" &>/mnt/status/build_pkgs.log ;;' . "\n" // TODO replace everywhere build_rpms.log with build_pkgs.log
1909 . ' debian|ubuntu)' . "\n"
1910 . ' su - build -c "bash /mnt/build_debs.sh" &>/mnt/status/build_pkgs.log ;;' . "\n"
1911 . ' *) echo "Unsupported distro" ;;' . "\n"
1912 . ' esac' . "\n"
1549 1913 . ' E=${?}' . "\n" . ' E=${?}' . "\n"
1550 . ' date +%s > /mnt/T_RPMS_END' . "\n"
1551 . ' rg_notify "build_rpms.sh finished with code ${E}"' . "\n"
1914 . ' E=0' . "\n" // TODO: for now, we do not error on this
1915 . ' date +%s > /mnt/T_MKPKGS_END' . "\n"
1916 . ' rg_notify "finished with code ${E}"' . "\n"
1552 1917 . ' if [ "${E}" != "0" ]; then' . "\n" . ' if [ "${E}" != "0" ]; then' . "\n"
1553 . ' ERR="build_rpms.sh returned ${E}"' . "\n"
1918 . ' ERR="build_rpms/debs.sh returned ${E}"' . "\n"
1554 1919 . ' break' . "\n" . ' break' . "\n"
1555 1920 . ' fi' . "\n" . ' fi' . "\n"
1556 1921 . "\n" . "\n"
1557 . ' rm -f ~/rg_op.err # it was owned by build user till now' . "\n"
1558 1922 . ' # Moving everything to build2 dir. TODO: Why?' . "\n" . ' # Moving everything to build2 dir. TODO: Why?' . "\n"
1559 . ' [ -d /mnt/target/rocketgit ] && mv -f /mnt/target/rocketgit /mnt/build2' . "\n"
1923 . ' [ -d /mnt/target/source/rocketgit ] && cp -rf /mnt/target/source/rocketgit /mnt/build2' . "\n"
1924 . ' # /mnt/target/* because we need the deb programs to access packages' . "\n"
1925 . ' chown build2:build2 /mnt/target' . "\n"
1926 . ' find /mnt/target -type f -maxdepth 1 -exec chown build2:build2 {} \;' . "\n"
1560 1927 . ' chown -R build2:build2 /mnt/build2 /mnt/rpmbuild' . "\n" . ' chown -R build2:build2 /mnt/build2 /mnt/rpmbuild' . "\n"
1561 1928 . "\n" . "\n"
1562 1929 . ' rg_notify "Starting build_rgfs.sh script"' . "\n" . ' rg_notify "Starting build_rgfs.sh script"' . "\n"
1563 1930 . ' echo; echo "`date`: Running build_rgfs.sh script"' . "\n" . ' echo; echo "`date`: Running build_rgfs.sh script"' . "\n"
1564 1931 . ' bash /mnt/build_rgfs.sh &>/mnt/status/build_rgfs.log' . "\n" . ' bash /mnt/build_rgfs.sh &>/mnt/status/build_rgfs.log' . "\n"
1565 1932 . ' if [ "${?}" != "0" ]; then' . "\n" . ' if [ "${?}" != "0" ]; then' . "\n"
1566 . ' echo "error building rgfs; trying to continue"' . "\n"
1933 . ' rg_notify "error building rgfs; trying to continue"' . "\n"
1567 1934 . ' fi' . "\n" . ' fi' . "\n"
1568 1935 . "\n" . "\n"
1569 1936 . ' if [ -x /mnt/build_repo.sh ]; then' . "\n" . ' if [ -x /mnt/build_repo.sh ]; then' . "\n"
1570 1937 . ' rg_notify "Starting build_repo.sh script"' . "\n" . ' rg_notify "Starting build_repo.sh script"' . "\n"
1571 1938 . ' echo; echo "`date`: Running build_repo.sh script"' . "\n" . ' echo; echo "`date`: Running build_repo.sh script"' . "\n"
1572 1939 . ' date +%s > /mnt/T_REPO_START' . "\n" . ' date +%s > /mnt/T_REPO_START' . "\n"
1940 . ' ls -l /home; mkdir -p /home/build2; chown build2:build2 /home/build2' . "\n"
1573 1941 . ' su - build2 -c "bash /mnt/build_repo.sh" &>/mnt/status/build_repo.log' . "\n" . ' su - build2 -c "bash /mnt/build_repo.sh" &>/mnt/status/build_repo.log' . "\n"
1574 1942 . ' E=${?}' . "\n" . ' E=${?}' . "\n"
1575 1943 . ' date +%s > /mnt/T_REPO_END' . "\n" . ' date +%s > /mnt/T_REPO_END' . "\n"
 
... ... function xhandle_one($key, $data)
1720 2088 } }
1721 2089
1722 2090 if (strcmp($op, 'BLD') == 0) { if (strcmp($op, 'BLD') == 0) {
1723 rg_log($key . ': ' . $jid . ': build job: ' . rg_array2string($u));
2091 rg_log($key . ': ' . $jid . ': build job: ' . rg_array2string_short($u));
1724 2092
1725 2093 if (isset($jobs[$jid])) { if (isset($jobs[$jid])) {
1726 2094 // TODO: this should not happen, right? // TODO: this should not happen, right?
 
... ... function xhandle_one($key, $data)
1748 2116 if (!isset($jobs[$jid]['cpus'])) if (!isset($jobs[$jid]['cpus']))
1749 2117 $jobs[$jid]['cpus'] = '2'; $jobs[$jid]['cpus'] = '2';
1750 2118 $jobs[$jid]['state'] = RG_JOB_INIT; $jobs[$jid]['state'] = RG_JOB_INIT;
2119 $jobs[$jid]['tmp'] = array();
1751 2120 $jobs[$jid]['dirty'] = 1; $jobs[$jid]['dirty'] = 1;
1752 2121 return; return;
1753 2122 } }
 
... ... function rg_job_upload_artifacts(&$job)
2099 2468 global $rg_log_dir; global $rg_log_dir;
2100 2469 global $last_reconnect; global $last_reconnect;
2101 2470
2102 rg_log('rg_job_upload_artifacts');
2471 $jid = $job['id'];
2472
2473 rg_log($jid . ': rg_job_upload_artifacts');
2103 2474
2104 2475 $f = $job['main'] . '/root/build2/rocketgit/artifacts'; $f = $job['main'] . '/root/build2/rocketgit/artifacts';
2105 2476 if (!file_exists($f)) { if (!file_exists($f)) {
2106 rg_log('No artifacts file - no work to do [' . $f . ']');
2477 rg_log($jid . ': No artifacts file - no work to do [' . $f . ']');
2107 2478 // TODO: Should we update the builder with the new state? Yes! // TODO: Should we update the builder with the new state? Yes!
2108 2479 $job['state'] = RG_JOB_FINISH; $job['state'] = RG_JOB_FINISH;
2109 2480 $job['dirty'] = 1; $job['dirty'] = 1;
2110 2481 return TRUE; return TRUE;
2111 2482 } }
2112 2483
2113 $jid = $job['id'];
2114 $root = $job['main'] . '/root/target/';
2484 $root = $job['main'] . '/root/target/source/';
2115 2485 $root_len = strlen($root); $root_len = strlen($root);
2116 2486
2117 2487 if (!isset($job['artifacts'])) { if (!isset($job['artifacts'])) {
 
... ... function rg_job_extract_info(&$job)
2282 2652 { {
2283 2653 global $conf; global $conf;
2284 2654
2285 rg_log_debug('extract_info: job: ' . rg_array2string($job));
2286
2287 2655 $jid = $job['id']; $jid = $job['id'];
2656 rg_log_debug($jid . ': extract_info: job: ' . rg_array2string($job));
2657
2288 2658 $emain = escapeshellarg($job['main']); $emain = escapeshellarg($job['main']);
2289 2659
2290 2660 $ret = FALSE; $ret = FALSE;
 
... ... function rg_job_extract_info(&$job)
2298 2668 $m = 'Main dir [' . $job['main'] $m = 'Main dir [' . $job['main']
2299 2669 . '] not present;' . '] not present;'
2300 2670 . ' probably disk space problems'; . ' probably disk space problems';
2301 rg_log($m);
2671 rg_log($jid . ': ' . $m);
2302 2672 $job['error2'] = $m; $job['error2'] = $m;
2303 2673 break; break;
2304 2674 } }
 
... ... function rg_job_extract_info(&$job)
2306 2676 $r = @file_get_contents($job['main'] . '/error.log'); $r = @file_get_contents($job['main'] . '/error.log');
2307 2677 if ($r !== FALSE) { if ($r !== FALSE) {
2308 2678 if (!empty($r)) if (!empty($r))
2309 rg_log('error set from file to [' . $r . ']');
2679 rg_log($jid . ': error set from file to [' . $r . ']');
2310 2680 $job['error'] = trim($r); $job['error'] = trim($r);
2311 2681 break; break;
2312 2682 } }
 
... ... function rg_job_extract_info(&$job)
2314 2684 $r = @file_get_contents($job['main'] . '/error2.log'); $r = @file_get_contents($job['main'] . '/error2.log');
2315 2685 if ($r !== FALSE) { if ($r !== FALSE) {
2316 2686 if (!empty($r)) if (!empty($r))
2317 rg_log('error2 set from file to [' . $r . ']');
2687 rg_log($jid . ': error2 set from file to [' . $r . ']');
2318 2688 $job['error2'] = trim($r); $job['error2'] = trim($r);
2319 2689 break; break;
2320 2690 } }
 
... ... function rg_job_extract_info(&$job)
2325 2695 $r = @stat($job['main'] . '/image2.raw'); $r = @stat($job['main'] . '/image2.raw');
2326 2696 if ($r === FALSE) { if ($r === FALSE) {
2327 2697 $m = 'missing image2 file'; $m = 'missing image2 file';
2328 rg_log($m);
2698 rg_log($jid . ': ' . $m);
2329 2699 $job['error'] = $m; $job['error'] = $m;
2330 2700 break; break;
2331 2701 } }
 
... ... function rg_job_extract_info(&$job)
2342 2712 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE); $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
2343 2713 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
2344 2714 $m = 'could not mount image: ' . $r['errmsg']; $m = 'could not mount image: ' . $r['errmsg'];
2345 rg_log($m);
2715 rg_log($jid . ': ' . $m);
2346 2716 $job['error'] = $m; $job['error'] = $m;
2347 2717 break; break;
2348 2718 } }
 
... ... function rg_job_extract_info(&$job)
2429 2799 unset($job['url']); unset($job['url']);
2430 2800 unset($job['head']); unset($job['head']);
2431 2801 unset($job['env']); unset($job['env']);
2432 rg_log_debug('state set to JOB_ARTIFACTS');
2802 rg_log_debug($jid . ': state set to JOB_ARTIFACTS');
2433 2803 $job['state'] = RG_JOB_ARTIFACTS; $job['state'] = RG_JOB_ARTIFACTS;
2434 2804 break; break;
2435 2805 } }
2436 2806
2437 2807 if (!empty($job['error'])) { if (!empty($job['error'])) {
2438 rg_log_debug('state set to JOB_ERROR (' . $job['error'] . ')');
2808 rg_log($jid . ': state set to JOB_ERROR (' . $job['error'] . ')');
2439 2809 $job['state'] = RG_JOB_ERROR; $job['state'] = RG_JOB_ERROR;
2440 2810 return; return;
2441 2811 } }
 
... ... function vm_extract_info($name)
2451 2821 $cmd = 'virsh domstats --raw ' . escapeshellarg($name); $cmd = 'virsh domstats --raw ' . escapeshellarg($name);
2452 2822 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE); $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
2453 2823 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
2454 rg_log('Could not get dom stats: ' . $r['errmsg']);
2824 //rg_log('Could not get dom stats: ' . $r['errmsg']); // Probably child finished
2455 2825 break; break;
2456 2826 } }
2457 2827
2458 rg_debug() && rg_log_debug('domstats: ' . rg_array2string($r['data']));
2828 //rg_log_debug('domstats: ' . rg_array2string_short($r['data']));
2459 2829 $data = array(); $data = array();
2460 2830 $t = explode("\n", $r['data']); $t = explode("\n", $r['data']);
2461 2831 foreach ($t as $line) { foreach ($t as $line) {
 
... ... function vm_extract_info($name)
2466 2836 $data[$x[0]] = $x[1]; $data[$x[0]] = $x[1];
2467 2837 } }
2468 2838
2469 $ret = array();
2470 2839 if (!isset($data['net.0.rx.bytes'])) if (!isset($data['net.0.rx.bytes']))
2471 2840 break; break;
2472 2841
2842 $ret = array();
2843 $ret['ts'] = time();
2473 2844 $ret['rx_bytes'] = $data['net.0.rx.bytes']; $ret['rx_bytes'] = $data['net.0.rx.bytes'];
2474 2845 $ret['rx_pkts'] = $data['net.0.rx.pkts']; $ret['rx_pkts'] = $data['net.0.rx.pkts'];
2475 2846 $ret['tx_bytes'] = $data['net.0.tx.bytes']; $ret['tx_bytes'] = $data['net.0.tx.bytes'];
 
... ... function vm_extract_info($name)
2490 2861 return $ret; return $ret;
2491 2862 } }
2492 2863
2864 /*
2865 * Store stats per minute and send them to the server
2866 * @cd - Current data
2867 */
2868 function vm_do_stats(&$job, $cd)
2869 {
2870 global $features;
2871
2872 do {
2873 if (!isset($features['stats'])) {
2874 rg_log_debug('stats feature is not supported by the server');
2875 break;
2876 }
2877
2878 $now = $cd['ts'];
2879 if (!isset($job['tmp']['stats_1m'])) {
2880 $job['tmp']['stats_1m'] = $cd;
2881 break;
2882 }
2883
2884 if ($job['tmp']['stats_1m']['ts'] + 60 > $now)
2885 break;
2886
2887 $ignore = array('ballon_current_mib', 'ballon_rss_mib');
2888 $d = array();
2889 foreach ($cd as $k => $v) {
2890 if (!isset($job['tmp']['stats_1m'][$k]))
2891 continue;
2892
2893 if (in_array($k, $ignore))
2894 continue;
2895
2896 $d[$k] = $v - $job['tmp']['stats_1m'][$k];
2897 }
2898 $d['ts'] = $now;
2899 //rg_log_debug('d: ' . print_r($d, TRUE));
2900
2901 $j = array(
2902 'op' => 'stats',
2903 'id' => $job['id'],
2904 'stats' => $d);
2905 rg_conn_enq('master', @json_encode($j) . "\n");
2906
2907 $job['tmp']['stats_1m'] = $cd;
2908 } while (0);
2909
2910 $job['stats'] = $cd;
2911 }
2912
2493 2913 /* /*
2494 2914 * Send stats about the worker * Send stats about the worker
2495 2915 */ */
 
... ... $stats = array('jobs' => 0);
2639 3059
2640 3060 $jobs = rg_load_files($conf['state'], 'job-[0-9]*.ser', 'id'); $jobs = rg_load_files($conf['state'], 'job-[0-9]*.ser', 'id');
2641 3061 if (!empty($jobs)) if (!empty($jobs))
2642 rg_log_ml('Jobs loaded from dir: ' . print_r($jobs, TRUE));
3062 rg_log_debug('Jobs loaded from dir: ' . rg_array2string_short($jobs));
2643 3063
2644 3064 rg_worker_connect(); rg_worker_connect();
2645 3065
 
... ... while(1) {
2761 3181 // TODO: what if we cannot extract info?! Wouldn't we lost stats?!! // TODO: what if we cannot extract info?! Wouldn't we lost stats?!!
2762 3182 $r = vm_extract_info($name); $r = vm_extract_info($name);
2763 3183 if ($r !== FALSE) if ($r !== FALSE)
2764 $job['stats'] = $r;
3184 vm_do_stats($job, $r);
2765 3185
2766 3186 // TODO: timeout must be controlled by user // TODO: timeout must be controlled by user
3187 // TODO: we may judje progress also about CPU/I/O/net activity
2767 3188 if ($job['start'] + 1 * 3600 < time()) { if ($job['start'] + 1 * 3600 < time()) {
2768 rg_log($jid . ': More than 6 hours without progress! Kill VM!');
3189 rg_log($jid . ': More than 1 hour without progress! Kill VM!');
2769 3190 $_name = 'rg-worker-' . $conf['id'] . '-' . $jid; $_name = 'rg-worker-' . $conf['id'] . '-' . $jid;
2770 3191 $cmd = 'virsh destroy ' . escapeshellarg($_name); $cmd = 'virsh destroy ' . escapeshellarg($_name);
2771 3192 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE); $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
 
... ... while(1) {
2839 3260 unset($xjob['last_reconnect']); unset($xjob['last_reconnect']);
2840 3261 unset($xjob['info_confirmed']); unset($xjob['info_confirmed']);
2841 3262 unset($xjob['dirty']); unset($xjob['dirty']);
3263 unset($xjob['tmp']);
2842 3264 $j_xjob = @json_encode($xjob); $j_xjob = @json_encode($xjob);
2843 3265 if ($j_xjob !== FALSE) { if ($j_xjob !== FALSE) {
2844 3266 // TODO: this is fragile. Better to iterate all jobs to compute stats. // TODO: this is fragile. Better to iterate all jobs to compute stats.
File techdocs/Certs.txt renamed from Certs.txt (similarity 100%)
File techdocs/rpm.txt changed (mode: 100644) (index 001df29..644a5ab)
... ... a .spec file is present in the repo and the user pushes.
7 7 - 'rg_wh_build_send' will trigger event 'rg_wh_build_send_one' for each enabled environments - 'rg_wh_build_send' will trigger event 'rg_wh_build_send_one' for each enabled environments
8 8 - 'rg_wh_build_send_one' will - 'rg_wh_build_send_one' will
9 9 - get the pkg_maps, repo and subrepo info - get the pkg_maps, repo and subrepo info
10 - sets exec:prepare_rpms and exec:copy_to_rgfs flags
10 - sets exec:prepare_pkgs
11 11 - will call 'rg_pkg_prepare_for_rgfs' to add rgfs details - will call 'rg_pkg_prepare_for_rgfs' to add rgfs details
12 12 - will call 'rg_pkg_prepare_for_dotrepo' to add info to create user repositories - will call 'rg_pkg_prepare_for_dotrepo' to add info to create user repositories
13 13 - will call 'rg_builder_add' - will call 'rg_builder_add'
 
... ... a .spec file is present in the repo and the user pushes.
15 15 - Worker will start the VM - Worker will start the VM
16 16 - Inside VM, script rg.sh is started - Inside VM, script rg.sh is started
17 17 - Checkout correct branch - Checkout correct branch
18 - .spec file is searched are BuildRequires are installed
18 - .spec file is searched and BuildRequires are installed
19 19 - 'build.sh' starts [as user 'build'] - 'build.sh' starts [as user 'build']
20 20 - Secrets are exported - Secrets are exported
21 21 - The commands defined in the webhook are run - The commands defined in the webhook are run
 
... ... a .spec file is present in the repo and the user pushes.
28 28 - gpg keys are stored in /mnt/build2 - gpg keys are stored in /mnt/build2
29 29 - Search for .rpm packages in /mnt/rpmbuild - Search for .rpm packages in /mnt/rpmbuild
30 30 - Imports gpg keys - Imports gpg keys
31 - If flag exec:prepare_rpms is set:
31 - If flag exec:prepare_pkgs is set:
32 32 - .rpms are copied into /mnt/build2/rpms/<pkg_repo_id}/{debug,os,src}[/username] - .rpms are copied into /mnt/build2/rpms/<pkg_repo_id}/{debug,os,src}[/username]
33 33 - A file A, containing the rpms, is created and rpms are signed - A file A, containing the rpms, is created and rpms are signed
34 34 - For each mapping - For each mapping
 
... ... a .spec file is present in the repo and the user pushes.
37 37 - if file A is empty, continue with next mapping - if file A is empty, continue with next mapping
38 38 - If a rpm file is already in the repo, remove the name from file A - If a rpm file is already in the repo, remove the name from file A
39 39 - if the build is done as uid 0, sign the '+pending' rpms - if the build is done as uid 0, sign the '+pending' rpms
40 - if exec:copy_to_rgfs flag is present, copy the signed rpms to rgfs dir
40 - copy the signed rpms to rgfs dir
41 41 - if uid is not 0 and pkg_repo uid != job_uid, save the pkg_subrepo_id into /mnt/build2/pkg_subrepo_dirty - if uid is not 0 and pkg_repo uid != job_uid, save the pkg_subrepo_id into /mnt/build2/pkg_subrepo_dirty
42 42 - If uid is 0 or pkg_repo_uid == job_uid, call rg_rpm_createrepo - If uid is 0 or pkg_repo_uid == job_uid, call rg_rpm_createrepo
43 43 - Unmount all rgfs dirs - Unmount all rgfs dirs
44 44
45 45 - VM is shutdown and logs and timings are collected - VM is shutdown and logs and timings are collected
46 46 - Worker notifies the Builder - Worker notifies the Builder
47 - Builder calls 'builder_done' function which will trigger 'wh_build_job_done'
47 - Builder calls 'builder_done' function which will trigger 'wh_build_job_done' event
48 48
49 49
50 50 == Scenario 2 == == Scenario 2 ==
 
... ... a .spec file is present in the repo and the user pushes.
97 97 - for each (subrepo, ver), call 'rg_pkg_subrepo_update_distro_info' - for each (subrepo, ver), call 'rg_pkg_subrepo_update_distro_info'
98 98 - if 'status:pkg_subrepo_dirty' is present, trigger 'pkg_subrepo_regenerate' event - if 'status:pkg_subrepo_dirty' is present, trigger 'pkg_subrepo_regenerate' event
99 99 Set by the 'worker', based on /root/build2/pkg_subrepo_dirty file Set by the 'worker', based on /root/build2/pkg_subrepo_dirty file
100 Set by exec:copy_to_rgfs phase of build_repo.sh when some .rpm are copied on rgfs
100 Set by build_repo.sh when some .rpm are copied on rgfs
101 101
102 102
103 103 == old == == old ==
File tests/gpg.php changed (mode: 100644) (index 1ceae39..a9cf6ae)
... ... $rg_no_db = TRUE;
13 13 require_once('common.php'); require_once('common.php');
14 14
15 15 $r = rg_gpg_key_gen('bla'); $r = rg_gpg_key_gen('bla');
16 rg_log_ml('r: ' . print_r($r, TRUE));
17 16 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
18 17 rg_log_ml('Cannot generate key: ' . $r['errmsg'] . '!'); rg_log_ml('Cannot generate key: ' . $r['errmsg'] . '!');
19 18 exit(1); exit(1);
20 19 } }
20 $pub = $r['pub_key'];
21 $priv = $r['priv_key'];
22
23
24 $r = rg_gpg_save_public_kr('tmp/gpg/public_kr1.out', $priv);
25 if ($r['ok'] != 1) {
26 rg_log_ml('Cannot save public keyring: ' . $r['errmsg'] . '!');
27 exit(1);
28 }
21 29
22 30
23 31 rg_log('Done!'); rg_log('Done!');
File tests/helpers.inc.php changed (mode: 100644) (index a8bf5e7..6438765)
... ... function rg_test_packages($rg_ui, $repo)
820 820 * Helper for getting the rpm repomd.xml * Helper for getting the rpm repomd.xml
821 821 */ */
822 822 function rg_test_packages_file($login_ui, $page_ui, $type, $pkg_repo_name, function rg_test_packages_file($login_ui, $page_ui, $type, $pkg_repo_name,
823 $pkg_subrepo_name, $file)
823 $pkg_subrepo_name, $distro, $major, $file)
824 824 { {
825 825 global $test_url; global $test_url;
826 826
827 rg_log_enter('test_packages_repomd');
827 rg_log_enter('test_packages_file');
828 828
829 829 $info = array('id' => $login_ui['username']); $info = array('id' => $login_ui['username']);
830 830
 
... ... function rg_test_packages_file($login_ui, $page_ui, $type, $pkg_repo_name,
832 832 if (strcmp($type, 'user') == 0) if (strcmp($type, 'user') == 0)
833 833 $url .= '/' . $page_ui['username']; $url .= '/' . $page_ui['username'];
834 834 $url .= '/' . $pkg_repo_name $url .= '/' . $pkg_repo_name
835 . '/' . $pkg_subrepo_name . '/fedora/34/x86_64/' . $file;
835 . '/' . $pkg_subrepo_name . '/' . $distro . '/' . $major . '/' . $file;
836 836
837 837 $r = do_req($info, $url, $data, $headers); $r = do_req($info, $url, $data, $headers);
838 838 if ($r === FALSE) { if ($r === FALSE) {
File tests/http.inc.php changed (mode: 100644) (index c8f3836..d1994b2)
... ... function do_req($info, $url, &$data, &$headers)
151 151 } }
152 152
153 153 $ret['rg_debug_html'] = $j; $ret['rg_debug_html'] = $j;
154 if (!empty($ret['rg_debug_html']))
155 rg_log_ml('rg_debug_html: '
156 . print_r($ret['rg_debug_html'], TRUE));
154 //if (!empty($ret['rg_debug_html']))
155 // rg_log_ml('rg_debug_html: '
156 // . print_r($ret['rg_debug_html'], TRUE));
157 157
158 158 $ret['body'] = $x[0] . $x[2]; $ret['body'] = $x[0] . $x[2];
159 159 } }
 
... ... function do_req($info, $url, &$data, &$headers)
185 185
186 186 // Check with tidy // Check with tidy
187 187 if (!stristr($ret['header'], 'Content-Type: ')) { if (!stristr($ret['header'], 'Content-Type: ')) {
188 // do nothing
188 rg_log('Content-Type header missing!');
189 exit(1);
189 190 } else if (stristr($ret['header'], 'Content-Type: application/octet-stream')) { } else if (stristr($ret['header'], 'Content-Type: application/octet-stream')) {
190 191 // do nothing // do nothing
191 192 } else if (stristr($ret['header'], 'Content-Type: application/x-rpm')) { } else if (stristr($ret['header'], 'Content-Type: application/x-rpm')) {
192 193 // do nothing // do nothing
194 } else if (stristr($ret['header'], 'Content-Type: text/plain')) {
195 // do nothing
193 196 } else if (stristr($ret['header'], 'Content-Type: text/xml')) { } else if (stristr($ret['header'], 'Content-Type: text/xml')) {
194 197 // do nothing - TODO: should we parse it? // do nothing - TODO: should we parse it?
195 198 } else if (stristr($ret['header'], 'Content-Type: text/html')) { } else if (stristr($ret['header'], 'Content-Type: text/html')) {
 
... ... function do_req($info, $url, &$data, &$headers)
212 215 @unlink($_tf . '.out'); @unlink($_tf . '.out');
213 216 } else if (stristr($ret['header'], 'Content-Type: application/json')) { } else if (stristr($ret['header'], 'Content-Type: application/json')) {
214 217 $ret['json'] = @json_decode($ret['body'], TRUE); $ret['json'] = @json_decode($ret['body'], TRUE);
215 if ($ret['json'] === NULL) {
218 if (empty($ret['json'])) {
216 219 rg_log('body: ' . $ret['body']); rg_log('body: ' . $ret['body']);
217 220 rg_log('Cannot decode JSON: ' . json_last_error_msg() . '!'); rg_log('Cannot decode JSON: ' . json_last_error_msg() . '!');
218 221 exit(1); exit(1);
File tests/wh_build.git.sh changed (mode: 100755) (index 3341da5..5de908e)
... ... mkdir -p rocketgit
24 24 echo " content_type = text/plain" echo " content_type = text/plain"
25 25 ) > rocketgit/artifacts ) > rocketgit/artifacts
26 26
27
28 mkdir -p debian/source
29
30 cat <<EOF > debian/rules
31 #!/usr/bin/make -f
32
33 DPKG_EXPORT_BUILDFLAGS = 1
34 include /usr/share/dpkg/default.mk
35 %:
36 dh \${@}
37 EOF
38 chmod a+x debian/rules
39
40 cat <<EOF > debian/copyright
41 Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
42 Upstream-Name: wh_build
43 Source: https://rocketgit.com/
44
45 Files: *
46 Copyright: 2015 Catalin(ux) M. BOIE <catab@embedromix.ro>
47 License: GPL-3+
48 <Put the license of the package here indented by 1 space>
49 <This follows the format of Description: lines in control file>
50 .
51 <Including paragraphs>
52 EOF
53
54 cat <<EOF > debian/control
55 Source: wh-build
56 Priority: optional
57 Maintainer: cata
58 Build-Depends: debhelper (>= 9), gcc, make
59 Standards-Version: 3.9.8
60 Section: misc
61 Homepage: https://rocketgit.com/
62 Vcs-Git: git://rocketgit.com/
63 Vcs-Browser: https://rocketgit.com/
64
65 Package: wh-build
66 Architecture: any
67 Depends: \${shlibs:Depends}, \${misc:Depends}
68 Description: Bla
69 EOF
70
71 echo "9" > debian/compat
72
73 cat <<EOF > debian/changelog
74 wh-build (0.1) unstable; urgency=low
75 * new release
76 -- Cata <rg-wh_build@embedromix.ro> Tue, 30 Nov 2021 11:14:00 +0200
77 EOF
78
79 echo "3.0 (native)" > debian/source/format
80
81
27 82 git add . git add .
28 83 git commit -a -m "c1" git commit -a -m "c1"
29 84
File tests/wh_build.php changed (mode: 100644) (index 766c6ae..3e6c880)
... ... $INC = dirname(__FILE__) . '/../inc';
11 11 require_once(dirname(__FILE__) . '/config.php'); require_once(dirname(__FILE__) . '/config.php');
12 12 require_once($INC . '/init.inc.php'); require_once($INC . '/init.inc.php');
13 13 require_once($INC . '/user.inc.php'); require_once($INC . '/user.inc.php');
14 require_once($INC . '/user/packages.inc.php');
14 15 require_once('helpers.inc.php'); require_once('helpers.inc.php');
15 16 require_once('http.inc.php'); require_once('http.inc.php');
16 17
 
... ... $extra = array(
77 78 'wh::idata::secrets::0::name' => 'secret1', // we cannot use <xss> here - it will be rejected by bash 'wh::idata::secrets::0::name' => 'secret1', // we cannot use <xss> here - it will be rejected by bash
78 79 'wh::idata::secrets::0::value' => 'value1<xss>', 'wh::idata::secrets::0::value' => 'value1<xss>',
79 80 'wh::idata::events' => 'P', 'wh::idata::events' => 'P',
80 'wh::idata::envs[fedora-34-x86_64]' => 'on',
81 'wh::idata::envs[fedora-35-x86_64]' => 'on',
82 'wh::idata::envs[debian-11-amd64]' => 'on',
81 83 'wh::idata::packages' => 'nano', 'wh::idata::packages' => 'nano',
82 84 'wh::idata::cmds::1::cmd' => 'make', 'wh::idata::cmds::1::cmd' => 'make',
83 85 'wh::idata::cmds::1::label_ok' => 'success <xss>', 'wh::idata::cmds::1::label_ok' => 'success <xss>',
84 'wh::idata::cmds::1::label_nok' => 'fail <xss>'
85 );
86 'wh::idata::cmds::1::label_nok' => 'fail <xss>');
86 87 rg_test_wh_add_edit($db, $rg_ui, 'build', 'generic', $extra); rg_test_wh_add_edit($db, $rg_ui, 'build', 'generic', $extra);
87 88 $wh_id = $extra['id']; $wh_id = $extra['id'];
88 89 rg_log('wh_id=' . $wh_id); rg_log('wh_id=' . $wh_id);
 
... ... $pkg_repo_pub = array(
100 101 rg_test_pkg_repo_add_edit($db, $rg_ui, $pkg_repo_pub); rg_test_pkg_repo_add_edit($db, $rg_ui, $pkg_repo_pub);
101 102
102 103
103 $pkg_subrepo_pub = array('sr::name' => 'stable');
104 $pkg_subrepo_pub = array('sr::name' => 'stablepub');
104 105 rg_test_pkg_subrepo_add_edit($db, $rg_ui, $pkg_repo_pub, $pkg_subrepo_pub); rg_test_pkg_subrepo_add_edit($db, $rg_ui, $pkg_repo_pub, $pkg_subrepo_pub);
105 106
106 107
 
... ... $pkg_repo_priv = array(
111 112 ); );
112 113 rg_test_pkg_repo_add_edit($db, $rg_ui, $pkg_repo_priv); rg_test_pkg_repo_add_edit($db, $rg_ui, $pkg_repo_priv);
113 114
114 $pkg_subrepo_priv = array('sr::name' => 'stable');
115 $pkg_subrepo_priv = array('sr::name' => 'stablepriv');
115 116 rg_test_pkg_subrepo_add_edit($db, $rg_ui, $pkg_repo_priv, $pkg_subrepo_priv); rg_test_pkg_subrepo_add_edit($db, $rg_ui, $pkg_repo_priv, $pkg_subrepo_priv);
116 117
117 118
 
... ... rg_log_exit();
156 157
157 158 rg_log(''); rg_log('');
158 159 rg_log_enter('Testing if hook executed with success'); rg_log_enter('Testing if hook executed with success');
159 $key = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $wh_id;
160 $r = test_wait_cache($key, 600);
161 $p = @$r['status']['cmds'][1];
162 if (strcmp($p['status'], '0') != 0) {
163 rg_log_ml('r: ' . print_r($r, TRUE));
164 rg_log('Sseems the build did not work well'
165 . ' [' . $p['status'] . ']! See above.');
166 exit(1);
167 }
160 $r = rg_test_packages($rg_ui, $repo);
161 // We have 1 more build for createrepo and one for Debian
162 do {
163 $r = rg_test_packages($rg_ui, $repo);
164 file_put_contents('wh_build_pkg_r.out', json_encode($r, JSON_PRETTY_PRINT));
165 file_put_contents('wh_build_pkg_debug.out', json_encode($r['rg_debug_html'], JSON_PRETTY_PRINT));
166
167 $_base = '/op/pkgrepo/user/' . $rg_ui['username']
168 . '/' . $pkg_repo_pub['pi::name'] . '/' . $pkg_subrepo_pub['sr::name'];
169 $pub_rpm_ready = strstr($r['body'], $_base . '/fedora');
170 $pub_deb_ready = strstr($r['body'], $_base . '/debian');
171
172 $_base = '/op/pkgrepo/user/' . $rg_ui['username']
173 . '/' . $pkg_repo_priv['pi::name'] . '/' . $pkg_subrepo_priv['sr::name'];
174 $priv_rpm_ready = strstr($r['body'], $_base . '/fedora');
175 $priv_deb_ready = strstr($r['body'], $_base . '/debian');
176 rg_log('pub_rpm_ready=' . ($pub_rpm_ready !== FALSE ? 'true' : 'false'));
177 rg_log('pub_deb_ready=' . ($pub_deb_ready !== FALSE ? 'true' : 'false'));
178 rg_log('priv_rpm_ready=' . ($priv_rpm_ready !== FALSE ? 'true' : 'false'));
179 rg_log('priv_deb_ready=' . ($priv_deb_ready !== FALSE ? 'true' : 'false'));
180 if ($pub_rpm_ready && $pub_deb_ready && $priv_rpm_ready && $priv_deb_ready)
181 break;
182
183 sleep(5);
184 } while (1);
168 185 rg_log_exit(); rg_log_exit();
169 186
170 187
 
... ... rg_log_exit();
175 192 rg_log(''); rg_log('');
176 193 rg_log_enter('Checking packages'); rg_log_enter('Checking packages');
177 194 $r = rg_test_packages($rg_ui, $repo); $r = rg_test_packages($rg_ui, $repo);
178 $e = '>os/+pending/' . $rg_ui['username']
179 . '/' . $rg_ui['username'] . '+' . $repo['name'] . '-0.1-1.x86_64.rpm<';
195 $e = '>' . $rg_ui['username'] . '+' . $repo['name'] . '-0.1-1.x86_64.rpm<';
180 196 if (!strstr($r['body'], $e)) { if (!strstr($r['body'], $e)) {
181 197 rg_log_ml('packages page: ' . $r['body']); rg_log_ml('packages page: ' . $r['body']);
182 rg_log('Link to os package not found [' . $e . ']!');
198 rg_log('Link to os rpm package not found [' . $e . ']!');
183 199 exit(1); exit(1);
184 200 } }
185 201 // TODO: check meta? // TODO: check meta?
 
... ... rg_log_exit();
190 206 rg_log(''); rg_log('');
191 207 rg_log_enter('Checking public dotrepo download'); rg_log_enter('Checking public dotrepo download');
192 208 $r = rg_test_packages_file($rg_ui, $rg_ui, 'user', $r = rg_test_packages_file($rg_ui, $rg_ui, 'user',
193 $pkg_repo_pub_name, 'stable',
194 'os/rocketgit-' . $rg_ui['username'] . '-'
195 . $pkg_repo_pub_name . '-stable-1.1-1.noarch.rpm');
209 $pkg_repo_pub_name, $pkg_subrepo_pub['sr::name'], 'fedora', 35,
210 'x86_64/os/rocketgit-' . $rg_ui['username'] . '-'
211 . $pkg_repo_pub_name . '-' . $pkg_subrepo_pub['sr::name'] . '-1.1-1.noarch.rpm');
196 212 // TODO: try to unpack the rpm? // TODO: try to unpack the rpm?
197 213 $e = 'content-type: application/x-rpm'; $e = 'content-type: application/x-rpm';
198 214 if (!stristr($r['header'], $e)) { if (!stristr($r['header'], $e)) {
 
... ... rg_log_exit();
207 223 rg_log(''); rg_log('');
208 224 rg_log_enter('Checking private dotrepo download'); rg_log_enter('Checking private dotrepo download');
209 225 $r = rg_test_packages_file($rg_ui, $rg_ui, 'user', $r = rg_test_packages_file($rg_ui, $rg_ui, 'user',
210 $pkg_repo_priv_name, 'stable',
211 'os/rocketgit-' . $rg_ui['username'] . '-'
212 . $pkg_repo_priv_name . '-stable-1.1-1.noarch.rpm');
226 $pkg_repo_priv_name, $pkg_subrepo_priv['sr::name'], 'fedora', 35,
227 'x86_64/os/rocketgit-' . $rg_ui['username'] . '-'
228 . $pkg_repo_priv_name . '-' . $pkg_subrepo_priv['sr::name'] . '-1.1-1.noarch.rpm');
213 229 // TODO: try to unpack the rpm? // TODO: try to unpack the rpm?
214 230 $e = 'content-type: application/x-rpm'; $e = 'content-type: application/x-rpm';
215 231 if (!stristr($r['header'], $e)) { if (!stristr($r['header'], $e)) {
 
... ... rg_log_exit();
223 239 rg_log(''); rg_log('');
224 240 rg_log_enter('Checking private dotrepo download (by bad user)'); rg_log_enter('Checking private dotrepo download (by bad user)');
225 241 $r = rg_test_packages_file($rg_bad, $rg_ui, 'user', $r = rg_test_packages_file($rg_bad, $rg_ui, 'user',
226 $pkg_repo_priv_name, 'stable',
227 'os/rocketgit-' . $rg_ui['username'] . '-'
228 . $pkg_repo_priv_name . '-stable-1.1-1.noarch.rpm');
242 $pkg_repo_priv_name, $pkg_subrepo_priv['sr::name'], 'fedora', 35,
243 'x86_64/os/rocketgit-' . $rg_ui['username'] . '-'
244 . $pkg_repo_priv_name . '-' . $pkg_subrepo_priv['sr::name'] . '-1.1-1.noarch.rpm');
229 245 // TODO: try to unpack the rpm? // TODO: try to unpack the rpm?
230 246 if ($r['ci']['http_code'] != 404) { if ($r['ci']['http_code'] != 404) {
231 247 rg_log('We must get 404 instead of ' . $r['ci']['http_code'] rg_log('We must get 404 instead of ' . $r['ci']['http_code']
 
... ... rg_log_exit();
238 254 rg_log(''); rg_log('');
239 255 rg_log_enter('Checking packages repomd download'); rg_log_enter('Checking packages repomd download');
240 256 $r = rg_test_packages_file($rg_ui, $rg_ui, 'user', $r = rg_test_packages_file($rg_ui, $rg_ui, 'user',
241 $pkg_repo_pub_name, 'stable',
242 'os/repodata/repomd.xml');
257 $pkg_repo_pub_name, $pkg_subrepo_pub['sr::name'], 'fedora', 35,
258 'x86_64/os/repodata/repomd.xml');
243 259 $e = '<?xml '; $e = '<?xml ';
244 260 if (!strstr($r['body'], $e)) { if (!strstr($r['body'], $e)) {
245 261 rg_log_ml('packages repomd page: ' . $r['body']); rg_log_ml('packages repomd page: ' . $r['body']);
 
... ... rg_log_exit();
258 274 rg_log(''); rg_log('');
259 275 rg_log_enter('Checking packages rpm download'); rg_log_enter('Checking packages rpm download');
260 276 $r = rg_test_packages_file($rg_ui, $rg_ui, 'user', $r = rg_test_packages_file($rg_ui, $rg_ui, 'user',
261 $pkg_repo_pub_name, 'stable',
262 'os/' . $rg_ui['username'] . '+' . $repo['name'] . '-0.1-1.x86_64.rpm');
277 $pkg_repo_pub_name, $pkg_subrepo_pub['sr::name'], 'fedora', 35,
278 'x86_64/os/' . $rg_ui['username'] . '+' . $repo['name'] . '-0.1-1.x86_64.rpm');
263 279 $e = 'content-type: application/x-rpm'; $e = 'content-type: application/x-rpm';
264 280 if (!stristr($r['header'], $e)) { if (!stristr($r['header'], $e)) {
265 281 rg_log_ml('headers: ' . $r['header']); rg_log_ml('headers: ' . $r['header']);
 
... ... if (!stristr($r['header'], $e)) {
269 285 rg_log_exit(); rg_log_exit();
270 286
271 287
288
289 ////////////////////////// Debian area starts
290
291 rg_log('');
292 rg_log_enter('Checking keyring as owner user');
293 $r = rg_test_packages_file($rg_ui, $rg_ui, 'user',
294 $pkg_repo_pub_name, $pkg_subrepo_pub['sr::name'],
295 'debian', 'bullseye', 'keyring');
296 $e = 'content-type: application/octet-stream';
297 if (!stristr($r['header'], $e) || ($r['ci']['http_code'] != 200)) {
298 rg_log_ml('headers: ' . $r['header']);
299 rg_log('Code/Content-Type is not ok [' . $e . ']!');
300 exit(1);
301 }
302 rg_log_exit();
303
304 rg_log('');
305 rg_log_enter('Checking auth as owner user');
306 $r = rg_test_packages_file($rg_ui, $rg_ui, 'user',
307 $pkg_repo_pub_name, $pkg_subrepo_pub['sr::name'],
308 'debian', 'bullseye', 'auth');
309 $e = 'content-type: text/plain';
310 if (!stristr($r['header'], $e) || ($r['ci']['http_code'] != 200)) {
311 rg_log_ml('headers: ' . $r['header']);
312 rg_log('Content-Type is not ok [' . $e . ']!');
313 exit(1);
314 }
315 if (strncmp($r['body'], 'machine ', 8) != 0) {
316 rg_log('Content of auth file does not start with machine keyword: [' . $r['body'] . ']!');
317 exit(1);
318 }
319 // TODO: check if password is ok
320 rg_log_exit();
321
322 rg_log('');
323 rg_log_enter('Downloading package as good (owner) user');
324 $u = rg_pkg_transform('deb', $rg_ui['username']);
325 $u1 = substr($u, 0, 1); $u2 = substr($u, 1, 1);
326 $r = rg_test_packages_file($rg_ui, $rg_ui, 'user',
327 $pkg_repo_priv_name, $pkg_subrepo_priv['sr::name'],
328 'debian', 'bullseye',
329 'pool/main/' . $u1 . '/' . $u2 . '/' . $u
330 . '+' . rg_pkg_transform('deb', $repo['name']) . '_0.1_amd64.deb');
331 rg_log_ml('r: ' . print_r($r, TRUE));
332 $e = 'content-type: application/octet-stream';
333 if (!stristr($r['header'], $e) || ($r['ci']['http_code'] != 200)) {
334 rg_log_ml('headers: ' . $r['header']);
335 rg_log('Content-Type is not ok [' . $e . ']!');
336 exit(1);
337 }
338 rg_log_exit();
339
340
341 rg_log('');
342 rg_log_enter('Checking auth as bad (not owner) user');
343 $r = rg_test_packages_file($rg_bad, $rg_ui, 'user',
344 $pkg_repo_priv_name, $pkg_subrepo_priv['sr::name'],
345 'debian', 'bullseye', 'auth');
346 if ($r['ci']['http_code'] != 404) {
347 rg_log_ml('headers: ' . $r['header']);
348 rg_log('We must get 404!');
349 exit(1);
350 }
351 rg_log_exit();
352
353 // TODO: bad user + password?
354
355 rg_log('');
356 rg_log_enter('Downloading package as bad (not owner) user');
357 $u = rg_pkg_transform('deb', $rg_ui['username']);
358 $u1 = substr($u, 0, 1); $u2 = substr($u, 1, 1);
359 $r = rg_test_packages_file($rg_bad, $rg_ui, 'user',
360 $pkg_repo_priv_name, $pkg_subrepo_priv['sr::name'],
361 'debian', 'bullseye',
362 'pool/main/' . $u1 . '/' . $u2 . '/' . $u
363 . '+' . rg_pkg_transform('deb', $repo['name']) . '_0.1_amd64.deb');
364 rg_log_ml('r: ' . print_r($r, TRUE));
365 if ($r['ci']['http_code'] != 404) {
366 rg_log_ml('headers: ' . $r['header']);
367 rg_log('We must get 404!');
368 exit(1);
369 }
370 rg_log_exit();
371
372 ////////////////////////// Debian area ends
373
374
375
272 376 rg_log(''); rg_log('');
273 377 rg_log_enter('Checking artifacts 1'); rg_log_enter('Checking artifacts 1');
274 $r = rg_test_artifacts_page($rg_ui, $repo, '/envs/fedora-34-x86_64');
275 $e = '<a href="/user/' . $rg_ui['username'] . '/' . $repo['name'] . '/artifacts/download/envs/fedora-34-x86_64/bla%C8%99.out">Download</a>';
378 $r = rg_test_artifacts_page($rg_ui, $repo, '/envs/fedora-35-x86_64');
379 $e = '<a href="/user/' . $rg_ui['username'] . '/' . $repo['name'] . '/artifacts/download/envs/fedora-35-x86_64/bla%C8%99.out">Download</a>';
276 380 if (!strstr($r['body'], $e)) { if (!strstr($r['body'], $e)) {
277 381 rg_log_ml('artifacts: ' . $r['body']); rg_log_ml('artifacts: ' . $r['body']);
278 382 rg_log('Link to artifact not found [' . $e . ']!'); rg_log('Link to artifact not found [' . $e . ']!');
279 383 exit(1); exit(1);
280 384 } }
281 $r = rg_test_artifacts_file($rg_ui, $repo, '/envs/fedora-34-x86_64/blaș.out');
385 $r = rg_test_artifacts_file($rg_ui, $repo, '/envs/fedora-35-x86_64/blaș.out');
282 386 rg_log_ml('blaș.out: ' . print_r($r, TRUE)); rg_log_ml('blaș.out: ' . print_r($r, TRUE));
283 387 $e = 'blaș' . "\n"; $e = 'blaș' . "\n";
284 388 if (strcmp($r['body'], $e) != 0) { if (strcmp($r['body'], $e) != 0) {
 
... ... if (!stristr($r['header'], $e)) {
301 405 rg_log_exit(); rg_log_exit();
302 406
303 407
408 rg_log('OK!');
409 exit(0);
410 // We ignore the rest for now, because we do 4 builds and test nothing!
411
304 412 rg_log(''); rg_log('');
305 413 rg_log_enter('Make a change and push again (for delta packages)'); rg_log_enter('Make a change and push again (for delta packages)');
306 rg_cache_unset($key, 0); // to not get the same cache info
307 414 $r = rg_exec('cd temp_repos/wh_build' $r = rg_exec('cd temp_repos/wh_build'
308 415 . ' && sed -i -e "s/^Version:.*0.1/Version: 0.2/" wh_build.spec' . ' && sed -i -e "s/^Version:.*0.1/Version: 0.2/" wh_build.spec'
416 . ' && sed -i -e "s/0.1/0.2/" debian/changelog'
309 417 . ' && git commit -a -m "new version"' . ' && git commit -a -m "new version"'
310 418 . ' && git push', . ' && git push',
311 419 '', FALSE, FALSE, FALSE); '', FALSE, FALSE, FALSE);
 
... ... rg_log_exit();
331 439
332 440
333 441 // TODO: test artifacts 2 (overwrite) // TODO: test artifacts 2 (overwrite)
334 // TODO: test rfs/rpm packages (by http)
442 // TODO: test rgfs/rpm packages (by http)
335 443
336 444
337 445 // TODO: add a test for 'map_into_source' // TODO: add a test for 'map_into_source'
338 446
339 447
340 // TODO: test that packages are in +pending (time race?)
341 448 rg_log('OK!'); rg_log('OK!');
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/rocketgit

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main