diff options
author | Eudyptula <eitan@mosenkis.net> | 2009-06-19 14:23:12 -0400 |
---|---|---|
committer | Eudyptula <eitan@mosenkis.net> | 2009-06-19 14:23:12 -0400 |
commit | 5494492326fe0f7ea6127cfeaa1858e3c03a7da0 (patch) | |
tree | f7ce84b76ef22067270a75bb63bb2d3f5d88ee87 | |
parent | Updated todo (diff) | |
download | ingenue-5494492326fe0f7ea6127cfeaa1858e3c03a7da0.tar.gz ingenue-5494492326fe0f7ea6127cfeaa1858e3c03a7da0.tar.bz2 ingenue-5494492326fe0f7ea6127cfeaa1858e3c03a7da0.zip |
Transitioned to support multiple profiles, chosen in the frontend, to use data in Packages file header, began restructuring of frontend build creator
-rw-r--r-- | backend/functions/build.php | 58 | ||||
-rw-r--r-- | backend/functions/get_profile_headers.php | 17 | ||||
-rw-r--r-- | frontend/functions/r_stripslashes.php | 13 | ||||
-rw-r--r-- | frontend/index.php | 4 | ||||
-rw-r--r-- | frontend/pages/wizard.php | 56 | ||||
-rwxr-xr-x | setup.php | 6 | ||||
-rw-r--r-- | shared/classes/buildopt.php | 20 | ||||
-rw-r--r-- | shared/classes/profile.php | 28 | ||||
-rw-r--r-- | shared/config.php | 3 | ||||
-rw-r--r-- | shared/functions/get_pkgdirs.php | 18 | ||||
-rw-r--r-- | todo | 3 |
11 files changed, 160 insertions, 66 deletions
diff --git a/backend/functions/build.php b/backend/functions/build.php index 9859020..3346218 100644 --- a/backend/functions/build.php +++ b/backend/functions/build.php @@ -1,39 +1,43 @@ <?php -// Sample variables (will be in config file or user input) -$conf['pkgdir']='/home/eitan/soc/tinderbox/default-linux-amd64'; -// $conf['cflags']='-march=nocona -O2 -pipe'; // Not needed in a binary install -// $conf['cxxflags']='$CFLAGS'; // Not needed in a binary install -$conf['chost']='x86_64-pc-linux-gnu'; -$conf['port_logdir']='$W/log'; -$conf['emerge_log_dir']=$conf['port_logdir']; -$conf['emerge_default_opts']='-t -K --color=n --root-deps=rdeps'; -$conf['portage_tmpdir']='$W/tmp'; $profile='/etc/make.profile'; // This is the main function that carries out a build from start to finish function build(&$build) { - global $conf, $profile; + global $pdo, $conf, $profile; + $r=$pdo->query('SELECT * FROM `buildopts` WHERE `build`="'.$build->id.'"'); + while ($opt=$r->fetch(PDO::FETCH_ASSOC)) { + $opt=new sql_buildopt($opt); + $opts[$opt->name]=$opt; + } + $profile=new sql_profile($opts['profile']->value); + $headers=get_profile_headers($profile); + $makeconf['pkgdir']=$conf['pkgdir_root'].'/'.$profile->pkgdir; + $makeconf['chost']=$headers['chost']; $build->status='build/started'; $build->write(); - define('W', WORK.'/build-'.$build->id); - fatal(log_status('Creating work directory '.W, mkdir(W, 0700))); - fatal(log_status('Creating '.W.'/image', mkdir(W.'/image', 0700))); - define('I', W.'/image'); - fatal(log_status('Creating '.W.'/config_root', mkdir(W.'/config_root', 0700))); - define('C', W.'/config_root'); - fatal(log_status('Creating '.C.'/etc', mkdir(C.'/etc', 0700))); - fatal(log_status('Creating '.C.'/etc/portage', mkdir(C.'/etc/portage', 0700))); - fatal(log_status('Creating '.W.'/log', mkdir(W.'/log', 0700))); - fatal(log_status('Creating '.W.'/tmp', mkdir(W.'/tmp', 0700))); - $makeconf='W="'.W.'"'."\n"; - foreach ($conf as $name => $val) { - $makeconf.=strtoupper($name).'="'.$val.'"'."\n"; + $W=WORK.'/build-'.$build->id; + fatal(log_status('Creating work directory '.$W, mkdir($W, 0700))); + $I=$W.'/image'; + fatal(log_status('Creating '.$I, mkdir($I, 0700))); + $C=$W.'/config_root'; + fatal(log_status('Creating '.$C, mkdir($C, 0700))); + fatal(log_status("Making symlink $C/etc -> $C", symlink('.', "$C/etc"))); + fatal(log_status('Creating '.$W.'/log', mkdir($W.'/log', 0700))); + $makeconf['port_logdir']=$W.'/log'; + $makeconf['emerge_log_dir']=$conf['port_logdir']; + fatal(log_status('Creating '.$W.'/tmp', mkdir($W.'/tmp', 0700))); + $makeconf['portage_tmpdir']=$W.'/tmp'; + $makeconf['emerge_default_opts']=$conf['emerge_default_opts']; + $contents=''; + foreach ($makeconf as $name => $val) { // TODO maybe shell_escape $val + $contents.=strtoupper($name).'="'.$val.'"'."\n"; } - fatal(log_status('Writing '.C.'/make.conf:'."\n".indent($makeconf), file_put_contents(C.'/etc/make.conf', $makeconf))); unset($makeconf); - fatal(log_status('Making make.profile symlink to '.$profile, symlink($profile, C.'/etc/make.profile'))); + fatal(log_status('Writing '.$C.'/make.conf:'."\n".indent($contents), 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'))); $env=array( - 'PORTAGE_CONFIGROOT' => C, - 'ROOT' => I + 'PORTAGE_CONFIGROOT' => $C, + 'ROOT' => $I ); fatal(!log_command($build, 'emerge --info', null, $env)!=0); fatal(!log_command($build, 'emerge -pv system', null, $env)!=0); diff --git a/backend/functions/get_profile_headers.php b/backend/functions/get_profile_headers.php new file mode 100644 index 0000000..0a63f61 --- /dev/null +++ b/backend/functions/get_profile_headers.php @@ -0,0 +1,17 @@ +<?php +function get_profile_headers($profile) { + global $conf; + $file=fopen($conf['pkgdir_root'].'/'.$profile->pkgdir.'/Packages', 'r'); + $headers=array(); + while (true) { + $line=rtrim(fgets($file)); + if (strlen($line) == 0) { + break; + } elseif (preg_match('/^([a-zA-Z0-9_-]+): (.*)$/', $line, $match)) { + $headers[strtolower($match[1])]=$match[2]; + } + } + fclose($file); + return $headers; +} +?> diff --git a/frontend/functions/r_stripslashes.php b/frontend/functions/r_stripslashes.php new file mode 100644 index 0000000..8d6dccb --- /dev/null +++ b/frontend/functions/r_stripslashes.php @@ -0,0 +1,13 @@ +<?php +function r_stripslashes(&$array) { + debug('r_stripslashes', print_r($array, true)); + foreach ($array as $key => $value) { + if (is_array($value)) { + $array[$key]=r_stripslashes($value); + } elseif (is_string($value)) { + $array[$key]=stripslashes($value); + } + } + return $array; +} +?> diff --git a/frontend/index.php b/frontend/index.php index 846a3f9..0677c58 100644 --- a/frontend/index.php +++ b/frontend/index.php @@ -7,9 +7,7 @@ require_once('include/constants.php'); require_once(SHARED.'/config.php'); require_once('include/setup.php'); register_shutdown_function('onshutdown', realpath('include/footer.php'), realpath('include/header.php')); -foreach ($_REQUEST as $key => $value) { - $request[$key]=get_magic_quotes_gpc()?stripslashes($value):$value; -} +$request=get_magic_quotes_gpc()?r_stripslashes($_REQUEST):$_REQUEST; $routing=fopen('routing.csv', 'r'); for ($line=fgets($routing, 32768); !feof($routing); $line=fgets($routing, 32768)) { $line=trim($line, "\r\n"); diff --git a/frontend/pages/wizard.php b/frontend/pages/wizard.php index 2e0066c..dee3c57 100644 --- a/frontend/pages/wizard.php +++ b/frontend/pages/wizard.php @@ -1,44 +1,32 @@ <?php function init_wizard() { - if (isset($GLOBALS['S']['user'])) { - return array('title' => 'Image Creator'); + global $S, $request; + // TODO we shouldn't have to set the step this way, it should be stored in SQL + if (isset($S['user'])) { + if (isset($request['finished'])) { + return 'wizard/end'; + } elseif (isset($request['step']) && is_array($request['step']) && count($request['step']) == 1) { + $keys=array_keys($request['step']); + if (is_numeric($keys[0]) && is_file(FRONTEND.'/pages/wizard/step'.$keys[0].'.php')) { + return 'wizard/step'.$keys[0]; + } else { + debug('Not numeric, or file not existant for '.$keys[0]); + } + } + return array('title' => 'Create'); } else { return 'login'; } } function body_wizard() { - global $request, $S; - if (isset($request['submit'])) { - $fails=0; - while (true) { - $id=randstring(6); - debug("Trying id=$id..."); - // Maybe we should query the DB, not see if insert fails? - $build=new sql_build($id, $S['user']->id, $request['name'], 'build/ready', null, null); - try { - if ($build->write()) { - if (is_dir(WORK.'/build-'.$id)) { - debug('failed... directory already exists (this is bad - it should be in the database)'); - $build->delete(); - } else { - break; - } - } - } catch (Exception $e) { - if (get_class($e) != 'PDOException' || !isset($e->errorInfo) || !isset($e->errorInfo[0]) || $e->errorInfo[0] != 23000) { - throw ($e); - } else { - debug('already taken in the database'); - } - } - if (++$fails >= 10) { - die(print_error('Something is wrong - failed 10 times to choose a unique build id')); -die; - } - } - echo '<h3>Build submitted</h3><p><b>ID: '.$id.'</b></p><p>Check your build\'s status <a href="'.url('logs/build'.$id).'">here</a>.</p>'; - } else { - echo '<form action="'.url('create').'" method="post"><h3>Request an image built</h3>Name of your build (optional): <input name="name" /><br/><input type="submit" name="submit" value="Submit" /></form>'; + global $S; + echo '<form action="'.url('create').'" method="post"><h3>Request an image built</h3>Name of your build (optional): <input name="name" /><br/>Profile: <select name="pkgdir">'; + $r=$S['pdo']->query('SELECT * FROM `profiles` WHERE `flags` NOT LIKE "%d%"'); // d for disabled + while ($profile=$r->fetch(PDO::FETCH_ASSOC)) { + $profile=new sql_profile($profile); + $display=$profile->name?$profile->name:($profile->pkgdir?$profile->pkgdir:'/'); + echo '<option value="'.htmlentities($profile->pkgdir).'">'.htmlentities($display).'</option>'; } + echo '</select><br/><input type="submit" name="step[1]" value="Start" /></form>'; } ?> @@ -26,6 +26,12 @@ foreach (get_declared_classes() as $class) { } echo_and_query($o->create_table()); } +foreach (get_pkgdirs() as $dir) { + echo 'Creating profile for '.$conf['pkgdir_root'].'/'.$dir.'...'; + $profile=new sql_profile($dir, null, null, ''); + $profile->write(); + echo "done\n"; +} do { if ($user->email) { echo 'Invalid entry: '.$user->email."\n"; diff --git a/shared/classes/buildopt.php b/shared/classes/buildopt.php new file mode 100644 index 0000000..e05192b --- /dev/null +++ b/shared/classes/buildopt.php @@ -0,0 +1,20 @@ +<?php +class sql_buildopt extends sql_row_obj { + protected $table='buildopts', $columns=array( + 'build' => array ( + 'type' => 'CHAR', + 'length' => 6, + 'not_null' => true + ), + 'name' => array ( + 'type' => 'VARCHAR', + 'length' => 255, + 'not_null' => true + ), + 'value' => array ( + 'type' => 'TEXT' + ) + + ); +} +?> diff --git a/shared/classes/profile.php b/shared/classes/profile.php new file mode 100644 index 0000000..b528b47 --- /dev/null +++ b/shared/classes/profile.php @@ -0,0 +1,28 @@ +<?php +class sql_profile extends sql_row_obj { + protected $table='profiles', $primary_key='pkgdir', $columns=array( + 'pkgdir' => array ( + 'type' => 'VARCHAR', + 'length' => 255, + 'not_null' => true + ), + 'name' => array ( + 'type' => 'VARCHAR', + 'length' => 255, + 'not_null' => true, + 'unique' => true + ), + 'order' => array ( + 'type' => 'TINYINT', + 'length' => 4, + 'not_null' => true + ), + 'flags' => array ( + 'type' => 'VARCHAR', + 'length' => 255, + 'not_null' => true + ) + + ); +} +?> diff --git a/shared/config.php b/shared/config.php index 12298ec..1eeb4ee 100644 --- a/shared/config.php +++ b/shared/config.php @@ -11,4 +11,7 @@ $conf['sessionlength']=1814400; // Time in seconds before sessions are purged $conf['timezone']=10800; // Time difference in seconds between UTC and the default timezone $conf['mod_rewrite']=true; // Use mod_rewrite for pretty URLs $conf['check_email_dns']=true; // Use DNS to check the domain of submitted emails for validity +$conf['pkgdir_root']='/home/eitan/soc/tinderbox'; // The directory to recursively search for pkgdirs in +$conf['emerge_default_opts']='-t -K --color=n --root-deps=rdeps'; // DON'T CHANGE UNLESS YOU KNOW WHAT YOU'RE DOING +$conf['portdir']='/usr/portage'; // The directory conatining the portage tree to use (/usr/portage unless you have a reason to think otherwise) ?> diff --git a/shared/functions/get_pkgdirs.php b/shared/functions/get_pkgdirs.php new file mode 100644 index 0000000..1f39420 --- /dev/null +++ b/shared/functions/get_pkgdirs.php @@ -0,0 +1,18 @@ +<?php +function get_pkgdirs($dir=null) { + global $conf; + if ($dir===null) { + $dir=$conf['pkgdir_root']; + } + if (is_file($dir.'/Packages')) { + // We assume that a dir with a Packages file will not contain other complete ppkgdirs + return array(substr($dir, strlen($conf['pkgdir_root'])+1)); + } else { + $return=array(); + foreach (glob ($dir.'/*', GLOB_ONLYDIR) as $subdir) { + $return=array_merge($return, get_pkgdirs($subdir)); + } + return $return; + } +} +?> @@ -6,5 +6,4 @@ Add signal handling to the backend so when you hit Ctrl-C, it doesn't leave the Find kernels Add a 'ctime' column to builds so we know which ones to start first Add status column of builds to log viewer -Parse Packages file for make.conf generation and make.profile linking -Support choosing the profile in frontend, backend +Post first weekly report to gentoo-dev, gentoo-soc |