From 07042f0831fca23aa8a8a64ad1c0d4a459f7ba4e Mon Sep 17 00:00:00 2001 From: Marco Esters Date: Thu, 19 Dec 2024 09:27:04 -0800 Subject: [PATCH] Implement `INSTALLER_UNATTENDED` for pkg installers (#915) * Use COMMAND_LINE_INSTALL to set INSTALLER_UNATTENDED for pkg installers * Expand test to pkg installers * Add news * Update documentation * Safely set INSTALLER_UNATTENDED to 1 for command-line installs --- CONSTRUCT.md | 2 +- constructor/construct.py | 2 +- constructor/osx/run_user_script.sh | 9 ++++++++- docs/source/construct-yaml.md | 2 +- examples/scripts/post_install.sh | 4 +--- news/915-installer-unattended-pkg | 19 +++++++++++++++++++ 6 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 news/915-installer-unattended-pkg diff --git a/CONSTRUCT.md b/CONSTRUCT.md index 401a3c2d4..a130dbabb 100644 --- a/CONSTRUCT.md +++ b/CONSTRUCT.md @@ -482,7 +482,7 @@ Path to a post-install script. Some notes: - For PKG installers, the shebang line is respected if present; otherwise, `bash` is used. The same variables mentioned for `sh` installers are available here. `${INSTALLER_TYPE}` is set to `PKG`. - `${INSTALLER_UNATTENDED}` is not supported and always set to `"?"`. + `${INSTALLER_UNATTENDED}` will be `"1"` for command line installs, `"0"` otherwise. - For Windows `.exe` installers, the script must be a `.bat` file. Installation path is available as `%PREFIX%`. Metadata about the installer can be found in the `%INSTALLER_NAME%`, `%INSTALLER_VER%`, diff --git a/constructor/construct.py b/constructor/construct.py index 795284f5b..a4393a619 100644 --- a/constructor/construct.py +++ b/constructor/construct.py @@ -356,7 +356,7 @@ - For PKG installers, the shebang line is respected if present; otherwise, `bash` is used. The same variables mentioned for `sh` installers are available here. `${INSTALLER_TYPE}` is set to `PKG`. - `${INSTALLER_UNATTENDED}` is not supported and always set to `"?"`. + `${INSTALLER_UNATTENDED}` will be `"1"` for command line installs, `"0"` otherwise. - For Windows `.exe` installers, the script must be a `.bat` file. Installation path is available as `%PREFIX%`. Metadata about the installer can be found in the `%INSTALLER_NAME%`, `%INSTALLER_VER%`, diff --git a/constructor/osx/run_user_script.sh b/constructor/osx/run_user_script.sh index ae3516039..9056b9ca1 100644 --- a/constructor/osx/run_user_script.sh +++ b/constructor/osx/run_user_script.sh @@ -30,7 +30,14 @@ export INSTALLER_NAME="{{ installer_name }}" export INSTALLER_VER="{{ installer_version }}" export INSTALLER_PLAT="{{ installer_platform }}" export INSTALLER_TYPE="PKG" -export INSTALLER_UNATTENDED="?" +# The value for COMMAND_LINE_INSTALL is not documented, +# but it is unset for interactive installations. To be +# safe, set the variable for non-interactive installation +# in a roundabout way. +export INSTALLER_UNATTENDED="${COMMAND_LINE_INSTALL:-0}" +if [[ "${INSTALLER_UNATTENDED}" != "0" ]]; then + INSTALLER_UNATTENDED="1" +fi export PRE_OR_POST="{{ pre_or_post }}" {{ script_env_variables }} diff --git a/docs/source/construct-yaml.md b/docs/source/construct-yaml.md index 401a3c2d4..a130dbabb 100644 --- a/docs/source/construct-yaml.md +++ b/docs/source/construct-yaml.md @@ -482,7 +482,7 @@ Path to a post-install script. Some notes: - For PKG installers, the shebang line is respected if present; otherwise, `bash` is used. The same variables mentioned for `sh` installers are available here. `${INSTALLER_TYPE}` is set to `PKG`. - `${INSTALLER_UNATTENDED}` is not supported and always set to `"?"`. + `${INSTALLER_UNATTENDED}` will be `"1"` for command line installs, `"0"` otherwise. - For Windows `.exe` installers, the script must be a `.bat` file. Installation path is available as `%PREFIX%`. Metadata about the installer can be found in the `%INSTALLER_NAME%`, `%INSTALLER_VER%`, diff --git a/examples/scripts/post_install.sh b/examples/scripts/post_install.sh index db0509f26..18d632a63 100644 --- a/examples/scripts/post_install.sh +++ b/examples/scripts/post_install.sh @@ -21,9 +21,7 @@ test "${CUSTOM_VARIABLE_1}" = 'FIR$T-CUSTOM_'\''STRING'\'' WITH SPACES AND @*! " # shellcheck disable=SC2016 # String interpolation disabling is deliberate test "${CUSTOM_VARIABLE_2}" = '$ECOND-CUSTOM_'\''STRING'\'' WITH SPACES AND @*! "CHARACTERS"' -if [[ "${INSTALLER_TYPE}" == "SH" ]]; then - test "${INSTALLER_UNATTENDED}" = "1" -fi +test "${INSTALLER_UNATTENDED}" = "1" if [[ $(uname -s) == Linux ]]; then if [[ ${INSTALLER_PLAT} != linux-* ]]; then diff --git a/news/915-installer-unattended-pkg b/news/915-installer-unattended-pkg new file mode 100644 index 000000000..7de8c7c08 --- /dev/null +++ b/news/915-installer-unattended-pkg @@ -0,0 +1,19 @@ +### Enhancements + +* Add `INSTALLER_UNATTENDED` environment variable for `pkg` installers. (#915) + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +*