summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/taskmanager/tasks/AptUpgrade.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/taskmanager/tasks/AptUpgrade.java')
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/AptUpgrade.java91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/AptUpgrade.java b/src/main/java/org/openslx/taskmanager/tasks/AptUpgrade.java
new file mode 100644
index 0000000..aabd54d
--- /dev/null
+++ b/src/main/java/org/openslx/taskmanager/tasks/AptUpgrade.java
@@ -0,0 +1,91 @@
+package org.openslx.taskmanager.tasks;
+
+import java.util.Map;
+
+import org.openslx.taskmanager.api.SystemCommandTask;
+
+import com.google.gson.annotations.Expose;
+
+public class AptUpgrade extends SystemCommandTask
+{
+
+ private static enum Mode
+ {
+ UPDATE, UPGRADE, FULL_UPGRADE, FIX, AUTOREMOVE;
+ }
+
+ @Expose
+ private Mode mode;
+
+ private final Output status = new Output();
+
+ @Override
+ protected boolean initTask()
+ {
+ this.timeoutSeconds = 600;
+ this.setStatusObject( status );
+ if ( mode == null ) {
+ this.status.error = "Invalid mode selected";
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ protected String[] initCommandLine()
+ {
+ if ( mode == Mode.UPDATE )
+ return new String[] { "sudo", "-n", "apt-get", "-y", "update" };
+ if ( mode == Mode.UPGRADE )
+ return new String[] { "sudo", "-n", "apt-get", "-y", "upgrade" };
+ if ( mode == Mode.AUTOREMOVE )
+ return new String[] { "sudo", "-n", "apt-get", "-y", "autoremove" };
+ if ( mode == Mode.FULL_UPGRADE )
+ return new String[] { "sudo", "-n", "apt-get", "-y", "full-upgrade" };
+ if ( mode == Mode.FIX )
+ return new String[] { "sudo", "-n", "apt-get", "-y", "install", "-f" };
+ return null;
+ }
+
+ @Override
+ protected void initEnvironment( Map<String, String> environment )
+ {
+ environment.put( "LANG", "C.UTF-8" );
+ environment.put( "LC_ALL", "C.UTF-8" );
+ environment.put( "DEBIAN_FRONTEND", "noninteractive" );
+ }
+
+ @Override
+ protected boolean processEnded( int exitCode )
+ {
+ return exitCode == 0;
+ }
+
+ @Override
+ protected void processStdOut( String line )
+ {
+ this.status.output.append( line );
+ this.status.output.append( '\n' );
+ while ( this.status.output.length() > 20000 ) {
+ this.status.output.delete( 0, 1000 );
+ }
+ }
+
+ @Override
+ protected void processStdErr( String line )
+ {
+ if ( status.error == null ) {
+ status.error = line;
+ } else {
+ status.error += "\n" + line;
+ }
+ }
+
+ private static class Output
+ {
+ private String error;
+
+ private StringBuilder output = new StringBuilder();
+ }
+
+}