Writing Installer scripts for AmiUpdate
Installer usually prompts for input and confirmation, which is not ideal for an automatic update procedure such as AmiUpdate uses. With some care, however, Installer can be made to install or update software without any user intervention. This guide describes how to achieve this using AmiUpdate's AutoInstall mechanism, and modification to an existing script.
Calling Installer from AutoInstall
AmiUpdate executes an AmigaDOS script called AutoInstall in the root of the archive. This script is a key part of the setup of Installer, to enable suppressing of prompting later. The script must CD to the directory which holds the installation script, and then call Installer with the following arguments:
Installer Install APPNAME AppAutoInstall DEFUSER NOVICE
Install should be the name of the Installer script, and AppAutoInstall can be anything you like, as long as it isn't the same as the APPNAME tooltype in the install script's icon. DEFUSER NOVICE stops Installer asking the user for the majority of tasks, even if (confirm) is used.
Essential Installer script changes
Normally the first thing the user has to do when starting up an Installer script is answer some questions on how knowledgeable they are about AmigaOS, and whether they want a logfile created. This appears when Installer encounters the (welcome) command, or at the very start if there is no welcome command in the script.
We must modify our existing script so (welcome) does not get called if it has been started from AutoInstall, by replacing it with the following two lines:
(if (= @app-name "AppAutoInstall") (set #AutoInstall 1)) (if (<> #AutoInstall 1) (welcome))
AppAutoInstall must be changed to the APPNAME given in the Installer command line earlier. The first line uses this to set a variable if the script was started by AutoInstall. The second line shows the welcome screen only if the script was started manually.
You may also want to add the following here, especially if the (startup) command is used in your script. Installer uses @app-name to mark user-startup sections, and if this doesn't match the app name used in manual installs the user will end up with duplicate entries in user-startup:
(set @app-name "App")
The second prompt that Installer always gives by default, is when it reaches the (exit) command or at the very end of the script. To counteract this, the (quiet) option of (exit) can be used. To ensure the script only exits quietly when being AutoInstalled, the following commands can be used:
(if (= #AutoInstall 1) ( (exit (quiet)) ) ; else ( (exit) ) )
Other Installer script changes
Even with the above changes, it is likely the script is still asking where it needs to be installed. As part of AmiUpdate, the application must write an environmental variable containing the path it is installed in. We can read this using Installer and use it as the destination for the rest of the process, as follows:
(set @default-dest (getenv "AppPaths/App"))
Where AppPaths/App is the env-var written by the application. The (askdir) command can then be bypassed - usually adding (default @default-dest) is sufficient to stop it appearing.
An advantage of using AmiUpdate is the rollback functionality utilised by copying files with CopyStore. This can be called by Installer quite happily, but remember to only call it if AmiUpdate has invoked the script and use (copylib) or (copyfiles) in other cases. eg:
(if (= #AutoInstall 1) ( (run "CopyStore App " @default-dest) ) ; else ( (copylib ...) ) )
App is the name of the file to be copied.
Any other questions the Installer script needs to ask should be skipped and provided with sensible defaults, if #AutoInstall is 1.
Always test your script with TestAutoInstall from the AmiUpdate website.
|© 2021 Unsatisfactory Software|