diff options
author | Simon Rettberg | 2023-07-03 18:16:09 +0200 |
---|---|---|
committer | Simon Rettberg | 2023-07-03 18:16:09 +0200 |
commit | f59d25e65344059e25a486523d55ff6487ed3d31 (patch) | |
tree | d013ffcb49435b443637597ec03dfd1c30d6e0f3 /src/main/java/org/openslx/taskmanager/tasks/AptUpgrade.java | |
parent | [IrcClient] Silence protocol log spam (diff) | |
download | tmlite-bwlp-f59d25e65344059e25a486523d55ff6487ed3d31.tar.gz tmlite-bwlp-f59d25e65344059e25a486523d55ff6487ed3d31.tar.xz tmlite-bwlp-f59d25e65344059e25a486523d55ff6487ed3d31.zip |
Add tasks for apt update and upgrade
Diffstat (limited to 'src/main/java/org/openslx/taskmanager/tasks/AptUpgrade.java')
-rw-r--r-- | src/main/java/org/openslx/taskmanager/tasks/AptUpgrade.java | 91 |
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(); + } + +} |