Documentation ¶
Overview ¶
Graphical Linux application installer for audiences that are used to Windows installers. Imitates the look and feel of NSIS, or rather Wizard97-type installers.
This installer will bundle any files and folders inside the "data" directory, to be installed via a GTK3-based GUI, or alternatively a commandline interface (referred to as a "silent" install).
See the README.md for usage info and customization instructions and see HACKING.md for a code structure overview.
Index ¶
- Constants
- func ExpandAllVariables(str string, variables VariableMap, untypedVariables map[string]interface{}) (expanded string)
- func ExpandVariables(str string, variables VariableMap) (expanded string)
- func GetResource(name string) (string, error)
- func GetResourceFiltered(name string, dirFilter *regexp.Regexp) (map[string]string, error)
- func MustGetResource(name string) string
- func MustGetResourceFiltered(name string, dirFilter *regexp.Regexp) map[string]string
- func Run() int
- func RunCliInstall(installerTempPath, target string, translator *Translator, config *Config)
- func RunGuiInstall(installerTempPath string, translator *Translator, config *Config) (err error)
- func RunTuiInstall(installerTempPath string, translator *Translator) (err error)
- func UnpackDataDir(from string, to string) error
- func UnpackResourceDir(from string, to string) error
- type BoxFile
- type Config
- type InstallFile
- type InstallStatus
- type Installer
- func (i *Installer) Abort()
- func (i *Installer) CheckSetInstallDir(installPath string) error
- func (i *Installer) DiskSpaceSufficient() bool
- func (i *Installer) Error() error
- func (i *Installer) ExecInstalled()
- func (i *Installer) NextFile() *InstallFile
- func (i *Installer) PostInstall(variablesList ...VariableMap)
- func (i *Installer) PreInstall()
- func (i *Installer) Progress() float64
- func (i *Installer) Rollback()
- func (i *Installer) SetProgressFunction(function func(InstallStatus))
- func (i *Installer) SizeString() string
- func (i *Installer) SpaceString() string
- func (i *Installer) StartCommandAvailable() bool
- func (i *Installer) StartInstall()
- func (i *Installer) WaitForDone()
- type Translator
- func (t *Translator) Expand(str string) (expanded string)
- func (t *Translator) Get(key string) string
- func (t *Translator) GetAll(key string) VariableMap
- func (t *Translator) GetAllList(key string) (versions []string)
- func (t *Translator) GetAllStringsRaw() VariableMap
- func (t *Translator) GetLanguage() string
- func (t *Translator) GetLanguages() (languages []string)
- func (t *Translator) SetLanguage(language string) (err error)
- type UntypedVariableMap
- type VariableMap
Constants ¶
const ( B int64 = 1 KiB = 1024 * B MiB = 1024 * KiB GiB = 1024 * MiB TiB = 1024 * GiB PiB = 1024 * TiB )
const (
DefaultLanguage string = "en"
)
Variables ¶
This section is empty.
Functions ¶
func ExpandAllVariables ¶
func ExpandAllVariables( str string, variables VariableMap, untypedVariables map[string]interface{}, ) (expanded string)
ExpandAllVariables is the same as ExpandVariables, except that it additionally takes untypedVariables, a string map of values of arbitrary type.
func ExpandVariables ¶
func ExpandVariables(str string, variables VariableMap) (expanded string)
ExpandVariables takes a string with template variables like {{.var}} and expands them with the given variables map.
func GetResource ¶
GetResource returns the contents of of a resources file with the given name as a string. If the file does not exists it returns an error.
func GetResourceFiltered ¶
GetResourceFiltered returns the contents of multiple resource files within the subdir specified by name, and the filename regexp given by dirFilter. If the directory name does not exist it returns an error.
func MustGetResource ¶
MustGetResource returns the contents of a resources file with the given name as a string. If the file does not exists it panics.
func MustGetResourceFiltered ¶
MustGetResourceFiltered returns the contents of multiple resource files within the subdir specified by name, and the filename regexp given by dirFilter. If the directory name does not exist it panics.
func Run ¶
func Run() int
Run parses commandline options (if any) and starts one of two installer modes, GUI or commandline mode.
Commandline parameters are:
-target // Target directory to install to -license // Print the software license and exit -accept // Accept the license. (This flag is only available if // "must_accept_license_on_cli" is set in the config file.) -lang // Choose install language. This also affects the GUI mode. -run // Run installed application after successful install.
Giving any commandline parameters other than -lang will trigger commandline, or "silent" mode. -target (and -accept if configured) are necessary to run commandline install. -lang will also set the default GUI language. It cannot, however, set the language of the -help output.
func RunCliInstall ¶
func RunCliInstall( installerTempPath, target string, translator *Translator, config *Config, )
RunCliInstall runs a "silent" installation, in the terminal with no further user interaction.
func RunGuiInstall ¶
func RunGuiInstall( installerTempPath string, translator *Translator, config *Config, ) (err error)
RunGuiInstall loads the gui.so plugin, and starts the installer GUI.
If the GUI can't be loaded for some reason, an error is returned. Most common reasons for error include (on Linux):
- no desktop running (headless servers, remote logins)
- GTK3 missing (Redhat/Centos 6 or older)
When the GUI fails to load it will try a last-ditch effort to show an error dialog with Zenity (which comes with e.g. RedHat/Centos 6). Beyond that there is no way to interact with the user graphically, and it will simply log the error, and print usage help to the terminal. (Which of course, will only be visible if started via commandline and not via double-click.)
func RunTuiInstall ¶
func RunTuiInstall(installerTempPath string, translator *Translator) (err error)
RunTuiInstall would start a terminal curses-based UI (unfinished and disabled).
func UnpackDataDir ¶
UnpackDataDir copies all data files from a subdir given by from to a path given by to. It returns an error if the boxes aren't opened yet, the path can't be written to, or anything else goes wrong.
func UnpackResourceDir ¶
UnpackResourceDir copies all resource files from a subdir given by from to a path given by to. It returns an error if the boxes aren't opened yet, the path can't be written to, or anything else goes wrong.
Types ¶
type Config ¶
type Config struct { Variables VariableMap `yaml:"variables,omitempty"` MustAcceptLicense bool `yaml:"must_accept_license"` DefaultInstallDirName string `yaml:"default_install_dir_name"` GuiCss string `yaml:"gui_css,omitempty"` // commandline config options NoLauncher bool RunInstalled bool }
Config holds a list of variables to be expanded in message strings, as well other settings for the installer.
Setting MustAcceptLicenseOnCli to true (the default) enables & requires the -accept flag.
DefaultInstallDirName is a string or template for the default application directory, into which to install.
NoLauncher is a flag from the command line that suppresses launcher shortcut creation.
RunInstalled is a flag from the command line that runs the installed application after installation completes successfully.
type InstallFile ¶
InstallFile is an augmented zip.FileInfo struct with both source and target path as well as a flag indicating wether the file has been copied to the target or not. Source and target path will be the same if the installation doesn't run from a subdir of the source data.
type InstallStatus ¶
type InstallStatus struct { S string File *InstallFile Done bool Aborted bool }
InstallStatus is a message struct that gets passed around at various times in the installation process. All fields are optional and contain the current file, a status string, wether the installer as a whole is finished or not, or wether it's been aborted and rolled back.
type Installer ¶
type Installer struct { Target string Status *InstallStatus CreateLauncher bool Done bool // contains filtered or unexported fields }
Installer represents a set of files and a target to be copied into. It contains information about the files, size, and status (done or not), as well as 3 different message channels, for each abort and its confirmation as well as status channel.
func NewInstaller ¶
NewInstaller creates a new Installer. You will still need to set the target path after initialization:
installer := NewInstaller() /* ... some other stuff happens ... */ installer.Target = "/some/output/path" /* and go: */ installer.StartInstall()
Alternatively you can just use NewInstallerTo() and set the target directly:
installer := NewInstallerTo("/some/output/path/") installer.StartInstall() /* some watch loop with 'installer.Status()' */
func NewInstallerTo ¶
NewInstallerTo creates a new installer with a target path.
func (*Installer) Abort ¶
func (i *Installer) Abort()
Abort can be called to stop the installer. The installer will usually not stop immediately, but finish copying the current file.
Use Rollback() instead of Abort() if you also want all files and directories rolled back and deleted.
func (*Installer) CheckSetInstallDir ¶
CheckSetInstallDir checks if the given directory is a valid, writable path. If it is it sets it as the installer's target directory. Returns err when the installPath exists but is not a directory, or when installPath (or the nearest existing parent) is not writable.
func (*Installer) DiskSpaceSufficient ¶
DiskSpaceSufficient returns true when the total size of files to be installed is smaller than the remaining available space on the disk that contains the installer's target path.
func (*Installer) ExecInstalled ¶
func (i *Installer) ExecInstalled()
ExecInstalled changes into the installer target directory, runs the start command set in the config file. This function replaces (or, on Windows, terminates) the installer process and never returns.
func (*Installer) NextFile ¶
func (i *Installer) NextFile() *InstallFile
NextFile returns the file that the installer will install next, or the one that is currently being installed.
func (*Installer) PostInstall ¶
func (i *Installer) PostInstall(variablesList ...VariableMap)
PostInstall runs a post-install script & creates an uninstaller as well as an optional launcher entry for the program.
func (*Installer) PreInstall ¶
func (i *Installer) PreInstall()
PreInstall runs a pre-install script, if a file hooks/pre-install.* exists in the resource directory. The file extension is OS-specific (.sh for Linux, .bat for Windows).
func (*Installer) Progress ¶
Progress returns the size ratio between already installed files and all files. The result is a float between 0.0 and 1.0, inclusive.
func (*Installer) Rollback ¶
func (i *Installer) Rollback()
Rollback can be used to abort and roll back (i.e. delete) the files and directories that have been installed so far. It will not delete files that haven't been written by the installer, but will delete any file that was overwritten by it.
Rollback implicitly calls Abort().
func (*Installer) SetProgressFunction ¶
func (i *Installer) SetProgressFunction(function func(InstallStatus))
SetProgressFunction takes a function which receives an InstallStatus, and calls it every time right before the installer starts to copy a file or directory.
func (*Installer) SizeString ¶
SizeString returns a human-readable string denoting the total size of all files contained in the installer, appending a size suffix as needed.
func (*Installer) SpaceString ¶
SpaceString returns a human-readable string denoting the remaining available space on the currently selected installer target path.
func (*Installer) StartCommandAvailable ¶
StartCommandAvailable is queried when deciding whether to install an application- launcher entry, or whether to enable running the application after a successful installation.
func (*Installer) StartInstall ¶
func (i *Installer) StartInstall()
StartInstall runs the installer in a separate goroutine and returns immediately. Use Status() to get updates about the progress.
func (*Installer) WaitForDone ¶
func (i *Installer) WaitForDone()
WaitForDone returns only after the installer has finished installing (or rolling back).
type Translator ¶
type Translator struct { Variables VariableMap // contains filtered or unexported fields }
func NewTranslator ¶
func NewTranslator() *Translator
NewTranslator returns a Translator without any variable lookup.
func NewTranslatorVar ¶
func NewTranslatorVar(variables VariableMap) *Translator
NewTranslatorVar returns a Translator with a variable lookup. It scans for any yaml files inside the languages folder in the resources box.
func (*Translator) Expand ¶
func (t *Translator) Expand(str string) (expanded string)
Expand expands template variables in the given str (if any) with the translator's current language's strings.
func (*Translator) Get ¶
func (t *Translator) Get(key string) string
Get returns the localized string for a given string key.
The strings may contain template references to variables, which in turn may contain template references back to message strings. Only one round-trip of string -> variable -> string lookup is performed (i.e. a template variable in a localized string which is used by another template variable will not be expanded and the raw template would appear in the output.)
func (*Translator) GetAll ¶
func (t *Translator) GetAll(key string) VariableMap
GetAll returns a map of all localizations for a given string, indexed by the language code.
func (*Translator) GetAllList ¶
func (t *Translator) GetAllList(key string) (versions []string)
GetAllList returns a flat string list of all localizations for a given string key.
func (*Translator) GetAllStringsRaw ¶
func (t *Translator) GetAllStringsRaw() VariableMap
GetAllStringsRaw returns the unexpanded string map of all strings for the current language.
func (*Translator) GetLanguage ¶
func (t *Translator) GetLanguage() string
GetLanguage returns the identifier (e.g. "en") for the current language.
func (*Translator) GetLanguages ¶
func (t *Translator) GetLanguages() (languages []string)
GetLanguages returns a list of identifiers for all available languages. The default language (if it has strings available) will be the first in the list, the rest is sorted alphabetically.
func (*Translator) SetLanguage ¶
func (t *Translator) SetLanguage(language string) (err error)
SetLanguage given a language code string (e.g.: "en"), sets the translator's language.
type UntypedVariableMap ¶
type UntypedVariableMap map[string]interface{}
UntypedVariableMap is a string-to-interface{} lookup
type VariableMap ¶
VariableMap is string-to-string lookup.
func MergeVariables ¶
func MergeVariables(varMaps ...VariableMap) VariableMap
MergeVariables combines several variable maps into a single one. Duplicate keys will be overridden by the value in the last map which has the key.