diff options
author | Eudyptula <eitan@mosenkis.net> | 2009-06-29 18:00:44 -0400 |
---|---|---|
committer | Eudyptula <eitan@mosenkis.net> | 2009-06-29 18:00:44 -0400 |
commit | d0172b464174f6ebc17a93f84e901618dd648adc (patch) | |
tree | 8e64402243d5b9a2e9dd8564dc1fcfba0fa8fb25 | |
parent | Added an send invitations form to frontend and email notifications to backend (diff) | |
download | ingenue-d0172b464174f6ebc17a93f84e901618dd648adc.tar.gz ingenue-d0172b464174f6ebc17a93f84e901618dd648adc.tar.bz2 ingenue-d0172b464174f6ebc17a93f84e901618dd648adc.zip |
Added image format option to frontend, tbz2 and preliminary Install CD and LiveCD support to backend
-rwxr-xr-x | backend/backend.php | 12 | ||||
-rw-r--r-- | backend/functions/build.php | 46 | ||||
-rw-r--r-- | backend/functions/url.php | 6 | ||||
-rw-r--r-- | depend | 1 | ||||
-rw-r--r-- | frontend/pages/downloadimage.php | 21 | ||||
-rw-r--r-- | frontend/wizard/step2.php | 1 | ||||
-rw-r--r-- | frontend/wizard/step3.php | 18 | ||||
-rwxr-xr-x | setup.php | 2 | ||||
-rw-r--r-- | shared/classes/build.php | 2 | ||||
-rw-r--r-- | shared/classes/buildopt.php | 2 | ||||
-rw-r--r-- | todo | 4 |
11 files changed, 95 insertions, 20 deletions
diff --git a/backend/backend.php b/backend/backend.php index 3cd0f07..4e2209a 100755 --- a/backend/backend.php +++ b/backend/backend.php @@ -25,10 +25,12 @@ if (isset($opts['k'])) { if (!posix_kill($pid, SIGTERM)) { debug("Failed to send SIGTERM to $pid"); die(1); + } else { + // TODO wait for $pid to exit } } else { debug("Couldn't send signal 0 to $pid"); - die(1); + die(0); } } else { debug('No PID file found'); @@ -54,9 +56,9 @@ while (true) { $build->status='build/running'; $build->write(); log_msg('Starting build id='.$build->id); - $image=null; + $success=null; try { - $image=build($build); + $success=build($build); } catch (Exception $e) { log_msg('Caught exception: '.$e->getMessage()); $build->status='finished/failed: '.$e->getMessage(); @@ -65,8 +67,8 @@ while (true) { } $build->finish=time(); log_msg('Finished with build id='.$build->id); - if (isset($image)) { - log_msg("Completed image at $image"); + if (isset($success)) { + log_msg("Completed build successfully"); $build->status='finished/success'; 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 <a href="'.url('logs/'.$build->id).'">'.url('logs/'.$build->id).'</a>'); } diff --git a/backend/functions/build.php b/backend/functions/build.php index 8037913..45a7415 100644 --- a/backend/functions/build.php +++ b/backend/functions/build.php @@ -9,7 +9,7 @@ function build(&$build) { $makeconf['chost']=$headers['chost']; $makeconf['accept_keywords']=$headers['accept_keywords']; $build->write(); - $W=WORK.'/build-'.$build->id; + $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))); @@ -35,8 +35,12 @@ function build(&$build) { 'PORTAGE_CONFIGROOT' => $C, 'PATH' => $_ENV['PATH'] ); - sql_task::execute_command('Log portage setup', 'emerge --info', $build, true, null, $env); + sql_task::execute_command('Log portage setup', 'emerge --info', $build, true, null, array_merge($env); +// sql_task::execute_command('Pre-installing baselayout', 'emerge baselayout', $build, true, null, array_merge($env, array('USE' => 'build'))); + // TODO create make.conf, make.profile in target /etc sql_task::execute_command('Install base system', 'emerge system', $build, true, null, $env); + if (isset($opts['image_type']) && $opts['image_type'] == 'livecd') + sql_task::execute_command('Install LiveCD utilities', 'emerge livecd-tools', $build, true, null, $env); if (isset($opts['install_packages'])) { $pkgs=array(); foreach (explode(' ', $opts['install_packages']) as $atom) { @@ -47,9 +51,39 @@ function build(&$build) { foreach ($pkgs as $atom) sql_task::execute_command('Install extra package '.$atom, 'emerge '.$atom, $build, true, null, $env); } - sql_task::execute_command('Compress finished image as tar/gzip', "tar -p --same-owner -czvf '$W/image.tar.gz' -C '$W/image' .", $build, true, null, $env); - rename($W.'/image.tar.gz', COMPLETED.'/build-'.$build->id.'.tar.gz'); - sql_task::execute_command('Delete work directory', 'rm -rf "'.$W.'"', $build, true, null, $env); - return COMPLETED.'/build-'.$build->id.'.tar.gz'; + $imgtype=isset($opts['image_type'])?$opts['image_type']:'tbz2'; + if ($imgtype == 'tbz2') { + sql_task::execute_command('Compress finished image to tar/bzip2', "tar -p --same-owner -cjvf '$W/image.tar.bz2' -C '$W/image' .", $build, true, null, $env); + rename($W.'/image.tar.bz2', COMPLETED.'/build-'.$build->id.'.tar.bz2') || throw_exception('rename failed'); + } elseif ($imgtype == 'tgz') { + sql_task::execute_command('Compress finished image to tar/gz', "tar -p --same-owner -czvf '$W/image.tar.gz' -C '$W/image' .", $build, true, null, $env); + rename($W.'/image.tar.gz', COMPLETED.'/build-'.$build->id.'.tar.gz') || throw_exception('rename failed'); + } elseif ($imgtype == 'livecd') { + sql_task::execute_command('Compress finished image to squashfs', "mksquashfs '$W/image' '$W/image.squashfs' -info ", $build, true, null, $env); + } else { + throw_exception('invalid image type: '.$imgtype); + } + if ($imgtype == 'livecd' || $imgtype == 'installcd') { + $minimaliso='/home/eitan/soc/install-amd64-minimal-20090625.iso'; + sql_task::execute_command('Mount minimal CD image', "mount -o loop -t iso9660 '$minimaliso' '$W/tmp'", $build, true, null, $env); + sql_task::execute_command('Copy CD image to writable temp directory', "cp -va '$W/tmp' '$W/cd'", $build, true, null, $env); + sql_task::execute_command('Unmount CD image', "umount '$W/tmp'", $build, true, null, $env); + if ($imgtype == 'livecd') { + rename($W.'/image.squashfs', $W.'/cd/image.squashfs') || throw_exception('rename failed'); + } else { + sql_task::execute_command('Copy kernel modules to image', "cp -va '$W/cd/lib/modules' '$W/image/lib/'", $build, true, null, $env); + sql_task::execute_command('Compress finished image to tar/bzip2', "tar -p --same-owner -cjvf '$W/image.tar.bz2' -C '$W/image' .", $build, true, null, $env); + rename($W.'/image.tar.bz2', $W.'/cd/image.tar.bz2') || throw_exception('rename failed'); + } + // TODO port the rest of /usr/lib/catalyst/targets/support/create-iso.sh + // ISOLINUX bootloader + // mkisofs -J -R -l ${mkisofs_zisofs_opts} -V "${clst_iso_volume_id}" -o ${1} -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table ${clst_target_path} + sql_task::execute_command('Create ISO image', "mkisofs -J -R -l -V 'Ingenue Build $build->id' -o '$W/image.iso' -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table '$W/cd'", $build, true, null, $env); + rename("$W/image.iso", COMPLETED.'/build-'.$build->id.'.iso') || throw_exception('rename failed'); + } + if (!$conf['debug']) { + sql_task::execute_command('Delete work directory', 'rm -rf "'.$W.'"', $build, true, null, $env); + } + return true; } ?> diff --git a/backend/functions/url.php b/backend/functions/url.php new file mode 100644 index 0000000..42c197f --- /dev/null +++ b/backend/functions/url.php @@ -0,0 +1,6 @@ +<?php +// TODO this needs to actually do something productive +function url($url) { + return 'http://soc/'.$url; +} +?> @@ -2,3 +2,4 @@ sys-apps/fakeroot ? sys-apps/portage # In case you use paludis www-servers/apache APACHE2_MODULES=rewrite? +sys-fs/squashfs-tools(-4.0?) diff --git a/frontend/pages/downloadimage.php b/frontend/pages/downloadimage.php index aaa48b3..7346e6a 100644 --- a/frontend/pages/downloadimage.php +++ b/frontend/pages/downloadimage.php @@ -14,16 +14,27 @@ function init_downloadimage() { return '404'; } $build=new sql_build($r->fetch(PDO::FETCH_ASSOC)); - $S['file']=COMPLETED.'/build-'.$build->id.'.tar.gz'; - if (!is_file($S['file'])) { - debug('downloadimage', 'image file '.$S['file'].' not found'); + $files=glob(COMPLETED.'/build-'.$build->id.'.*'); + if (count($files)) { + if (count($files) > 1) { + debug('downloadimage', 'extraneous file(s) found - don\'t know which to give them'); + return '404'; + } + $S['file']=$files[0]; + if (!is_readable($S['file'])) { + debug('downloadimage', 'found file, but no read perms'); + return '404'; + } + $ext=substr($S['file'], strpos($S['file'], '.')); + } else { + debug('downloadimage', 'image file not found'); return '404'; } - contenttype('application/x-gzip'); + contenttype('application/octet-stream'); header('Content-Length: '.filesize($S['file'])); header('Content-Description: File Transfer'); header('Content-Transfer-Encoding: binary'); - header('Content-Disposition: attachment; filename="ingenue-'.$build->id.'.tar.gz"'); + header('Content-Disposition: attachment; filename="ingenue-'.$build->id.$ext); } function body_downloadimage() { global $S; diff --git a/frontend/wizard/step2.php b/frontend/wizard/step2.php index 1978f92..7667b95 100644 --- a/frontend/wizard/step2.php +++ b/frontend/wizard/step2.php @@ -33,6 +33,5 @@ function wizard_process_step2() { $opt=new sql_buildopt($S['wizard.build']->id, 'install_packages', $packages); $opt->write(); } - return true; } ?> diff --git a/frontend/wizard/step3.php b/frontend/wizard/step3.php new file mode 100644 index 0000000..42e5211 --- /dev/null +++ b/frontend/wizard/step3.php @@ -0,0 +1,18 @@ +<?php +function wizard_init_step3() { + return array('title' => 'Step 3 - Image Format'); +} +function wizard_body_step3() { + echo 'Image type: <select name="image_type"><option value="tgz">Tar/Gzip</option><option value="tbz2">Tar/Bzip2</option><option value="installcd">Installer CD with Tar/Bzip2 image</option><option value="livecd">LiveCD</option></select><br/>'; +} +function wizard_process_step3() { + global $S, $request; + if (isset($request['image_type'])) { + debug('wizard', 'step3: image type='.$request['image_type']); + $opt=new sql_buildopt($S['wizard.build']->id, 'image_type', $request['image_type']); + $opt->write(); + } else { + debug('wizard', 'step3: no image_type variable'); + } + return true; +} @@ -69,7 +69,7 @@ do { if ($interactive) { system('stty echo'); } -$user->passhash=sha1($pass); +$user->passhash=substr($pass, 0, 5)=='sha1:'?substr($pass, 5):sha1($pass); $user->flags='a'; // Admin $user->write(); ?> diff --git a/shared/classes/build.php b/shared/classes/build.php index fd02aa9..3d37ec3 100644 --- a/shared/classes/build.php +++ b/shared/classes/build.php @@ -90,7 +90,7 @@ class sql_build extends sql_row_obj { } elseif ($status[1]='running') { // Add link to regular log viewer? // Build stage X - $html.='<span class="status building">[building]</span><br/><span class="links"><a href="'.url('logs/'.$this->id.'/live').'">Watch</a></span>'; + $html.='<span class="status building">[building]</span><br/><span class="links"><a href="'.url('logs/'.$this->id.'/live').'">Watch</a> • <a href="'.url('logs/'.$this->id).'"> Build log</a></span>'; } else { throw_exception('Unrecognized build status '.$this->status); } diff --git a/shared/classes/buildopt.php b/shared/classes/buildopt.php index b4b5226..68dc3cd 100644 --- a/shared/classes/buildopt.php +++ b/shared/classes/buildopt.php @@ -1,6 +1,6 @@ <?php class sql_buildopt extends sql_row_obj { - protected $table='buildopts', $columns=array( + protected $table='buildopts', $primary_key=array('build', 'name'), $columns=array( 'build' => array ( 'type' => 'CHAR', 'length' => 6, @@ -20,3 +20,7 @@ Separate variables we got from the URL from the rest, stop using $request, inste Replace STDOUT, STDERR, echo in backend with variable - either STDOUT, STDERR, or file Go back and figure out what should be log_msg and what should be debug, etc. Support ~arch installation or remove it from listings +Completely plan out how frontend modules should function - each step needs to report if it finished successfully (required values) +Change over wizard to work on configurations, not actual builds +See if I can figure any way to use classes instead of funny named functions (namespaces in 5.3.0 perhaps) - also needs to have a depend of some sort so we can make a quick-config page that doesn't show things that we don't have enough info for yet (use AJAX to show them when we're ready) +Allow backend to define bail-out functions to call when it dies (things like unmounting the ISO it was copying) |