blob: 741c71ed807a2481ae32994ba8ecbce91dd8ec68 (
plain) (
tree)
|
|
package org.openslx.taskmanager.tasks;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.openslx.taskmanager.api.AbstractTask;
import com.google.gson.annotations.Expose;
public class CompileIPxe extends AbstractTask
{
@Expose
private String defaultentry = null;
@Expose
private int timeout = 0;
@Expose
private String custom = null;
private Output status = new Output();
@Override
protected boolean initTask()
{
this.setStatusObject( this.status );
if ( this.defaultentry == null )
this.defaultentry = "net";
if ( this.custom == null )
this.custom = "";
return true;
}
@Override
protected boolean execute()
{
// Prepare menu
String template;
try {
template = FileUtils.readFileToString( new File( "./data/pxemenu.template" ), StandardCharsets.UTF_8 );
} catch ( IOException e ) {
status.error = e.toString();
return false;
}
// Substitutions
template = template.replaceAll( "%timeout%", Integer.toString( this.timeout * 10 ) );
template = template.replaceAll( "%totaltimeout%", Integer.toString( this.timeout * 40 ) );
template = template.replaceAll( "%default%", this.defaultentry );
template = template.replaceAll( "%custom%", this.custom );
// Default selection net
if ( this.defaultentry.equals( "net" ) )
template = template.replaceAll( "%default-net%", "MENU DEFAULT" );
else
template = template.replaceAll( "%default-net%", "" );
// Default selection hdd
if ( this.defaultentry.equals( "hdd" ) )
template = template.replaceAll( "%default-hdd%", "MENU DEFAULT" );
else
template = template.replaceAll( "%default-hdd%", "" );
// Write out
try {
FileUtils.writeStringToFile( new File( "/srv/openslx/tftp/pxelinux.cfg/default" ), template, StandardCharsets.UTF_8 );
} catch ( IOException e ) {
status.error = e.toString();
return false;
}
return true;
}
class Output
{
protected String error = null;
}
}
|