| 1 |
#!/bin/fish |
| 2 |
# |
| 3 |
# INSTALL_TEST_SH, fish test launcher for install non-reg suite |
| 4 |
# Copyright (C) 2017-2021 Xavier Delaruelle |
| 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 |
set progpath (status -f): |
| 22 |
set progdir (dirname $progpath) |
| 23 |
if [ -z "$progdir" ] |
| 24 |
set progdir '.' |
| 25 |
end |
| 26 |
set ret 0 |
| 27 |
|
| 28 |
# print message on stderr then exit |
| 29 |
function echo_error |
| 30 |
echo "ERROR: $argv[1]" >&2 |
| 31 |
exit 1 |
| 32 |
end |
| 33 |
|
| 34 |
if [ (count $argv) -lt 4 ] |
| 35 |
# print usage message |
| 36 |
echo_error "Usage: $progpath initfile mode shell command" |
| 37 |
end |
| 38 |
|
| 39 |
set initfile $argv[1] |
| 40 |
set mode $argv[2] |
| 41 |
set sh $argv[3] |
| 42 |
set cmdlist $argv[4..-1] |
| 43 |
|
| 44 |
# get shell kind and options for sublaunch |
| 45 |
set shname (basename $sh) |
| 46 |
switch $shname |
| 47 |
case bash ksh ksh93 zsh |
| 48 |
set shkind 'sh' |
| 49 |
case tcsh |
| 50 |
set shkind 'csh' |
| 51 |
case '*' |
| 52 |
set shkind $shname |
| 53 |
end |
| 54 |
switch $shkind |
| 55 |
# ignore global csh system init file to avoid side effect |
| 56 |
case csh |
| 57 |
set shopts '-f' |
| 58 |
case '*' |
| 59 |
set shopts '' |
| 60 |
end |
| 61 |
|
| 62 |
# init module via autoinit cmd if modulecmd.tcl is initfile |
| 63 |
if [ (basename $initfile) = 'modulecmd.tcl' ] |
| 64 |
set autoinit 0 |
| 65 |
else |
| 66 |
set autoinit 1 |
| 67 |
end |
| 68 |
|
| 69 |
if [ $autoinit -eq 0 -a ! -x $initfile ] |
| 70 |
echo_error "Cannot execute $initfile" |
| 71 |
else if [ $autoinit -ne 0 -a ! -r $initfile ] |
| 72 |
echo_error "Cannot read $initfile" |
| 73 |
end |
| 74 |
|
| 75 |
# source module init file if first step of given mode |
| 76 |
if [ "$mode" = 'top' -o "$mode" = 'sub' -o "$mode" = 'subsub' ] |
| 77 |
if [ $autoinit -eq 0 ] |
| 78 |
eval \"$initfile\" $shname autoinit | source - |
| 79 |
else |
| 80 |
source $initfile |
| 81 |
end |
| 82 |
end |
| 83 |
|
| 84 |
# execute command list or perform recursive call |
| 85 |
switch $mode |
| 86 |
case top launch |
| 87 |
for cmd in (echo "$cmdlist" | tr ';' '\n') |
| 88 |
eval $cmd |
| 89 |
set ret (math $ret+$status) |
| 90 |
end |
| 91 |
case sub sublaunch |
| 92 |
eval $sh $shopts $progdir/install_test_$shkind \"$initfile\" launch $sh \ |
| 93 |
"(echo '$cmdlist' | sed 's|;|\\;|')"; |
| 94 |
set ret $status; |
| 95 |
case subsub |
| 96 |
eval $sh $shopts $progdir/install_test_$shkind \"$initfile\" sublaunch $sh \ |
| 97 |
"(echo '$cmdlist' | sed 's|;|\\;|')"; |
| 98 |
set ret $status; |
| 99 |
case '*' |
| 100 |
echo_error "Unrecognized mode option. Valid mode are 'top', 'sub', 'subsub'" |
| 101 |
end |
| 102 |
|
| 103 |
# throw command exit code |
| 104 |
exit $ret |
| 105 |
|
| 106 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: |