diff options
Diffstat (limited to 'backend')
-rwxr-xr-x | backend/backend.php | 42 | ||||
-rw-r--r-- | backend/modules/gentoo_portage/build.php | 41 |
2 files changed, 62 insertions, 21 deletions
diff --git a/backend/backend.php b/backend/backend.php index cde76f0..2ee7357 100755 --- a/backend/backend.php +++ b/backend/backend.php @@ -56,7 +56,7 @@ while (true) { $build->status='build/running'; $build->write(); log_msg('Starting build id='.$build->id); - $success=null; + $file=null; try { $opts=$build->get_buildopts(); $module=$opts['backend_module']; @@ -67,7 +67,7 @@ while (true) { // TODO check that build_proc exists $workdir=WORK.'/build-'.$build->id; fatal(log_status('Creating work directory '.$workdir, mkdir($workdir, 0700))); - $success=$build_proc($build, $opts, $workdir); + $file=$build_proc($build, $opts, $workdir); if (!$conf['debug']) { execute_command('Delete work directory', 'rm -rf "'.$workdir.'"'); } @@ -79,16 +79,46 @@ while (true) { } $build->finish=time(); log_msg('Finished with build id='.$build->id); - if (isset($success)) { + if (isset($file)) { log_msg("Completed build successfully"); - $build->status='finished/success'; + if ($conf['split_setup']) { + $build->status='finished/uploading'; + $build->write(); + $key=randstring(30); + $opt=new sql_buildopt($build->id, 'uploadkey', $key); + $opt->write(); + $c=curl_init($conf['frontend_location'].'/backend/upload_image'); + curl_setopt($c, CURLOPT_POST, 1); + curl_setopt($c, CURLOPT_POSTFIELDS, array( + 'build' => $build->id, + 'key' => $key, + 'file' => "@$file" + )); + curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); + $result=curl_exec($c); + if ($conf['debug'] && is_string($result)) { + debug($result); + } + if ($result === false || strpos($result, 'Upload successful') === false) { + $build->status='finished/failed: upload failed'.($result === false?' - '.curl_error($c):''); + } else { + debug("Transferred $file... unlinking it"); + unlink($file); + $build->status='finished/success'; + } + } else { + $build->status='finished/success'; + $base=basename($file); + $ext=substr($base, 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 <a href="'.url('logs/'.$build->id).'">'.url('logs/'.$build->id).'</a>'); } $build->write(); unset($build); } -// log_msg('Sleeping...', false); + // log_msg('Sleeping...', false); sleep(5); -// log_msg("done"); + // log_msg("done"); } ?> diff --git a/backend/modules/gentoo_portage/build.php b/backend/modules/gentoo_portage/build.php index f23408f..c2d0be8 100644 --- a/backend/modules/gentoo_portage/build.php +++ b/backend/modules/gentoo_portage/build.php @@ -29,7 +29,13 @@ function gentoo_portage_build(&$build, &$opts, &$W) { 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 - execute_command_with_env('Install base system', 'emerge system', $prtg_cfgrt); + 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 (isset($opts['image_type']) && $opts['image_type'] == 'livecd') execute_command_with_env('Install LiveCD utilities', 'emerge -1 livecd-tools', $prtg_cfgrt); if (isset($opts['install_packages'])) { @@ -44,11 +50,13 @@ function gentoo_portage_build(&$build, &$opts, &$W) { } $imgtype=isset($opts['image_type'])?$opts['image_type']:'tbz2'; if ($imgtype == 'tbz2') { - execute_command('Compress finished image to tar/bzip2', "tar -p --same-owner -cjvf '$W/image.tar.bz2' -C '$W/image' ."); - rename($W.'/image.tar.bz2', COMPLETED.'/build-'.$build->id.'.tar.bz2') || throw_exception('rename failed'); + execute_command('Compress finished image to tar/bzip2', "tar -p --same-owner -cjvf '$W/image.tar.bz2' -C '$I' ."); + return "$W/image.tar.bz2"; +// rename($W.'/image.tar.bz2', COMPLETED.'/build-'.$build->id.'.tar.bz2') || throw_exception('rename failed'); } elseif ($imgtype == 'tgz') { - execute_command('Compress finished image to tar/gz', "tar -p --same-owner -czvf '$W/image.tar.gz' -C '$W/image' ."); - rename($W.'/image.tar.gz', COMPLETED.'/build-'.$build->id.'.tar.gz') || throw_exception('rename failed'); + execute_command('Compress finished image to tar/gz', "tar -p --same-owner -czvf '$W/image.tar.gz' -C '$I' ."); + return "$W/image.tar.gz"; +// rename($W.'/image.tar.gz', COMPLETED.'/build-'.$build->id.'.tar.gz') || throw_exception('rename failed'); } elseif ($imgtype == 'livecd' || $imgtype == 'installcd') { if (strpos($headers['chost'], 'x86_64') === false) $minimaliso='/home/eitan/soc/install-x86-minimal-20090623.iso'; @@ -57,34 +65,37 @@ function gentoo_portage_build(&$build, &$opts, &$W) { execute_command_with_env('Mount minimal CD image', "mount -o loop -t iso9660 '$minimaliso' '$W/tmp'", $prtg_cfgrt); // TODO check if env is necessary (and for umount) execute_command('Copy CD image to writable temp directory', "cp -va '$W/tmp' '$W/cd'"); execute_command_with_env('Unmount CD image', "umount '$W/tmp'", $prtg_cfgrt); - execute_command('Copy kernel and initrd from CD to image', "cp -va '$W/cd/isolinux/gentoo' '$W/cd/isolinux/gentoo.igz' '$W/image/boot/'"); + execute_command('Copy kernel and initrd from CD to image', "cp -va '$W/cd/isolinux/gentoo' '$W/cd/isolinux/gentoo.igz' '$I/boot/'"); file_put_contents("$W/unsquashfs-files", "/lib64/modules\n\lib\modules\n"); - execute_command('Copy kernel modules from SquashFS to image', "unsquashfs -i -d '$W/image' -e '$W/unsquashfs-files' '$W/cd/image.squashfs'"); + execute_command('Copy kernel modules from SquashFS to image', "unsquashfs -i -d '$I' -e '$W/unsquashfs-files' '$W/cd/image.squashfs'"); if ($imgtype == 'livecd') { rename("$W/cd/image.squashfs", "$W/image.squashfs.old") || debug('Failed to move old SquashFS'); - execute_command('Compress finished image to squashfs', "mksquashfs '$W/image' '$W/cd/image.squashfs' -noappend -info"); + execute_command('Compress finished image to squashfs', "mksquashfs '$I' '$W/cd/image.squashfs' -noappend -info"); } else // Install CD - execute_command('Compress finished image to tar/bzip2', "tar -p --same-owner -cjvf '$W/cd/image.tar.bz2' -C '$W/image' ."); + execute_command('Compress finished image to tar/bzip2', "tar -p --same-owner -cjvf '$W/cd/image.tar.bz2' -C '$I' ."); // TODO port the rest of /usr/lib/catalyst/targets/support/create-iso.sh to support other bootloaders // 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} 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'"); - rename("$W/image.iso", COMPLETED.'/build-'.$build->id.'.iso') || throw_exception('rename failed'); + return "$W/image.iso"; +// rename("$W/image.iso", COMPLETED.'/build-'.$build->id.'.iso') || throw_exception('rename failed'); } elseif ($imgtype == 'jffs2') { - execute_command('Create JFFS2 image', "mkfs.jffs2 -x lzo -n -e 0x20000 -l -p -r '$W/image' -o '$W/image.jffs2'"); - rename("$W/image.jffs2", COMPLETED.'/build-'.$build->id.'.jffs2') || throw_exception ('rename failed'); + execute_command('Create JFFS2 image', "mkfs.jffs2 -x lzo -n -e 0x20000 -l -p -r '$I' -o '$W/image.jffs2'"); + return "$W/image.jffs2"; +// rename("$W/image.jffs2", COMPLETED.'/build-'.$build->id.'.jffs2') || throw_exception ('rename failed'); } elseif ($imgtype == 'ext2') { execute_command('Make blank file for ext2 image', "dd if=/dev/zero of='$W/image.ext2' bs=1024 count=1048576"); execute_command('Make ext2 filesystem', "mke2fs -t ext2 -F '$W/image.ext2'"); makedir('ext2'); execute_command('Mount ext2 image', "mount -o loop -t ext2 '$W/image.ext2' '$W/ext2'"); - execute_command('Copy files to ext2', "cp -va '$W/image/*' '$W/ext2/'"); + execute_command('Copy files to ext2', "cp -va '$I/*' '$W/ext2/'"); execute_command('Unmount ext2 image', "umount '$W/ext2'"); execute_command('Compress ext2 image', "gzip '$W/image.ext2'"); - rename("$W/image.ext2.gz", COMPLETED.'/build-'.$build->id.'.ext2.gz') || throw_exception('rename failed'); + return "$W/image.ext2.gz"; +// rename("$W/image.ext2.gz", COMPLETED.'/build-'.$build->id.'.ext2.gz') || throw_exception('rename failed'); } else { throw_exception('invalid image type: '.$imgtype); } - return true; +// return true; } ?> |