diff options
author | Simon Rettberg | 2015-01-23 19:19:58 +0100 |
---|---|---|
committer | Simon Rettberg | 2015-01-23 19:19:58 +0100 |
commit | 2eb5cea8578c2884c6f30fa379212bbfc1554bed (patch) | |
tree | 12d4eb781782e07e41b084444a2185a978e90c98 /src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java | |
parent | Pimp my boot menu (diff) | |
download | tmlite-bwlp-2eb5cea8578c2884c6f30fa379212bbfc1554bed.tar.gz tmlite-bwlp-2eb5cea8578c2884c6f30fa379212bbfc1554bed.tar.xz tmlite-bwlp-2eb5cea8578c2884c6f30fa379212bbfc1554bed.zip |
Stuff
Diffstat (limited to 'src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java')
-rw-r--r-- | src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java | 86 |
1 files changed, 77 insertions, 9 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java b/src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java index 741c71e..a5b436f 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java +++ b/src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java @@ -2,15 +2,21 @@ package org.openslx.taskmanager.tasks; import java.io.File; import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import org.apache.commons.io.FileUtils; +import org.apache.log4j.Logger; +import org.openslx.satserver.util.Exec; import org.openslx.taskmanager.api.AbstractTask; import com.google.gson.annotations.Expose; public class CompileIPxe extends AbstractTask { + private static final Logger LOG = Logger.getLogger( CompileIPxe.class ); @Expose private String defaultentry = null; @@ -18,6 +24,10 @@ public class CompileIPxe extends AbstractTask private int timeout = 0; @Expose private String custom = null; + @Expose + private String ipaddress = null; + @Expose + private String masterpassword = null; private Output status = new Output(); @@ -25,16 +35,32 @@ public class CompileIPxe extends AbstractTask protected boolean initTask() { this.setStatusObject( this.status ); + if ( this.ipaddress == null || this.ipaddress.isEmpty() ) { + status.error = "No IP address given!"; + return false; + } if ( this.defaultentry == null ) this.defaultentry = "net"; if ( this.custom == null ) this.custom = ""; + if ( this.masterpassword == null ) + this.masterpassword = ""; return true; } @Override protected boolean execute() { + boolean ret = true; + if ( !updateMenu() ) + ret = false; + if ( !updateIpxe() ) + ret = false; + return ret; + } + + private boolean updateMenu() + { // Prepare menu String template; try { @@ -44,27 +70,69 @@ public class CompileIPxe extends AbstractTask 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 ); + template = template.replace( "%timeout%", Integer.toString( this.timeout * 10 ) ); + template = template.replace( "%totaltimeout%", Integer.toString( this.timeout * 40 ) ); + template = template.replace( "%default%", this.defaultentry ); + template = template.replace( "%custom%", this.custom ); + template = template.replace( "%ipaddress%", this.ipaddress ); + template = template.replace( "%masterpassword%", this.masterpassword ); // Default selection net if ( this.defaultentry.equals( "net" ) ) - template = template.replaceAll( "%default-net%", "MENU DEFAULT" ); + template = template.replace( "%default-net%", "MENU DEFAULT" ); else - template = template.replaceAll( "%default-net%", "" ); + template = template.replace( "%default-net%", "" ); // Default selection hdd if ( this.defaultentry.equals( "hdd" ) ) - template = template.replaceAll( "%default-hdd%", "MENU DEFAULT" ); + template = template.replace( "%default-hdd%", "MENU DEFAULT" ); else - template = template.replaceAll( "%default-hdd%", "" ); + template = template.replace( "%default-hdd%", "" ); + // Write out + try { + Charset cs; + if ( Charset.isSupported( "IBM437" ) ) + cs = Charset.forName( "IBM437" ); + else if ( Charset.isSupported( "Cp437" ) ) + cs = Charset.forName( "Cp437" ); + else + cs = StandardCharsets.UTF_8; + FileUtils.writeStringToFile( new File( "/srv/openslx/tftp/pxelinux.cfg/default" ), template, cs ); + } catch ( IOException e ) { + status.error = e.toString(); + return false; + } + return true; + } + + private boolean updateIpxe() + { + // Prepare menu + String template; + try { + template = FileUtils.readFileToString( new File( "./data/ipxe-embed.template" ), StandardCharsets.UTF_8 ); + } catch ( IOException e ) { + status.error = e.toString(); + return false; + } + // Substitution + template = template.replace( "%ipaddress%", this.ipaddress ); // Write out try { - FileUtils.writeStringToFile( new File( "/srv/openslx/tftp/pxelinux.cfg/default" ), template, StandardCharsets.UTF_8 ); + FileUtils.writeStringToFile( new File( "/opt/openslx/ipxe/ipxelinux.ipxe" ), template, StandardCharsets.UTF_8 ); } catch ( IOException e ) { status.error = e.toString(); return false; } + // Compile + if ( 0 != Exec.syncAt( "/opt/openslx/ipxe/src", "make", "EMBED=../ipxelinux.ipxe,../pxelinux.0", "bin/undionly.kkkpxe" ) ) { + status.error = "Compiling ipxelinux.0 failed"; + return false; + } + try { + FileUtils.copyFile( new File( "/opt/openslx/ipxe/src/bin/undionly.kkkpxe" ), new File( "/srv/openslx/tftp/v4/ipxelinux.0" ) ); + } catch ( Exception e ) { + status.error = e.toString(); + return false; + } return true; } |