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 StringALL_FLAGprotected static StringDEBUG_FLAGprotected static StringDIR_ARGstatic BooleanEXECUTABLE_DEFAULTprotected static StringHELP_FLAGprotected static StringHELP_OPTIONprotected static StringINSTALL_OPTIONprotected static StringLIST_OPTIONprotected static StringLOG_ARGprotected static StringNO_PACER_FLAGprotected static StringNOTES_OPTIONprotected static StringOA4MP_FLAGstatic StringoperationKeyprotected static StringPREPROCESS_FLAGprotected static StringREMOVE_OPTIONprotected static StringUPDATE_OPTIONstatic BooleanUPDATEABLE_DEFAULTprotected static StringUPGRADE_OPTIONstatic BooleanUSE_TEMPLATES_DEFAULTprotected static StringVERSION_FLAGprotected static StringVERSION_LATESTprotected static StringVERSIONS_OPTION
-
Constructor Summary
Constructors Constructor Description WebInstaller()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanapplyExecutable(File file)booleanapplySkipUpdate(File file)returns true if shold be skipped.booleanapplyTemplate(File file)static longcopyStream(InputStream inputStream, OutputStream outputStream)Copies one stream to another.protected StringcreateID(int length)A hexadecimal identifier, all upper case.protected StringcreateSecret(int length)Creates a random secret that is url-encoding safe.protected voiddoInstallOrUpdate(boolean isUpdate)protected voiddoList()protected voiddoRemove(boolean isCleanup)protected StringdoReplace(String currentLine)Apply the templates to the argument (the current line usually).protected Longdownload(URL url, File targetFile)StringgetAppName()ArgMapgetArgMap()protected StringgetID(int length)Creates a hexadecimal identifier.InstallConfigurationgetInstallConfiguration()StringgetLastestConfigFileName()Override this as needed to get the latest version of your configuration file as a resource.WritergetLogger()protected StringgetMessage(String resourcePath)Prints a message from a resource, doing all template replacements on the content.protected StringgetMessage(String resourcePath, boolean skipTemplates)Prints a message (e.g.PacergetPacer()FilegetRoot()protected StringgetSecret(int length)Creates a base 64 encoded, URL safe secret.protected StringgetSetup()Set the resource name (default is /setup.yaml) which will be read.protected InputStreamgetSetupIS()Map<String,String>getTemplates()protected StringgetVersionFileName(String version)protected ListingestYaml(InputStream is)The inputStream contains YAML.protected booleaninit(String[] args)You can override this.booleanisDebugOn()protected booleanisExec(DirectoryEntry de, FileEntry fe)protected booleanisNotUpdateable(DirectoryEntry de, FileEntry fe)protected booleanisUseTemplate(DirectoryEntry de, FileEntry fe)protected voidlistVersions()static voidmain(String[] args)This can't run since its just the superclass, so the main method is to let us test if it bootstraps right, reads arguments, etc.protected voidnukeDir(File dir)Remove the contents of the directory.protected voidprintMoreArgHelp()Printed as part of the flags section in the default help.protected voidprintMoreExamplesHelp()Printed at the very end of help.protected voidprocess()Actually do the operationprotected intprocessFileEntry(SingleSourceSet sss, DirectoryEntry de, FileEntry fe, File target, boolean isUpdate, int doneCount, int totalFileCount)protected intprocessZipArchive(SingleSourceSet sss, DirectoryEntry de, ZipArchive zfe, File target, boolean isUpdate, int doneCount, int totalFileCount)protected longprocessZipFile(URL sourceURL, DirectoryEntry de, boolean isUpdate)protected InstallConfigurationImporterreadConfig(InputStream cfgStream)read the configuration file as an input stream.protected voidsay(String x)voidsetDebugOn(boolean debugOn)voidsetRoot(File root)voidsetTemplates(Map<String,String> templates)protected voidsetupArgMap(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 voidshowHelp()protected voidshowReleaseNotes(String versionName)voidshutdown()For shut down tasks.protected voidtrace(String message)
-
-
-
Field Detail
-
UPDATE_OPTION
protected static final String UPDATE_OPTION
- See Also:
- Constant Field Values
-
UPGRADE_OPTION
protected static final String UPGRADE_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
-
PREPROCESS_FLAG
protected static final String PREPROCESS_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 IOExceptionPrinted 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 IOExceptionPrinted 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 theInstallConfigurationfor 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 theArgMapif 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)
This can't run since its just the superclass, so the main method is to let us test if it bootstraps right, reads arguments, etc.- Parameters:
args-
-
getRoot
public File getRoot()
-
setRoot
public void setRoot(File root)
-
doReplace
protected String doReplace(String currentLine)
Apply the templates to the argument (the current line usually).- Parameters:
currentLine-- Returns:
-
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. May start with a digit.- Parameters:
length- the number of bytes for this identifier. size is 2*length.- Returns:
-
getSecret
protected String getSecret(int length)
Creates a base 64 encoded, URL safe secret. The length refers to bytes so the size of the secret is at most ⌈4*length/3. Does not pad.- Parameters:
length-- Returns:
-
getID
protected String getID(int length)
Creates a hexadecimal identifier. The length is the number of bytes and the size of the ID is 2*length.- Parameters:
length-- Returns:
-
-