| 1 |
#!/usr/bin/env pwsh |
| 2 |
# |
| 3 |
# INSTALL_TEST_PWSH, pwsh test script for install non-reg suite |
| 4 |
# Copyright (C) 2024 Simon Lukas Märtens |
| 5 |
# |
| 6 |
# This program is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 2 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
########################################################################## |
| 20 |
|
| 21 |
param ( |
| 22 |
[Parameter(Mandatory)] [string]$initfile, |
| 23 |
[Parameter(ValueFromRemainingArguments)] [string[]] $cmdlist |
| 24 |
) |
| 25 |
|
| 26 |
if (-not (Test-Path $initfile)) { |
| 27 |
Write-Error "Cannot read $initfile" |
| 28 |
exit 1 |
| 29 |
} |
| 30 |
|
| 31 |
# suppress ANSI escape sequences (the errors are rendered in red by default) |
| 32 |
$env:__SuppressAnsiEscapeSequences = $true |
| 33 |
|
| 34 |
# source module init file |
| 35 |
. $initfile |
| 36 |
|
| 37 |
# execute command list |
| 38 |
$code = 0 |
| 39 |
$runml = 0 |
| 40 |
$ret = $null |
| 41 |
foreach ($cmdargs in $cmdlist.Split(':')) { |
| 42 |
$cmd_is_query = "$cmdargs" -match '(is-loaded|is-avail|is-used|is-saved)' |
| 43 |
|
| 44 |
# call ml procedure instead of module |
| 45 |
if ($cmdargs -eq 'ml') { |
| 46 |
$runml = 1 |
| 47 |
$ret = $null |
| 48 |
} else { |
| 49 |
$cmd_to_execute = "" |
| 50 |
if ($runml -eq 0) { |
| 51 |
$cmd_to_execute += "envmodule" |
| 52 |
} else { |
| 53 |
$cmd_to_execute += "ml" |
| 54 |
} |
| 55 |
|
| 56 |
# if command equals to NOARG string, means call with no arg passed |
| 57 |
if ($cmdargs -ne 'NOARG') { |
| 58 |
$cmd_to_execute += ' ' + ($cmdargs.Split(',') | ForEach-Object { |
| 59 |
if ($_ -match '[-\s\.$''"]' -or $_ -eq '') { |
| 60 |
if ($_ -match "[']") { |
| 61 |
'"' + $_ + '"' |
| 62 |
} else { |
| 63 |
"'" + $_ + "'" |
| 64 |
} |
| 65 |
} else { |
| 66 |
$_ |
| 67 |
} |
| 68 |
}) -join ' ' |
| 69 |
} |
| 70 |
|
| 71 |
$ret = Invoke-Expression $cmd_to_execute |
| 72 |
|
| 73 |
if ($cmd_is_query) { |
| 74 |
$code = [int]!$ret |
| 75 |
} elseif ($LastExitCode -ne 0) { |
| 76 |
$code = $LastExitCode |
| 77 |
} |
| 78 |
} |
| 79 |
if ($null -ne $ret -and !$cmd_is_query) { |
| 80 |
Write-Output $ret |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
Remove-Item -Path "env:__SuppressAnsiEscapeSequences" |
| 85 |
|
| 86 |
exit $code |
| 87 |
|
| 88 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: |