Commit Graph

67 Commits

Author SHA1 Message Date
Xavier Delaruelle
661c47aa17 init: translate `` into $() for sh-kind shells 2022-02-24 17:46:41 +01:00
Dimitri Papadopoulos
68f400fccf init: fix typo in comment 2022-02-17 07:51:31 +01:00
Xavier Delaruelle
ee37f69f46 install: add --with-bashcompletiondir configure opt
Add the --with-bashcompletiondir option to the configure installation
script to define a particular installation directory for the bash
completion script.

If option is not defined, bash completion script is installed by default
in initdir and it is sourced in bash init script. If option is set,
completion script is installed in designated directory and bash init
script does not source it.
2021-11-24 08:51:03 +01:00
Xavier Delaruelle
0c1ae43a2f Add output redirection handling on sh module function
Update the definition of the module function for sh shell family (sh,
bash, ksh and zsh) to support the output redirection.

Now both _module_raw and module shell functions are always defined.
Default redirection behavior depends on the interactiveness of the shell
when the autoinit command is run. Then shell code is set in module
function definition to adapt behavior depending on
MODULES_REDIRECT_OUTPUT environment variable value or
--redirect/--no-redirect command-line switches.
2021-10-17 20:10:36 +02:00
Xavier Delaruelle
7d61eace20 init: always set code for silent_shell_debug code
Update initialization scripts to make the code for the
silent_shell_debug mechanism always defined there.
2021-08-31 07:22:01 +02:00
Xavier Delaruelle
956b377873 Restore quarantine if __MODULES_QUARANTINE_SET defined
Introduce the __MODULES_QUARANTINE_SET environment variable to put back
when starting modulecmd.tcl run the environment set on hold by
initialization script (for autoinit calls) or by module shell function
(for regular calls).

This new environment variable is tested to apply quarantine unhold
mechanism instead of checking if the run_quarantine configuration option
is set and shell accurately supports the mecanishm. With this change it
is possible to enable or disable the quarantine support at module
initialization time (through initrc configuration file) instead of
freezing this configuration when building the modulecmd.tcl script.
2021-08-25 07:29:16 +02:00
Xavier Delaruelle
f6194a9c5e init: quarantine mech always set for autoinit call
Update initialization scripts to make the quarantine mechanism always
defined for the module autoinit call.
2021-08-25 06:07:46 +02:00
Xavier Delaruelle
fc690085b0 Use '__MODULES_QUAR_' prefix on env var set in quarantine
Rename the environment variables used to indirectly pass to
`modulecmd.tcl` the value of variables set in quarantine (variables
whose name finishes with `_modquar`). A `__MODULES_QUAR_` prefix is
applied to the name of these variables instead of the `_modquar` suffix
to indicate they are intended for Modules internal use of only.
2021-07-25 10:17:04 +02:00
Xavier Delaruelle
91380cdbee init: remove compat version-related code 2021-07-24 14:06:09 +02:00
Xavier Delaruelle
4919ae356e init: ensure ml is defined in bash/ksh subshells 2020-01-09 20:38:50 +01:00
Xavier Delaruelle
5a33a474d5 Use initconf in etcdir rather initdir if it exists
Take into account Modules initialization configurations found in ``etc``
directory if they exist rather in ``init`` directory. If ``initrc``
configuration file is found in ``etcdir`` then it is preferred over
``modulerc`` file in ``initdir``. Following the same trend,
``modulespath`` configuration file is found in ``etcdir`` then it is
preferred over ``.modulespath`` file in ``initdir``.
2019-07-10 07:04:52 +02:00
Xavier Delaruelle
d09153f317 Add ability to disable shell startup file set
Introduce the ability not to set the shell startup file that ensure
``module`` command is defined once shell has been initialized. Setting
shell startup file currently means defining ``ENV`` and ``BASH_ENV``
environment variable to the Modules bourne shell initialization script.
``./configure`` options ``--enable-set-shell-startup`` and
``--disable-set-shell-startup`` define if shell startup should be set or
not by default. It could be superseded with the
``MODULES_SET_SHELL_STARTUP`` environment variable, that could be set
with ``config`` module sub-command through the ``set_shell_startup``
option.
2019-07-04 20:09:22 +02:00
Xavier Delaruelle
2a07bedebd init: improve readability of var definition operations
Improve readability of variable definition operations by writing one
definition operation per line rather having multiple commands on a single
line like 'VAR=val; export VAR'.

Fixes #225.
2019-05-08 11:04:36 +02:00
Xavier Delaruelle
34e5547147 init: init MANPATH if not set to preserve man sysconfig
In shell initialization scripts, initialize MANPATH if not set with a
value that preserves manpath system configuration even after addition
of paths to this variable by modulefiles

Fixes #224
2019-02-23 15:12:30 +01:00
Xavier Delaruelle
df677ff5ce init: skip shell env alteration if autoinit cmd failed
Fixes #208
2018-11-09 17:36:11 +01:00
Xavier Delaruelle
8fa93a271d install: add --enable-quarantine-support configure opt
Add the ability to control whether or not code to support quarantine
mechanism should be added to the module function and initialization
scripts. Enabled by default

Fixes #167
2018-09-05 06:02:43 +02:00
Xavier Delaruelle
f700e055d4 install: add --enable-silent-shell-debug-support configure opt
Add the ability to control whether or not code to support silent shell
debug should be added to the module function and sh-kind initialization
scripts. Enabled by default

Fixes #166
2018-09-03 07:43:50 +02:00
Xavier Delaruelle
924b10864c init: split unset of shdbg and quar-related vars 2018-09-02 18:43:01 +02:00
Xavier Delaruelle
e5e16def77 init: init/export _module_raw if stderr attached to term
To get coherent with the test made by modulecmd.tcl to determine if
autoinit sub-command has to produce code for the '_module_raw' shell
function, export this function (or initialize it on compat mode) if
stderr is attached to a terminal.

Was previously testing stdout, whereas modulecmd.tcl is checking stderr,
which led to inconsistencies as described in [1].

Fixes #169

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1575479
2018-05-19 11:39:03 +02:00
Xavier Delaruelle
9df232de14 install: add --enable-append-{bin,man}path configure opts
Add the ability to append rather prepend the man or bin directory when
adding these directory to the relative environment variable is enabled
(with --enable-set-manpath or --enable-set-binpath).

Takes the form of 2 new configure options: --enable-append-manpath and
--enable-append-binpath. No effect if set but relative
--enable-set-{bin,man}path option is unset or disabled.
2018-05-03 07:09:11 +02:00
Xavier Delaruelle
6a3860bf8b Rename _moduleraw shell func in _module_raw
To use a common _module_ prefix for all module-related internal shell
functions as suggested by Paul FM [1].

[1] https://sourceforge.net/p/modules/mailman/message/36230667/
2018-05-02 21:09:13 +02:00
Xavier Delaruelle
468f16f9ec init: shield autoinit res from param expansion on sh-shells
Quote autoinit result for eval interpretation on SH-kind shells to
avoid parameter expansion to randomly occur on generated code
depending on file or directory names of current working directory.

Test basic module commands in install testsuite with a
'something (test)' file existing in current working directory.

Fixes bug reported at [1].

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1549664
2018-03-01 19:15:44 +01:00
Xavier Delaruelle
170d88b5d9 install/init: use MANPATH if manpath cmd not there 2018-02-01 18:53:25 +01:00
Xavier Delaruelle
4bd42fb5c5 init: use default value on undef var in sh shells
To avoid unbound variables on bash '-eu' mode for instance, use a
default value on undefined variable. Adapt SH init scripts and autoinit
code.

Add 'bash -eu' to the list of tested shells on 'testinstall' suite.

Fixes #151
2018-01-26 20:48:05 +01:00
Xavier Delaruelle
33941816c0 Expose current modulecmd with MODULES_CMD env var 2018-01-03 08:33:22 +01:00
Xavier Delaruelle
a6a93c5ff1 Silent sh-shells debug if MODULES_SILENT_SHELL_DEBUG
Introduce MODULES_SILENT_SHELL_DEBUG environment variable to silent the
xtrace and verbose output on sh-kind shells.

When set (means MODULES_SILENT_SHELL_DEBUG=1), current xtrace and
verbose flags are saved then these shell properties are disabled. Once
execution is finished, saved setup is restored.

This mechanism is defined on initialization scripts, at the beginning to
silent, at the end to restore defined behavior. It is also defined
within the module function following exact same principle.

By default, xtrace and verbose shell properties are applied to module
function and initialization script if enabled in calling shell script or
interactive session. These properties are disabled in module context only
if MODULES_SILENT_SHELL_DEBUG is set to '1'.

Notice that if xtrace/verbose properties are set, shell code that
leads to disable them when MODULES_SILENT_SHELL_DEBUG is set will be
outputed as debugging is set during these operations.

The mechanism only applies to the SH-shell family.

Closes #121
2017-11-14 09:55:45 +01:00
Xavier Delaruelle
d918ee6d86 install: add --with-quarantine-vars
Add --with-quarantine-vars configure option to define quarantine
mechanism configuration at build time.

Value passed to the configure option will be used by Makefile to
initialize in the various initialization scripts the
MODULES_RUN_QUARANTINE variable and eventual MODULES_RUNENV_<VAR>.
2017-11-12 16:56:40 +01:00
Xavier Delaruelle
7a36a422f3 Handle IFS in a sh-compatible way
On sh shell like dash, IFS cannot be local var. Also when setting IFS
with the "IFS=$' ';" syntax $ character is also added to the IFS value.
2017-11-11 17:04:17 +01:00
Xavier Delaruelle
8d5f8fe6cc Ensure correct IFS on sh-kind script or func
With quarantine mechanism sh-kind init scripts or module function are
sensitive to IFS value. If space character is not part of IFS, eval
command will not be able to understand command-line string.

This commit add code in init scripts and module function to guaranty
correct value for IFS.
2017-11-11 16:30:30 +01:00
Xavier Delaruelle
b3fcd93b24 Improve variable name check in MODULES_RUN_QUARANTINE
A variable name cannot start with a [0-9] character.
2017-11-11 16:30:30 +01:00
Xavier Delaruelle
7a2906233c Validate variable names set in MODULES_RUN_QUARANTINE
Test that the names of the environment variable defined in
MODULES_RUN_QUARANTINE are valid names.

Add test in quarantine setup code within init scripts (silent check) and
also test in modulecmd.tcl. The latter reports a warning if a bad name
is detected.

Add a non-regression test in modules.00-init and install.00-init test
suites.
2017-11-11 16:30:30 +01:00
Xavier Delaruelle
cd1786ab3f init: setup quarantine before autoinit for SH shells
As now a call to modulecmd.tcl defines the module function and
surrounding initial environment, this execution should also be shield
against bad environment with quarantine mechanism.
2017-11-11 16:30:22 +01:00
Xavier Delaruelle
519d08e98d init: shell scripts now rely on autoinit command
Make use of autoinit module command to initialize module command and its
initial surrounding environment (default value for MODULESHOME,
MODULEPATH, LOADEDMODULES and parse of init/.modulespath).

Then if compatibility version is currently activated redefined the
module command to point to the compat binary. But the compat version
will benefit from the surrounding environment initialization made by
autoinit.

With this change, activated compatibility version will also get its
environment initialized by the init/modulerc file whereas before this
change only the main version was affected by this setup file.
2017-10-23 22:35:27 +02:00
Xavier Delaruelle
f6f76143f7 init: redirect stderr msg on stdout if terminal
Change from previous behavior where redirection were set if shell was
interactive. With this change, a 'sh script' command launched from a
terminal session will setup module stderr redirection whereas previously
it was not the case as script was not ran in interactive mode.

Shell interactive mode is useful to know that interaction will occur on
stdin (interesting for completion setup). Knowing session is attached to
a terminal seems to be the good pivot to adapt stdout or stderr
functioning (help to determine if PAGER mode can be enabled or not on
'git')
2017-10-17 22:35:04 +02:00
Xavier Delaruelle
5c7314c059 init: rename use compat var in MODULES_USE_COMPAT_VERSION
Use a distinguishable prefix for environment variables relative to the
Modules software: 'MODULES_'.
2017-09-22 21:32:37 +02:00
Xavier Delaruelle
fc5674846c init: adapt scripts to --enable-compat-version build
Introduce MODULE_USE_COMPAT_VERSION environment variable to control the
activation of the compatibility version rather main version in case of
--enable-compat-version installation.

The initialization script of the shells supporting compatibility version
are adapted to define the 'module' command based on the modulecmd-compat
binary if MODULE_USE_COMPAT_VERSION is set to 1. Elsewhere module is
based on modulecmd.tcl.

'switchml' function of alias is reintroduced to switch between main and
compatibility version based on the state of the
MODULE_USE_COMPAT_VERSION environment variable.

Acknowledgment: this development has been made and funded within the
framework of the PRACE Fifth Implementation Phase (PRACE-5IP) project
(http://www.prace-ri.eu/). PRACE-5IP receives funding from the EU's
Horizon 2020 research and innovation programme (2014-2020) under grant
agreement no. 730913.
2017-09-13 06:30:19 +02:00
Xavier Delaruelle
d6b87dfe26 install: remove features linking to external C version
Remove the --enable-set-switchml, --enable-use-cver-dotmodulespath,
--with-cver-initdir, --with-cver-bindir and --with-cver-mandir configure
option that previously enabled to link Modules-Tcl installation to an
external Modules-C installation.

This change is an initial step toward a bundled installation of Tcl/C
versions, so the external linking support will transform into a dual
flavor installation.
2017-09-06 07:28:37 +02:00
Xavier Delaruelle
4c7dd94360 init: module source @initdir@/modulerc rather shell source
Like for other lang init scripts.
2017-09-05 06:04:53 +02:00
Bert Wesarg
39d7b0126b init: Do not pollute tab-completion with moduleraw command. 2017-06-25 07:20:14 +02:00
Xavier Delaruelle
5fff7e67f3 install: fix reset of regular path in switchml
Avoid resetting regular path (/usr/bin) or manpath (/usr/share/man) when
switching from Tcl to C version in switchml utility.
2017-03-14 21:55:53 +01:00
Xavier Delaruelle
63f5918d4c init: do not load modulerc config is env already set
If MODULEPATH or LOADEDMODULES is already set, do not source the
modulerc configuration file in init scripts.

As a consequence, if .modulespath sets a module path, then modulerc will
be ignored which clarifies how default configuration is loaded: if both
.modulespath and modulerc are defined, .modulespath takes precedence
over modulerc.

So if .modulespath sets a module path, all loaded modules defined in the
modulerc file will be ignored.
2017-03-06 06:09:15 +01:00
Xavier Delaruelle
3293765e2e init: define switchml tool in shell init scripts
Introduce 'switchml' tool, a shell function (or alias for csh or tcsh
shells) that swap currently enabled Modules version (C or Tcl) by the
other version (C or Tcl).

In case a swapped version was defining specific PATH or MANPATH entries,
these specific entries are removed when switching to the other version
to avoid still relying on the binaries and man pages of the swapped-out
version.
2017-03-06 06:09:15 +01:00
Xavier Delaruelle
95984d243f init: set PATH and MANPATH in shell init scripts
Add the possibility to set PATH and MANPATH in shell init scripts
(sh-like, csh-like and fish scripts) if specific option are enabled in
makefile (enabled by default). With this, bin directory and man
directory of the modules-tcl installation are prepended to the MANPATH
and PATH environment variables.

Prepending is required for PATH as manpath utility in its default Linux
setup will automatically set MANPATH from PATH change, so if we want
MANPATH to be prepended, PATH has to be prepended.
2017-03-06 06:09:08 +01:00
Xavier Delaruelle
99668416d8 Introduce an installation process
Introduce an 'install' target in makefiles to provide an installation
process for modules-tcl.

Defines installation paths with Makefile variables in order to avoid
having a ./configure step. Install paths are set during the 'make' step
by passing 'prefix', 'libexecdir', 'mandir', etc arguments to the make
command. If no path definitions are passed to the 'make' command,
installation will be made in '/usr/local/modules-tcl' by default.

Installation paths provided (or set from the default value found in
Makefile) are saved at the 'make' step in a .makeinstallpath file. Then
at the 'make install' step, this .makeinstallpath file is read and make
knows where to install modules-tcl.

These paths definitions are also used to translate *.in init script to
their installed version.

modulecmd.tcl script is by default set to be installed in the libexec
directory to follow FHS specification (as this script is an executable
but not directly accessed by users).
2017-03-06 05:32:37 +01:00
Xavier Delaruelle
b8dd781a8d init: ensure module definition in sh-like sub-shells
Adapt shell init scripts (sh-like, csh-like and fish) to get module
defined in sh-like sub-shells. The method to define the module function
in interactive or non-interactive sh-like sub-shells vary according to
the shell flavor.

The below table is an attempt to summarize the method to use to get
'module' function defined in sub-shell depending of the SH-shell kind
and if the sub-shell is in interactive mode or not.

                                  +-----+----------+-----------+-------+
                                  | ENV | BASH_ENV | export -f | FPATH |
+-------------+-------------------+-----+----------+-----------+-------+
|             |inter sub-shell    |     |          |     X     |       |
|BASH         +-------------------+-----+----------+-----------+-------+
|             |non-inter sub-shell|     |    X     |     X     |       |
+-------------+-------------------+-----+----------+-----------+-------+
|             |inter sub-shell    |  X  |          |     X     |       |
|SH           +-------------------+-----+----------+-----------+-------+
|(BASH-compat)|non-inter sub-shell|     |          |     X     |       |
+-------------+-------------------+-----+----------+-----------+-------+
|             |inter sub-shell    |  X  |          |           |   X(*)|
|SH           +-------------------+-----+----------+-----------+-------+
|(ZSH-compat) |non-inter sub-shell|  X  |          |           |   X(*)|
+-------------+-------------------+-----+----------+-----------+-------+
|             |inter sub-shell    |  X  |          |           |   X   |
|KSH          +-------------------+-----+----------+-----------+-------+
|             |non-inter sub-shell|     |          |           |   X   |
+-------------+-------------------+-----+----------+-----------+-------+
|             |inter sub-shell    |  X  |          |           |   X(*)|
|KSH          +-------------------+-----+----------+-----------+-------+
|(ZSH-compat) |non-inter sub-shell|  X  |          |           |   X(*)|
+-------------+-------------------+-----+----------+-----------+-------+
|             |inter sub-shell    |     |          |           |   X(*)|
|ZSH          +-------------------+-----+----------+-----------+-------+
|             |non-inter sub-shell|     |          |           |   X(*)|
+-------------+-------------------+-----+----------+-----------+-------+
                                                   (*) autoload required

Shell init scripts have been adapted to implement these different method
to cover most of the initialization cases.

Note that 'zsh' requires to declare with autoload the functions put in
FPATH directory so there is no gain to configure FPATH for 'zsh' compare
to a bare source of the 'zsh' init script.
2017-03-06 05:32:01 +01:00
Xavier Delaruelle
3a1847d0a4 init: set MODULEPATH if not defined
Initialize MODULEPATH variable if not defined, with an empty string or
with the content of the init/.modulespath file if it exists and it is
readable. This file contains a list of module paths, one per line or
many per line separated by colon character.

This way of initializing MODULEPATH has been retrieved from C version
init scripts in order for sysadmins to keep a familiar concept to set
default MODULEPATH.
2017-03-06 05:32:01 +01:00
Xavier Delaruelle
1a4c236302 init: set empty LOADEDMODULES if not defined 2017-03-06 05:32:01 +01:00
Xavier Delaruelle
483a14d787 init: introduce SHELLNAME var to replace in script
With SHELLNAME replacement variable, tcsh init script is derivated from
csh init script.
2017-03-06 05:31:50 +01:00
Xavier Delaruelle
8f32d8485f init: do not source init/modulerc if not readable 2017-03-05 09:21:59 +01:00
Xavier Delaruelle
14575a3497 init: get and set TCLSH in init scripts
As for MODULESHOME, get 'tclsh' location from Makefile then replace
'@TCLSH@' pattern in shell init scripts with found location rather than
guessing it in the init scripts.

By doing so, same 'tclsh' location search is applied to all init
scripts. Search is performed with 'command' to look at a predefined list
of PATHs in order to be resilient to the current PATH content.
2017-03-05 09:21:59 +01:00