From 205d8f7db261f05af59c7ad23b7425abd60f059d Mon Sep 17 00:00:00 2001
From: hypercubus <hypercubus>
Date: Tue, 24 Aug 2004 09:04:53 +0000
Subject: [PATCH] initial commit of ServiceManager class; API is complete, so
 integration with routerconsole can proceed, but return of error messages is
 not yet implemented, meaning returned exit values will all be null for now

---
 .../net/i2p/router/web/ServiceManager.java    | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 apps/routerconsole/java/src/net/i2p/router/web/ServiceManager.java

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ServiceManager.java b/apps/routerconsole/java/src/net/i2p/router/web/ServiceManager.java
new file mode 100644
index 0000000000..493bf453fc
--- /dev/null
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ServiceManager.java
@@ -0,0 +1,65 @@
+/*
+ * I2P - An anonymous, secure, and fully-distributed communication network.
+ * 
+ * ServiceManager.java
+ * 2004 The I2P Project
+ * http://www.i2p.net
+ * This code is public domain.
+ */
+
+package net.i2p.router.web;
+
+//import java.io.InputStream;
+
+import net.i2p.util.ShellCommand;
+
+/**
+ * Handles installation and uninstallation of I2P as a service.
+ * 
+ * @author hypercubus
+ */
+public class ServiceManager {
+
+    private static final boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows") ? true : false;
+
+    private ShellCommand _shellCommand = new ShellCommand();
+
+    /**
+     * Invokes the service wrapper installation script via a shell process.
+     * 
+     * @return <code>null</code> if the installation was successful, otherwise
+     *         a <code>String</code> containing the shell output including error
+     *         messages is returned.
+     */
+    public String installService() {
+        return exec("install_i2p_service_" + (IS_WINDOWS ? "winnt.bat" : "unix"));
+    }
+
+    /**
+     * Invokes the service wrapper uninstallation script via a shell process.
+     * 
+     * @return <code>null</code> if the uninstallation was successful, otherwise
+     *         a <code>String</code> containing the shell output including error
+     *         messages is returned.
+     */
+    public String uninstallService() {
+        return exec("uninstall_i2p_service_" + (IS_WINDOWS ? "winnt.bat" : "unix"));
+    }
+
+    private String exec(String command) {
+
+//        InputStream  StdoutStream = _shellCommand.getInputStream();
+//        InputStream  StderrStream = _shellCommand.getErrorStream();
+        StringBuffer result       = null;
+
+        if (_shellCommand.executeAndWait(command))
+            return null;
+
+        else
+            if (result.toString().equals(""))
+                return null;
+
+            else
+                return result.toString();
+    }
+}
-- 
GitLab