Package edu.uiuc.ncsa.security.installer
Class WebInstaller
- java.lang.Object
-
- edu.uiuc.ncsa.security.installer.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
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
ALL_FLAG
protected static String
DEBUG_FLAG
protected static String
DIR_ARG
static Boolean
EXECUTABLE_DEFAULT
protected static String
HELP_FLAG
protected static String
HELP_OPTION
protected static String
INSTALL_OPTION
protected static String
LIST_OPTION
protected static String
LOG_ARG
protected static String
NO_PACER_FLAG
protected static String
NOTES_OPTION
protected static String
OA4MP_FLAG
static String
operationKey
protected static String
REMOVE_OPTION
protected static String
UPDATE_OPTION
static Boolean
UPDATEABLE_DEFAULT
static Boolean
USE_TEMPLATES_DEFAULT
protected static String
VERSION_FLAG
protected static String
VERSION_LATEST
protected static String
VERSIONS_OPTION
-
Constructor Summary
Constructors Constructor Description WebInstaller()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
applyExecutable(File file)
boolean
applySkipUpdate(File file)
returns true if shold be skipped.boolean
applyTemplate(File file)
static long
copyStream(InputStream inputStream, OutputStream outputStream)
Copies one stream to another.protected String
createID(int length)
A hexadecimal identifier, all upper caseprotected String
createSecret(int length)
Creates a random secret that is url-encoding safe.protected void
doInstallOrUpdate(boolean isUpdate)
protected void
doList()
protected void
doRemove(boolean isCleanup)
protected String
doReplace(String currentLine)
protected Long
download(URL url, File targetFile)
String
getAppName()
ArgMap
getArgMap()
InstallConfiguration
getInstallConfiguration()
String
getLastestConfigFileName()
Override this as needed to get the latest version of your configuration file as a resource.Writer
getLogger()
protected String
getMessage(String resourcePath)
Prints a message from a resource, doing all template replacements on the content.protected String
getMessage(String resourcePath, boolean skipTemplates)
Prints a message (e.g.Pacer
getPacer()
File
getRoot()
protected String
getSetup()
Set the resource name (default is /setup.yaml) which will be read.protected InputStream
getSetupIS()
Map<String,String>
getTemplates()
protected String
getVersionFileName(String version)
protected List
ingestYaml(InputStream is)
The inputStream contains YAML.protected boolean
init(String[] args)
You can override this.boolean
isDebugOn()
protected boolean
isExec(DirectoryEntry de, FileEntry fe)
protected boolean
isNotUpdateable(DirectoryEntry de, FileEntry fe)
protected boolean
isUseTemplate(DirectoryEntry de, FileEntry fe)
protected void
listVersions()
static void
main(String[] args)
protected void
nukeDir(File dir)
Remove the contents of the directory.protected void
printMoreArgHelp()
Printed as part of the flags section in the default help.protected void
printMoreExamplesHelp()
Printed at the very end of help.protected void
process()
Actually do the operationprotected int
processFileEntry(SingleSourceSet sss, DirectoryEntry de, FileEntry fe, File target, boolean isUpdate, int doneCount, int totalFileCount)
protected int
processZipArchive(SingleSourceSet sss, DirectoryEntry de, ZipArchive zfe, File target, boolean isUpdate, int doneCount, int totalFileCount)
protected long
processZipFile(URL sourceURL, DirectoryEntry de, boolean isUpdate)
protected InstallConfigurationImporter
readConfig(InputStream cfgStream)
read the configuration file as an input stream.protected void
say(String x)
void
setDebugOn(boolean debugOn)
void
setRoot(File root)
void
setTemplates(Map<String,String> templates)
protected void
setupArgMap(String[] args)
If you need to add more arguments to theArgMap
, rather than overriding that class, just set them here.protected Map<String,String>
setupTemplates()
Sets up templates.protected void
showHelp()
protected void
showReleaseNotes(String versionName)
void
shutdown()
For shut down tasks.protected void
trace(String message)
-
-
-
Field Detail
-
UPDATE_OPTION
protected static final String UPDATE_OPTION
- See Also:
- Constant Field Values
-
HELP_FLAG
protected static final String HELP_FLAG
- See Also:
- Constant Field Values
-
NO_PACER_FLAG
protected static final String NO_PACER_FLAG
- See Also:
- Constant Field Values
-
HELP_OPTION
protected static final String HELP_OPTION
- See Also:
- Constant Field Values
-
DIR_ARG
protected static final String DIR_ARG
- See Also:
- Constant Field Values
-
LOG_ARG
protected static final String LOG_ARG
- See Also:
- Constant Field Values
-
DEBUG_FLAG
protected static final String DEBUG_FLAG
- See Also:
- Constant Field Values
-
INSTALL_OPTION
protected static final String INSTALL_OPTION
- See Also:
- Constant Field Values
-
NOTES_OPTION
protected static final String NOTES_OPTION
- See Also:
- Constant Field Values
-
LIST_OPTION
protected static final String LIST_OPTION
- See Also:
- Constant Field Values
-
REMOVE_OPTION
protected static final String REMOVE_OPTION
- See Also:
- Constant Field Values
-
VERSIONS_OPTION
protected static final String VERSIONS_OPTION
- See Also:
- Constant Field Values
-
OA4MP_FLAG
protected static final String OA4MP_FLAG
- See Also:
- Constant Field Values
-
ALL_FLAG
protected static final String ALL_FLAG
- See Also:
- Constant Field Values
-
VERSION_FLAG
protected static final String VERSION_FLAG
- See Also:
- Constant Field Values
-
VERSION_LATEST
protected static final String VERSION_LATEST
- See Also:
- Constant Field Values
-
USE_TEMPLATES_DEFAULT
public static final Boolean USE_TEMPLATES_DEFAULT
-
EXECUTABLE_DEFAULT
public static final Boolean EXECUTABLE_DEFAULT
-
UPDATEABLE_DEFAULT
public static final Boolean UPDATEABLE_DEFAULT
-
operationKey
public static final String operationKey
- See Also:
- Constant Field Values
-
-
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
-
download
protected Long download(URL url, File targetFile) throws IOException
- 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
-
processZipFile
protected long processZipFile(URL sourceURL, DirectoryEntry de, boolean isUpdate) throws IOException
- Throws:
IOException
-
readConfig
protected InstallConfigurationImporter readConfig(InputStream cfgStream) throws IOException
read the configuration file as an input stream. This also creates and initializes theInstallConfiguration
for this installation. At the end of this method, you should be able to start processing.- Parameters:
cfgStream
-- 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
-
getInstallConfiguration
public InstallConfiguration getInstallConfiguration()
-
init
protected boolean init(String[] args) throws Throwable
You can override this. Note that this only creates theArgMap
if it does not exist.- Parameters:
args
-- Throws:
Throwable
-
showReleaseNotes
protected void showReleaseNotes(String versionName) throws IOException
- Throws:
IOException
-
setupArgMap
protected void setupArgMap(String[] args)
If you need to add more arguments to theArgMap
, 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)
-
getLogger
public Writer getLogger()
-
trace
protected void trace(String message) throws IOException
- Throws:
IOException
-
isDebugOn
public boolean isDebugOn()
-
setDebugOn
public void setDebugOn(boolean debugOn)
-
say
protected void say(String x) throws IOException
- Throws:
IOException
-
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
-
doInstallOrUpdate
protected void doInstallOrUpdate(boolean isUpdate) throws Throwable
- Throws:
Throwable
-
processZipArchive
protected int processZipArchive(SingleSourceSet sss, DirectoryEntry de, ZipArchive zfe, File target, boolean isUpdate, int doneCount, int totalFileCount) throws IOException
- Throws:
IOException
-
processFileEntry
protected int processFileEntry(SingleSourceSet sss, DirectoryEntry de, FileEntry fe, File target, boolean isUpdate, int doneCount, int totalFileCount) throws IOException
- Throws:
IOException
-
isUseTemplate
protected boolean isUseTemplate(DirectoryEntry de, FileEntry fe)
-
isNotUpdateable
protected boolean isNotUpdateable(DirectoryEntry de, FileEntry fe)
-
isExec
protected boolean isExec(DirectoryEntry de, FileEntry fe)
-
doRemove
protected void doRemove(boolean isCleanup) throws IOException
- Throws:
IOException
-
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
-
listVersions
protected void listVersions() throws IOException
- Throws:
IOException
-
doList
protected void doList() throws IOException
- Throws:
IOException
-
getSetup
protected String getSetup()
Set the resource name (default is /setup.yaml) which will be read. Alternately, you can overridegetSetupIS()
which would read the setup file from anywhere as long as it ends up in anInputStream
.- Returns:
-
getSetupIS
protected InputStream getSetupIS() throws FileNotFoundException
- Throws:
FileNotFoundException
-
getPacer
public Pacer getPacer()
-
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:
-
-