From 5634227db6e7264c908a582685770b88f6ba69e5 Mon Sep 17 00:00:00 2001 From: Eudyptula Date: Wed, 15 Jul 2009 19:42:53 -0400 Subject: Divided gentoo_portage backend into several parts; Added another config step to choose which options to offer next; Added timezone selection; Fixed pkglist script; Little fixes --- backend/backend.php | 6 +-- backend/modules/gentoo_portage/build.php | 47 ++++++------------------ backend/modules/gentoo_portage/emerge-system.php | 11 ++++++ backend/modules/gentoo_portage/packages.php | 5 +++ backend/modules/gentoo_portage/setup.php | 19 ++++++++++ backend/modules/gentoo_portage/timezone.php | 3 ++ frontend/classes/wizard_api.php | 29 +++++++++------ frontend/modules/gentoo/step1.php | 1 - frontend/modules/gentoo/step2.php | 2 - frontend/modules/gentoo/step3.php | 12 +----- frontend/modules/gentoo/step4.php | 15 ++++++++ frontend/modules/gentoo_common.php | 2 +- frontend/pages/configurations/manager.php | 11 +++--- frontend/pages/configurations/wizard.php | 1 - pkglist.php | 10 +++-- shared/classes/configuration.php | 2 + shared/config.php | 3 +- shared/functions/get_timezones.php | 25 +++++++++++++ shared/functions/load_config.php | 2 +- shared/include/defaults.php | 3 +- todo | 2 + 21 files changed, 132 insertions(+), 79 deletions(-) create mode 100644 backend/modules/gentoo_portage/emerge-system.php create mode 100644 backend/modules/gentoo_portage/packages.php create mode 100644 backend/modules/gentoo_portage/setup.php create mode 100644 backend/modules/gentoo_portage/timezone.php create mode 100644 frontend/modules/gentoo/step4.php create mode 100644 shared/functions/get_timezones.php diff --git a/backend/backend.php b/backend/backend.php index 6ba8af6..1f05d6f 100755 --- a/backend/backend.php +++ b/backend/backend.php @@ -67,9 +67,7 @@ while (true) { } $opts=$build->get_opts(); $build_proc=$build->module.'_build'; - foreach (glob(BACKEND."/modules/$build->module/*.php") as $inc) { - require_once($inc); - } + require_once(BACKEND."/modules/$build->module/build.php"); // TODO check that build_proc exists $workdir=WORK.'/build-'.$build->id; fatal(log_status('Creating work directory '.$workdir, mkdir($workdir, 0700))); @@ -118,7 +116,7 @@ while (true) { } else { $build->status='finished/success'; $base=basename($file); - $ext=substr($base, substr($base, strpos($base, '.'))); + $ext=substr($base, strpos($base, '.')); rename($file, COMPLETED.'/build-'.$build->id.$ext); } xhtmlemail('"'.$owner->name.'" <'.$owner->email.'>', null, $conf['title'].' build finished', 'Your build has completed successfully. You can find more information and download the completed image at '.url('logs/'.$build->id).''); diff --git a/backend/modules/gentoo_portage/build.php b/backend/modules/gentoo_portage/build.php index 7d8b1bc..fab11e2 100644 --- a/backend/modules/gentoo_portage/build.php +++ b/backend/modules/gentoo_portage/build.php @@ -6,47 +6,22 @@ function gentoo_portage_build(&$build, &$opts, &$W) { $headers=$profile->get_headers(); $I=$W.'/image'; $C=$W.'/config_root'; + $extra=explode(' ', $opts['options']); 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'], - 'accept_keywords' => $headers['accept_keywords'], - 'root' => $I, - 'port_logdir' => "$W/log", - 'emerge_log_dir' => "$W/log", - 'portage_tmpdir' => "$W/tmp", - 'emerge_default_opts' => $conf['emerge_default_opts'] - ); - $contents=''; - foreach ($makeconf as $name => $val) - $contents.=strtoupper($name).'='.escapeshellarg($val)."\n"; - 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'))); + require(dirname(__FILE__).'/setup.php'); // __DIR__ in 5.3.0 $prtg_cfgrt=array('PORTAGE_CONFIGROOT' => $C); - execute_command_with_env('Log portage setup', 'emerge --info', $prtg_cfgrt); -// 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); - 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'); + 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)) { + require(dirname(__FILE__).'/timezone.php'); // __DIR__ 5.3.0 } - if (isset($opts['image_type']) && $opts['image_type'] == 'livecd') + if ($opts['bundler'] == 'livecd') execute_command_with_env('Install LiveCD utilities', 'emerge -1 livecd-tools', $prtg_cfgrt); - if (isset($opts['install_packages'])) { - $pkgs=array(); - foreach (explode(' ', $opts['install_packages']) as $atom) { - $pkgs[]=escapeshellarg($atom); - } - if (count($pkgs) > 1) - execute_command_with_env('Check that extra packages will install', 'emerge -p '.implode(' ', $pkgs), $prtg_cfgrt); - foreach ($pkgs as $atom) - execute_command_with_env('Install extra package '.$atom, 'emerge '.$atom, $prtg_cfgrt); + if (strlen($opts['install_packages'])) { + $pkgs=explode(' ', $opts['install_packages']); + require(dirname(__FILE__).'/packages.php'); // __DIR__ 5.3.0 } return $I; } diff --git a/backend/modules/gentoo_portage/emerge-system.php b/backend/modules/gentoo_portage/emerge-system.php new file mode 100644 index 0000000..b273c29 --- /dev/null +++ b/backend/modules/gentoo_portage/emerge-system.php @@ -0,0 +1,11 @@ + '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); + 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 new file mode 100644 index 0000000..345b425 --- /dev/null +++ b/backend/modules/gentoo_portage/packages.php @@ -0,0 +1,5 @@ + &$pkg) + $pkg=escapeshellarg($pkg); +execute_command_with_env('Install packages', 'emerge '.implode(' ', $pkgs), $prtg_cfgrt); +?> diff --git a/backend/modules/gentoo_portage/setup.php b/backend/modules/gentoo_portage/setup.php new file mode 100644 index 0000000..c2d5e78 --- /dev/null +++ b/backend/modules/gentoo_portage/setup.php @@ -0,0 +1,19 @@ + $conf['pkgdir_root'].'/'.$profile->pkgdir, + 'chost' => $headers['chost'], + 'accept_keywords' => $headers['accept_keywords'], + 'root' => $I, + 'port_logdir' => "$W/log", + 'emerge_log_dir' => "$W/log", + 'portage_tmpdir' => "$W/tmp", + 'emerge_default_opts' => $conf['emerge_default_opts'] +); +$contents=''; +foreach ($makeconf as $name => $val) + $contents.=strtoupper($name).'='.escapeshellarg($val)."\n"; +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'))); +?> diff --git a/backend/modules/gentoo_portage/timezone.php b/backend/modules/gentoo_portage/timezone.php new file mode 100644 index 0000000..c3f05b0 --- /dev/null +++ b/backend/modules/gentoo_portage/timezone.php @@ -0,0 +1,3 @@ + diff --git a/frontend/classes/wizard_api.php b/frontend/classes/wizard_api.php index 049f3cc..f4c672e 100644 --- a/frontend/classes/wizard_api.php +++ b/frontend/classes/wizard_api.php @@ -85,7 +85,7 @@ class wizard_step { return $this->configuration->get_opt($opt); } private function echo_buttons() { - echo '
'; + echo ($this->step > 1?' ':' ').'
'; } } abstract class wizard { @@ -186,9 +186,8 @@ class wizard_select extends wizard_input { echo htmlentities($label); } if ($rw) - echo "\n"; - else - echo "
\n"; + echo ''; + echo "
\n"; } public function process() { global $request; @@ -209,7 +208,7 @@ class wizard_radio extends wizard_select { echo "$this->label:
\n"; $i=0; foreach ($this->options as $val => $label) { - echo "\thtmlname-$i\" name=\"$this->htmlname\" value=\"".$i."\"".($this->opt_is($this->optname, $val)?' checked="checked"':'')."\" />\n"; + echo "\thtmlname-$i\" name=\"$this->htmlname\" value=\"".$i."\"".($this->opt_is($this->optname, $val)?' checked="checked"':'')."\" />
\n"; $i++; } } @@ -222,21 +221,29 @@ class wizard_checkbox_array extends wizard_input { $this->delim=$delim; } public function output($rw=true) { - echo "$this->label:
\n"; + if (strlen($this->label)) + echo "$this->label:
\n"; $i=0; foreach ($this->array as $val => $label) { - echo "\thtmlname-$i\" name=\"$this->htmlname[$i]\"".($this->opt_has($this->optname, $val, $this->delim)?' checked="checked"':'')." />
\n"; + $label=htmlentities($label); + if ($rw) + echo "\thtmlname-$i\" name=\"$this->htmlname[$i]\"".($this->opt_has($this->optname, $val, $this->delim)?' checked="checked"':'')." />
\n"; + elseif ($this->opt_has($this->optname, $val, $this->delim)) + echo "$label
\n"; $i++; } } public function process() { global $request; $val=array(); - $vals=array_keys($this->array); - foreach ($request[$this->htmlname] as $i) { - $val[]=$vals[$i]; + if (isset($request[$this->htmlname])) { + $vals=array_keys($this->array); + foreach ($request[$this->htmlname] as $i => $null) { + $val[]=$vals[$i]; + } } - $this->set_opt($this->optname, implode($this->delim, $vals)); + $this->set_opt($this->optname, implode($this->delim, $val)); + return true; } public function verify() { if (($vals=$this->get_opt($this->optname)) === null) return null; diff --git a/frontend/modules/gentoo/step1.php b/frontend/modules/gentoo/step1.php index 2b7a9f2..297f7c0 100644 --- a/frontend/modules/gentoo/step1.php +++ b/frontend/modules/gentoo/step1.php @@ -1,5 +1,4 @@ query('SELECT * FROM `gentoo_profiles` WHERE `flags` NOT LIKE "%d%"'); while ($profile=$r->fetch(PDO::FETCH_ASSOC)) { diff --git a/frontend/modules/gentoo/step2.php b/frontend/modules/gentoo/step2.php index da023c6..b5b95df 100644 --- a/frontend/modules/gentoo/step2.php +++ b/frontend/modules/gentoo/step2.php @@ -1,6 +1,4 @@ get_opt('profile')); $pkgs=$profile->get_packages(); $meta=array( diff --git a/frontend/modules/gentoo/step3.php b/frontend/modules/gentoo/step3.php index 0643856..a420a0f 100644 --- a/frontend/modules/gentoo/step3.php +++ b/frontend/modules/gentoo/step3.php @@ -1,13 +1,3 @@ select('bundler', 'bundler', 'Image type', array( - 'tgz' => 'Tar/Gzip', - 'tbz2' => 'Tar/Bzip2', - 'installcd' => 'Installer CD with Tar/Bzip2', - 'livecd' => 'LiveCD', - 'ext2' => 'ext2', - 'jffs2' => 'jffs2' -)); +$this->checkbox_array('options', 'options', null, array('timezone' => 'Select timezone')); ?> diff --git a/frontend/modules/gentoo/step4.php b/frontend/modules/gentoo/step4.php new file mode 100644 index 0000000..b5edf91 --- /dev/null +++ b/frontend/modules/gentoo/step4.php @@ -0,0 +1,15 @@ +get_opt('options')); +if (in_array('timezone', $opts)) + $this->select('timezone', 'timezone', 'Timezone', get_timezones()); +// TODO This shouldn't be a step at all, it should be in wizard.php to choose between bundlers +// TODO This shouldn't be part of configurations, except possibly a default value. It should be for builds +$this->select('bundler', 'bundler', 'Image type', array( + 'tgz' => 'Tar/Gzip', + 'tbz2' => 'Tar/Bzip2', + 'installcd' => 'Installer CD with Tar/Bzip2', + 'livecd' => 'LiveCD', + 'ext2' => 'ext2', + 'jffs2' => 'jffs2' +)); +?> diff --git a/frontend/modules/gentoo_common.php b/frontend/modules/gentoo_common.php index bc72b0b..ee2e7f1 100644 --- a/frontend/modules/gentoo_common.php +++ b/frontend/modules/gentoo_common.php @@ -1,4 +1,4 @@ diff --git a/frontend/pages/configurations/manager.php b/frontend/pages/configurations/manager.php index 68297fe..0488a11 100644 --- a/frontend/pages/configurations/manager.php +++ b/frontend/pages/configurations/manager.php @@ -9,11 +9,7 @@ function init_configurations_manager() { function body_configurations_manager() { global $S, $request, $conf; echo '

Configurations Manager

'; - $r=$S['pdo']->query('SELECT * FROM `configurations` WHERE `owner`='.$S['user']->id); - if ($r->rowCount() == 0) { - echo print_warning('You have no configurations.').'Create a configuration'; - return; - } elseif (isset($request['build']) && isset($request['configuration'])) { + if (isset($request['build']) && isset($request['configuration'])) { $c=new sql_configuration($request['configuration']); if ($c->owner!=$S['user']->id) { echo print_error('You do not have permission to build this configuration.'); @@ -26,6 +22,11 @@ function body_configurations_manager() { echo print_error('Invalid configuration', 'Your configuration could not be submitted for build. Please return to id/$build").'">step '.$build.' and continue configuration from there.'); } } + $r=$S['pdo']->query('SELECT * FROM `configurations` WHERE `owner`='.$S['user']->id); + if ($r->rowCount() == 0) { + echo print_warning('You have no configurations.').'Create a configuration'; + return; + } echo '
'.(count($conf['modules']) > 1?'':'').''."\n"; $ready=0; while($c=$r->fetch(PDO::FETCH_ASSOC)) { diff --git a/frontend/pages/configurations/wizard.php b/frontend/pages/configurations/wizard.php index cc46405..947e321 100644 --- a/frontend/pages/configurations/wizard.php +++ b/frontend/pages/configurations/wizard.php @@ -35,7 +35,6 @@ function init_configurations_wizard() { } } elseif (isset($request['init'])) { $S['wizard']['configuration']=new sql_configuration(); - wizard::set_configuration($S['wizard']['configuration']); $configuration=&$S['wizard']['configuration']; $configuration->name=$request['name']; $mod=isset($request['mod']) && isset($conf['modules'][$request['mod']])?$conf['modules'][$request['mod']]:$conf['modules'][0]; diff --git a/pkglist.php b/pkglist.php index cc22686..a0c577c 100755 --- a/pkglist.php +++ b/pkglist.php @@ -9,10 +9,12 @@ while ($p=$r->fetch(PDO::FETCH_ASSOC)) { $p=new sql_gentoo_profile($p); echo ($p->name?$p->name:$p->pkgdir)."\n"; $packages=$p->get_packages(); - foreach ($packages as $cat => $pkg) { - foreach ($pkg as $name => $vers) { - foreach ($vers as $ver => $attrs) { - echo ($attrs['masked']?color('[MASKED] ', 'red'):'')."$cat/$name-$ver: ".$attrs['description']."\n"; + foreach ($packages as $bcat => $lcats) { + foreach ($lcats as $lcat => $pkgs) { + foreach ($pkgs as $name => $vers) { + foreach ($vers as $ver => $attrs) { + echo ($attrs['masked']?color('[MASKED] ', 'red'):'')."$bcat$lcat/$name-$ver: ".$attrs['desc']."\n"; + } } } } diff --git a/shared/classes/configuration.php b/shared/classes/configuration.php index 32200d4..157610b 100644 --- a/shared/classes/configuration.php +++ b/shared/classes/configuration.php @@ -37,6 +37,8 @@ class sql_configuration extends conf_build_common { for ($i=1; $i<=$module->numsteps; $i++) { $step=new wizard_step($this, $i); if (!$step->verify()) { + $this->status=$i; + $this->write(); return $i; } } diff --git a/shared/config.php b/shared/config.php index 2f73991..3920ad1 100644 --- a/shared/config.php +++ b/shared/config.php @@ -11,6 +11,7 @@ $debug=true; // Whether to print debugging information // $cookiename='ingenueid'; // Name of the cookie to send for keeping sessions // $sessionlength=1814400; // Time in seconds before sessions are purged // $mod_rewrite=true; // Use mod_rewrite for pretty URLs +// $timezone_root='/usr/share/zoneinfo'; // Directory to search for timezone data (sys-libs/timezone-data) $emailfrom='noreply@gentoo.org'; // Used as the From: field in emails $check_email_dns=true; // Use DNS to check the domain of submitted emails for validity // $split_setup=false; // Whether the frontend and backend are running on different hosts @@ -21,7 +22,7 @@ $check_email_dns=true; // Use DNS to check the domain of submitted emails for va // $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 --color=y --root-deps=rdeps'; // DON'T CHANGE UNLESS YOU KNOW WHAT YOU'RE DOING +// $emerge_default_opts='-t -v -K -n --color=y --root-deps=rdeps'; // DON'T CHANGE UNLESS YOU KNOW WHAT YOU'RE DOING // $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/functions/get_timezones.php b/shared/functions/get_timezones.php new file mode 100644 index 0000000..4c495cd --- /dev/null +++ b/shared/functions/get_timezones.php @@ -0,0 +1,25 @@ + diff --git a/shared/functions/load_config.php b/shared/functions/load_config.php index 7bf94b4..ac660f7 100644 --- a/shared/functions/load_config.php +++ b/shared/functions/load_config.php @@ -3,7 +3,7 @@ function load_config() { require(SHARED.'/include/defaults.php'); require(SHARED.'/config.php'); $modules=explode(' ', $modules); - foreach (explode(' ', 'title sqlhost sqluser sqlpass sqldb debug modules bundlers cookiename sessionlength mod_rewrite emailfrom check_email_dns split_setup registration invite logview_max progressbar_width pkgdir_root emerge_default_opts portdir frontend_location backend_id') as $var) { + foreach (explode(' ', 'title sqlhost sqluser sqlpass sqldb debug modules bundlers cookiename sessionlength mod_rewrite timezone_root emailfrom check_email_dns split_setup registration invite logview_max progressbar_width pkgdir_root emerge_default_opts portdir frontend_location backend_id') as $var) { if (isset($$var)) { $GLOBALS['conf'][$var]=$$var; } diff --git a/shared/include/defaults.php b/shared/include/defaults.php index 66862a8..4462abb 100644 --- a/shared/include/defaults.php +++ b/shared/include/defaults.php @@ -21,6 +21,7 @@ $bundlers=implode(' ', $bundlers); $cookiename='ingenueid'; $sessionlength=1814400; $mod_rewrite=true; +$timezone_root='/usr/share/zoneinfo'; $emailfrom='noreply@noreply.net'; $check_email_dns=false; $split_setup=false; @@ -28,7 +29,7 @@ $registration=false; $invite='admin'; $logview_max=1000; $progressbar_width=350; -$emerge_default_opts='-t -v -K --color=y --root-deps=rdeps'; +$emerge_default_opts='-t -v -K -n --color=y --root-deps=rdeps'; $portdir='/usr/portage'; //$backend_id=gethostname(); // TODO Uncomment in 5.3.0 ?> diff --git a/todo b/todo index ae16bcf..0c277a1 100644 --- a/todo +++ b/todo @@ -22,3 +22,5 @@ Move gentoo_profiles setup out of the general setup.php, allow per-module setup Move bundler selection out of gentoo module and generalize it (switch to builds instead of configurations) Improve the quality of base system creation (if necessary) Allow config viewing for builds, not just logs +Write basic command-line wrapper to bkisofs and replace the ISO mounter with it +Fix emerge system cache to discard properly -- cgit v1.2.3-65-gdbad
IDNameModuleStatusOptionsBuilds