Class WebInstaller


  • public class WebInstaller
    extends Object
    This installs from a GitHub release. The main feature is a YAML file that tells where the files go. This is packaged as a complete application with minimal dependencies.

    Created by Jeff Gaynor
    on 6/13/24 at 7:38 AM

    • Constructor Detail

      • WebInstaller

        public WebInstaller()
    • Method Detail

      • getAppName

        public String getAppName()
      • showHelp

        protected void showHelp()
      • printMoreArgHelp

        protected void printMoreArgHelp()
                                 throws IOException
        Printed as part of the flags section in the default help. If you have custom flags, put help for them here.
        Throws:
        IOException
      • printMoreExamplesHelp

        protected void printMoreExamplesHelp()
                                      throws IOException
        Printed at the very end of help. This is where you can put spscific examples of help for your application.
        Throws:
        IOException
      • copyStream

        public static long copyStream​(InputStream inputStream,
                                      OutputStream outputStream)
                               throws IOException
        Copies one stream to another. Does not close or flush! This returns the total number of bytes copied.
        Parameters:
        inputStream -
        outputStream -
        Returns:
        Throws:
        IOException
      • ingestYaml

        protected List ingestYaml​(InputStream is)
                           throws IOException
        The inputStream contains YAML. This normalizes it so the result is a list with entries of maps.
        Parameters:
        is -
        Returns:
        Throws:
        IOException
      • getMessage

        protected String getMessage​(String resourcePath,
                                    boolean skipTemplates)
                             throws IOException
        Prints a message (e.g. post install instructions, post update). This takes the path as a resource. Note that this does replacements on the contents of the message unless skipTemplates is false
        Parameters:
        resourcePath -
        skipTemplates -
        Returns:
        Throws:
        IOException
      • getMessage

        protected String getMessage​(String resourcePath)
                             throws IOException
        Prints a message from a resource, doing all template replacements on the content.
        Parameters:
        resourcePath -
        Returns:
        Throws:
        IOException
      • setTemplates

        public void setTemplates​(Map<String,​String> templates)
      • init

        protected boolean init​(String[] args)
                        throws Throwable
        You can override this. Note that this only creates the ArgMap if it does not exist.
        Parameters:
        args -
        Throws:
        Throwable
      • setupArgMap

        protected void setupArgMap​(String[] args)
        If you need to add more arguments to the ArgMap, rather than overriding that class, just set them here. This is called immediately after it is created, but before anything else accesses the arg map.
        Parameters:
        args -
      • getLastestConfigFileName

        public String getLastestConfigFileName()
        Override this as needed to get the latest version of your configuration file as a resource.
        Returns:
      • getArgMap

        public ArgMap getArgMap()
      • main

        public static void main​(String[] args)
      • getRoot

        public File getRoot()
      • setRoot

        public void setRoot​(File root)
      • doReplace

        protected String doReplace​(String currentLine)
      • getLogger

        public Writer getLogger()
      • isDebugOn

        public boolean isDebugOn()
      • setDebugOn

        public void setDebugOn​(boolean debugOn)
      • setupTemplates

        protected Map<String,​String> setupTemplates()
                                                   throws IOException
        Sets up templates. Override to add your own. This sets exactly one, ${}ROOT} which is the directory the user specified as the root of the install.
        Throws:
        IOException
      • process

        protected void process()
                        throws Throwable
        Actually do the operation
        Throws:
        Throwable
      • doInstallOrUpdate

        protected void doInstallOrUpdate​(boolean isUpdate)
                                  throws Throwable
        Throws:
        Throwable
      • nukeDir

        protected void nukeDir​(File dir)
                        throws IOException
        Remove the contents of the directory. At the end of this, the directory is empty. It does not delete the directory, however
        Parameters:
        dir -
        Throws:
        IOException
      • getVersionFileName

        protected String getVersionFileName​(String version)
      • getSetup

        protected String getSetup()
        Set the resource name (default is /setup.yaml) which will be read. Alternately, you can override getSetupIS() which would read the setup file from anywhere as long as it ends up in an InputStream.
        Returns:
      • getPacer

        public Pacer getPacer()
      • shutdown

        public void shutdown()
                      throws Throwable
        For shut down tasks.
        Throws:
        Throwable
      • applyTemplate

        public boolean applyTemplate​(File file)
      • applyExecutable

        public boolean applyExecutable​(File file)
      • applySkipUpdate

        public boolean applySkipUpdate​(File file)
        returns true if shold be skipped.
        Parameters:
        file -
        Returns:
      • createSecret

        protected String createSecret​(int length)
        Creates a random secret that is url-encoding safe.
        Parameters:
        length - The number of bytes for the secret
        Returns:
      • createID

        protected String createID​(int length)
        A hexadecimal identifier, all upper case
        Parameters:
        length - the number of bytes for this identifier
        Returns: