Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ export INSTALLER_NAME='{{ installer_name }}'
export INSTALLER_VER='{{ installer_version }}'
export INSTALLER_PLAT='{{ installer_platform }}'
export INSTALLER_TYPE="SH"

# Installers should ignore pre-existing configuration files.
unset CONDARC
unset MAMBARC

THIS_DIR=$(DIRNAME=$(dirname "$0"); cd "$DIRNAME"; pwd)
THIS_FILE=$(basename "$0")
THIS_PATH="$THIS_DIR/$THIS_FILE"
export INSTALLER_PATH="${THIS_PATH}"
PREFIX="{{ default_prefix }}"
BATCH={{ 1 if batch_mode else 0 }}
FORCE=0
Expand Down
3 changes: 2 additions & 1 deletion constructor/nsis/main.nsi.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,8 @@ Section "Install"
File /nonfatal /r {{ index_cache }}
File /r {{ repodata_record }}


System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("INSTALLER_PLUGINSDIR", "$PLUGINSDIR")'
System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("INSTALLER_PATH", "$EXEPATH")'
{%- for key, escaped_val in SCRIPT_ENV_VARIABLES | items %}
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("{{ key }}", {{ escaped_val }}).r0'
{%- endfor %}
Expand Down
5 changes: 5 additions & 0 deletions constructor/osx/run_user_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export INSTALLER_NAME="{{ installer_name }}"
export INSTALLER_VER="{{ installer_version }}"
export INSTALLER_PLAT="{{ installer_platform }}"
export INSTALLER_TYPE="PKG"

# PACKAGE_PATH is poorly documented, and might not exist across all OS versions
if [ -n "${PACKAGE_PATH:-}" ]; then
export INSTALLER_PATH="$PACKAGE_PATH" # The path to the .pkg installer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add a default value? What we are trying to achieve here doesn't seem to be well-supported by Apple for .pkg installers, however, I found this and it worked for me when I tested locally. However, it's a poorly documented variable and might not always work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, it's a poorly documented variable

That is, unfortunately, not unusual. This code may fail though with set -u. Here is how I solved it for another variable:

# 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a default variable makes sense here. If the location of the installer cannot be detected because the variable is not defined, then it shouldn't be set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the 0 is necessary, I used the :- syntax as well (if [ -n "${PACKAGE_PATH:-}" ]; then) but this situation evaluates to an empty string if unset.

fi
# 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
Expand Down
5 changes: 5 additions & 0 deletions examples/extra_envs/test_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ if not exist "%PREFIX%\envs\dav1d\conda-meta\history" exit 1
if exist "%PREFIX%\envs\dav1d\python.exe" exit 1
"%PREFIX%\envs\dav1d\Library\bin\dav1d.exe" --version || goto :error

if not exist "%INSTALLER_PATH%" (
echo ERROR: "INSTALLER_PATH=%INSTALLER_PATH%" points to a file that does not exist!
exit 1
)

goto :EOF

:error
Expand Down
10 changes: 10 additions & 0 deletions examples/scripts/post_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ if "%PREFIX%" == "" exit 1
if not "%CUSTOM_VARIABLE_1%" == "FIR$T-CUSTOM_STRING WITH SPACES AND @*! CHARACTERS" exit 1
if not "%CUSTOM_VARIABLE_2%" == "$ECOND-CUSTOM_STRING WITH SPACES AND @*! CHARACTERS" exit 1
if not exist "%PREFIX%\pre_install_sentinel.txt" exit 1

if not exist "%INSTALLER_PATH%" (
echo ERROR: "INSTALLER_PATH=%INSTALLER_PATH%" points to a file that does not exist!
exit 1
)

if not exist "%INSTALLER_PLUGINSDIR%" (
echo ERROR: "INSTALLER_PLUGINSDIR=%INSTALLER_PLUGINSDIR%" points to a directory that does not exist!
exit 1
)
5 changes: 5 additions & 0 deletions examples/scripts/post_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ else # macOS
fi
fi
test -f "${PREFIX}/pre_install_sentinel.txt"

if [ ! -e "$INSTALLER_PATH" ]; then
printf 'ERROR: INSTALLER_PATH does not exist: %s\n' "$INSTALLER_PATH" >&2
exit 1
fi
20 changes: 20 additions & 0 deletions news/1151-installer-path-variable
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Enhancements

An environment variable `INSTALLER_PATH` is now defined for `post_install` scripts and set to the path of the installer executable while the installer is running.
* EXE: An environment variable `INSTALLER_PLUGINSDIR` is now also defined, it serves the same purpose as the NSIS variable `PLUGINSDIR`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
An environment variable `INSTALLER_PATH` is now defined for `post_install` scripts and set to the path of the installer executable while the installer is running.
* EXE: An environment variable `INSTALLER_PLUGINSDIR` is now also defined, it serves the same purpose as the NSIS variable `PLUGINSDIR`.
* An environment variable `INSTALLER_PATH` is now defined for pre-install and post-install scripts, and set to the path of the installer executable while the installer is running. (#1151)
* EXE: An environment variable `INSTALLER_PLUGINSDIR` is now also defined, it serves the same purpose as the NSIS variable `$PLUGINSDIR`. (#1151)

Please always add the PR number (and issue number, not applicable here) to the new items.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I keep forgetting that. Thanks for the reminder!


### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
Loading