summaryrefslogtreecommitdiff
blob: 324a37037df07392d31c6c90179625b0e5c98d88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
$r=query('SELECT * FROM `cache` WHERE `type`="portage"');
if ($r->rowCount() > 0) {
	$entry=new sql_cache_entry($r->fetch(PDO::FETCH_ASSOC));
	$file=CACHE."/$entry->file";
	execute_command('Unpack portage snapshot', "tar -xvjpf '$file' -C '$imagedir/usr'");
} else {
	start_internal_task('Copy local portage tree to image');
	foreach (glob("{$S['conf']['portdir']}/*") as $from) {
		$file=substr($from, strlen($S['conf']['portdir'])+1);
		// Skip distfiles, binary packages, and potential overlay directories
		if ($file == 'distfiles' || $file == 'packages' || $file == 'local' || $file == 'overlay') continue;
		$cmd="cp -av -t '$imagedir/usr/portage/' '$from'";
		error_get_last();
		@shell_exec($cmd);
		// TODO something wrong with this end_internal task being in the foreach
		end_internal_task((int)(bool)error_get_last());
	}
	end_internal_task(0);
}
start_internal_task('Set up portage in image');
$use=explode(' ', $headers['use']);
foreach(explode(' ', shell_exec(dirname(__FILE__).'/profile_use.py '.escapeshellarg("{$S['conf']['portdir']}/profiles/{$headers['profile']}"))) as $flag)
	if (($i=array_search($flag, $use)) !== false)
		unset($use[$i]);
$makeconf=array(
	'chost' => $headers['chost'],
	'accept_keywords' => $headers['accept_keywords'],
	'gentoo_mirrors' => $headers['gentoo_mirrors'],
	'use' => implode(' ', $use)
);
$contents='';
foreach ($makeconf as $name => $val)
	$contents.=strtoupper($name).'="'.str_replace('"', '\"', $val)."\"\n";
unset($makeconf);
log_msg("/etc/make.conf:\n$contents");
log_status('Writing /etc/make.conf', file_put_contents("$imagedir/etc/make.conf", $contents));
log_status('Remove previous make.profile', unlink("$imagedir/etc/make.profile"), false);
log_status("Symlink make.profile -> /usr/portage/profiles/{$headers['profile']}", symlink("/usr/portage/profiles/{$headers['profile']}", "$imagedir/etc/make.profile"));
end_internal_task(0);
?>