summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-07-22 16:36:34 -0400
committerEudyptula <eitan@mosenkis.net>2009-07-22 16:36:34 -0400
commit7654432e0cc4463e2a8b195665f957f516b0685d (patch)
tree25f64c0fbfcabd1bcffabc47c7ccf57598cf6a8e
parentIntegrated bkisofs-cli into livecd and installcd bundlers, fixed various thin... (diff)
downloadingenue-7654432e0cc4463e2a8b195665f957f516b0685d.tar.gz
ingenue-7654432e0cc4463e2a8b195665f957f516b0685d.tar.bz2
ingenue-7654432e0cc4463e2a8b195665f957f516b0685d.zip
Cleaned up backend logging; moved emerge into a function; etc.
-rw-r--r--backend/functions/execution.php38
-rw-r--r--backend/functions/makedirs.php2
-rw-r--r--backend/functions/order_management.php26
-rw-r--r--backend/modules/gentoo_portage/build.php23
-rw-r--r--backend/modules/gentoo_portage/dev-manager.php7
-rw-r--r--backend/modules/gentoo_portage/emerge-system.php7
-rw-r--r--backend/modules/gentoo_portage/packages.php16
-rw-r--r--backend/modules/gentoo_portage/setup.php10
-rw-r--r--backend/modules/gentoo_portage/timezone.php1
-rw-r--r--shared/config.php2
-rw-r--r--shared/include/defaults.php2
-rw-r--r--todo3
12 files changed, 76 insertions, 61 deletions
diff --git a/backend/functions/execution.php b/backend/functions/execution.php
index f35e8c9..fbdb72f 100644
--- a/backend/functions/execution.php
+++ b/backend/functions/execution.php
@@ -1,28 +1,4 @@
<?php
-function task_get_order() {
- global $build;
- static $buildid=null;
- static $order=null;
- if ($build->id === $buildid) {
- $order++;
- } else {
- $buildid=$build->id;
- $order=0;
- }
- return $order;
-}
-function buildlog_entry_get_order() {
- global $build, $task;
- static $buildid, $taskorder, $order;
- if ($buildid === $build->id && $taskorder === $task->order) {
- $order++;
- } else {
- $buildid=$build->id;
- $taskorder=$task->order;
- $order=0;
- }
- return $order;
-}
function execute_command_with_all($description, $command, $fatal=true, $path=null, $env=null) {
global $build, $task;
if (isset($task))
@@ -80,6 +56,7 @@ function log_msg($msg, $nl=true) {
global $build, $task;
if (!isset($task)) {
start_internal_task($msg);
+ debug('log_msg creating task... this is bad');
return;
}
$msg.=$nl?"\n":'';
@@ -88,10 +65,17 @@ function log_msg($msg, $nl=true) {
$entry->write();
}
function log_status($msg, $cmd) {
- start_internal_task($msg);
+ global $task;
+ if ($istask=!isset($task)) {
+ start_internal_task($msg);
+ } else {
+ log_msg($msg, false);
+ }
$status=is_string($cmd)?eval((strpos($cmd, 'return') === false?'return ':'').$cmd):$cmd;
- end_internal_task($status?0:1);
- debug("... ".($status?color('[success]', 'green'):color('[failure]', 'red')));
+ if ($istask)
+ end_internal_task($status?0:1);
+ else
+ log_msg("... ".($status?color('[success]', 'green'):color('[failure]', 'red')));
return $status;
}
?>
diff --git a/backend/functions/makedirs.php b/backend/functions/makedirs.php
index 68b0ba4..de5f243 100644
--- a/backend/functions/makedirs.php
+++ b/backend/functions/makedirs.php
@@ -14,6 +14,6 @@ function makedir($dir) {
if (substr($dir, 0, 1) != '/')
$dir="$workdir/$dir";
if (!is_dir($dir))
- fatal(log_status('Creating '.$dir, mkdir($dir, 0700, true)));
+ fatal(log_status('Create '.$dir, mkdir($dir, 0700, true)));
}
?>
diff --git a/backend/functions/order_management.php b/backend/functions/order_management.php
new file mode 100644
index 0000000..306e42d
--- /dev/null
+++ b/backend/functions/order_management.php
@@ -0,0 +1,26 @@
+<?php
+function task_get_order() {
+ global $build;
+ static $buildid=null;
+ static $order=null;
+ if ($build->id === $buildid) {
+ $order++;
+ } else {
+ $buildid=$build->id;
+ $order=0;
+ }
+ return $order;
+}
+function buildlog_entry_get_order() {
+ global $build, $task;
+ static $buildid, $taskorder, $order;
+ if ($buildid === $build->id && $taskorder === $task->order) {
+ $order++;
+ } else {
+ $buildid=$build->id;
+ $taskorder=$task->order;
+ $order=0;
+ }
+ return $order;
+}
+?>
diff --git a/backend/modules/gentoo_portage/build.php b/backend/modules/gentoo_portage/build.php
index 1b18bf5..8e664e8 100644
--- a/backend/modules/gentoo_portage/build.php
+++ b/backend/modules/gentoo_portage/build.php
@@ -1,40 +1,31 @@
<?php
+require_once(dirname(__FILE__).'/packages.php'); // __DIR__ 5.3.0
// This is the main function that carries out a build from start to finish
function gentoo_portage_build(&$build, &$opts, &$W) {
global $conf;
$profile=new sql_gentoo_profile($opts['profile']);
$headers=$profile->get_headers();
- $I=$W.'/image';
- $C=$W.'/config_root';
+ $I="$W/image";
$extra=explode(' ', $opts['options']);
- makedirs($I, $C, "$W/log", "$W/tmp");
- fatal(log_status("Making symlink $C/etc -> .", symlink('.', "$C/etc")));
require(dirname(__FILE__).'/setup.php'); // __DIR__ in 5.3.0
- $prtg_cfgrt=array('PORTAGE_CONFIGROOT' => $C);
if ($conf['debug'])
execute_command_with_env('Log portage setup', 'emerge --info', $prtg_cfgrt);
require(dirname(__FILE__).'/emerge-system.php'); // __DIR__ 5.3.0
- if (in_array('timezone', $extra)) {
- $pkgs='sys-libs/timezone-data';
- require(dirname(__FILE__).'/packages.php'); // __DIR__ 5.3.0
+ if (in_array('timezone', $extra))
require(dirname(__FILE__).'/timezone.php'); // __DIR__ 5.3.0
- }
if (in_array('dev-manager', $extra))
require(dirname(__FILE__).'/dev-manager.php'); // __DIR__ 5.3.0
if ($opts['bundler'] == 'livecd')
- execute_command_with_env('Install LiveCD utilities', 'emerge -1 livecd-tools', $prtg_cfgrt);
+ portage_install('app-misc/livecd-tools', 'Install LiveCD utilities');
if (strlen($opts['pkgsets'])) {
foreach (explode(' ', $opts['pkgsets']) as $pkgset) {
if (strlen($opts['pkgset-'.$pkgset])) {
- $pkgs=$opts['pkgset-'.$pkgset];
- require(dirname(__FILE__).'/packages.php'); // __DIR__ 5.3.0
+ portage_install($opts['pkgset-'.$pkgset]);
}
}
}
- if (strlen($opts['install_packages'])) {
- $pkgs=$opts['install_packages'];
- require(dirname(__FILE__).'/packages.php'); // __DIR__ 5.3.0
- }
+ if (strlen($opts['install_packages']))
+ portage_install($opts['install_packages'], 'Install selected packages');
return $I;
}
?>
diff --git a/backend/modules/gentoo_portage/dev-manager.php b/backend/modules/gentoo_portage/dev-manager.php
index 47a95ac..40c06fb 100644
--- a/backend/modules/gentoo_portage/dev-manager.php
+++ b/backend/modules/gentoo_portage/dev-manager.php
@@ -1,9 +1,8 @@
<?php
if ($opts['dev-manager'] == 'udev') {
- $pkgs='sys-fs/udev';
+ portage_install('sys-fs/udev');
} else { // if ($opts['dev-manager'] == 'static-dev') {
- execute_command_with_env('Uninstall udev', 'emerge -C sys-fs/udev', $prtg_cfgrt);
- $pkgs='sys-fs/static-dev';
+ portage_install('sys-fs/udev', 'Uninstall udev', '-C');
+ portage_install('sys-fs/static-dev');
}
-require(dirname(__FILE__).'/packages.php');
?>
diff --git a/backend/modules/gentoo_portage/emerge-system.php b/backend/modules/gentoo_portage/emerge-system.php
index b273c29..728ff5a 100644
--- a/backend/modules/gentoo_portage/emerge-system.php
+++ b/backend/modules/gentoo_portage/emerge-system.php
@@ -1,10 +1,11 @@
<?php
-// execute_command_with_env('Pre-installing baselayout', 'emerge baselayout', array_merge($prtg_cfgrt, array('USE' => 'build')));
-// TODO create make.conf, make.profile in target /etc
if (is_file(CACHE.'/system-'.$profile->id.'.tar.gz') && filemtime(CACHE.'/system-'.$profile->id.'.tar.gz') > filemtime($conf['pkgdir_root'].'/'.$profile->pkgdir.'/Packages')) {
execute_command('Unpack cached base system', "tar -zxvf '".CACHE."/system-$profile->id.tar.gz' -C '$I'");
} else {
- execute_command_with_env('Install base system', 'emerge system', $prtg_cfgrt);
+ // TODO create make.conf, make.profile in target /etc
+ // May not be necessary and requires compiling=bad
+// portage_install('baselayout', 'Pre-install baselayout', '--oneshot --nodeps', 'build bootstrap');
+ portage_install('system', 'Install base system');
execute_command('Cache base system for reuse', "tar -p --same-owner -czvf '$W/image.tar.gz' -C '$I' .");
rename("$W/image.tar.gz", CACHE.'/system-'.$profile->id.'.tar.gz');
}
diff --git a/backend/modules/gentoo_portage/packages.php b/backend/modules/gentoo_portage/packages.php
index fc76026..e8be4bb 100644
--- a/backend/modules/gentoo_portage/packages.php
+++ b/backend/modules/gentoo_portage/packages.php
@@ -1,7 +1,13 @@
<?php
-if (!is_array($pkgs))
- $pkgs=explode(' ', $pkgs);
-foreach ($pkgs as $i => &$pkg)
- $pkg=escapeshellarg($pkg);
-execute_command_with_env('Install '.(count($pkgs) > 1?'packages':$pkgs[0]), 'emerge '.implode(' ', $pkgs), $prtg_cfgrt);
+function portage_install($pkgs, $desc=null, $opts=null, $use=null) {
+ global $prtg_cfgrt, $conf;
+ $opts=$conf['emerge_default_opts'].' '.($opts === null?'-K -n --root-deps=rdeps':$opts);
+ if (!is_array($pkgs))
+ $pkgs=explode(' ', $pkgs);
+ if ($desc === null)
+ $desc='Install '.(count($pkgs) > 1?'packages':$pkgs[0]);
+ foreach ($pkgs as $i => &$pkg)
+ $pkg=escapeshellarg($pkg);
+ execute_command_with_env($desc, ($use?'env USE="'.(is_array($use)?implode(' ', $use):$use).'" ':'').'emerge '.($opts?$opts.' ':'').implode(' ', $pkgs), $prtg_cfgrt);
+}
?>
diff --git a/backend/modules/gentoo_portage/setup.php b/backend/modules/gentoo_portage/setup.php
index c2d5e78..b9ca765 100644
--- a/backend/modules/gentoo_portage/setup.php
+++ b/backend/modules/gentoo_portage/setup.php
@@ -1,4 +1,8 @@
<?php
+start_internal_task('Create portage target environment');
+$C=$W.'/config_root';
+makedirs($I, $C, "$W/log", "$W/tmp");
+fatal(log_status("Making symlink $C/etc -> .", symlink('.', "$C/etc")));
$makeconf=array(
'pkgdir' => $conf['pkgdir_root'].'/'.$profile->pkgdir,
'chost' => $headers['chost'],
@@ -6,8 +10,7 @@ $makeconf=array(
'root' => $I,
'port_logdir' => "$W/log",
'emerge_log_dir' => "$W/log",
- 'portage_tmpdir' => "$W/tmp",
- 'emerge_default_opts' => $conf['emerge_default_opts']
+ 'portage_tmpdir' => "$W/tmp"
);
$contents='';
foreach ($makeconf as $name => $val)
@@ -16,4 +19,7 @@ unset($makeconf);
fatal(log_status('Writing '.$C.'/make.conf', file_put_contents($C.'/etc/make.conf', $contents)));
unset($contents);
fatal(log_status('Making make.profile symlink to '.$conf['portdir'].'/profiles/'.$headers['profile'], symlink($conf['portdir'].'/profiles/'.$headers['profile'], $C.'/etc/make.profile')));
+global $prtg_cfgrt;
+$prtg_cfgrt=array('PORTAGE_CONFIGROOT' => $C);
+end_internal_task(0);
?>
diff --git a/backend/modules/gentoo_portage/timezone.php b/backend/modules/gentoo_portage/timezone.php
index c3f05b0..3ac2774 100644
--- a/backend/modules/gentoo_portage/timezone.php
+++ b/backend/modules/gentoo_portage/timezone.php
@@ -1,3 +1,4 @@
<?php
+portage_install('sys-libs/timezone-data');
execute_command('Making timezone symlink', "ln -sf '/usr/share/zoneinfo/{$opts['timezone']}' '$I/etc/localtime'");
?>
diff --git a/shared/config.php b/shared/config.php
index 82efa59..4461c67 100644
--- a/shared/config.php
+++ b/shared/config.php
@@ -22,7 +22,7 @@ $split_setup=true; // Whether the frontend and backend are running on different
// $progressbar_width=350; // The width, in pixels, of the config wizard progress bar
// Backend options:
$pkgdir_root='/home/eitan/soc/tinderbox'; // The directory to recursively search for pkgdirs (Backend only)
-// $emerge_default_opts='-t -v -K -n --color=y --root-deps=rdeps'; // DON'T CHANGE UNLESS YOU KNOW WHAT YOU'RE DOING
+// $emerge_default_opts='-v --color=y'; // Options to add to all emerge commands
// $portdir='/usr/portage'; // The directory conatining the portage tree to use (/usr/portage unless you have a reason to think otherwise)
$frontend_location='http://soc'; // The base address of the frontend installation
$backend_id='red'; // A name or other way of identifying this backend as opposed to other backends working for the same frontend TODO use gethostname() by default in 5.3.0
diff --git a/shared/include/defaults.php b/shared/include/defaults.php
index 4462abb..b384257 100644
--- a/shared/include/defaults.php
+++ b/shared/include/defaults.php
@@ -29,7 +29,7 @@ $registration=false;
$invite='admin';
$logview_max=1000;
$progressbar_width=350;
-$emerge_default_opts='-t -v -K -n --color=y --root-deps=rdeps';
+$emerge_default_opts='-v --color=y';
$portdir='/usr/portage';
//$backend_id=gethostname(); // TODO Uncomment in 5.3.0
?>
diff --git a/todo b/todo
index 4099525..e86c34f 100644
--- a/todo
+++ b/todo
@@ -1,5 +1,4 @@
Write a live git ebuild
-Fix up backend logging so everything isn't its own task
Have builds and tasks not give links to logs if we're already viewing the logs
Consider logging env. passed to tasks, path if we ever use it
Add a statistics page
@@ -16,3 +15,5 @@ Allow config viewing for builds, not just configurations
Check if emerge system cache discards properly
Add `flags` column to configurations, builds, use it to implement public and private things
Clean up backend API
+Add 'cancel', 'delete' options to builds
+Add build->configuration and configuration duplication